feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Performs character escaping and write the result
|
||||
* to the output.
|
||||
*
|
||||
* @since 1.0.1
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface CharacterEscapeHandler {
|
||||
|
||||
/**
|
||||
* @param ch The array of characters.
|
||||
* @param start The starting position.
|
||||
* @param length The number of characters to use.
|
||||
* @param isAttVal true if this is an attribute value literal.
|
||||
*/
|
||||
void escape( char ch[], int start, int length, boolean isAttVal, Writer out ) throws IOException;
|
||||
|
||||
}
|
||||
374
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/DataWriter.java
Normal file
374
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/DataWriter.java
Normal file
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
//@@3RD PARTY CODE@@
|
||||
|
||||
// DataWriter.java - XML writer for data-oriented files.
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
/**
|
||||
* Write data- or field-oriented XML.
|
||||
*
|
||||
* <p>This filter pretty-prints field-oriented XML without mixed content.
|
||||
* all added indentation and newlines will be passed on down
|
||||
* the filter chain (if any).</p>
|
||||
*
|
||||
* <p>In general, all whitespace in an XML document is potentially
|
||||
* significant, so a general-purpose XML writing tool like the
|
||||
* {@link XMLWriter} class cannot
|
||||
* add newlines or indentation.</p>
|
||||
*
|
||||
* <p>There is, however, a large class of XML documents where information
|
||||
* is strictly fielded: each element contains either character data
|
||||
* or other elements, but not both. For this special case, it is possible
|
||||
* for a writing tool to provide automatic indentation and newlines
|
||||
* without requiring extra work from the user. Note that this class
|
||||
* will likely not yield appropriate results for document-oriented
|
||||
* XML like XHTML pages, which mix character data and elements together.</p>
|
||||
*
|
||||
* <p>This writer will automatically place each start tag on a new line,
|
||||
* optionally indented if an indent step is provided (by default, there
|
||||
* is no indentation). If an element contains other elements, the end
|
||||
* tag will also appear on a new line with leading indentation. Consider,
|
||||
* for example, the following code:</p>
|
||||
*
|
||||
* <pre>
|
||||
* DataWriter w = new DataWriter();
|
||||
*
|
||||
* w.setIndentStep(2);
|
||||
* w.startDocument();
|
||||
* w.startElement("Person");
|
||||
* w.dataElement("name", "Jane Smith");
|
||||
* w.dataElement("date-of-birth", "1965-05-23");
|
||||
* w.dataElement("citizenship", "US");
|
||||
* w.endElement("Person");
|
||||
* w.endDocument();
|
||||
* </pre>
|
||||
*
|
||||
* <p>This code will produce the following document:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <?xml version="1.0" standalone="yes"?>
|
||||
*
|
||||
* <Person>
|
||||
* <name>Jane Smith</name>
|
||||
* <date-of-birth>1965-05-23</date-of-birth>
|
||||
* <citizenship>US</citizenship>
|
||||
* </Person>
|
||||
* </pre>
|
||||
*
|
||||
* <p>This class inherits from {@link XMLWriter},
|
||||
* and provides all of the same support for Namespaces.</p>
|
||||
*
|
||||
* @since 1.0
|
||||
* @author David Megginson, david@megginson.com
|
||||
* @version 0.2
|
||||
* @see XMLWriter
|
||||
*/
|
||||
public class DataWriter extends XMLWriter
|
||||
{
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Constructors.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Create a new data writer for the specified output.
|
||||
*
|
||||
* @param writer The character stream where the XML document
|
||||
* will be written.
|
||||
* @param encoding
|
||||
* If non-null string is specified, it is written as a part
|
||||
* of the XML declaration.
|
||||
*/
|
||||
public DataWriter ( Writer writer, String encoding, CharacterEscapeHandler _escapeHandler )
|
||||
{
|
||||
super(writer,encoding,_escapeHandler);
|
||||
}
|
||||
|
||||
|
||||
public DataWriter (Writer writer, String encoding ) {
|
||||
this( writer, encoding, DumbEscapeHandler.theInstance );
|
||||
}
|
||||
|
||||
public DataWriter (Writer writer) {
|
||||
this( writer, null, DumbEscapeHandler.theInstance );
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Accessors and setters.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Return the current indent step.
|
||||
*
|
||||
* <p>Return the current indent step: each start tag will be
|
||||
* indented by this number of spaces times the number of
|
||||
* ancestors that the element has.</p>
|
||||
*
|
||||
* @return The number of spaces in each indentation step,
|
||||
* or 0 or less for no indentation.
|
||||
* @see #setIndentStep(int)
|
||||
*
|
||||
* @deprecated
|
||||
* Only return the length of the indent string.
|
||||
*/
|
||||
public int getIndentStep ()
|
||||
{
|
||||
return indentStep.length();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the current indent step.
|
||||
*
|
||||
* @param indentStep The new indent step (0 or less for no
|
||||
* indentation).
|
||||
* @see #getIndentStep()
|
||||
*
|
||||
* @deprecated
|
||||
* Should use the version that takes string.
|
||||
*/
|
||||
public void setIndentStep (int indentStep)
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for( ; indentStep>0; indentStep-- ) s.append(' ');
|
||||
setIndentStep(s.toString());
|
||||
}
|
||||
|
||||
public void setIndentStep(String s) {
|
||||
this.indentStep = s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Override methods from XMLWriter.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Reset the writer so that it can be reused.
|
||||
*
|
||||
* <p>This method is especially useful if the writer failed
|
||||
* with an exception the last time through.</p>
|
||||
*
|
||||
* @see XMLWriter#reset()
|
||||
*/
|
||||
public void reset ()
|
||||
{
|
||||
depth = 0;
|
||||
state = SEEN_NOTHING;
|
||||
stateStack = new Stack();
|
||||
super.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write a start tag.
|
||||
*
|
||||
* <p>Each tag will begin on a new line, and will be
|
||||
* indented by the current indent step times the number
|
||||
* of ancestors that the element has.</p>
|
||||
*
|
||||
* <p>The newline and indentation will be passed on down
|
||||
* the filter chain through regular characters events.</p>
|
||||
*
|
||||
* @param uri The element's Namespace URI.
|
||||
* @param localName The element's local name.
|
||||
* @param qName The element's qualified (prefixed) name.
|
||||
* @param atts The element's attribute list.
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the start tag, or if a filter further
|
||||
* down the chain raises an exception.
|
||||
* @see XMLWriter#startElement(String, String, String, Attributes)
|
||||
*/
|
||||
public void startElement (String uri, String localName,
|
||||
String qName, Attributes atts)
|
||||
throws SAXException
|
||||
{
|
||||
stateStack.push(SEEN_ELEMENT);
|
||||
state = SEEN_NOTHING;
|
||||
if (depth > 0) {
|
||||
super.characters("\n");
|
||||
}
|
||||
doIndent();
|
||||
super.startElement(uri, localName, qName, atts);
|
||||
depth++;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write an end tag.
|
||||
*
|
||||
* <p>If the element has contained other elements, the tag
|
||||
* will appear indented on a new line; otherwise, it will
|
||||
* appear immediately following whatever came before.</p>
|
||||
*
|
||||
* <p>The newline and indentation will be passed on down
|
||||
* the filter chain through regular characters events.</p>
|
||||
*
|
||||
* @param uri The element's Namespace URI.
|
||||
* @param localName The element's local name.
|
||||
* @param qName The element's qualified (prefixed) name.
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the end tag, or if a filter further
|
||||
* down the chain raises an exception.
|
||||
* @see XMLWriter#endElement(String, String, String)
|
||||
*/
|
||||
public void endElement (String uri, String localName, String qName)
|
||||
throws SAXException
|
||||
{
|
||||
depth--;
|
||||
if (state == SEEN_ELEMENT) {
|
||||
super.characters("\n");
|
||||
doIndent();
|
||||
}
|
||||
super.endElement(uri, localName, qName);
|
||||
state = stateStack.pop();
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Write a empty element tag.
|
||||
// *
|
||||
// * <p>Each tag will appear on a new line, and will be
|
||||
// * indented by the current indent step times the number
|
||||
// * of ancestors that the element has.</p>
|
||||
// *
|
||||
// * <p>The newline and indentation will be passed on down
|
||||
// * the filter chain through regular characters events.</p>
|
||||
// *
|
||||
// * @param uri The element's Namespace URI.
|
||||
// * @param localName The element's local name.
|
||||
// * @param qName The element's qualified (prefixed) name.
|
||||
// * @param atts The element's attribute list.
|
||||
// * @exception org.xml.sax.SAXException If there is an error
|
||||
// * writing the empty tag, or if a filter further
|
||||
// * down the chain raises an exception.
|
||||
// * @see XMLWriter#emptyElement(String, String, String, Attributes)
|
||||
// */
|
||||
// public void emptyElement (String uri, String localName,
|
||||
// String qName, Attributes atts)
|
||||
// throws SAXException
|
||||
// {
|
||||
// state = SEEN_ELEMENT;
|
||||
// if (depth > 0) {
|
||||
// super.characters("\n");
|
||||
// }
|
||||
// doIndent();
|
||||
// super.emptyElement(uri, localName, qName, atts);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Write a sequence of characters.
|
||||
*
|
||||
* @param ch The characters to write.
|
||||
* @param start The starting position in the array.
|
||||
* @param length The number of characters to use.
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the characters, or if a filter further
|
||||
* down the chain raises an exception.
|
||||
* @see XMLWriter#characters(char[], int, int)
|
||||
*/
|
||||
public void characters (char ch[], int start, int length)
|
||||
throws SAXException
|
||||
{
|
||||
state = SEEN_DATA;
|
||||
super.characters(ch, start, length);
|
||||
}
|
||||
|
||||
public void comment(char ch[], int start, int length) throws SAXException {
|
||||
if (depth > 0) {
|
||||
super.characters("\n");
|
||||
}
|
||||
doIndent();
|
||||
super.comment(ch,start,length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Internal methods.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Print indentation for the current level.
|
||||
*
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the indentation characters, or if a filter
|
||||
* further down the chain raises an exception.
|
||||
*/
|
||||
private void doIndent ()
|
||||
throws SAXException
|
||||
{
|
||||
if (depth > 0) {
|
||||
char[] ch = indentStep.toCharArray();
|
||||
for( int i=0; i<depth; i++ )
|
||||
characters(ch, 0, ch.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Constants.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final static Object SEEN_NOTHING = new Object();
|
||||
private final static Object SEEN_ELEMENT = new Object();
|
||||
private final static Object SEEN_DATA = new Object();
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Internal state.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
private Object state = SEEN_NOTHING;
|
||||
private Stack stateStack = new Stack();
|
||||
|
||||
private String indentStep = "";
|
||||
private int depth = 0;
|
||||
|
||||
}
|
||||
|
||||
// end of DataWriter.java
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
/**
|
||||
* Delegating {@link XMLStreamWriter}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
abstract class DelegatingXMLStreamWriter implements XMLStreamWriter {
|
||||
private final XMLStreamWriter writer;
|
||||
|
||||
public DelegatingXMLStreamWriter(XMLStreamWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public void writeStartElement(String localName) throws XMLStreamException {
|
||||
writer.writeStartElement(localName);
|
||||
}
|
||||
|
||||
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||
writer.writeStartElement(namespaceURI, localName);
|
||||
}
|
||||
|
||||
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||
writer.writeStartElement(prefix, localName, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||
writer.writeEmptyElement(namespaceURI, localName);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||
writer.writeEmptyElement(prefix, localName, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String localName) throws XMLStreamException {
|
||||
writer.writeEmptyElement(localName);
|
||||
}
|
||||
|
||||
public void writeEndElement() throws XMLStreamException {
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
public void writeEndDocument() throws XMLStreamException {
|
||||
writer.writeEndDocument();
|
||||
}
|
||||
|
||||
public void close() throws XMLStreamException {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public void flush() throws XMLStreamException {
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
public void writeAttribute(String localName, String value) throws XMLStreamException {
|
||||
writer.writeAttribute(localName, value);
|
||||
}
|
||||
|
||||
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
|
||||
writer.writeAttribute(prefix, namespaceURI, localName, value);
|
||||
}
|
||||
|
||||
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
|
||||
writer.writeAttribute(namespaceURI, localName, value);
|
||||
}
|
||||
|
||||
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
|
||||
writer.writeNamespace(prefix, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
|
||||
writer.writeDefaultNamespace(namespaceURI);
|
||||
}
|
||||
|
||||
public void writeComment(String data) throws XMLStreamException {
|
||||
writer.writeComment(data);
|
||||
}
|
||||
|
||||
public void writeProcessingInstruction(String target) throws XMLStreamException {
|
||||
writer.writeProcessingInstruction(target);
|
||||
}
|
||||
|
||||
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
|
||||
writer.writeProcessingInstruction(target, data);
|
||||
}
|
||||
|
||||
public void writeCData(String data) throws XMLStreamException {
|
||||
writer.writeCData(data);
|
||||
}
|
||||
|
||||
public void writeDTD(String dtd) throws XMLStreamException {
|
||||
writer.writeDTD(dtd);
|
||||
}
|
||||
|
||||
public void writeEntityRef(String name) throws XMLStreamException {
|
||||
writer.writeEntityRef(name);
|
||||
}
|
||||
|
||||
public void writeStartDocument() throws XMLStreamException {
|
||||
writer.writeStartDocument();
|
||||
}
|
||||
|
||||
public void writeStartDocument(String version) throws XMLStreamException {
|
||||
writer.writeStartDocument(version);
|
||||
}
|
||||
|
||||
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
|
||||
writer.writeStartDocument(encoding, version);
|
||||
}
|
||||
|
||||
public void writeCharacters(String text) throws XMLStreamException {
|
||||
writer.writeCharacters(text);
|
||||
}
|
||||
|
||||
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
|
||||
writer.writeCharacters(text, start, len);
|
||||
}
|
||||
|
||||
public String getPrefix(String uri) throws XMLStreamException {
|
||||
return writer.getPrefix(uri);
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix, String uri) throws XMLStreamException {
|
||||
writer.setPrefix(prefix, uri);
|
||||
}
|
||||
|
||||
public void setDefaultNamespace(String uri) throws XMLStreamException {
|
||||
writer.setDefaultNamespace(uri);
|
||||
}
|
||||
|
||||
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
|
||||
writer.setNamespaceContext(context);
|
||||
}
|
||||
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return writer.getNamespaceContext();
|
||||
}
|
||||
|
||||
public Object getProperty(String name) throws IllegalArgumentException {
|
||||
return writer.getProperty(name);
|
||||
}
|
||||
}
|
||||
311
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/DomSerializer.java
Normal file
311
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/DomSerializer.java
Normal file
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.sun.xml.internal.txw2.TxwException;
|
||||
|
||||
/**
|
||||
* {@link XmlSerializer} for {@link javax.xml.transform.dom.DOMResult} and {@link org.w3c.dom.Node}.
|
||||
*
|
||||
* @author Ryan.Shoemaker@Sun.COM
|
||||
*/
|
||||
public class DomSerializer implements XmlSerializer {
|
||||
|
||||
// delegate to SaxSerializer
|
||||
private final SaxSerializer serializer;
|
||||
|
||||
public DomSerializer(Node node) {
|
||||
Dom2SaxAdapter adapter = new Dom2SaxAdapter(node);
|
||||
serializer = new SaxSerializer(adapter,adapter,false);
|
||||
}
|
||||
|
||||
public DomSerializer(DOMResult domResult) {
|
||||
Node node = domResult.getNode();
|
||||
|
||||
if (node == null) {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.newDocument();
|
||||
domResult.setNode(doc);
|
||||
serializer = new SaxSerializer(new Dom2SaxAdapter(doc),null,false);
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new TxwException(pce);
|
||||
}
|
||||
} else {
|
||||
serializer = new SaxSerializer(new Dom2SaxAdapter(node),null,false);
|
||||
}
|
||||
}
|
||||
|
||||
// XmlSerializer api's - delegate to SaxSerializer
|
||||
public void startDocument() {
|
||||
serializer.startDocument();
|
||||
}
|
||||
|
||||
public void beginStartTag(String uri, String localName, String prefix) {
|
||||
serializer.beginStartTag(uri, localName, prefix);
|
||||
}
|
||||
|
||||
public void writeAttribute(String uri, String localName, String prefix, StringBuilder value) {
|
||||
serializer.writeAttribute(uri, localName, prefix, value);
|
||||
}
|
||||
|
||||
public void writeXmlns(String prefix, String uri) {
|
||||
serializer.writeXmlns(prefix, uri);
|
||||
}
|
||||
|
||||
public void endStartTag(String uri, String localName, String prefix) {
|
||||
serializer.endStartTag(uri, localName, prefix);
|
||||
}
|
||||
|
||||
public void endTag() {
|
||||
serializer.endTag();
|
||||
}
|
||||
|
||||
public void text(StringBuilder text) {
|
||||
serializer.text(text);
|
||||
}
|
||||
|
||||
public void cdata(StringBuilder text) {
|
||||
serializer.cdata(text);
|
||||
}
|
||||
|
||||
public void comment(StringBuilder comment) {
|
||||
serializer.comment(comment);
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
serializer.endDocument();
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
// no flushing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Builds a DOM tree from SAX2 events.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
class Dom2SaxAdapter implements ContentHandler, LexicalHandler {
|
||||
|
||||
private final Node _node;
|
||||
private final Stack _nodeStk = new Stack();
|
||||
private boolean inCDATA;
|
||||
|
||||
public final Element getCurrentElement() {
|
||||
return (Element) _nodeStk.peek();
|
||||
}
|
||||
|
||||
/**
|
||||
* Document object that owns the specified node.
|
||||
*/
|
||||
private final Document _document;
|
||||
|
||||
/**
|
||||
* @param node
|
||||
* Nodes will be created and added under this object.
|
||||
*/
|
||||
public Dom2SaxAdapter(Node node)
|
||||
{
|
||||
_node = node;
|
||||
_nodeStk.push(_node);
|
||||
|
||||
if( node instanceof Document )
|
||||
this._document = (Document)node;
|
||||
else
|
||||
this._document = node.getOwnerDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fresh empty DOM document and adds nodes under this document.
|
||||
*/
|
||||
public Dom2SaxAdapter() throws ParserConfigurationException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setValidating(false);
|
||||
|
||||
_document = factory.newDocumentBuilder().newDocument();
|
||||
_node = _document;
|
||||
_nodeStk.push( _document );
|
||||
}
|
||||
|
||||
public Node getDOM() {
|
||||
return _node;
|
||||
}
|
||||
|
||||
public void startDocument() {
|
||||
}
|
||||
|
||||
public void endDocument(){
|
||||
}
|
||||
|
||||
public void startElement(String namespace, String localName, String qName, Attributes attrs){
|
||||
|
||||
// some broken DOM implementatino (we confirmed it with SAXON)
|
||||
// return null from this method.
|
||||
Element element = _document.createElementNS(namespace, qName);
|
||||
|
||||
if( element==null ) {
|
||||
// if so, report an user-friendly error message,
|
||||
// rather than dying mysteriously with NPE.
|
||||
throw new TxwException("Your DOM provider doesn't support the createElementNS method properly");
|
||||
}
|
||||
|
||||
// process namespace bindings
|
||||
for( int i=0; i<unprocessedNamespaces.size(); i+=2 ) {
|
||||
String prefix = (String)unprocessedNamespaces.get(i+0);
|
||||
String uri = (String)unprocessedNamespaces.get(i+1);
|
||||
|
||||
String qname;
|
||||
if( "".equals(prefix) || prefix==null )
|
||||
qname = "xmlns";
|
||||
else
|
||||
qname = "xmlns:"+prefix;
|
||||
|
||||
// older version of Xerces (I confirmed that the bug is gone with Xerces 2.4.0)
|
||||
// have a problem of re-setting the same namespace attribute twice.
|
||||
// work around this bug removing it first.
|
||||
if( element.hasAttributeNS("http://www.w3.org/2000/xmlns/",qname) ) {
|
||||
// further workaround for an old Crimson bug where the removeAttribtueNS
|
||||
// method throws NPE when the element doesn't have any attribute.
|
||||
// to be on the safe side, check the existence of attributes before
|
||||
// attempting to remove it.
|
||||
// for details about this bug, see org.apache.crimson.tree.ElementNode2
|
||||
// line 540 or the following message:
|
||||
// https://jaxb.dev.java.net/servlets/ReadMsg?list=users&msgNo=2767
|
||||
element.removeAttributeNS("http://www.w3.org/2000/xmlns/",qname);
|
||||
}
|
||||
// workaround until here
|
||||
|
||||
element.setAttributeNS("http://www.w3.org/2000/xmlns/",qname, uri);
|
||||
}
|
||||
unprocessedNamespaces.clear();
|
||||
|
||||
|
||||
int length = attrs.getLength();
|
||||
for(int i=0;i<length;i++){
|
||||
String namespaceuri = attrs.getURI(i);
|
||||
String value = attrs.getValue(i);
|
||||
String qname = attrs.getQName(i);
|
||||
element.setAttributeNS(namespaceuri, qname, value);
|
||||
}
|
||||
// append this new node onto current stack node
|
||||
getParent().appendChild(element);
|
||||
// push this node onto stack
|
||||
_nodeStk.push(element);
|
||||
}
|
||||
|
||||
private final Node getParent() {
|
||||
return (Node) _nodeStk.peek();
|
||||
}
|
||||
|
||||
public void endElement(String namespace, String localName, String qName){
|
||||
_nodeStk.pop();
|
||||
}
|
||||
|
||||
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
Node text;
|
||||
if(inCDATA)
|
||||
text = _document.createCDATASection(new String(ch, start, length));
|
||||
else
|
||||
text = _document.createTextNode(new String(ch, start, length));
|
||||
getParent().appendChild(text);
|
||||
}
|
||||
|
||||
public void comment(char ch[], int start, int length) throws SAXException {
|
||||
getParent().appendChild(_document.createComment(new String(ch,start,length)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ignorableWhitespace(char[] ch, int start, int length) {
|
||||
}
|
||||
|
||||
public void processingInstruction(String target, String data) throws org.xml.sax.SAXException{
|
||||
Node node = _document.createProcessingInstruction(target, data);
|
||||
getParent().appendChild(node);
|
||||
}
|
||||
|
||||
public void setDocumentLocator(Locator locator) {
|
||||
}
|
||||
|
||||
public void skippedEntity(String name) {
|
||||
}
|
||||
|
||||
private ArrayList unprocessedNamespaces = new ArrayList();
|
||||
|
||||
public void startPrefixMapping(String prefix, String uri) {
|
||||
unprocessedNamespaces.add(prefix);
|
||||
unprocessedNamespaces.add(uri);
|
||||
}
|
||||
|
||||
public void endPrefixMapping(String prefix) {
|
||||
}
|
||||
|
||||
public void startDTD(String name, String publicId, String systemId) throws SAXException {
|
||||
}
|
||||
|
||||
public void endDTD() throws SAXException {
|
||||
}
|
||||
|
||||
public void startEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
public void endEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
public void startCDATA() throws SAXException {
|
||||
inCDATA = true;
|
||||
}
|
||||
|
||||
public void endCDATA() throws SAXException {
|
||||
inCDATA = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Escape everything above the US-ASCII code range.
|
||||
* A fallback position.
|
||||
*
|
||||
* Works with any JDK, any encoding.
|
||||
*
|
||||
* @since 1.0.1
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class DumbEscapeHandler implements CharacterEscapeHandler {
|
||||
|
||||
private DumbEscapeHandler() {} // no instanciation please
|
||||
|
||||
public static final CharacterEscapeHandler theInstance = new DumbEscapeHandler();
|
||||
|
||||
public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
|
||||
int limit = start+length;
|
||||
for (int i = start; i < limit; i++) {
|
||||
switch (ch[i]) {
|
||||
case '&':
|
||||
out.write("&");
|
||||
break;
|
||||
case '<':
|
||||
out.write("<");
|
||||
break;
|
||||
case '>':
|
||||
out.write(">");
|
||||
break;
|
||||
case '\"':
|
||||
if (isAttVal) {
|
||||
out.write(""");
|
||||
} else {
|
||||
out.write('\"');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (ch[i] > '\u007f') {
|
||||
out.write("&#");
|
||||
out.write(Integer.toString(ch[i]));
|
||||
out.write(';');
|
||||
} else {
|
||||
out.write(ch[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* Shows the call sequence of {@link XmlSerializer} methods.
|
||||
*
|
||||
* Useful for debugging and learning how TXW works.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class DumpSerializer implements XmlSerializer {
|
||||
private final PrintStream out;
|
||||
|
||||
public DumpSerializer(PrintStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
public void beginStartTag(String uri, String localName, String prefix) {
|
||||
out.println('<'+prefix+':'+localName);
|
||||
}
|
||||
|
||||
public void writeAttribute(String uri, String localName, String prefix, StringBuilder value) {
|
||||
out.println('@'+prefix+':'+localName+'='+value);
|
||||
}
|
||||
|
||||
public void writeXmlns(String prefix, String uri) {
|
||||
out.println("xmlns:"+prefix+'='+uri);
|
||||
}
|
||||
|
||||
public void endStartTag(String uri, String localName, String prefix) {
|
||||
out.println('>');
|
||||
}
|
||||
|
||||
public void endTag() {
|
||||
out.println("</ >");
|
||||
}
|
||||
|
||||
public void text(StringBuilder text) {
|
||||
out.println(text);
|
||||
}
|
||||
|
||||
public void cdata(StringBuilder text) {
|
||||
out.println("<![CDATA[");
|
||||
out.println(text);
|
||||
out.println("]]>");
|
||||
}
|
||||
|
||||
public void comment(StringBuilder comment) {
|
||||
out.println("<!--");
|
||||
out.println(comment);
|
||||
out.println("-->");
|
||||
}
|
||||
|
||||
public void startDocument() {
|
||||
out.println("<?xml?>");
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
out.println("done");
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
out.println("flush");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* {@link XMLFilterImpl} that does indentation to SAX events.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class IndentingXMLFilter extends XMLFilterImpl implements LexicalHandler {
|
||||
private LexicalHandler lexical;
|
||||
|
||||
public IndentingXMLFilter() {
|
||||
}
|
||||
|
||||
public IndentingXMLFilter(ContentHandler handler) {
|
||||
setContentHandler(handler);
|
||||
}
|
||||
|
||||
public IndentingXMLFilter(ContentHandler handler, LexicalHandler lexical) {
|
||||
setContentHandler(handler);
|
||||
setLexicalHandler(lexical);
|
||||
}
|
||||
|
||||
public LexicalHandler getLexicalHandler() {
|
||||
return lexical;
|
||||
}
|
||||
|
||||
public void setLexicalHandler(LexicalHandler lexical) {
|
||||
this.lexical = lexical;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current indent step.
|
||||
*
|
||||
* <p>Return the current indent step: each start tag will be
|
||||
* indented by this number of spaces times the number of
|
||||
* ancestors that the element has.</p>
|
||||
*
|
||||
* @return The number of spaces in each indentation step,
|
||||
* or 0 or less for no indentation.
|
||||
* @see #setIndentStep(int)
|
||||
*
|
||||
* @deprecated
|
||||
* Only return the length of the indent string.
|
||||
*/
|
||||
public int getIndentStep ()
|
||||
{
|
||||
return indentStep.length();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the current indent step.
|
||||
*
|
||||
* @param indentStep The new indent step (0 or less for no
|
||||
* indentation).
|
||||
* @see #getIndentStep()
|
||||
*
|
||||
* @deprecated
|
||||
* Should use the version that takes string.
|
||||
*/
|
||||
public void setIndentStep (int indentStep)
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for( ; indentStep>0; indentStep-- ) s.append(' ');
|
||||
setIndentStep(s.toString());
|
||||
}
|
||||
|
||||
public void setIndentStep(String s) {
|
||||
this.indentStep = s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Override methods from XMLWriter.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Write a start tag.
|
||||
*
|
||||
* <p>Each tag will begin on a new line, and will be
|
||||
* indented by the current indent step times the number
|
||||
* of ancestors that the element has.</p>
|
||||
*
|
||||
* <p>The newline and indentation will be passed on down
|
||||
* the filter chain through regular characters events.</p>
|
||||
*
|
||||
* @param uri The element's Namespace URI.
|
||||
* @param localName The element's local name.
|
||||
* @param qName The element's qualified (prefixed) name.
|
||||
* @param atts The element's attribute list.
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the start tag, or if a filter further
|
||||
* down the chain raises an exception.
|
||||
* @see XMLWriter#startElement(String, String, String,Attributes)
|
||||
*/
|
||||
public void startElement (String uri, String localName,
|
||||
String qName, Attributes atts)
|
||||
throws SAXException {
|
||||
stateStack.push(SEEN_ELEMENT);
|
||||
state = SEEN_NOTHING;
|
||||
if (depth > 0) {
|
||||
writeNewLine();
|
||||
}
|
||||
doIndent();
|
||||
super.startElement(uri, localName, qName, atts);
|
||||
depth++;
|
||||
}
|
||||
|
||||
private void writeNewLine() throws SAXException {
|
||||
super.characters(NEWLINE,0,NEWLINE.length);
|
||||
}
|
||||
|
||||
private static final char[] NEWLINE = {'\n'};
|
||||
|
||||
|
||||
/**
|
||||
* Write an end tag.
|
||||
*
|
||||
* <p>If the element has contained other elements, the tag
|
||||
* will appear indented on a new line; otherwise, it will
|
||||
* appear immediately following whatever came before.</p>
|
||||
*
|
||||
* <p>The newline and indentation will be passed on down
|
||||
* the filter chain through regular characters events.</p>
|
||||
*
|
||||
* @param uri The element's Namespace URI.
|
||||
* @param localName The element's local name.
|
||||
* @param qName The element's qualified (prefixed) name.
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the end tag, or if a filter further
|
||||
* down the chain raises an exception.
|
||||
* @see XMLWriter#endElement(String, String, String)
|
||||
*/
|
||||
public void endElement (String uri, String localName, String qName)
|
||||
throws SAXException
|
||||
{
|
||||
depth--;
|
||||
if (state == SEEN_ELEMENT) {
|
||||
writeNewLine();
|
||||
doIndent();
|
||||
}
|
||||
super.endElement(uri, localName, qName);
|
||||
state = stateStack.pop();
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Write a empty element tag.
|
||||
// *
|
||||
// * <p>Each tag will appear on a new line, and will be
|
||||
// * indented by the current indent step times the number
|
||||
// * of ancestors that the element has.</p>
|
||||
// *
|
||||
// * <p>The newline and indentation will be passed on down
|
||||
// * the filter chain through regular characters events.</p>
|
||||
// *
|
||||
// * @param uri The element's Namespace URI.
|
||||
// * @param localName The element's local name.
|
||||
// * @param qName The element's qualified (prefixed) name.
|
||||
// * @param atts The element's attribute list.
|
||||
// * @exception org.xml.sax.SAXException If there is an error
|
||||
// * writing the empty tag, or if a filter further
|
||||
// * down the chain raises an exception.
|
||||
// * @see XMLWriter#emptyElement(String, String, String, Attributes)
|
||||
// */
|
||||
// public void emptyElement (String uri, String localName,
|
||||
// String qName, Attributes atts)
|
||||
// throws SAXException
|
||||
// {
|
||||
// state = SEEN_ELEMENT;
|
||||
// if (depth > 0) {
|
||||
// super.characters("\n");
|
||||
// }
|
||||
// doIndent();
|
||||
// super.emptyElement(uri, localName, qName, atts);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Write a sequence of characters.
|
||||
*
|
||||
* @param ch The characters to write.
|
||||
* @param start The starting position in the array.
|
||||
* @param length The number of characters to use.
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the characters, or if a filter further
|
||||
* down the chain raises an exception.
|
||||
* @see XMLWriter#characters(char[], int, int)
|
||||
*/
|
||||
public void characters (char ch[], int start, int length)
|
||||
throws SAXException
|
||||
{
|
||||
state = SEEN_DATA;
|
||||
super.characters(ch, start, length);
|
||||
}
|
||||
|
||||
public void comment(char ch[], int start, int length) throws SAXException {
|
||||
if (depth > 0) {
|
||||
writeNewLine();
|
||||
}
|
||||
doIndent();
|
||||
if(lexical!=null)
|
||||
lexical.comment(ch,start,length);
|
||||
}
|
||||
|
||||
public void startDTD(String name, String publicId, String systemId) throws SAXException {
|
||||
if(lexical!=null)
|
||||
lexical.startDTD(name, publicId, systemId);
|
||||
}
|
||||
|
||||
public void endDTD() throws SAXException {
|
||||
if(lexical!=null)
|
||||
lexical.endDTD();
|
||||
}
|
||||
|
||||
public void startEntity(String name) throws SAXException {
|
||||
if(lexical!=null)
|
||||
lexical.startEntity(name);
|
||||
}
|
||||
|
||||
public void endEntity(String name) throws SAXException {
|
||||
if(lexical!=null)
|
||||
lexical.endEntity(name);
|
||||
}
|
||||
|
||||
public void startCDATA() throws SAXException {
|
||||
if(lexical!=null)
|
||||
lexical.startCDATA();
|
||||
}
|
||||
|
||||
public void endCDATA() throws SAXException {
|
||||
if(lexical!=null)
|
||||
lexical.endCDATA();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Internal methods.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Print indentation for the current level.
|
||||
*
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the indentation characters, or if a filter
|
||||
* further down the chain raises an exception.
|
||||
*/
|
||||
private void doIndent ()
|
||||
throws SAXException
|
||||
{
|
||||
if (depth > 0) {
|
||||
char[] ch = indentStep.toCharArray();
|
||||
for( int i=0; i<depth; i++ )
|
||||
characters(ch, 0, ch.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Constants.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final static Object SEEN_NOTHING = new Object();
|
||||
private final static Object SEEN_ELEMENT = new Object();
|
||||
private final static Object SEEN_DATA = new Object();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Internal state.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
private Object state = SEEN_NOTHING;
|
||||
private Stack<Object> stateStack = new Stack<Object>();
|
||||
|
||||
private String indentStep = "";
|
||||
private int depth = 0;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class IndentingXMLStreamWriter extends DelegatingXMLStreamWriter {
|
||||
private final static Object SEEN_NOTHING = new Object();
|
||||
private final static Object SEEN_ELEMENT = new Object();
|
||||
private final static Object SEEN_DATA = new Object();
|
||||
|
||||
private Object state = SEEN_NOTHING;
|
||||
private Stack<Object> stateStack = new Stack<Object>();
|
||||
|
||||
private String indentStep = " ";
|
||||
private int depth = 0;
|
||||
|
||||
public IndentingXMLStreamWriter(XMLStreamWriter writer) {
|
||||
super(writer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current indent step.
|
||||
*
|
||||
* <p>Return the current indent step: each start tag will be
|
||||
* indented by this number of spaces times the number of
|
||||
* ancestors that the element has.</p>
|
||||
*
|
||||
* @return The number of spaces in each indentation step,
|
||||
* or 0 or less for no indentation.
|
||||
* @see #setIndentStep(int)
|
||||
*
|
||||
* @deprecated
|
||||
* Only return the length of the indent string.
|
||||
*/
|
||||
public int getIndentStep() {
|
||||
return indentStep.length();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the current indent step.
|
||||
*
|
||||
* @param indentStep The new indent step (0 or less for no
|
||||
* indentation).
|
||||
* @see #getIndentStep()
|
||||
*
|
||||
* @deprecated
|
||||
* Should use the version that takes string.
|
||||
*/
|
||||
public void setIndentStep(int indentStep) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (; indentStep > 0; indentStep--) s.append(' ');
|
||||
setIndentStep(s.toString());
|
||||
}
|
||||
|
||||
public void setIndentStep(String s) {
|
||||
this.indentStep = s;
|
||||
}
|
||||
|
||||
private void onStartElement() throws XMLStreamException {
|
||||
stateStack.push(SEEN_ELEMENT);
|
||||
state = SEEN_NOTHING;
|
||||
if (depth > 0) {
|
||||
super.writeCharacters("\n");
|
||||
}
|
||||
doIndent();
|
||||
depth++;
|
||||
}
|
||||
|
||||
private void onEndElement() throws XMLStreamException {
|
||||
depth--;
|
||||
if (state == SEEN_ELEMENT) {
|
||||
super.writeCharacters("\n");
|
||||
doIndent();
|
||||
}
|
||||
state = stateStack.pop();
|
||||
}
|
||||
|
||||
private void onEmptyElement() throws XMLStreamException {
|
||||
state = SEEN_ELEMENT;
|
||||
if (depth > 0) {
|
||||
super.writeCharacters("\n");
|
||||
}
|
||||
doIndent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print indentation for the current level.
|
||||
*
|
||||
* @exception org.xml.sax.SAXException If there is an error
|
||||
* writing the indentation characters, or if a filter
|
||||
* further down the chain raises an exception.
|
||||
*/
|
||||
private void doIndent() throws XMLStreamException {
|
||||
if (depth > 0) {
|
||||
for (int i = 0; i < depth; i++)
|
||||
super.writeCharacters(indentStep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeStartDocument() throws XMLStreamException {
|
||||
super.writeStartDocument();
|
||||
super.writeCharacters("\n");
|
||||
}
|
||||
|
||||
public void writeStartDocument(String version) throws XMLStreamException {
|
||||
super.writeStartDocument(version);
|
||||
super.writeCharacters("\n");
|
||||
}
|
||||
|
||||
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
|
||||
super.writeStartDocument(encoding, version);
|
||||
super.writeCharacters("\n");
|
||||
}
|
||||
|
||||
public void writeStartElement(String localName) throws XMLStreamException {
|
||||
onStartElement();
|
||||
super.writeStartElement(localName);
|
||||
}
|
||||
|
||||
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||
onStartElement();
|
||||
super.writeStartElement(namespaceURI, localName);
|
||||
}
|
||||
|
||||
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||
onStartElement();
|
||||
super.writeStartElement(prefix, localName, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||
onEmptyElement();
|
||||
super.writeEmptyElement(namespaceURI, localName);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||
onEmptyElement();
|
||||
super.writeEmptyElement(prefix, localName, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String localName) throws XMLStreamException {
|
||||
onEmptyElement();
|
||||
super.writeEmptyElement(localName);
|
||||
}
|
||||
|
||||
public void writeEndElement() throws XMLStreamException {
|
||||
onEndElement();
|
||||
super.writeEndElement();
|
||||
}
|
||||
|
||||
public void writeCharacters(String text) throws XMLStreamException {
|
||||
state = SEEN_DATA;
|
||||
super.writeCharacters(text);
|
||||
}
|
||||
|
||||
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
|
||||
state = SEEN_DATA;
|
||||
super.writeCharacters(text, start, len);
|
||||
}
|
||||
|
||||
public void writeCData(String data) throws XMLStreamException {
|
||||
state = SEEN_DATA;
|
||||
super.writeCData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
/**
|
||||
* Factory for producing XmlSerializers for various Result types.
|
||||
*
|
||||
* @author Ryan.Shoemaker@Sun.COM
|
||||
*/
|
||||
public abstract class ResultFactory {
|
||||
|
||||
/**
|
||||
* Do not instanciate.
|
||||
*/
|
||||
private ResultFactory() {}
|
||||
|
||||
/**
|
||||
* Factory method for producing {@link XmlSerializer) from {@link javax.xml.transform.Result}.
|
||||
*
|
||||
* This method supports {@link javax.xml.transform.sax.SAXResult},
|
||||
* {@link javax.xml.transform.stream.StreamResult}, and {@link javax.xml.transform.dom.DOMResult}.
|
||||
*
|
||||
* @param result the Result that will receive output from the XmlSerializer
|
||||
* @return an implementation of XmlSerializer that will produce output on the supplied Result
|
||||
*/
|
||||
public static XmlSerializer createSerializer(Result result) {
|
||||
if (result instanceof SAXResult)
|
||||
return new SaxSerializer((SAXResult) result);
|
||||
if (result instanceof DOMResult)
|
||||
return new DomSerializer((DOMResult) result);
|
||||
if (result instanceof StreamResult)
|
||||
return new StreamSerializer((StreamResult) result);
|
||||
if (result instanceof TXWResult)
|
||||
return new TXWSerializer(((TXWResult)result).getWriter());
|
||||
|
||||
throw new UnsupportedOperationException("Unsupported Result type: " + result.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
213
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/SaxSerializer.java
Normal file
213
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/SaxSerializer.java
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import com.sun.xml.internal.txw2.TxwException;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* {@link XmlSerializer} for {@link SAXResult} and {@link ContentHandler}.
|
||||
*
|
||||
* @author Ryan.Shoemaker@Sun.COM
|
||||
*/
|
||||
public class SaxSerializer implements XmlSerializer {
|
||||
|
||||
private final ContentHandler writer;
|
||||
private final LexicalHandler lexical;
|
||||
|
||||
public SaxSerializer(ContentHandler handler) {
|
||||
this(handler,null,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link XmlSerializer} that writes SAX events.
|
||||
*
|
||||
* <p>
|
||||
* Sepcifying a non-null {@link LexicalHandler} allows applications
|
||||
* to write comments and CDATA sections.
|
||||
*/
|
||||
public SaxSerializer(ContentHandler handler,LexicalHandler lex) {
|
||||
this(handler, lex, true);
|
||||
}
|
||||
|
||||
public SaxSerializer(ContentHandler handler,LexicalHandler lex, boolean indenting) {
|
||||
if(!indenting) {
|
||||
writer = handler;
|
||||
lexical = lex;
|
||||
} else {
|
||||
IndentingXMLFilter indenter = new IndentingXMLFilter(handler, lex);
|
||||
writer = indenter;
|
||||
lexical = indenter;
|
||||
}
|
||||
}
|
||||
|
||||
public SaxSerializer(SAXResult result) {
|
||||
this(result.getHandler(),result.getLexicalHandler());
|
||||
}
|
||||
|
||||
|
||||
// XmlSerializer implementation
|
||||
|
||||
public void startDocument() {
|
||||
try {
|
||||
writer.startDocument();
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// namespace prefix bindings
|
||||
// add in #writeXmlns and fired in #endStartTag
|
||||
private final Stack<String> prefixBindings = new Stack<String>();
|
||||
|
||||
public void writeXmlns(String prefix, String uri) {
|
||||
// defend against parsers that pass null in for "xmlns" prefix
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
if (prefix.equals("xml")) {
|
||||
return;
|
||||
}
|
||||
|
||||
prefixBindings.add(uri);
|
||||
prefixBindings.add(prefix);
|
||||
}
|
||||
|
||||
// element stack
|
||||
private final Stack<String> elementBindings = new Stack<String>();
|
||||
|
||||
public void beginStartTag(String uri, String localName, String prefix) {
|
||||
// save element bindings for #endTag
|
||||
elementBindings.add(getQName(prefix, localName));
|
||||
elementBindings.add(localName);
|
||||
elementBindings.add(uri);
|
||||
}
|
||||
|
||||
// attribute storage
|
||||
// attrs are buffered in #writeAttribute and sent to the content
|
||||
// handler in #endStartTag
|
||||
private final AttributesImpl attrs = new AttributesImpl();
|
||||
|
||||
public void writeAttribute(String uri, String localName, String prefix, StringBuilder value) {
|
||||
attrs.addAttribute(uri,
|
||||
localName,
|
||||
getQName(prefix, localName),
|
||||
"CDATA",
|
||||
value.toString());
|
||||
}
|
||||
|
||||
public void endStartTag(String uri, String localName, String prefix) {
|
||||
try {
|
||||
while (prefixBindings.size() != 0) {
|
||||
writer.startPrefixMapping(prefixBindings.pop(), // prefix
|
||||
prefixBindings.pop() // uri
|
||||
);
|
||||
}
|
||||
|
||||
writer.startElement(uri,
|
||||
localName,
|
||||
getQName(prefix, localName),
|
||||
attrs);
|
||||
|
||||
attrs.clear();
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endTag() {
|
||||
try {
|
||||
writer.endElement(elementBindings.pop(), // uri
|
||||
elementBindings.pop(), // localName
|
||||
elementBindings.pop() // qname
|
||||
);
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void text(StringBuilder text) {
|
||||
try {
|
||||
writer.characters(text.toString().toCharArray(), 0, text.length());
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void cdata(StringBuilder text) {
|
||||
if(lexical==null)
|
||||
throw new UnsupportedOperationException("LexicalHandler is needed to write PCDATA");
|
||||
|
||||
try {
|
||||
lexical.startCDATA();
|
||||
text(text);
|
||||
lexical.endCDATA();
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void comment(StringBuilder comment) {
|
||||
try {
|
||||
if(lexical==null)
|
||||
throw new UnsupportedOperationException("LexicalHandler is needed to write comments");
|
||||
else
|
||||
lexical.comment(comment.toString().toCharArray(), 0, comment.length() );
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
try {
|
||||
writer.endDocument();
|
||||
} catch (SAXException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
// noop
|
||||
}
|
||||
|
||||
// other methods
|
||||
private static String getQName(String prefix, String localName) {
|
||||
final String qName;
|
||||
if (prefix == null || prefix.length() == 0)
|
||||
qName = localName;
|
||||
else
|
||||
qName = prefix + ':' + localName;
|
||||
|
||||
return qName;
|
||||
}
|
||||
}
|
||||
145
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/StaxSerializer.java
Normal file
145
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/StaxSerializer.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import com.sun.xml.internal.txw2.TxwException;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
/**
|
||||
* XML serializer for StAX XMLStreamWriter.
|
||||
*
|
||||
* TODO: add support for XMLEventWriter (if it makes sense)
|
||||
*
|
||||
* @author Ryan.Shoemaker@Sun.COM
|
||||
*/
|
||||
|
||||
public class StaxSerializer implements XmlSerializer {
|
||||
private final XMLStreamWriter out;
|
||||
|
||||
public StaxSerializer(XMLStreamWriter writer) {
|
||||
this(writer,true);
|
||||
}
|
||||
|
||||
public StaxSerializer(XMLStreamWriter writer, boolean indenting) {
|
||||
if(indenting)
|
||||
writer = new IndentingXMLStreamWriter(writer);
|
||||
this.out = writer;
|
||||
}
|
||||
|
||||
public void startDocument() {
|
||||
try {
|
||||
out.writeStartDocument();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void beginStartTag(String uri, String localName, String prefix) {
|
||||
try {
|
||||
out.writeStartElement(prefix, localName, uri);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeAttribute(String uri, String localName, String prefix, StringBuilder value) {
|
||||
try {
|
||||
out.writeAttribute(prefix, uri, localName, value.toString());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeXmlns(String prefix, String uri) {
|
||||
try {
|
||||
if (prefix.length() == 0) {
|
||||
out.setDefaultNamespace(uri);
|
||||
} else {
|
||||
out.setPrefix(prefix, uri);
|
||||
}
|
||||
|
||||
// this method handles "", null, and "xmlns" prefixes properly
|
||||
out.writeNamespace(prefix, uri);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endStartTag(String uri, String localName, String prefix) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public void endTag() {
|
||||
try {
|
||||
out.writeEndElement();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void text(StringBuilder text) {
|
||||
try {
|
||||
out.writeCharacters(text.toString());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void cdata(StringBuilder text) {
|
||||
try {
|
||||
out.writeCData(text.toString());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void comment(StringBuilder comment) {
|
||||
try {
|
||||
out.writeComment(comment.toString());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
try {
|
||||
out.writeEndDocument();
|
||||
out.flush();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
try {
|
||||
out.flush();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import com.sun.xml.internal.txw2.TxwException;
|
||||
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* {@link XmlSerializer} for {@link javax.xml.transform.stream.StreamResult}.
|
||||
*
|
||||
* @author Ryan.Shoemaker@Sun.COM
|
||||
*/
|
||||
public class StreamSerializer implements XmlSerializer {
|
||||
|
||||
// delegate to SaxSerializer
|
||||
private final SaxSerializer serializer;
|
||||
|
||||
private final XMLWriter writer;
|
||||
|
||||
public StreamSerializer(OutputStream out) {
|
||||
this(createWriter(out));
|
||||
}
|
||||
|
||||
public StreamSerializer(OutputStream out,String encoding) throws UnsupportedEncodingException {
|
||||
this(createWriter(out,encoding));
|
||||
}
|
||||
|
||||
public StreamSerializer(Writer out) {
|
||||
this(new StreamResult(out));
|
||||
}
|
||||
|
||||
public StreamSerializer(StreamResult streamResult) {
|
||||
// if this method opened a stream, let it close it
|
||||
final OutputStream[] autoClose = new OutputStream[1];
|
||||
|
||||
if (streamResult.getWriter() != null)
|
||||
writer = createWriter(streamResult.getWriter());
|
||||
else if (streamResult.getOutputStream() != null)
|
||||
writer = createWriter(streamResult.getOutputStream());
|
||||
else if (streamResult.getSystemId() != null) {
|
||||
String fileURL = streamResult.getSystemId();
|
||||
|
||||
fileURL = convertURL(fileURL);
|
||||
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(fileURL);
|
||||
autoClose[0] = fos;
|
||||
writer = createWriter(fos);
|
||||
} catch (IOException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
} else
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
// now delegate to the SaxSerializer
|
||||
serializer = new SaxSerializer(writer,writer,false) {
|
||||
public void endDocument() {
|
||||
super.endDocument();
|
||||
if(autoClose[0]!=null) {
|
||||
try {
|
||||
autoClose[0].close();
|
||||
} catch (IOException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
autoClose[0] = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private StreamSerializer(XMLWriter writer) {
|
||||
this.writer = writer;
|
||||
// now delegate to the SaxSerializer
|
||||
serializer = new SaxSerializer(writer,writer,false);
|
||||
}
|
||||
|
||||
private String convertURL(String url) {
|
||||
url = url.replace('\\', '/');
|
||||
url = url.replaceAll("//","/");
|
||||
url = url.replaceAll("//","/");
|
||||
if (url.startsWith("file:/")) {
|
||||
if (url.substring(6).indexOf(":") > 0)
|
||||
url = url.substring(6);
|
||||
else
|
||||
url = url.substring(5);
|
||||
} // otherwise assume that it's a file name
|
||||
return url;
|
||||
}
|
||||
|
||||
// XmlSerializer api's - delegate to SaxSerializer
|
||||
public void startDocument() {
|
||||
serializer.startDocument();
|
||||
}
|
||||
|
||||
public void beginStartTag(String uri, String localName, String prefix) {
|
||||
serializer.beginStartTag(uri, localName, prefix);
|
||||
}
|
||||
|
||||
public void writeAttribute(String uri, String localName, String prefix, StringBuilder value) {
|
||||
serializer.writeAttribute(uri, localName, prefix, value);
|
||||
}
|
||||
|
||||
public void writeXmlns(String prefix, String uri) {
|
||||
serializer.writeXmlns(prefix, uri);
|
||||
}
|
||||
|
||||
public void endStartTag(String uri, String localName, String prefix) {
|
||||
serializer.endStartTag(uri, localName, prefix);
|
||||
}
|
||||
|
||||
public void endTag() {
|
||||
serializer.endTag();
|
||||
}
|
||||
|
||||
public void text(StringBuilder text) {
|
||||
serializer.text(text);
|
||||
}
|
||||
|
||||
public void cdata(StringBuilder text) {
|
||||
serializer.cdata(text);
|
||||
}
|
||||
|
||||
public void comment(StringBuilder comment) {
|
||||
serializer.comment(comment);
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
serializer.endDocument();
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
serializer.flush();
|
||||
try {
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
throw new TxwException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// other supporting code
|
||||
private static XMLWriter createWriter(Writer w) {
|
||||
// buffering improves the performance
|
||||
DataWriter dw = new DataWriter(new BufferedWriter(w));
|
||||
dw.setIndentStep(" ");
|
||||
return dw;
|
||||
}
|
||||
|
||||
private static XMLWriter createWriter(OutputStream os, String encoding) throws UnsupportedEncodingException {
|
||||
XMLWriter writer = createWriter(new OutputStreamWriter(os,encoding));
|
||||
writer.setEncoding(encoding);
|
||||
return writer;
|
||||
}
|
||||
|
||||
private static XMLWriter createWriter(OutputStream os) {
|
||||
try {
|
||||
return createWriter(os,"UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// UTF-8 is supported on all platforms.
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
66
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/TXWResult.java
Normal file
66
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/TXWResult.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import com.sun.xml.internal.txw2.TypedXmlWriter;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
/**
|
||||
* Allow you to wrap {@link TypedXmlWriter} into a {@link Result}
|
||||
* so that it can be passed to {@link ResultFactory}.
|
||||
*
|
||||
* <p>
|
||||
* This class doesn't extend from known {@link Result} type,
|
||||
* so it won't work elsewhere.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class TXWResult implements Result {
|
||||
private String systemId;
|
||||
|
||||
private TypedXmlWriter writer;
|
||||
|
||||
public TXWResult(TypedXmlWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public TypedXmlWriter getWriter() {
|
||||
return writer;
|
||||
}
|
||||
|
||||
public void setWriter(TypedXmlWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
public void setSystemId(String systemId) {
|
||||
this.systemId = systemId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import com.sun.xml.internal.txw2.TypedXmlWriter;
|
||||
import com.sun.xml.internal.txw2.TXW;
|
||||
|
||||
/**
|
||||
* Dummpy implementation to pass through {@link TypedXmlWriter}
|
||||
* to {@link TXW}
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class TXWSerializer implements XmlSerializer {
|
||||
public final TypedXmlWriter txw;
|
||||
|
||||
public TXWSerializer(TypedXmlWriter txw) {
|
||||
this.txw = txw;
|
||||
}
|
||||
|
||||
public void startDocument() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void beginStartTag(String uri, String localName, String prefix) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void writeAttribute(String uri, String localName, String prefix, StringBuilder value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void writeXmlns(String prefix, String uri) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void endStartTag(String uri, String localName, String prefix) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void endTag() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void text(StringBuilder text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void cdata(StringBuilder text) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void comment(StringBuilder comment) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
1075
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/XMLWriter.java
Normal file
1075
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/XMLWriter.java
Normal file
File diff suppressed because it is too large
Load Diff
152
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/XmlSerializer.java
Normal file
152
jdkSrc/jdk8/com/sun/xml/internal/txw2/output/XmlSerializer.java
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.txw2.output;
|
||||
|
||||
import com.sun.xml.internal.txw2.TypedXmlWriter;
|
||||
|
||||
|
||||
/**
|
||||
* Low-level typeless XML writer driven from {@link TypedXmlWriter}.
|
||||
*
|
||||
* <p>
|
||||
* Applications can use one of the predefined implementations to
|
||||
* send TXW output to the desired location/format, or they can
|
||||
* choose to implement this interface for custom output.
|
||||
*
|
||||
* <p>
|
||||
* One {@link XmlSerializer} instance is responsible for writing
|
||||
* one XML document.
|
||||
*
|
||||
* <h2>Call Sequence</h2>
|
||||
* TXW calls methods on this interface in the following order:
|
||||
*
|
||||
* <pre>
|
||||
* WHOLE_SEQUENCE := startDocument ELEMENT endDocument
|
||||
* ELEMENT := beginStartTag writeXmlns* writeAttribute* endStartTag CONTENT endTag
|
||||
* CONTENT := (text|ELEMENT)*
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* TXW maintains all the in-scope namespace bindings and prefix allocation.
|
||||
* The {@link XmlSerializer} implementation should just use the prefix
|
||||
* specified.
|
||||
* </p>
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface XmlSerializer {
|
||||
/**
|
||||
* The first method to be called.
|
||||
*/
|
||||
void startDocument();
|
||||
|
||||
/**
|
||||
* Begins writing a start tag.
|
||||
*
|
||||
* @param uri
|
||||
* the namespace URI of the element. Can be empty but never be null.
|
||||
* @param prefix
|
||||
* the prefix that should be used for this element. Can be empty,
|
||||
* but never null.
|
||||
*/
|
||||
void beginStartTag(String uri,String localName,String prefix);
|
||||
|
||||
/**
|
||||
* Writes an attribute.
|
||||
*
|
||||
* @param value
|
||||
* The value of the attribute. It's the callee's responsibility to
|
||||
* escape special characters (such as <, >, and &) in this buffer.
|
||||
*
|
||||
* @param uri
|
||||
* the namespace URI of the attribute. Can be empty but never be null.
|
||||
* @param prefix
|
||||
* the prefix that should be used for this attribute. Can be empty,
|
||||
* but never null.
|
||||
*/
|
||||
void writeAttribute(String uri,String localName,String prefix,StringBuilder value);
|
||||
|
||||
/**
|
||||
* Writes a namespace declaration.
|
||||
*
|
||||
* @param uri
|
||||
* the namespace URI to be declared. Can be empty but never be null.
|
||||
* @param prefix
|
||||
* the prefix that is allocated. Can be empty but never be null.
|
||||
*/
|
||||
void writeXmlns(String prefix,String uri);
|
||||
|
||||
/**
|
||||
* Completes the start tag.
|
||||
*
|
||||
* @param uri
|
||||
* the namespace URI of the element. Can be empty but never be null.
|
||||
* @param prefix
|
||||
* the prefix that should be used for this element. Can be empty,
|
||||
* but never null.
|
||||
*/
|
||||
void endStartTag(String uri,String localName,String prefix);
|
||||
|
||||
/**
|
||||
* Writes an end tag.
|
||||
*/
|
||||
void endTag();
|
||||
|
||||
/**
|
||||
* Writes PCDATA.
|
||||
*
|
||||
* @param text
|
||||
* The character data to be written. It's the callee's responsibility to
|
||||
* escape special characters (such as <, >, and &) in this buffer.
|
||||
*/
|
||||
void text(StringBuilder text);
|
||||
|
||||
/**
|
||||
* Writes CDATA.
|
||||
*/
|
||||
void cdata(StringBuilder text);
|
||||
|
||||
/**
|
||||
* Writes a comment.
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* if the writer doesn't support writing a comment, it can throw this exception.
|
||||
*/
|
||||
void comment(StringBuilder comment);
|
||||
|
||||
/**
|
||||
* The last method to be called.
|
||||
*/
|
||||
void endDocument();
|
||||
|
||||
/**
|
||||
* Flush the buffer.
|
||||
*
|
||||
* This method is called when applications invoke {@link TypedXmlWriter#commit(boolean)}
|
||||
* method. If the implementation performs any buffering, it should flush the buffer.
|
||||
*/
|
||||
void flush();
|
||||
}
|
||||
Reference in New Issue
Block a user