1 package net.sourceforge.formview.displayer; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.Map ; 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 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 35 protected FastHashMap hProperties = new FastHashMap(); 36 37 43 protected ArrayList lProperties = new ArrayList (); 44 45 49 protected FastHashMap hBehaviours = new FastHashMap(); 50 51 57 protected ArrayList lBehaviours = new ArrayList (); 58 59 private String name; 60 private String attributesName; 61 62 public String getName() { 63 return name; 64 } 65 66 public void setName(String name) { 67 this.name = name; 68 } 69 70 public String getAttributesName() { 71 return attributesName; 72 } 73 74 public void setAttributesName(String 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 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 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 toString() { 103 StringBuffer results = new StringBuffer (); 104 results.append("name = " + name + "\n"); 105 for (Iterator i = lProperties.iterator(); i.hasNext();) { 107 results.append("\tProperty: \n"); 108 results.append(i.next()); 109 results.append("\n"); 110 } 111 for (Iterator 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 defaultBehaviour, Map contextValuesMap, Element htmlElement, OutputDocument htmlOutputDocument) { 122 AttributesOutputSegment htmlOutputSegment = new AttributesOutputSegment(htmlElement.getAttributes(), true); 124 Map htmlAttributesMap = htmlOutputSegment.getMap(); 125 126 StringBuffer htmlContentToInsertBefore = new StringBuffer (""); 127 StringBuffer htmlContentToInsertAfter = new StringBuffer (""); 128 StringBuffer htmlContentToReplace = new StringBuffer (""); 129 for (Iterator iter = lProperties.iterator(); iter.hasNext();) { 131 Property property = (Property) iter.next(); 132 property.processHTML(field, defaultBehaviour, contextValuesMap, htmlContentToInsertBefore, htmlContentToInsertAfter, htmlContentToReplace, htmlAttributesMap); 133 } 134 for (Iterator 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 htmlOutputDocument.add(new StringOutputSegment(htmlElement, htmlContentToReplace.toString())); 143 } 144 else { 145 146 if (htmlContentToInsertBefore.length() > 0 ){ 147 htmlOutputDocument.add(new StringOutputSegment(htmlElement.getBegin(), htmlElement.getBegin(), htmlContentToInsertBefore.toString())); 149 } 150 151 if (htmlContentToInsertAfter.length() > 0 ){ 152 htmlOutputDocument.add(new StringOutputSegment(htmlElement.getEnd(),htmlElement.getEnd(), htmlContentToInsertAfter.toString())); 154 } 155 156 htmlOutputDocument.add(htmlOutputSegment); 158 } 159 160 } 161 162 } 163 | Popular Tags |