01: /*
02: * Created on Feb 9, 2005
03: *
04: */
05: package com.sun.portal.wireless.htmlconversion;
06:
07: import java.util.HashMap;
08:
09: import com.sun.portal.wireless.htmlconversion.processors.*;
10:
11: /**
12: * Singleton class holding a registry mapping TagProcessor implementations to the
13: * corresponding HTML tag.
14: *
15: * @author ashwin.mathew@sun.com
16: */
17: public class TagProcessorRegistry {
18:
19: private static TagProcessorRegistry instance = new TagProcessorRegistry();
20:
21: private HashMap processorMap = new HashMap();
22:
23: /**
24: * Private constructor for singleton, used to register all TagProcessor
25: * implementations.
26: */
27: private TagProcessorRegistry() {
28: registerTagProcessor(new AmlTextTagProcessor());
29: registerTagProcessor(new AmlDocumentTitleTagProcessor());
30: registerTagProcessor(new AmlBrTagProcessor());
31: registerTagProcessor(new AmlListTagProcessor());
32: registerTagProcessor(new AmlOrderedListTagProcessor());
33: registerTagProcessor(new AmlListItemTagProcessor());
34: registerTagProcessor(new AmlDocumentTagProcessor());
35: registerTagProcessor(new AmlPageTagProcessor());
36: registerTagProcessor(new AmlLinkTagProcessor());
37: registerTagProcessor(new AmlFormTagProcessor());
38: registerTagProcessor(new HtmlInputTagProcessor());
39: registerTagProcessor(new AmlInputTagProcessor());
40: registerTagProcessor(new AmlFormSubmitTagProcessor());
41: registerTagProcessor(new AmlFormResetTagProcessor());
42: registerTagProcessor(new AmlCheckBoxTagProcessor());
43: registerTagProcessor(new AmlChoiceTagProcessor());
44: registerTagProcessor(new AmlOptionTagProcessor());
45: registerTagProcessor(new HtmlRadioTagProcessor());
46: registerTagProcessor(new AmlTextAreaTagProcessor());
47: registerTagProcessor(new HtmlButtonTagProcessor());
48: registerTagProcessor(new AmlTableTagProcessor());
49: registerTagProcessor(new AmlTableRowTagProcessor());
50: registerTagProcessor(new AmlTableColTagProcessor());
51: registerTagProcessor(new HtmlIgnoreTagProcessor());
52: registerTagProcessor(new AmlImageTagProcessor());
53: registerTagProcessor(new HtmlBaseTagProcessor());
54: }
55:
56: public static TagProcessorRegistry getInstance() {
57: return instance;
58: }
59:
60: /**
61: * Returns the processor for the named tag - it's assumed that all tag names
62: * are lower case.
63: * @param tag
64: * @return
65: */
66: public TagProcessor getProcessor(String tag) {
67: return (TagProcessor) processorMap.get(tag);
68: }
69:
70: /**
71: * Registers a tag processor, mapping it to all the tags in it's
72: * supported tags list.
73: * @param processor
74: */
75: public void registerTagProcessor(TagProcessor processor) {
76: // First add all the HTML tags
77: String[] supportedTags = processor.getSupportedTags();
78:
79: for (int i = 0; i < supportedTags.length; i++) {
80: processorMap.put(supportedTags[i], processor);
81: }
82:
83: // Also add the AML tag name
84: String amlTag = processor.getAmlTag();
85: if (amlTag != null) {
86: processorMap.put(amlTag, processor);
87: }
88: }
89:
90: }
|