KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > displayer > DisplayerConfig


1 package net.sourceforge.formview.displayer;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import net.sourceforge.formview.FieldView;
8
9 import org.apache.commons.collections.FastHashMap;
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 import au.id.jericho.lib.html.AttributesOutputSegment;
14 import au.id.jericho.lib.html.Element;
15 import au.id.jericho.lib.html.OutputDocument;
16 import au.id.jericho.lib.html.StringOutputSegment;
17
18 /**
19  * Description : Displayers Config.
20  *
21  * @version 1.0.0
22  * @author <a HREF="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
23  *
24  */

25 public class DisplayerConfig implements IHTMLDisplayer {
26     
27     private static final long serialVersionUID = 1L;
28     
29     protected static Log log = LogFactory.getLog(DisplayersConfigResources.class);
30
31     /**
32      * <code>FastHashMap</code> of <code>Propertis</code> stored under
33      * a <code>name</code> key.
34      */

35     protected FastHashMap hProperties = new FastHashMap();
36
37     /**
38      * List of <code>Property</code>s. Used to maintain
39      * the order they were added in although individual
40      * <code>Property</code>s can be retrieved using
41      * <code>Map</code> of <code>Property</code>s.
42      */

43     protected ArrayList JavaDoc lProperties = new ArrayList JavaDoc();
44     
45     /**
46      * <code>FastHashMap</code> of <code>Behaviours</code> stored under
47      * a <code>name</code> key.
48      */

49     protected FastHashMap hBehaviours = new FastHashMap();
50  
51     /**
52      * List of <code>Behaviour</code>s. Used to maintain
53      * the order they were added in although individual
54      * <code>Behaviour</code>s can be retrieved using
55      * <code>Map</code> of <code>Behaviour</code>s.
56      */

57     protected ArrayList JavaDoc lBehaviours = new ArrayList JavaDoc();
58     
59     private String JavaDoc name;
60     private String JavaDoc attributesName;
61
62     public String JavaDoc getName() {
63         return name;
64     }
65
66     public void setName(String JavaDoc name) {
67         this.name = name;
68     }
69
70     public String JavaDoc getAttributesName() {
71         return attributesName;
72     }
73
74     public void setAttributesName(String JavaDoc attributesName) {
75         this.attributesName = attributesName;
76     }
77
78     public void addProperty(Property property) {
79         addProperty(property.getName(), property);
80     }
81     
82     public void addProperty(String JavaDoc name, Property property) {
83         if (log.isDebugEnabled()) {
84             log.debug("Adding Property => Name : " + name);
85         }
86         this.lProperties.add(property);
87         this.hProperties.put(name, property);
88     }
89
90     public void addBehaviour(Behaviour behaviour) {
91         addBehaviour(behaviour.getName(), behaviour);
92     }
93     
94     public void addBehaviour(String JavaDoc name, Behaviour behaviour) {
95         if (log.isDebugEnabled()) {
96             log.debug("Adding Behaviour => Name : " + name);
97         }
98         this.lBehaviours.add(behaviour);
99         this.hBehaviours.put(name, behaviour);
100     }
101     
102     public String JavaDoc toString() {
103         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
104         results.append("name = " + name + "\n");
105         // Loop for Property
106
for (Iterator JavaDoc i = lProperties.iterator(); i.hasNext();) {
107             results.append("\tProperty: \n");
108             results.append(i.next());
109             results.append("\n");
110         }
111         // Loop for Behaviour
112
for (Iterator JavaDoc i = lBehaviours.iterator(); i.hasNext();) {
113             results.append("\tBehaviour: \n");
114             results.append(i.next());
115             results.append("\n");
116         }
117         results.append("\n");
118         return results.toString();
119     }
120     
121     public void processHTML(FieldView field, String JavaDoc defaultBehaviour, Map JavaDoc contextValuesMap, Element htmlElement, OutputDocument htmlOutputDocument) {
122         // Construct OUT Map of attributes of element
123
AttributesOutputSegment htmlOutputSegment = new AttributesOutputSegment(htmlElement.getAttributes(), true);
124         Map JavaDoc htmlAttributesMap = htmlOutputSegment.getMap();
125
126         StringBuffer JavaDoc htmlContentToInsertBefore = new StringBuffer JavaDoc("");
127         StringBuffer JavaDoc htmlContentToInsertAfter = new StringBuffer JavaDoc("");
128         StringBuffer JavaDoc htmlContentToReplace = new StringBuffer JavaDoc("");
129         // Loop for Property
130
for (Iterator JavaDoc iter = lProperties.iterator(); iter.hasNext();) {
131             Property property = (Property) iter.next();
132             property.processHTML(field, defaultBehaviour, contextValuesMap, htmlContentToInsertBefore, htmlContentToInsertAfter, htmlContentToReplace, htmlAttributesMap);
133         }
134         // Loop for Behaviour
135
for (Iterator JavaDoc iter = lBehaviours.iterator(); iter.hasNext();) {
136             Behaviour behaviour = (Behaviour) iter.next();
137             behaviour.processHTML(field, defaultBehaviour, contextValuesMap, htmlContentToInsertBefore, htmlContentToInsertAfter, htmlContentToReplace, htmlAttributesMap);
138         }
139
140         if (htmlContentToReplace.length() > 0) {
141             // HTML content must replace element HTML
142
htmlOutputDocument.add(new StringOutputSegment(htmlElement, htmlContentToReplace.toString()));
143         }
144         else {
145         
146             if (htmlContentToInsertBefore.length() > 0 ){
147                 // HTML content must be insert before element HTML
148
htmlOutputDocument.add(new StringOutputSegment(htmlElement.getBegin(), htmlElement.getBegin(), htmlContentToInsertBefore.toString()));
149             }
150         
151             if (htmlContentToInsertAfter.length() > 0 ){
152                 // HTML content must be insert after element HTML
153
htmlOutputDocument.add(new StringOutputSegment(htmlElement.getEnd(),htmlElement.getEnd(), htmlContentToInsertAfter.toString()));
154             }
155         
156             // Add Attribute which has been added
157
htmlOutputDocument.add(htmlOutputSegment);
158         }
159         
160     }
161     
162 }
163
Popular Tags