286N/A/*
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A *
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 *
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 *
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 *
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 * questions.
286N/A */
286N/A
286N/A/*
286N/A * Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
286N/A */
286N/A
286N/Apackage javax.xml.stream;
286N/A
286N/Aimport javax.xml.transform.Result;
286N/A
286N/A/**
286N/A * Defines an abstract implementation of a factory for
286N/A * getting XMLEventWriters and XMLStreamWriters.
286N/A *
286N/A * The following table defines the standard properties of this specification.
286N/A * Each property varies in the level of support required by each implementation.
286N/A * The level of support required is described in the 'Required' column.
286N/A *
286N/A * <table border="2" rules="all" cellpadding="4">
286N/A * <thead>
286N/A * <tr>
286N/A * <th align="center" colspan="2">
286N/A * Configuration parameters
286N/A * </th>
286N/A * </tr>
286N/A * </thead>
286N/A * <tbody>
286N/A * <tr>
286N/A * <th>Property Name</th>
286N/A * <th>Behavior</th>
286N/A * <th>Return type</th>
286N/A * <th>Default Value</th>
286N/A * <th>Required</th>
286N/A * </tr>
286N/A * <tr><td>javax.xml.stream.isRepairingNamespaces</td><td>defaults prefixes on the output side</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
286N/A * </tbody>
286N/A * </table>
286N/A *
286N/A * <p>The following paragraphs describe the namespace and prefix repair algorithm:</p>
286N/A *
286N/A * <p>The property can be set with the following code line:
286N/A * <code>setProperty("javax.xml.stream.isRepairingNamespaces",new Boolean(true|false));</code></p>
286N/A *
286N/A * <p>This property specifies that the writer default namespace prefix declarations.
286N/A * The default value is false. </p>
286N/A *
286N/A * <p>If a writer isRepairingNamespaces it will create a namespace declaration
286N/A * on the current StartElement for
286N/A * any attribute that does not
286N/A * currently have a namespace declaration in scope. If the StartElement
286N/A * has a uri but no prefix specified a prefix will be assigned, if the prefix
286N/A * has not been declared in a parent of the current StartElement it will be declared
286N/A * on the current StartElement. If the defaultNamespace is bound and in scope
286N/A * and the default namespace matches the URI of the attribute or StartElement
286N/A * QName no prefix will be assigned.</p>
286N/A *
286N/A * <p>If an element or attribute name has a prefix, but is not
286N/A * bound to any namespace URI, then the prefix will be removed
286N/A * during serialization.</p>
286N/A *
286N/A * <p>If element and/or attribute names in the same start or
286N/A * empty-element tag are bound to different namespace URIs and
286N/A * are using the same prefix then the element or the first
286N/A * occurring attribute retains the original prefix and the
286N/A * following attributes have their prefixes replaced with a
286N/A * new prefix that is bound to the namespace URIs of those
286N/A * attributes. </p>
286N/A *
286N/A * <p>If an element or attribute name uses a prefix that is
286N/A * bound to a different URI than that inherited from the
286N/A * namespace context of the parent of that element and there
286N/A * is no namespace declaration in the context of the current
286N/A * element then such a namespace declaration is added. </p>
286N/A *
286N/A * <p>If an element or attribute name is bound to a prefix and
286N/A * there is a namespace declaration that binds that prefix
286N/A * to a different URI then that namespace declaration is
286N/A * either removed if the correct mapping is inherited from
286N/A * the parent context of that element, or changed to the
286N/A * namespace URI of the element or attribute using that prefix.</p>
286N/A *
286N/A * @version 1.2
286N/A * @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
286N/A * @see XMLInputFactory
286N/A * @see XMLEventWriter
286N/A * @see XMLStreamWriter
286N/A * @since 1.6
286N/A */
286N/Apublic abstract class XMLOutputFactory {
286N/A /**
286N/A * Property used to set prefix defaulting on the output side
286N/A */
286N/A public static final String IS_REPAIRING_NAMESPACES=
286N/A "javax.xml.stream.isRepairingNamespaces";
286N/A
286N/A static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
286N/A
286N/A protected XMLOutputFactory(){}
286N/A
286N/A /**
286N/A * Create a new instance of the factory.
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLOutputFactory newInstance()
286N/A throws FactoryConfigurationError
286N/A {
286N/A return (XMLOutputFactory) FactoryFinder.find("javax.xml.stream.XMLOutputFactory",
286N/A DEFAULIMPL);
286N/A }
286N/A
286N/A /**
286N/A * Create a new instance of the factory.
286N/A * This static method creates a new factory instance. This method uses the
286N/A * following ordered lookup procedure to determine the XMLOutputFactory
286N/A * implementation class to load:
286N/A * Use the javax.xml.stream.XMLOutputFactory system property.
286N/A * Use the properties file "lib/stax.properties" in the JRE directory.
286N/A * This configuration file is in standard java.util.Properties format
286N/A * and contains the fully qualified name of the implementation class
286N/A * with the key being the system property defined above.
286N/A * Use the Services API (as detailed in the JAR specification), if available,
286N/A * to determine the classname. The Services API will look for a classname
286N/A * in the file META-INF/services/javax.xml.stream.XMLOutputFactory in jars
286N/A * available to the runtime.
286N/A * Platform default XMLOutputFactory instance.
286N/A *
286N/A * Once an application has obtained a reference to a XMLOutputFactory it
286N/A * can use the factory to configure and obtain stream instances.
286N/A *
286N/A * Note that this is a new method that replaces the deprecated newInstance() method.
286N/A * No changes in behavior are defined by this replacement method relative to the
286N/A * deprecated method.
286N/A *
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLOutputFactory newFactory()
286N/A throws FactoryConfigurationError
286N/A {
286N/A return (XMLOutputFactory) FactoryFinder.find("javax.xml.stream.XMLOutputFactory",
286N/A DEFAULIMPL);
286N/A }
286N/A
286N/A /**
286N/A * Create a new instance of the factory.
286N/A *
286N/A * @param factoryId Name of the factory to find, same as
286N/A * a property name
286N/A * @param classLoader classLoader to use
286N/A * @return the factory implementation
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A *
286N/A * @deprecated This method has been deprecated because it returns an
286N/A * instance of XMLInputFactory, which is of the wrong class.
286N/A * Use the new method {@link #newFactory(java.lang.String,
286N/A * java.lang.ClassLoader)} instead.
286N/A */
286N/A public static XMLInputFactory newInstance(String factoryId,
286N/A ClassLoader classLoader)
286N/A throws FactoryConfigurationError {
286N/A try {
286N/A //do not fallback if given classloader can't find the class, throw exception
286N/A return (XMLInputFactory) FactoryFinder.find(factoryId, classLoader, null);
286N/A } catch (FactoryFinder.ConfigurationError e) {
286N/A throw new FactoryConfigurationError(e.getException(),
286N/A e.getMessage());
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Create a new instance of the factory.
286N/A * If the classLoader argument is null, then the ContextClassLoader is used.
286N/A *
286N/A * Note that this is a new method that replaces the deprecated
286N/A * newInstance(String factoryId, ClassLoader classLoader) method.
286N/A *
286N/A * No changes in behavior are defined by this replacement method relative
286N/A * to the deprecated method.
286N/A *
286N/A *
286N/A * @param factoryId Name of the factory to find, same as
286N/A * a property name
286N/A * @param classLoader classLoader to use
286N/A * @return the factory implementation
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLOutputFactory newFactory(String factoryId,
286N/A ClassLoader classLoader)
286N/A throws FactoryConfigurationError {
286N/A try {
286N/A //do not fallback if given classloader can't find the class, throw exception
286N/A return (XMLOutputFactory) FactoryFinder.find(factoryId, classLoader, null);
286N/A } catch (FactoryFinder.ConfigurationError e) {
286N/A throw new FactoryConfigurationError(e.getException(),
286N/A e.getMessage());
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Create a new XMLStreamWriter that writes to a writer
286N/A * @param stream the writer to write to
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamWriter that writes to a stream
286N/A * @param stream the stream to write to
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamWriter that writes to a stream
286N/A * @param stream the stream to write to
286N/A * @param encoding the encoding to use
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream,
286N/A String encoding) throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.
286N/A * @param result the result to write to
286N/A * @throws UnsupportedOperationException if this method is not
286N/A * supported by this XMLOutputFactory
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;
286N/A
286N/A
286N/A /**
286N/A * Create a new XMLEventWriter that writes to a JAXP result. This method is optional.
286N/A * @param result the result to write to
286N/A * @throws UnsupportedOperationException if this method is not
286N/A * supported by this XMLOutputFactory
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventWriter that writes to a stream
286N/A * @param stream the stream to write to
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream) throws XMLStreamException;
286N/A
286N/A
286N/A
286N/A /**
286N/A * Create a new XMLEventWriter that writes to a stream
286N/A * @param stream the stream to write to
286N/A * @param encoding the encoding to use
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream,
286N/A String encoding) throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventWriter that writes to a writer
286N/A * @param stream the stream to write to
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventWriter createXMLEventWriter(java.io.Writer stream) throws XMLStreamException;
286N/A
286N/A /**
286N/A * Allows the user to set specific features/properties on the underlying implementation.
286N/A * @param name The name of the property
286N/A * @param value The value of the property
286N/A * @throws java.lang.IllegalArgumentException if the property is not supported
286N/A */
286N/A public abstract void setProperty(java.lang.String name,
286N/A Object value)
286N/A throws IllegalArgumentException;
286N/A
286N/A /**
286N/A * Get a feature/property on the underlying implementation
286N/A * @param name The name of the property
286N/A * @return The value of the property
286N/A * @throws java.lang.IllegalArgumentException if the property is not supported
286N/A */
286N/A public abstract Object getProperty(java.lang.String name)
286N/A throws IllegalArgumentException;
286N/A
286N/A /**
286N/A * Query the set of properties that this factory supports.
286N/A *
286N/A * @param name The name of the property (may not be null)
286N/A * @return true if the property is supported and false otherwise
286N/A */
286N/A public abstract boolean isPropertySupported(String name);
286N/A}