1 | package org.greenstone.gsdl3.gs3build.schema;
|
---|
2 |
|
---|
3 | import org.w3c.dom.Element;
|
---|
4 | import org.w3c.dom.Node;
|
---|
5 | import org.w3c.dom.NodeList;
|
---|
6 |
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.ArrayList;
|
---|
9 |
|
---|
10 | public class Schema
|
---|
11 | {
|
---|
12 | List children;
|
---|
13 |
|
---|
14 | public Schema(Node node)
|
---|
15 | {
|
---|
16 | this.children = new ArrayList();
|
---|
17 |
|
---|
18 | NodeList elements = node.getChildNodes();
|
---|
19 |
|
---|
20 | System.out.println("Schema has " + elements.getLength() + " children");
|
---|
21 | for (int e = 0; e < elements.getLength(); e++) {
|
---|
22 | System.out.println("Subcomponent " + e);
|
---|
23 | // TODO: actually test what is being parsed here!
|
---|
24 | if (elements.item(e).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) {
|
---|
25 | continue;
|
---|
26 | }
|
---|
27 |
|
---|
28 | System.out.println(elements.item(e));
|
---|
29 |
|
---|
30 | Element element = (Element) elements.item(e);
|
---|
31 |
|
---|
32 | String elementName = element.getLocalName();
|
---|
33 | String fullName = element.getNodeName();
|
---|
34 | String valueName = element.getNodeValue();
|
---|
35 |
|
---|
36 | System.out.println(elementName + " " + fullName + " " + valueName);
|
---|
37 |
|
---|
38 | if (elementName == null) {
|
---|
39 | elementName = fullName;
|
---|
40 | }
|
---|
41 |
|
---|
42 | System.out.println(elementName);
|
---|
43 | elementName = SchemaNode.getElementName(elementName);
|
---|
44 |
|
---|
45 | if (elementName.equals("element")) {
|
---|
46 |
|
---|
47 | SchemaElement thisElement = new SchemaElement(element);
|
---|
48 | /*
|
---|
49 | NodeList attributes = element.getElementsByTagName("attribute");
|
---|
50 |
|
---|
51 | for (int i = 0; i < attributes.getLength(); i++) {
|
---|
52 | Element attribute = (Element) attributes.item(i);
|
---|
53 | // handle that attribute, create its node and check what you get out
|
---|
54 | try {
|
---|
55 | SchemaAttribute thisAttribute = new SchemaAttribute(attribute);
|
---|
56 | thisElement.addAttribute(thisAttribute);
|
---|
57 | }
|
---|
58 | catch (SchemaException ex) {
|
---|
59 | // do nothing at the moment - though a malformed attribute should be
|
---|
60 | // cause for throwing everything in the air
|
---|
61 | }
|
---|
62 | }*/
|
---|
63 | this.children.add(thisElement);
|
---|
64 | }
|
---|
65 | else {
|
---|
66 | try {
|
---|
67 | Object child = SchemaNodeFactory.makeNode(element);
|
---|
68 | if (child != null) {
|
---|
69 | this.children.add(child);
|
---|
70 | }
|
---|
71 | }
|
---|
72 | catch (SchemaException metaEx)
|
---|
73 | {
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | } |
---|