File Source: RuntimeConfigDefsParser.java
/*
P/P * Method: org.apache.roller.weblogger.config.runtime.RuntimeConfigDefsParser__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18 /*
19 * RuntimeConfigDefsParser.java
20 *
21 * Created on June 4, 2005, 1:57 PM
22 */
23
24 package org.apache.roller.weblogger.config.runtime;
25
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.util.Iterator;
29 import java.util.List;
30 import org.jdom.Document;
31 import org.jdom.Element;
32 import org.jdom.JDOMException;
33 import org.jdom.input.SAXBuilder;
34
35
36 /**
37 * The parser for the rollerRuntimeConfigDefs.xml file.
38 * This class uses jdom to unmarshall the xml into a series of java objects.
39 *
40 * @author Allen Gilliland
41 */
42 public class RuntimeConfigDefsParser {
43
44 /** Creates a new instance of RuntimeConfigDefsParser */
/*
P/P * Method: void org.apache.roller.weblogger.config.runtime.RuntimeConfigDefsParser()
*/
45 public RuntimeConfigDefsParser() {}
46
47
48 /**
49 * Unmarshall the given input stream into our defined
50 * set of Java objects.
51 **/
52 public RuntimeConfigDefs unmarshall(InputStream instream)
53 throws IOException, JDOMException {
54
/*
P/P * Method: RuntimeConfigDefs unmarshall(InputStream)
*
* Preconditions:
* instream != null
*
* Presumptions:
* java.util.Iterator:next(...)@67 != null
* org.jdom.Document:getRootElement(...)@63 != null
* org.jdom.Element:getChildren(...)@64 != null
* org.jdom.input.SAXBuilder:build(...)@61 != null
*
* Postconditions:
* return_value == &new RuntimeConfigDefs(unmarshall#1)
* new ArrayList(RuntimeConfigDefs#1) num objects == 1
* new RuntimeConfigDefs(unmarshall#1) num objects == 1
* return_value.configDefs == &new ArrayList(RuntimeConfigDefs#1)
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@66: {0}, {1}
*/
55 if(instream == null)
56 throw new IOException("InputStream is null!");
57
58 RuntimeConfigDefs configs = new RuntimeConfigDefs();
59
60 SAXBuilder builder = new SAXBuilder();
61 Document doc = builder.build(instream);
62
63 Element root = doc.getRootElement();
64 List configdefs = root.getChildren("config-def");
65 Iterator iter = configdefs.iterator();
66 while (iter.hasNext()) {
67 Element e = (Element) iter.next();
68 configs.addConfigDef(this.elementToConfigDef(e));
69 }
70
71 return configs;
72 }
73
74
75 private ConfigDef elementToConfigDef(Element element) {
76
/*
P/P * Method: ConfigDef elementToConfigDef(Element)
*
* Preconditions:
* element != null
*
* Presumptions:
* java.util.Iterator:next(...)@85 != null
* org.jdom.Element:getChildren(...)@81 != null
*
* Postconditions:
* return_value == &new ConfigDef(elementToConfigDef#1)
* new ArrayList(ConfigDef#1) num objects == 1
* new ConfigDef(elementToConfigDef#1) num objects == 1
* return_value.displayGroups == &new ArrayList(ConfigDef#1)
* init'ed(return_value.name)
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@83: {0}, {1}
*/
77 ConfigDef configdef = new ConfigDef();
78
79 configdef.setName(element.getAttributeValue("name"));
80
81 List displaygroups = element.getChildren("display-group");
82 Iterator iter = displaygroups.iterator();
83 while (iter.hasNext())
84 {
85 Element e = (Element) iter.next();
86 configdef.addDisplayGroup(this.elementToDisplayGroup(e));
87 }
88
89 return configdef;
90 }
91
92
93 private DisplayGroup elementToDisplayGroup(Element element) {
94
/*
P/P * Method: DisplayGroup elementToDisplayGroup(Element)
*
* Preconditions:
* element != null
*
* Presumptions:
* java.util.Iterator:next(...)@104 != null
* org.jdom.Element:getChildren(...)@100 != null
*
* Postconditions:
* return_value == &new DisplayGroup(elementToDisplayGroup#1)
* new ArrayList(DisplayGroup#1) num objects == 1
* new DisplayGroup(elementToDisplayGroup#1) num objects == 1
* init'ed(return_value.key)
* init'ed(return_value.name)
* return_value.propertyDefs == &new ArrayList(DisplayGroup#1)
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@102: {0}, {1}
*/
95 DisplayGroup displaygroup = new DisplayGroup();
96
97 displaygroup.setName(element.getAttributeValue("name"));
98 displaygroup.setKey(element.getAttributeValue("key"));
99
100 List displaygroups = element.getChildren("property-def");
101 Iterator iter = displaygroups.iterator();
102 while (iter.hasNext())
103 {
104 Element e = (Element) iter.next();
105 displaygroup.addPropertyDef(this.elementToPropertyDef(e));
106 }
107
108 return displaygroup;
109 }
110
111
112 private PropertyDef elementToPropertyDef(Element element) {
113
/*
P/P * Method: PropertyDef elementToPropertyDef(Element)
*
* Preconditions:
* element != null
*
* Postconditions:
* return_value == &new PropertyDef(elementToPropertyDef#1)
* new PropertyDef(elementToPropertyDef#1) num objects == 1
* init'ed(return_value.cols)
* init'ed(return_value.defaultValue)
* init'ed(return_value.key)
* init'ed(return_value.name)
* init'ed(return_value.rows)
* init'ed(return_value.type)
*
* Test Vectors:
* org.jdom.Element:getChild(...)@122: Addr_Set{null}, Inverse{null}
* org.jdom.Element:getChild(...)@125: Addr_Set{null}, Inverse{null}
*/
114 PropertyDef prop = new PropertyDef();
115
116 prop.setName(element.getAttributeValue("name"));
117 prop.setKey(element.getAttributeValue("key"));
118 prop.setType(element.getChildText("type"));
119 prop.setDefaultValue(element.getChildText("default-value"));
120
121 // optional elements
122 if(element.getChild("rows") != null)
123 prop.setRows(element.getChildText("rows"));
124
125 if(element.getChild("cols") != null)
126 prop.setCols(element.getChildText("cols"));
127
128 return prop;
129 }
130
131 }
SofCheck Inspector Build Version : 2.18479
| RuntimeConfigDefsParser.java |
2009-Jan-02 14:25:00 |
| RuntimeConfigDefsParser.class |
2009-Sep-04 03:12:32 |