01: /*
02: * Copyright (C) 2004, 2005, 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 07. March 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io.xml;
13:
14: import com.thoughtworks.xstream.io.xml.xppdom.Xpp3Dom;
15:
16: /**
17: * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
18: * @version $Id: XppDomReader.java 1345 2007-12-11 01:50:12Z joehni $
19: */
20: public class XppDomReader extends AbstractDocumentReader {
21:
22: private Xpp3Dom currentElement;
23:
24: public XppDomReader(Xpp3Dom xpp3Dom) {
25: super (xpp3Dom);
26: }
27:
28: /**
29: * @since 1.2
30: */
31: public XppDomReader(Xpp3Dom xpp3Dom, XmlFriendlyReplacer replacer) {
32: super (xpp3Dom, replacer);
33: }
34:
35: public String getNodeName() {
36: return unescapeXmlName(currentElement.getName());
37: }
38:
39: public String getValue() {
40: String text = null;
41:
42: try {
43: text = currentElement.getValue();
44: } catch (Exception e) {
45: // do nothing.
46: }
47:
48: return text == null ? "" : text;
49: }
50:
51: public String getAttribute(String attributeName) {
52: return currentElement.getAttribute(attributeName);
53: }
54:
55: public String getAttribute(int index) {
56: return currentElement.getAttribute(currentElement
57: .getAttributeNames()[index]);
58: }
59:
60: public int getAttributeCount() {
61: return currentElement.getAttributeNames().length;
62: }
63:
64: public String getAttributeName(int index) {
65: return unescapeXmlName(currentElement.getAttributeNames()[index]);
66: }
67:
68: protected Object getParent() {
69: return currentElement.getParent();
70: }
71:
72: protected Object getChild(int index) {
73: return currentElement.getChild(index);
74: }
75:
76: protected int getChildCount() {
77: return currentElement.getChildCount();
78: }
79:
80: protected void reassignCurrentElement(Object current) {
81: this .currentElement = (Xpp3Dom) current;
82: }
83:
84: }
|