1 25 package org.snipsnap.render.macro.list; 26 27 import java.io.IOException ; 28 import java.io.Writer ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 32 38 public class ExampleListFormatter implements ListFormatter { 39 public String getName() { 40 return "number"; 41 } 42 43 46 public void format(Writer writer, Linkable current, String listComment, Collection c, String emptyText, boolean showSize) 47 throws IOException { 48 writer.write("<div class=\"list\"><div class=\"list-title\">"); 49 writer.write(listComment); 50 if (showSize) { 51 writer.write(" ("); 52 writer.write("" + c.size()); 53 writer.write(")"); 54 } 55 writer.write("</div>"); 56 if (c.size() > 0) { 57 writer.write("<ol>"); 58 Iterator nameIterator = c.iterator(); 59 while (nameIterator.hasNext()) { 60 writer.write("<li>"); 61 Object object = nameIterator.next(); 62 if (object instanceof Linkable) { 63 writer.write(((Linkable) object).getLink()); 64 } else if (object instanceof Nameable) { 65 writer.write(((Nameable) object).getName()); 66 } else { 67 writer.write(object.toString()); 68 } 69 writer.write("</li>"); 70 } 71 writer.write("</ol>"); 72 } else { 73 writer.write(emptyText); 74 } 75 writer.write("</div>"); 76 } 77 } 78 | Popular Tags |