|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.jconfig.parser; |
|
8 |
| |
|
9 |
| import org.jconfig.Configuration; |
|
10 |
| import org.jconfig.DefaultConfiguration; |
|
11 |
| import org.w3c.dom.Document; |
|
12 |
| import org.w3c.dom.NamedNodeMap; |
|
13 |
| import org.w3c.dom.Node; |
|
14 |
| import org.w3c.dom.NodeList; |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| public class DefaultConfigParser extends AbstractConfigParser { |
|
21 |
| |
|
22 |
10
| public DefaultConfigParser() {
|
|
23 |
| } |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
10
| public Configuration parse(Document doc,String configName) {
|
|
31 |
10
| Configuration configuration = new DefaultConfiguration(configName);
|
|
32 |
10
| String currentCategory;
|
|
33 |
10
| getBaseConfigName(doc, configuration);
|
|
34 |
10
| getVariables(doc,configuration);
|
|
35 |
10
| getIncludeProperties(doc, configuration);
|
|
36 |
| |
|
37 |
10
| NodeList nl = doc.getElementsByTagName("category");
|
|
38 |
10
| for (int i = 0; i < nl.getLength(); i++) {
|
|
39 |
| |
|
40 |
42
| Node n = nl.item(i);
|
|
41 |
| |
|
42 |
42
| NamedNodeMap curAtt = n.getAttributes();
|
|
43 |
42
| Node curNode = curAtt.getNamedItem("name");
|
|
44 |
42
| currentCategory = curNode.getNodeValue();
|
|
45 |
42
| configuration.setCategory(currentCategory);
|
|
46 |
| |
|
47 |
42
| for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
|
|
48 |
388
| if (child.getNodeName().equals("property")) {
|
|
49 |
| |
|
50 |
| |
|
51 |
155
| NamedNodeMap myAtt = child.getAttributes();
|
|
52 |
155
| Node myNode = myAtt.getNamedItem("name");
|
|
53 |
155
| String name = myNode.getNodeValue();
|
|
54 |
155
| myNode = myAtt.getNamedItem("value");
|
|
55 |
155
| String value = myNode.getNodeValue();
|
|
56 |
| |
|
57 |
155
| if (name != null && value != null) {
|
|
58 |
| |
|
59 |
| |
|
60 |
155
| configuration.setProperty(name,value,currentCategory);
|
|
61 |
| } |
|
62 |
| } |
|
63 |
| } |
|
64 |
| } |
|
65 |
10
| return configuration;
|
|
66 |
| } |
|
67 |
| } |