KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > config > PropertySheetElementReader


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.config;
18
19 import java.util.Iterator JavaDoc;
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 /**
27  * Custom element reader to parse config for property sheets
28  *
29  * @author gavinc
30  */

31 public class PropertySheetElementReader implements ConfigElementReader
32 {
33    public static final String JavaDoc ELEMENT_PROPERTY_SHEET = "property-sheet";
34    public static final String JavaDoc ELEMENT_SHOW_PROPERTY = "show-property";
35    public static final String JavaDoc ELEMENT_SHOW_ASSOC = "show-association";
36    public static final String JavaDoc ELEMENT_SHOW_CHILD_ASSOC = "show-child-association";
37    public static final String JavaDoc ATTR_NAME = "name";
38    public static final String JavaDoc ATTR_DISPLAY_LABEL = "displayLabel";
39    public static final String JavaDoc ATTR_DISPLAY_LABEL_ID = "displayLabelId";
40    public static final String JavaDoc ATTR_READ_ONLY = "readOnly";
41    public static final String JavaDoc ATTR_CONVERTER = "converter";
42    public static final String JavaDoc ATTR_SHOW_IN_EDIT_MODE = "showInEditMode";
43    
44    /**
45     * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
46     */

47    public ConfigElement parse(Element element)
48    {
49       PropertySheetConfigElement configElement = null;
50       
51       if (element != null)
52       {
53          String JavaDoc 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          // go through the items to show
64
Iterator JavaDoc<Element> items = element.elementIterator();
65          while (items.hasNext())
66          {
67             Element item = items.next();
68             String JavaDoc propName = item.attributeValue(ATTR_NAME);
69             String JavaDoc label = item.attributeValue(ATTR_DISPLAY_LABEL);
70             String JavaDoc labelId = item.attributeValue(ATTR_DISPLAY_LABEL_ID);
71             String JavaDoc readOnly = item.attributeValue(ATTR_READ_ONLY);
72             String JavaDoc converter = item.attributeValue(ATTR_CONVERTER);
73             String JavaDoc inEdit = item.attributeValue(ATTR_SHOW_IN_EDIT_MODE);
74             
75             if (ELEMENT_SHOW_PROPERTY.equals(item.getName()))
76             {
77                // add the property to show to the custom config element
78
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