1 9 package org.jboss.portal.core.util; 10 11 import java.io.Writer ; 12 import java.util.HashMap ; 13 14 import org.jboss.portal.format.render.AbstractRenderer; 15 import org.jboss.portal.format.render.bbcodehtml.ToHTMLConfig; 16 import org.jboss.portal.format.render.bbcodehtml.ToHTMLRenderer; 17 import org.jboss.portal.format.render.bbcodehtml.ToTextRenderer; 18 import org.jboss.portal.format.util.CLLoader; 19 20 23 public class RendererFactory 24 { 25 public static final ThreadLocal renderers = new ThreadLocal () 26 { 27 protected Object initialValue() 28 { 29 return new HashMap (); 30 } 31 }; 32 33 public static final String BBCODEHTML2HTML = "BBCODEHTML2HTML"; 34 35 public static final String BBCODEHTML2TEXT = "BBCODEHTML2TEXT"; 36 37 private static final String TEMPLATE_LOCATION = "org/jboss/portal/format/template"; 38 39 public static AbstractRenderer get(String key, Writer out) 40 { 41 HashMap map = (HashMap ) renderers.get(); 42 AbstractRenderer renderer = (AbstractRenderer) map.get(key); 43 if (renderer == null) 44 { 45 if (BBCODEHTML2HTML.equals(key)) 46 { 47 ToHTMLConfig config = new ToHTMLConfig(); 49 config.setLoader(new CLLoader(TEMPLATE_LOCATION)); 50 renderer = new ToHTMLRenderer(config); 51 map.put(BBCODEHTML2HTML, renderer); 52 } 53 else if (BBCODEHTML2TEXT.equals(key)) 54 { 55 renderer = new ToTextRenderer(); 56 map.put(BBCODEHTML2TEXT, renderer); 57 } 58 } 59 renderer.setWriter(out); 60 return renderer; 61 } 62 } 63 | Popular Tags |