KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > ComponentPropertyDefinitionController


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.cms.controllers.kernel.impl.simple;
25
26 import java.io.StringReader JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.xerces.parsers.DOMParser;
31 import org.infoglue.cms.applications.databeans.ComponentPropertyDefinition;
32 import org.infoglue.cms.applications.databeans.ComponentPropertyOptionDefinition;
33 import org.infoglue.cms.entities.kernel.BaseEntityVO;
34 import org.w3c.dom.Document JavaDoc;
35 import org.w3c.dom.Element JavaDoc;
36 import org.w3c.dom.Node JavaDoc;
37 import org.w3c.dom.NodeList JavaDoc;
38 import org.xml.sax.InputSource JavaDoc;
39
40 /**
41  * This class handles aspects of component properties definitions.
42  *
43  * @author Mattias Bogeblad
44  */

45
46 public class ComponentPropertyDefinitionController extends BaseController
47 {
48
49     /**
50      * Factory method
51      */

52
53     public static ComponentPropertyDefinitionController getController()
54     {
55         return new ComponentPropertyDefinitionController();
56     }
57     
58     public List JavaDoc parseComponentPropertyDefinitions(String JavaDoc xml)
59     {
60         List JavaDoc componentPropertyDefinitions = new ArrayList JavaDoc();
61         
62         if(xml == null || xml.equals(""))
63             return componentPropertyDefinitions;
64         
65         try
66         {
67             InputSource JavaDoc xmlSource = new InputSource JavaDoc(new StringReader JavaDoc(xml));
68
69             DOMParser parser = new DOMParser();
70             parser.parse(xmlSource);
71             Document JavaDoc document = parser.getDocument();
72
73             NodeList JavaDoc nl = document.getElementsByTagName("properties");
74             for(int i=0; i<nl.getLength(); i++)
75             {
76                 Node JavaDoc propertiesNode = nl.item(i);
77                 Element JavaDoc propertiesElement = (Element JavaDoc)propertiesNode;
78                 
79                 NodeList JavaDoc propertyNodeList = propertiesElement.getElementsByTagName("property");
80                 for(int j=0; j<propertyNodeList.getLength(); j++)
81                 {
82                     Node JavaDoc propertyNode = propertyNodeList.item(j);
83                     Element JavaDoc propertyElement = (Element JavaDoc)propertyNode;
84                     
85                     String JavaDoc name = propertyElement.getAttribute("name");
86                     String JavaDoc type = propertyElement.getAttribute("type");
87                     String JavaDoc entity = propertyElement.getAttribute("entity");
88                     String JavaDoc multiple = propertyElement.getAttribute("multiple");
89                     String JavaDoc allowedContentTypeNames = propertyElement.getAttribute("allowedContentTypeDefinitionNames");
90                     String JavaDoc description = propertyElement.getAttribute("description");
91                                         
92                     ComponentPropertyDefinition cpd = new ComponentPropertyDefinition(name, type, entity, new Boolean JavaDoc(multiple), allowedContentTypeNames, description);
93
94                     
95                     NodeList JavaDoc optionsNodeList = propertyElement.getElementsByTagName("option");
96                     for(int k=0; k<optionsNodeList.getLength(); k++)
97                     {
98                         Node JavaDoc optionNode = optionsNodeList.item(k);
99                         Element JavaDoc optionElement = (Element JavaDoc)optionNode;
100                         
101                         String JavaDoc optionName = optionElement.getAttribute("name");
102                         String JavaDoc optionValue = optionElement.getAttribute("value");
103                                             
104                         ComponentPropertyOptionDefinition cpod = new ComponentPropertyOptionDefinition(optionName, optionValue);
105                         
106                         cpd.getOptions().add(cpod);
107                     }
108
109                     
110                     componentPropertyDefinitions.add(cpd);
111                 }
112             }
113         }
114         catch(Exception JavaDoc e)
115         {
116             e.printStackTrace();
117         }
118         
119         return componentPropertyDefinitions;
120     }
121
122     public BaseEntityVO getNewVO()
123     {
124         return null;
125     }
126
127     
128     
129 }
130
Popular Tags