StringXMLStreamWriter.java 5 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
11

Matt Tucker's avatar
Matt Tucker committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
package org.jivesoftware.util;

import java.io.StringWriter;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
 * <p>A convenience for serializing XML to a String similar to StringWriter.</p>
 *
 * @author Iain Shigeoka
 */
public class StringXMLStreamWriter implements XMLStreamWriter {

    private XMLStreamWriter ser;
    private StringWriter writer;

    public StringXMLStreamWriter() {
        writer = new StringWriter();
        try {
            ser = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
        }
        catch (Exception e) {
            //
        }
    }

    public void setPrefix(String prefix, String namespace) throws
            IllegalArgumentException, IllegalStateException, XMLStreamException {
        ser.setPrefix(prefix, namespace);
    }

    public void setDefaultNamespace(String name) throws XMLStreamException {
        ser.setDefaultNamespace(name);
    }

    public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException {
        ser.setNamespaceContext(namespaceContext);
    }

    public NamespaceContext getNamespaceContext() {
        return ser.getNamespaceContext();
    }

    public Object getProperty(String name) throws IllegalArgumentException {
        return ser.getProperty(name);
    }

    public void writeStartElement(String name) throws XMLStreamException {
        ser.writeStartElement(name);
    }

    public void writeStartElement(String name, String name1) throws XMLStreamException {
        ser.writeStartElement(name, name1);

    }

    public void writeStartElement(String name, String name1, String name2) throws XMLStreamException {
        ser.writeStartElement(name, name1, name2);
    }

    public void writeEmptyElement(String name, String name1) throws XMLStreamException {
        ser.writeEmptyElement(name, name1);
    }

    public void writeEmptyElement(String name, String name1, String name2) throws XMLStreamException {
        ser.writeEmptyElement(name, name1, name2);
    }

    public void writeEmptyElement(String name) throws XMLStreamException {
        ser.writeEmptyElement(name);
    }

    public void writeEndElement() throws XMLStreamException {
        ser.writeEndElement();
    }

    public void writeEndDocument() throws XMLStreamException {
        ser.writeEndDocument();
    }

    public void close() throws XMLStreamException {
        ser.close();
    }

    public void flush() throws XMLStreamException {
        ser.flush();
    }

    public void writeAttribute(String name, String name1) throws XMLStreamException {
        ser.writeAttribute(name, name1);
    }

    public void writeAttribute(String name, String name1, String name2, String name3) throws XMLStreamException {
        ser.writeAttribute(name, name1, name2, name3);
    }

    public void writeAttribute(String name, String name1, String name2) throws XMLStreamException {
        ser.writeAttribute(name, name1, name2);
    }

    public void writeNamespace(String name, String name1) throws XMLStreamException {
        ser.writeAttribute(name, name1);
    }

    public void writeDefaultNamespace(String name) throws XMLStreamException {
        ser.writeDefaultNamespace(name);
    }

    public void writeComment(String name) throws XMLStreamException {
        ser.writeComment(name);
    }

    public void writeProcessingInstruction(String name) throws XMLStreamException {
        ser.writeProcessingInstruction(name);
    }

    public void writeProcessingInstruction(String name, String name1) throws XMLStreamException {
        ser.writeProcessingInstruction(name, name1);
    }

    public void writeCData(String name) throws XMLStreamException {
        ser.writeCData(name);
    }

    public void writeDTD(String name) throws XMLStreamException {
        ser.writeDTD(name);
    }

    public void writeEntityRef(String name) throws XMLStreamException {
        ser.writeEntityRef(name);
    }

    public void writeStartDocument() throws XMLStreamException {
        ser.writeStartDocument();
    }

    public void writeStartDocument(String name) throws XMLStreamException {
        ser.writeStartDocument(name);
    }

    public void writeStartDocument(String name, String name1) throws XMLStreamException {
        ser.writeStartDocument(name, name1);
    }

    public void writeCharacters(String name) throws XMLStreamException {
        ser.writeCharacters(name);
    }

    public void writeCharacters(char[] chars, int i, int i1) throws XMLStreamException {
        ser.writeCharacters(chars, i, i1);
    }

    public String getPrefix(String name) throws XMLStreamException {
        return ser.getPrefix(name);
    }

    public String toString() {
        return writer.toString();
    }
}