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 03. September 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io.xml;
13:
14: import nu.xom.Attribute;
15: import nu.xom.Element;
16:
17: public class XomWriter extends AbstractDocumentWriter {
18:
19: /**
20: * @since 1.2.1
21: */
22: public XomWriter() {
23: this (null);
24: }
25:
26: public XomWriter(final Element parentElement) {
27: this (parentElement, new XmlFriendlyReplacer());
28: }
29:
30: /**
31: * @since 1.2
32: */
33: public XomWriter(final Element parentElement,
34: final XmlFriendlyReplacer replacer) {
35: super (parentElement, replacer);
36: }
37:
38: protected Object createNode(final String name) {
39: final Element newNode = new Element(escapeXmlName(name));
40: final Element top = top();
41: if (top != null) {
42: top().appendChild(newNode);
43: }
44: return newNode;
45: }
46:
47: public void addAttribute(final String name, final String value) {
48: top().addAttribute(new Attribute(escapeXmlName(name), value));
49: }
50:
51: public void setValue(final String text) {
52: top().appendChild(text);
53: }
54:
55: private Element top() {
56: return (Element) getCurrent();
57: }
58: }
|