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: public class XppDomWriter extends AbstractDocumentWriter {
17: public XppDomWriter() {
18: this (null, new XmlFriendlyReplacer());
19: }
20:
21: /**
22: * @since 1.2.1
23: */
24: public XppDomWriter(final Xpp3Dom parent) {
25: this (parent, new XmlFriendlyReplacer());
26: }
27:
28: /**
29: * @since 1.2
30: */
31: public XppDomWriter(final XmlFriendlyReplacer replacer) {
32: this (null, replacer);
33: }
34:
35: /**
36: * @since 1.2.1
37: */
38: public XppDomWriter(final Xpp3Dom parent,
39: final XmlFriendlyReplacer replacer) {
40: super (parent, replacer);
41: }
42:
43: public Xpp3Dom getConfiguration() {
44: return (Xpp3Dom) getTopLevelNodes().get(0);
45: }
46:
47: protected Object createNode(final String name) {
48: final Xpp3Dom newNode = new Xpp3Dom(escapeXmlName(name));
49: final Xpp3Dom top = top();
50: if (top != null) {
51: top().addChild(newNode);
52: }
53: return newNode;
54: }
55:
56: public void setValue(final String text) {
57: top().setValue(text);
58: }
59:
60: public void addAttribute(final String key, final String value) {
61: top().setAttribute(escapeXmlName(key), value);
62: }
63:
64: private Xpp3Dom top() {
65: return (Xpp3Dom) getCurrent();
66: }
67: }
|