01: /*
02: * CM Parser Helper
03: */
04:
05: package com.icesoft.jsfmeta.eclipse;
06:
07: import java.io.File;
08: import java.io.IOException;
09: import java.util.Iterator;
10: import java.util.Map;
11: import java.util.TreeMap;
12: import javax.xml.parsers.DocumentBuilder;
13: import javax.xml.parsers.DocumentBuilderFactory;
14: import javax.xml.parsers.ParserConfigurationException;
15: import org.w3c.dom.Document;
16: import org.w3c.dom.Element;
17: import org.w3c.dom.NamedNodeMap;
18: import org.w3c.dom.Node;
19: import org.xml.sax.ErrorHandler;
20: import org.xml.sax.SAXException;
21: import org.xml.sax.SAXParseException;
22:
23: public class CMParserHelper {
24:
25: private TreeMap propertyTypeTreeMap = new TreeMap();
26:
27: public CMParserHelper() {
28: }
29:
30: public void getInfo() {
31: try {
32:
33: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
34: .newInstance();
35: DocumentBuilder documentBuilder = documentBuilderFactory
36: .newDocumentBuilder();
37:
38: documentBuilder.setErrorHandler(new ErrorHandler() {
39: public void error(SAXParseException e) {
40: e.printStackTrace();
41: }
42:
43: public void fatalError(SAXParseException e)
44: throws SAXException {
45: e.printStackTrace();
46: }
47:
48: public void warning(SAXParseException e) {
49: e.printStackTrace();
50: }
51: });
52:
53: Document document = documentBuilder
54: .parse(new File(
55: "./src/main/resources/conf/eclipse.schema/jsfhtml.xml"));
56:
57: Element element = document.getDocumentElement();
58: traversal(element, "\t");
59:
60: for (Iterator iterator = propertyTypeTreeMap.entrySet()
61: .iterator(); iterator.hasNext();) {
62: Map.Entry entry = (Map.Entry) iterator.next();
63: System.out.println("key=" + entry.getKey() + " value="
64: + entry.getValue());
65: }
66: } catch (SAXException ex) {
67: ex.printStackTrace();
68: } catch (ParserConfigurationException ex) {
69: ex.printStackTrace();
70: } catch (IOException ex) {
71: ex.printStackTrace();
72: }
73: }
74:
75: public void traversal(Element element, String indentString) {
76:
77: for (Node firstChild = element.getFirstChild(); firstChild != null; firstChild = firstChild
78: .getNextSibling()) {
79:
80: int nodeType = firstChild.getNodeType();
81: switch (nodeType) {
82: case Node.ELEMENT_NODE: {
83: NamedNodeMap map = firstChild.getAttributes();
84: Object objectValue = map.getNamedItem("type");
85: if (objectValue != null && objectValue instanceof Node) {
86: Node attrImpl = (Node) objectValue;
87: propertyTypeTreeMap.put(attrImpl.getNodeValue(),
88: attrImpl.getNodeValue() + "_type");
89: }
90: traversal((Element) firstChild, indentString);
91: }
92: case Node.TEXT_NODE: {
93:
94: }
95: }
96: }
97: }
98:
99: }
|