01: package org.zaval.tools.i18n.translator;
02:
03: import java.io.*;
04: import java.util.*;
05: import org.zaval.xml.*;
06:
07: class XmlReader {
08: private XmlElement xml;
09:
10: public XmlReader(InputStream in) throws IOException,
11: XmlParseException {
12: xml = new XmlElement();
13: xml.parse(new InputStreamReader(in));
14: }
15:
16: public XmlReader(String body) throws IOException, XmlParseException {
17: xml = new XmlElement();
18: xml.parse(new StringReader(body));
19: }
20:
21: public XmlElement getRootNode() {
22: return xml;
23: }
24:
25: public Hashtable getTable() {
26: Hashtable ask = new Hashtable();
27: Enumeration en = xml.enumerateChildren();
28: while (en.hasMoreElements()) {
29: XmlElement child = (XmlElement) en.nextElement();
30: getTable(ask, child, "");
31: }
32: return ask;
33: }
34:
35: private void getTable(Hashtable place, XmlElement root,
36: String prefix) {
37: String xmap = (String) root.getAttribute("lang");
38: if (xmap != null)
39: xmap = xmap;
40: if (xmap == null)
41: xmap = (String) root.getAttribute("name");
42: if (xmap == null)
43: xmap = root.getName();
44: String name = prefix + xmap + "!";
45:
46: Enumeration en;
47: /*
48: en = root.enumerateAttributeNames();
49: while (en.hasMoreElements()) {
50: Object key = en.nextElement();
51: Object val = root.getAttribute((String)key);
52: place.put(name + key, val);
53: }
54: */
55: if (root.getContent() != null)
56: place.put(prefix + xmap, root.getContent());
57:
58: en = root.enumerateChildren();
59: while (en.hasMoreElements()) {
60: XmlElement child = (XmlElement) en.nextElement();
61: getTable(place, child, name);
62: }
63: }
64: }
|