286N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/A * This code is free software; you can redistribute it and/or modify it 286N/A * under the terms of the GNU General Public License version 2 only, as 286N/A * published by the Free Software Foundation. Oracle designates this 286N/A * particular file as subject to the "Classpath" exception as provided 286N/A * by Oracle in the LICENSE file that accompanied this code. 286N/A * This code is distributed in the hope that it will be useful, but WITHOUT 286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/A * version 2 for more details (a copy is included in the LICENSE file that 286N/A * accompanied this code). 286N/A * You should have received a copy of the GNU General Public License version 286N/A * 2 along with this work; if not, write to the Free Software Foundation, 286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A * or visit www.oracle.com if you need additional information or have any 286N/A * This class implements a StAX XMLStreamWriter. It extends 286N/A * <code>AbstractMap</code> in order to support a getter for 286N/A * implementation-specific properties. For example, you can get 286N/A * the underlying <code>OutputStream</code> by casting an instance 286N/A * of this class to <code>Map</code> and calling 286N/A * <code>getProperty(OUTPUTSTREAM_PROPERTY)</code>. 286N/A * @author Santiago.Pericas-Geertsen@sun.com 286N/A * @author Sunitha.Reddy@sun.com 286N/A * This flag can be used to turn escaping off for content. It does 286N/A * not apply to attribute content. 286N/A * Flag for the value of repairNamespace property 286N/A * Underlying Writer to which characters are written. 286N/A * Underlying OutputStream to which <code>fWriter</code> 286N/A * writes to. May be null if unknown. 286N/A * Collects attributes when the writer is in reparing mode. 286N/A * Collects namespace declarations when the writer is in reparing mode. 286N/A * Namespace context encapsulating user specified context 286N/A * and context built by the writer 286N/A * Reference to PropertyManager 286N/A * Flag to track if start tag is opened 286N/A * Boolean flag to indicate, if instance can be reused 286N/A * In some cases, this charset encoder is used to determine if a char is 286N/A * encodable by underlying writer. For example, an 8-bit char from the 286N/A * extended ASCII set is not encodable by 7-bit ASCII encoder. Unencodable 286N/A * chars are escaped using XML numeric entities. 286N/A * This is used to hold the namespace for attributes which happen to have 286N/A * the same uri as the default namespace; It's added to avoid changing the 286N/A * current impl. which has many redundant code for the repair mode 286N/A * Creates a new instance of XMLStreamWriterImpl. Uses platform's default 286N/A * @param outputStream Underlying stream to write the bytes to 286N/A * @param props Properties used by this writer 286N/A // cannot call this(outputStream, null, props); for constructor, 286N/A // OutputStreamWriter charsetName cannot be null 286N/A // use default encoding 286N/A * Creates a new instance of XMLStreamWriterImpl. 286N/A * @param outputStream Underlying stream to write the bytes 286N/A * @param encoding Encoding used to convert chars into bytes 286N/A * @param props Properties used by this writer 286N/A * Creates a new instance of XMLStreamWriterImpl using a Writer. 286N/A * @param writer Underlying writer to which chars are written 286N/A * @param props Properties used by this writer 286N/A * Creates a new instance of XMLStreamWriterImpl using a StreamResult. 286N/A * A StreamResult encasupates an OutputStream, a Writer or a SystemId. 286N/A * @param writer Underlying writer to which chars are written 286N/A * @param props Properties used by this writer 286N/A * Initialize an instance of this XMLStreamWriter. Allocate new instances 286N/A * for all the data structures. Set internal flags based on property values. 286N/A // Set internal state based on property values 286N/A * Reset this instance so that it can be re-used. Do not read properties 286N/A * again. The method <code>setOutput(StreamResult, encoding)</code> must 286N/A * be called after this one. 286N/A * Reset this instance so that it can be re-used. Clears but does not 286N/A * re-allocate internal data structures. 286N/A * @param resetProperties Indicates if properties should be read again 286N/A "close() Must be called before calling reset()");
286N/A * Use a StreamResult to initialize the output for this XMLStreamWriter. Check 286N/A * for OutputStream, Writer and then systemId, in that order. 286N/A * @param sr StreamResult encapsulating output information 286N/A * @param encoding Encoding to be used except when a Writer is available 286N/A * Utility method to create a writer when passed an OutputStream. Make 286N/A * sure to wrap an <code>OutputStreamWriter</code> using an 286N/A * <code>XMLWriter</code> for performance reasons. 286N/A * @param os Underlying OutputStream 286N/A * @param encoding Encoding used to convert chars into bytes 286N/A /** Can this instance be reused 286N/A * @return boolean boolean value to indicate if this instance can be reused or not 286N/A * Close this XMLStreamWriter by closing underlying writer. 286N/A * Flush this XMLStreamWriter by flushin underlying writer. 286N/A * Return <code>NamespaceContext</code> being used by the writer. 286N/A * @return NamespaceContext 286N/A * Return a prefix associated with specified uri, or null if the 286N/A * @param uri The namespace uri 286N/A * @throws XMLStreamException if uri specified is "" or null 286N/A * Returns value associated with the specified property name. 286N/A * @param str Property name 286N/A * @throws IllegalArgumentException if the specified property is not supported 286N/A * @return value associated with the specified property. 286N/A * Set the specified URI as default namespace in the current namespace context. 286N/A * @param uri Namespace URI 286N/A * Sets the current <code>NamespaceContext</code> for prefix and uri bindings. 286N/A * This context becomes the root namespace context for writing and 286N/A * will replace the current root namespace context. Subsequent calls 286N/A * to setPrefix and setDefaultNamespace will bind namespaces using 286N/A * the context passed to the method as the root context for resolving 286N/A * namespaces. This method may only be called once at the start of the 286N/A * document. It does not cause the namespaces to be declared. If a 286N/A * namespace URI to prefix mapping is found in the namespace context 286N/A * it is treated as declared and the prefix may be used by the 286N/A * <code>XMLStreamWriter</code>. 286N/A * @param namespaceContext the namespace context to use for this writer, may not be null 286N/A * @throws XMLStreamException 286N/A * Sets the prefix the uri is bound to. This prefix is bound in the scope of 286N/A * the current START_ELEMENT / END_ELEMENT pair. If this method is called before 286N/A * a START_ELEMENT has been written the prefix is bound in the root scope. 286N/A * @throws XMLStreamException 286N/A "Attribute not associated with any element");
286N/A true,
// true = escapeChars 286N/A true);
// true = escapeDoubleQuotes 286N/A "Attribute not associated with any element");
286N/A true,
// true = escapeChars 286N/A true);
// true = escapeDoubleQuotes 286N/A "Attribute not associated with any element");
286N/A * Write default Namespace. 286N/A * If namespaceURI == null, 286N/A * then it is assumed to be equivilent to {@link XMLConstants.NULL_NS_URI}, 286N/A * i.e. there is no Namespace. 286N/A * @param namespaceURI NamespaceURI to declare. 286N/A * @throws XMLStreamException 286N/A * Namespaces in XML, 5.2 Namespace Defaulting</a> 286N/A // normalize namespaceURI 286N/A "Namespace Attribute not associated with any element");
286N/A "xmlns has been already bound to " +
tmp +
286N/A // use common namespace code with a prefix == null for xmlns="..." 286N/A //fWriter.write(CLOSE_EMPTY_ELEMENT); 286N/A //fWriter.write(CLOSE_EMPTY_ELEMENT); 286N/A "No element was found to write: " 286N/A * Write a Namespace declaration. 286N/A * If namespaceURI == null, 286N/A * then it is assumed to be equivilent to {@link XMLConstants.NULL_NS_URI}, 286N/A * i.e. there is no Namespace. 286N/A * @param prefix Prefix to bind. 286N/A * @param namespaceURI NamespaceURI to declare. 286N/A * @throws XMLStreamException 286N/A * Namespaces in XML, 5.2 Namespace Defaulting</a> 286N/A // normalize namespaceURI 286N/A "Invalid state: start tag is not opened at writeNamespace(" 286N/A // is this the default Namespace? 286N/A true,
// true = escapeChars 286N/A true);
// true = escapeDoubleQuotes 286N/A * @throws XMLStreamException 286N/A * @throws XMLStreamException 286N/A * @throws XMLStreamException 286N/A //fWriter.write(DEFAULT_ENCODING); 286N/A * @throws XMLStreamException 286N/A //Revisit : What about standalone ? 286N/A // If the equality check failed, check for charset encoding aliases 286N/A // If no alias matches the encoding name, then report error 286N/A +
"' and input paramter for writeStartDocument() method '" 286N/A * @throws XMLStreamException 286N/A * @throws XMLStreamException 286N/A * @throws XMLStreamException 286N/A * Writes XML content to underlying writer. Escapes characters unless 286N/A * escaping character feature is turned off. 286N/A // Index of the next char to be written 286N/A // Escape this char as underlying encoder cannot handle it 286N/A // Write any pending data 286N/A false);
// false = escapeDoubleQuotes 286N/A * Writes XML content to underlying writer. Escapes characters unless 286N/A * escaping character feature is turned off. 286N/A // Index of the next char to be written 286N/A // Escape this char as underlying encoder cannot handle it 286N/A // Write any pending data 286N/A * marks close of start tag and writes the same into the writer. 286N/A * marks open of start tag and writes the same into the writer. 286N/A //the uri happens to be the same as that of the default namespace 286N/A for (
int i =
0; i <
1; i++) {
286N/A * return the prefix if the attribute has an uri the same as that of the default namespace 286N/A * Correct's namespaces as per requirements of isReparisingNamespace property. 286N/A /* If 'attr' is an attribute and it is in no namespace(which means that prefix="", uri=""), attr's 286N/A *If element and/or attribute names in the same start or empty-element tag 286N/A *are bound to different namespace URIs and are using the same prefix then 286N/A *the element or the first occurring attribute retains the original prefix 286N/A *and the following attributes have their prefixes replaced with a new prefix 286N/A *that is bound to the namespace URIs of those attributes. 286N/A //No namespace mapping found , so declare prefix. 286N/A for (
int k =
0; k <
1; k++) {
286N/A // QName.equals relies on identity equality, so we can't use it, 286N/A // because prefixes aren't interned 286N/A *If an element or attribute name is bound to a prefix and there is a namespace 286N/A *declaration that binds that prefix to a different URI then that namespace declaration 286N/A *is either removed if the correct mapping is inherited from the parent context of that element, 286N/A *or changed to the namespace URI of the element or attribute using that prefix. 286N/A //check for null prefix. 286N/A //see if you need to add to symbole table. 286N/A * Start of Internal classes. 286N/A /** The size of the stack. */ 286N/A /** Default constructor. */ 286N/A * Pushes an element on the stack. 286N/A * <strong>Note:</strong> The QName values are copied into the 286N/A * stack. In other words, the caller does <em>not</em> orphan 286N/A * the element to the stack. Also, the QName object returned 286N/A * is <em>not</em> orphaned to the caller. It should be 286N/A * considered read-only. 286N/A * @param element The element to push onto the stack. 286N/A * @return Returns the actual QName object that stores the 286N/A * Pops an element off of the stack by setting the values of 286N/A * <strong>Note:</strong> The object returned is <em>not</em> 286N/A * orphaned to the caller. Therefore, the caller should consider 286N/A * the object to be read-only. 286N/A /** Clears the stack without throwing away existing QName objects. */ 286N/A * This function is as a result of optimization done for endElement -- 286N/A * we dont need to set the value for every end element we encouter. 286N/A * For Well formedness checks we can have the same QName object that was pushed. 286N/A * the values will be set only if application need to know about the endElement 286N/A * -- neeraj.bajaj@sun.com 286N/A * Maintains element state . localName for now. 286N/A * Implementation of NamespaceContext . 286N/A //root namespace context set by user. 286N/A //context built by the writer. 286N/A // -- Map Interface -------------------------------------------------- 286N/A * Returns the value associated to an implementation-specific 286N/A * Overrides the method defined in AbstractMap which is 286N/A * not completely implemented. Calling toString() in 286N/A * AbstractMap would cause an unsupported exection to 286N/A * Overrides the method defined in AbstractMap 286N/A * This is required by the toString() method 286N/A * Overrides the method defined in AbstractMap 286N/A * This is required to satisfy the contract for hashCode.