KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > format > render > bbcodehtml > ToHTMLConfig


1 package org.jboss.portal.format.render.bbcodehtml;
2
3 import java.util.HashSet JavaDoc;
4 import java.util.Set JavaDoc;
5
6 import org.apache.log4j.Logger;
7 import org.jboss.portal.format.template.BuildException;
8 import org.jboss.portal.format.template.Template;
9 import org.jboss.portal.format.template.TemplateLoader;
10 import org.jboss.portal.format.template.TemplateRepository;
11 import org.jboss.portal.format.util.CLLoader;
12 import org.jboss.portal.format.util.Loader;
13
14 /**
15  */

16 public class ToHTMLConfig
17 {
18
19    /**
20     * Template name constants.
21     */

22
23    public static final String JavaDoc TPL_THEME_CODE_B_CLOSE = "b_close";
24    public static final String JavaDoc TPL_THEME_CODE_B_OPEN = "b_open";
25    public static final String JavaDoc TPL_THEME_CODE_CODE_CLOSE = "code_close";
26    public static final String JavaDoc TPL_THEME_CODE_CODE_OPEN = "code_open";
27    public static final String JavaDoc TPL_THEME_CODE_COLOR_CLOSE = "color_close";
28    public static final String JavaDoc TPL_THEME_CODE_COLOR_OPEN = "color_open";
29    public static final String JavaDoc TPL_THEME_CODE_EMAIL = "email";
30    public static final String JavaDoc TPL_THEME_CODE_I_CLOSE = "i_close";
31    public static final String JavaDoc TPL_THEME_CODE_I_OPEN = "i_open";
32    public static final String JavaDoc TPL_THEME_CODE_IMG = "img";
33    public static final String JavaDoc TPL_THEME_CODE_LISTITEM = "listitem";
34    public static final String JavaDoc TPL_THEME_CODE_OLIST_CLOSE = "olist_close";
35    public static final String JavaDoc TPL_THEME_CODE_OLIST_OPEN = "olist_open";
36    public static final String JavaDoc TPL_THEME_CODE_QUOTE_CLOSE = "quote_close";
37    public static final String JavaDoc TPL_THEME_CODE_QUOTE_OPEN = "quote_open";
38    public static final String JavaDoc TPL_THEME_CODE_QUOTE_USERNAME_OPEN = "quote_username_open";
39    public static final String JavaDoc TPL_THEME_CODE_SIZE_CLOSE = "size_close";
40    public static final String JavaDoc TPL_THEME_CODE_SIZE_OPEN = "size_open";
41    public static final String JavaDoc TPL_THEME_CODE_U_CLOSE = "u_close";
42    public static final String JavaDoc TPL_THEME_CODE_U_OPEN = "u_open";
43    public static final String JavaDoc TPL_THEME_CODE_ULIST_CLOSE = "ulist_close";
44    public static final String JavaDoc TPL_THEME_CODE_ULIST_OPEN = "ulist_open";
45    public static final String JavaDoc TPL_THEME_CODE_URL = "url";
46
47    public static final int FILTER_MODE_ALWAYS_PRINT = 0;
48    public static final int FILTER_MODE_NEVER_PRINT = 1;
49    public static final int FILTER_MODE_PRINT_IF_NOT_IN_TAGS = 2;
50    public static final int FILTER_MODE_PRINT_IF_IN_TAGS = 3;
51
52    public static final int OUTPUT_MODE_REMOVE = 0;
53    public static final int OUTPUT_MODE_DISPLAY = 1;
54
55    private static final Loader loader = new CLLoader(ToHTMLRenderer.class.getClassLoader(), "");
56    private static final TemplateRepository defaultRepository = createRepository(loader);
57
58    Template r_ulist_open;
59    Template r_ulist_close;
60    Template r_olist_open;
61    Template r_olist_close;
62    Template r_listitem;
63    Template r_quote_open;
64    Template r_quote_close;
65    Template r_quote_username_open;
66    Template r_code_open;
67    Template r_code_close;
68    Template r_b_open;
69    Template r_b_close;
70    Template r_u_open;
71    Template r_u_close;
72    Template r_i_open;
73    Template r_i_close;
74    Template r_color_open;
75    Template r_color_close;
76    Template r_size_open;
77    Template r_size_close;
78    Template r_img;
79    Template r_url;
80    Template r_email;
81
82    private Set JavaDoc tags = new HashSet JavaDoc();
83    private int filterMode = FILTER_MODE_ALWAYS_PRINT;
84    private int ouputMode = OUTPUT_MODE_REMOVE;
85    private int maxTextWidth = 100;
86
87    public ToHTMLConfig()
88    {
89       setRepository(defaultRepository);
90    }
91
92    public void setLoader(Loader loader)
93    {
94       TemplateRepository repository = createRepository(loader);
95       setRepository(repository);
96    }
97
98    public int getMaxTextWidth()
99    {
100       return maxTextWidth;
101    }
102
103    public void setMaxTextWidth(int maxTextWidth)
104    {
105       this.maxTextWidth = maxTextWidth;
106    }
107
108    public void setTags(Set JavaDoc tags)
109     {
110        this.tags = tags;
111     }
112
113     public Set JavaDoc getTags()
114     {
115        return tags;
116     }
117
118     public int getFilterMode()
119     {
120        return filterMode;
121     }
122
123     public void setFilterMode(int filterMode)
124     {
125        this.filterMode = filterMode;
126     }
127
128    public int getOuputMode()
129    {
130       return ouputMode;
131    }
132
133    public void setOuputMode(int ouputMode)
134    {
135       this.ouputMode = ouputMode;
136    }
137
138    public boolean print(String JavaDoc tag)
139    {
140       switch (filterMode)
141       {
142       case FILTER_MODE_NEVER_PRINT:
143          return false;
144       case FILTER_MODE_PRINT_IF_NOT_IN_TAGS:
145          return !tags.contains(tag);
146       case FILTER_MODE_PRINT_IF_IN_TAGS:
147          return tags.contains(tag);
148       case FILTER_MODE_ALWAYS_PRINT:
149          return true;
150       }
151       return false;
152    }
153
154    private void setRepository(TemplateRepository repository)
155    {
156       r_ulist_open = repository.createTemplate(TPL_THEME_CODE_ULIST_OPEN);
157       r_ulist_close = repository.createTemplate(TPL_THEME_CODE_ULIST_CLOSE);
158       r_olist_open = repository.createTemplate(TPL_THEME_CODE_OLIST_OPEN);
159       r_olist_close = repository.createTemplate(TPL_THEME_CODE_OLIST_CLOSE);
160       r_listitem = repository.createTemplate(TPL_THEME_CODE_LISTITEM);
161       r_quote_open = repository.createTemplate(TPL_THEME_CODE_QUOTE_OPEN);
162       r_quote_close = repository.createTemplate(TPL_THEME_CODE_QUOTE_CLOSE);
163       r_quote_username_open = repository.createTemplate(TPL_THEME_CODE_QUOTE_USERNAME_OPEN);
164       r_code_open = repository.createTemplate(TPL_THEME_CODE_CODE_OPEN);
165       r_code_close = repository.createTemplate(TPL_THEME_CODE_CODE_CLOSE);
166       r_b_open = repository.createTemplate(TPL_THEME_CODE_B_OPEN);
167       r_b_close = repository.createTemplate(TPL_THEME_CODE_B_CLOSE);
168       r_u_open = repository.createTemplate(TPL_THEME_CODE_U_OPEN);
169       r_u_close = repository.createTemplate(TPL_THEME_CODE_U_CLOSE);
170       r_i_open = repository.createTemplate(TPL_THEME_CODE_I_OPEN);
171       r_i_close = repository.createTemplate(TPL_THEME_CODE_I_CLOSE);
172       r_color_open = repository.createTemplate(TPL_THEME_CODE_COLOR_OPEN);
173       r_color_close = repository.createTemplate(TPL_THEME_CODE_COLOR_CLOSE);
174       r_size_open = repository.createTemplate(TPL_THEME_CODE_SIZE_OPEN);
175       r_size_close = repository.createTemplate(TPL_THEME_CODE_SIZE_CLOSE);
176       r_img = repository.createTemplate(TPL_THEME_CODE_IMG);
177       r_url = repository.createTemplate(TPL_THEME_CODE_URL);
178       r_email = repository.createTemplate(TPL_THEME_CODE_EMAIL);
179    }
180
181    private static void loadTemplate(TemplateLoader repository, String JavaDoc name)
182    {
183       try
184       {
185          repository.addTemplate(name, "/" + name + ".tpl");
186       }
187       catch (BuildException e)
188       {
189          Logger.getLogger(ToHTMLRenderer.class).error("Cannot load template : " + name, e);
190       }
191    }
192
193    private static TemplateLoader createRepository(Loader loader)
194    {
195       TemplateLoader repository = new TemplateLoader(loader);
196       loadTemplate(repository, TPL_THEME_CODE_ULIST_OPEN);
197       loadTemplate(repository, TPL_THEME_CODE_ULIST_CLOSE);
198       loadTemplate(repository, TPL_THEME_CODE_OLIST_OPEN);
199       loadTemplate(repository, TPL_THEME_CODE_OLIST_CLOSE);
200       loadTemplate(repository, TPL_THEME_CODE_LISTITEM);
201       loadTemplate(repository, TPL_THEME_CODE_QUOTE_OPEN);
202       loadTemplate(repository, TPL_THEME_CODE_QUOTE_CLOSE);
203       loadTemplate(repository, TPL_THEME_CODE_QUOTE_USERNAME_OPEN);
204       loadTemplate(repository, TPL_THEME_CODE_CODE_OPEN);
205       loadTemplate(repository, TPL_THEME_CODE_CODE_CLOSE);
206       loadTemplate(repository, TPL_THEME_CODE_B_OPEN);
207       loadTemplate(repository, TPL_THEME_CODE_B_CLOSE);
208       loadTemplate(repository, TPL_THEME_CODE_U_OPEN);
209       loadTemplate(repository, TPL_THEME_CODE_U_CLOSE);
210       loadTemplate(repository, TPL_THEME_CODE_I_OPEN);
211       loadTemplate(repository, TPL_THEME_CODE_I_CLOSE);
212       loadTemplate(repository, TPL_THEME_CODE_COLOR_OPEN);
213       loadTemplate(repository, TPL_THEME_CODE_COLOR_CLOSE);
214       loadTemplate(repository, TPL_THEME_CODE_SIZE_OPEN);
215       loadTemplate(repository, TPL_THEME_CODE_SIZE_CLOSE);
216       loadTemplate(repository, TPL_THEME_CODE_IMG);
217       loadTemplate(repository, TPL_THEME_CODE_URL);
218       loadTemplate(repository, TPL_THEME_CODE_EMAIL);
219       return repository;
220    }
221 }
222
Popular Tags