KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > util > RendererFactory


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.util;
10
11 import java.io.Writer JavaDoc;
12 import java.util.HashMap JavaDoc;
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 /**
21  * @author <a HREF="theute@jboss.org">Thomas Heute </a> $Revision: 1.1 $
22  */

23 public class RendererFactory
24 {
25    public static final ThreadLocal JavaDoc renderers = new ThreadLocal JavaDoc()
26    {
27       protected Object JavaDoc initialValue()
28       {
29          return new HashMap JavaDoc();
30       }
31    };
32
33    public static final String JavaDoc BBCODEHTML2HTML = "BBCODEHTML2HTML";
34
35    public static final String JavaDoc BBCODEHTML2TEXT = "BBCODEHTML2TEXT";
36
37    private static final String JavaDoc TEMPLATE_LOCATION = "org/jboss/portal/format/template";
38
39    public static AbstractRenderer get(String JavaDoc key, Writer JavaDoc out)
40    {
41       HashMap JavaDoc map = (HashMap JavaDoc) renderers.get();
42       AbstractRenderer renderer = (AbstractRenderer) map.get(key);
43       if (renderer == null)
44       {
45          if (BBCODEHTML2HTML.equals(key))
46          {
47             // Load the template
48
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