1 17 package org.alfresco.web.config; 18 19 import java.util.Iterator ; 20 21 import org.alfresco.config.ConfigElement; 22 import org.alfresco.config.ConfigException; 23 import org.alfresco.config.xml.elementreader.ConfigElementReader; 24 import org.dom4j.Element; 25 26 31 public class PropertySheetElementReader implements ConfigElementReader 32 { 33 public static final String ELEMENT_PROPERTY_SHEET = "property-sheet"; 34 public static final String ELEMENT_SHOW_PROPERTY = "show-property"; 35 public static final String ELEMENT_SHOW_ASSOC = "show-association"; 36 public static final String ELEMENT_SHOW_CHILD_ASSOC = "show-child-association"; 37 public static final String ATTR_NAME = "name"; 38 public static final String ATTR_DISPLAY_LABEL = "displayLabel"; 39 public static final String ATTR_DISPLAY_LABEL_ID = "displayLabelId"; 40 public static final String ATTR_READ_ONLY = "readOnly"; 41 public static final String ATTR_CONVERTER = "converter"; 42 public static final String ATTR_SHOW_IN_EDIT_MODE = "showInEditMode"; 43 44 47 public ConfigElement parse(Element element) 48 { 49 PropertySheetConfigElement configElement = null; 50 51 if (element != null) 52 { 53 String name = element.getName(); 54 if (name.equals(ELEMENT_PROPERTY_SHEET) == false) 55 { 56 throw new ConfigException("PropertySheetElementReader can only parse " + 57 ELEMENT_PROPERTY_SHEET + "elements, " + "the element passed was '" + 58 name + "'"); 59 } 60 61 configElement = new PropertySheetConfigElement(); 62 63 Iterator <Element> items = element.elementIterator(); 65 while (items.hasNext()) 66 { 67 Element item = items.next(); 68 String propName = item.attributeValue(ATTR_NAME); 69 String label = item.attributeValue(ATTR_DISPLAY_LABEL); 70 String labelId = item.attributeValue(ATTR_DISPLAY_LABEL_ID); 71 String readOnly = item.attributeValue(ATTR_READ_ONLY); 72 String converter = item.attributeValue(ATTR_CONVERTER); 73 String inEdit = item.attributeValue(ATTR_SHOW_IN_EDIT_MODE); 74 75 if (ELEMENT_SHOW_PROPERTY.equals(item.getName())) 76 { 77 configElement.addProperty(propName, label, labelId, readOnly, converter, inEdit); 79 } 80 else if (ELEMENT_SHOW_ASSOC.equals(item.getName())) 81 { 82 configElement.addAssociation(propName, label, labelId, readOnly, converter, inEdit); 83 } 84 else if (ELEMENT_SHOW_CHILD_ASSOC.equals(item.getName())) 85 { 86 configElement.addChildAssociation(propName, label, labelId, readOnly, converter, inEdit); 87 } 88 } 89 } 90 91 return configElement; 92 } 93 94 } 95 | Popular Tags |