1 25 26 package org.snipsnap.render.macro; 27 28 import org.radeox.util.Service; 29 import org.radeox.util.logging.Logger; 30 import org.snipsnap.render.macro.parameter.SnipMacroParameter; 31 import org.snipsnap.render.macro.list.ListFormatter; 32 import org.snipsnap.render.macro.list.SimpleList; 33 import org.snipsnap.render.macro.list.Linkable; 34 35 import java.io.IOException ; 36 import java.io.Writer ; 37 import java.util.Collection ; 38 import java.util.HashMap ; 39 import java.util.Iterator ; 40 import java.util.Map ; 41 42 48 49 public abstract class ListOutputMacro extends SnipMacro { 50 51 private static Map formatterMap = new HashMap (); 52 53 static { 54 55 Iterator macroIt = Service.providers(ListFormatter.class); 56 while (macroIt.hasNext()) { 57 try { 58 ListFormatter formatter = (ListFormatter) macroIt.next(); 59 formatterMap.put(formatter.getName().toLowerCase(), formatter); 60 Logger.debug("Loaded list formatter: " + formatter.getName()); 61 } catch (Exception e) { 62 Logger.warn("ListOutputMacro: unable to load list formatter", e); 63 } 64 } 65 66 } 67 68 private final static ListFormatter defaultFormatter = new SimpleList(); 69 70 public void output(Writer writer, Linkable root, String listComment, Collection c, String emptyText, String style, boolean showSize) throws IOException { 71 ListFormatter formatter = (ListFormatter) ListOutputMacro.formatterMap.get(style != null ? style.toLowerCase() : null); 72 73 if (formatter != null) { 74 formatter.format(writer, root, listComment, c, emptyText, showSize); 75 } else { 76 ListOutputMacro.defaultFormatter.format(writer, root, listComment, c, emptyText, showSize); 77 } 78 } 79 80 81 public abstract void execute(Writer writer, SnipMacroParameter params) throws IllegalArgumentException , IOException ; 82 } 83 84 | Popular Tags |