1 17 package org.alfresco.web.config; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.alfresco.config.ConfigElement; 24 import org.alfresco.config.ConfigException; 25 import org.alfresco.config.xml.elementreader.ConfigElementReader; 26 import org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty; 27 import org.dom4j.Element; 28 29 34 public class AdvancedSearchElementReader implements ConfigElementReader 35 { 36 public static final String ELEMENT_CONTENTTYPES = "content-types"; 37 public static final String ELEMENT_TYPE = "type"; 38 public static final String ELEMENT_CUSTOMPROPS = "custom-properties"; 39 public static final String ELEMENT_METADATA = "meta-data"; 40 public static final String ATTRIBUTE_NAME = "name"; 41 public static final String ATTRIBUTE_TYPE = "type"; 42 public static final String ATTRIBUTE_PROPERTY = "property"; 43 public static final String ATTRIBUTE_ASPECT = "aspect"; 44 public static final String ATTRIBUTE_DISPLAYLABEL = "displayLabelId"; 45 46 49 @SuppressWarnings ("unchecked") 50 public ConfigElement parse(Element element) 51 { 52 AdvancedSearchConfigElement configElement = null; 53 54 if (element != null) 55 { 56 String name = element.getName(); 57 if (name.equals(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID) == false) 58 { 59 throw new ConfigException("AdvancedSearchElementReader can only parse " + 60 AdvancedSearchConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + 61 name + "'"); 62 } 63 64 configElement = new AdvancedSearchConfigElement(); 65 66 Element contentTypes = element.element(ELEMENT_CONTENTTYPES); 68 if (contentTypes != null) 69 { 70 Iterator <Element> typesItr = contentTypes.elementIterator(ELEMENT_TYPE); 71 List <String > types = new ArrayList <String >(5); 72 while (typesItr.hasNext()) 73 { 74 Element contentType = typesItr.next(); 75 String type = contentType.attributeValue(ATTRIBUTE_NAME); 76 if (type != null) 77 { 78 types.add(type); 79 } 80 } 81 configElement.setContentTypes(types); 82 } 83 84 Element customProps = element.element(ELEMENT_CUSTOMPROPS); 86 if (customProps != null) 87 { 88 Iterator <Element> propsItr = customProps.elementIterator(ELEMENT_METADATA); 89 List <CustomProperty> props = new ArrayList <CustomProperty>(5); 90 while (propsItr.hasNext()) 91 { 92 Element propElement = propsItr.next(); 93 String type = propElement.attributeValue(ATTRIBUTE_TYPE); 94 String aspect = propElement.attributeValue(ATTRIBUTE_ASPECT); 95 String prop = propElement.attributeValue(ATTRIBUTE_PROPERTY); 96 String labelId = propElement.attributeValue(ATTRIBUTE_DISPLAYLABEL); 97 props.add(new AdvancedSearchConfigElement.CustomProperty(type, aspect, prop, labelId)); 98 } 99 configElement.setCustomProperties(props); 100 } 101 } 102 103 return configElement; 104 } 105 } 106 | Popular Tags |