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.Source;
286N/Aimport javax.xml.stream.util.XMLEventAllocator;
286N/A
286N/A/**
286N/A * Defines an abstract implementation of a factory for getting streams.
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="5">
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.isValidating</td><td>Turns on/off implementation specific DTD validation</td><td>Boolean</td><td>False</td><td>No</td></tr>
286N/A * <tr><td>javax.xml.stream.isNamespaceAware</td><td>Turns on/off namespace processing for XML 1.0 support</td><td>Boolean</td><td>True</td><td>True (required) / False (optional)</td></tr>
286N/A * <tr><td>javax.xml.stream.isCoalescing</td><td>Requires the processor to coalesce adjacent character data</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
286N/A * <tr><td>javax.xml.stream.isReplacingEntityReferences</td><td>replace internal entity references with their replacement text and report them as characters</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
286N/A *<tr><td>javax.xml.stream.isSupportingExternalEntities</td><td>Resolve external parsed entities</td><td>Boolean</td><td>Unspecified</td><td>Yes</td></tr>
286N/A *<tr><td>javax.xml.stream.supportDTD</td><td>Use this property to request processors that do not support DTDs</td><td>Boolean</td><td>True</td><td>Yes</td></tr>
286N/A *<tr><td>javax.xml.stream.reporter</td><td>sets/gets the impl of the XMLReporter </td><td>javax.xml.stream.XMLReporter</td><td>Null</td><td>Yes</td></tr>
286N/A *<tr><td>javax.xml.stream.resolver</td><td>sets/gets the impl of the XMLResolver interface</td><td>javax.xml.stream.XMLResolver</td><td>Null</td><td>Yes</td></tr>
286N/A *<tr><td>javax.xml.stream.allocator</td><td>sets/gets the impl of the XMLEventAllocator interface</td><td>javax.xml.stream.util.XMLEventAllocator</td><td>Null</td><td>Yes</td></tr>
286N/A * </tbody>
286N/A * </table>
286N/A *
286N/A *
286N/A * @version 1.2
286N/A * @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
286N/A * @see XMLOutputFactory
286N/A * @see XMLEventReader
286N/A * @see XMLStreamReader
286N/A * @see EventFilter
286N/A * @see XMLReporter
286N/A * @see XMLResolver
286N/A * @see javax.xml.stream.util.XMLEventAllocator
286N/A * @since 1.6
286N/A */
286N/A
286N/Apublic abstract class XMLInputFactory {
286N/A /**
286N/A * The property used to turn on/off namespace support,
286N/A * this is to support XML 1.0 documents,
286N/A * only the true setting must be supported
286N/A */
286N/A public static final String IS_NAMESPACE_AWARE=
286N/A "javax.xml.stream.isNamespaceAware";
286N/A
286N/A /**
286N/A * The property used to turn on/off implementation specific validation
286N/A */
286N/A public static final String IS_VALIDATING=
286N/A "javax.xml.stream.isValidating";
286N/A
286N/A /**
286N/A * The property that requires the parser to coalesce adjacent character data sections
286N/A */
286N/A public static final String IS_COALESCING=
286N/A "javax.xml.stream.isCoalescing";
286N/A
286N/A /**
286N/A * Requires the parser to replace internal
286N/A * entity references with their replacement
286N/A * text and report them as characters
286N/A */
286N/A public static final String IS_REPLACING_ENTITY_REFERENCES=
286N/A "javax.xml.stream.isReplacingEntityReferences";
286N/A
286N/A /**
286N/A * The property that requires the parser to resolve external parsed entities
286N/A */
286N/A public static final String IS_SUPPORTING_EXTERNAL_ENTITIES=
286N/A "javax.xml.stream.isSupportingExternalEntities";
286N/A
286N/A /**
286N/A * The property that requires the parser to support DTDs
286N/A */
286N/A public static final String SUPPORT_DTD=
286N/A "javax.xml.stream.supportDTD";
286N/A
286N/A /**
286N/A * The property used to
286N/A * set/get the implementation of the XMLReporter interface
286N/A */
286N/A public static final String REPORTER=
286N/A "javax.xml.stream.reporter";
286N/A
286N/A /**
286N/A * The property used to set/get the implementation of the XMLResolver
286N/A */
286N/A public static final String RESOLVER=
286N/A "javax.xml.stream.resolver";
286N/A
286N/A /**
286N/A * The property used to set/get the implementation of the allocator
286N/A */
286N/A public static final String ALLOCATOR=
286N/A "javax.xml.stream.allocator";
286N/A
286N/A static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
286N/A
286N/A protected XMLInputFactory(){}
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 XMLInputFactory newInstance()
286N/A throws FactoryConfigurationError
286N/A {
286N/A return (XMLInputFactory) FactoryFinder.find(
286N/A "javax.xml.stream.XMLInputFactory",
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.
286N/A * This method uses the following ordered lookup procedure to determine
286N/A * the XMLInputFactory implementation class to load:
286N/A * Use the javax.xml.stream.XMLInputFactory 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.XMLInputFactory in jars
286N/A * available to the runtime.
286N/A * Platform default XMLInputFactory instance.
286N/A *
286N/A * Once an application has obtained a reference to a XMLInputFactory 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
286N/A * the deprecated method.
286N/A *
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLInputFactory newFactory()
286N/A throws FactoryConfigurationError
286N/A {
286N/A return (XMLInputFactory) FactoryFinder.find(
286N/A "javax.xml.stream.XMLInputFactory",
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 to maintain API consistency.
286N/A * All newInstance methods have been replaced with corresponding
286N/A * newFactory methods. The replacement {@link
286N/A * #newFactory(java.lang.String, java.lang.ClassLoader)} method
286N/A * defines no changes in behavior.
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 * No changes in behavior are defined by this replacement method relative
286N/A * to the deprecated method.
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 XMLInputFactory 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 (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 XMLStreamReader from a reader
286N/A * @param reader the XML data to read from
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamReader createXMLStreamReader(java.io.Reader reader)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamReader from a JAXP source. This method is optional.
286N/A * @param source the source to read from
286N/A * @throws UnsupportedOperationException if this method is not
286N/A * supported by this XMLInputFactory
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamReader createXMLStreamReader(Source source)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamReader from a java.io.InputStream
286N/A * @param stream the InputStream to read from
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamReader from a java.io.InputStream
286N/A * @param stream the InputStream to read from
286N/A * @param encoding the character encoding of the stream
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream, String encoding)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamReader from a java.io.InputStream
286N/A * @param systemId the system ID of the stream
286N/A * @param stream the InputStream to read from
286N/A */
286N/A public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.InputStream stream)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLStreamReader from a java.io.InputStream
286N/A * @param systemId the system ID of the stream
286N/A * @param reader the InputStream to read from
286N/A */
286N/A public abstract XMLStreamReader createXMLStreamReader(String systemId, java.io.Reader reader)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from a reader
286N/A * @param reader the XML data to read from
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(java.io.Reader reader)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from a reader
286N/A * @param systemId the system ID of the input
286N/A * @param reader the XML data to read from
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(String systemId, java.io.Reader reader)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from an XMLStreamReader. After being used
286N/A * to construct the XMLEventReader instance returned from this method
286N/A * the XMLStreamReader must not be used.
286N/A * @param reader the XMLStreamReader to read from (may not be modified)
286N/A * @return a new XMLEventReader
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(XMLStreamReader reader)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from a JAXP source.
286N/A * Support of this method is optional.
286N/A * @param source the source to read from
286N/A * @throws UnsupportedOperationException if this method is not
286N/A * supported by this XMLInputFactory
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(Source source)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from a java.io.InputStream
286N/A * @param stream the InputStream to read from
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from a java.io.InputStream
286N/A * @param stream the InputStream to read from
286N/A * @param encoding the character encoding of the stream
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a new XMLEventReader from a java.io.InputStream
286N/A * @param systemId the system ID of the stream
286N/A * @param stream the InputStream to read from
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createXMLEventReader(String systemId, java.io.InputStream stream)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a filtered reader that wraps the filter around the reader
286N/A * @param reader the reader to filter
286N/A * @param filter the filter to apply to the reader
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * Create a filtered event reader that wraps the filter around the event reader
286N/A * @param reader the event reader to wrap
286N/A * @param filter the filter to apply to the event reader
286N/A * @throws XMLStreamException
286N/A */
286N/A public abstract XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
286N/A throws XMLStreamException;
286N/A
286N/A /**
286N/A * The resolver that will be set on any XMLStreamReader or XMLEventReader created
286N/A * by this factory instance.
286N/A */
286N/A public abstract XMLResolver getXMLResolver();
286N/A
286N/A /**
286N/A * The resolver that will be set on any XMLStreamReader or XMLEventReader created
286N/A * by this factory instance.
286N/A * @param resolver the resolver to use to resolve references
286N/A */
286N/A public abstract void setXMLResolver(XMLResolver resolver);
286N/A
286N/A /**
286N/A * The reporter that will be set on any XMLStreamReader or XMLEventReader created
286N/A * by this factory instance.
286N/A */
286N/A public abstract XMLReporter getXMLReporter();
286N/A
286N/A /**
286N/A * The reporter that will be set on any XMLStreamReader or XMLEventReader created
286N/A * by this factory instance.
286N/A * @param reporter the resolver to use to report non fatal errors
286N/A */
286N/A public abstract void setXMLReporter(XMLReporter reporter);
286N/A
286N/A /**
559N/A * Allows the user to set specific feature/property on the underlying
559N/A * implementation. The underlying implementation is not required to support
559N/A * every setting of every property in the specification and may use
559N/A * IllegalArgumentException to signal that an unsupported property may not be
559N/A * set with the specified value.
559N/A * <p>
559N/A * All implementations that implement JAXP 1.5 or newer are required to
559N/A * support the {@link javax.xml.XMLConstants#ACCESS_EXTERNAL_DTD} property.
559N/A * </p>
559N/A * <ul>
559N/A * <li>
559N/A * <p>
559N/A * Access to external DTDs, external Entity References is restricted to the
559N/A * protocols specified by the property. If access is denied during parsing
559N/A * due to the restriction of this property, {@link javax.xml.stream.XMLStreamException}
559N/A * will be thrown by the {@link javax.xml.stream.XMLStreamReader#next()} or
559N/A * {@link javax.xml.stream.XMLEventReader#nextEvent()} method.
559N/A * </p>
559N/A * </li>
559N/A * </ul>
286N/A * @param name The name of the property (may not be null)
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, Object value)
286N/A throws java.lang.IllegalArgumentException;
286N/A
286N/A /**
286N/A * Get the value of a feature/property from the underlying implementation
286N/A * @param name The name of the property (may not be null)
286N/A * @return The value of the property
286N/A * @throws IllegalArgumentException if the property is not supported
286N/A */
286N/A public abstract Object getProperty(java.lang.String name)
286N/A throws java.lang.IllegalArgumentException;
286N/A
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
286N/A /**
286N/A * Set a user defined event allocator for events
286N/A * @param allocator the user defined allocator
286N/A */
286N/A public abstract void setEventAllocator(XMLEventAllocator allocator);
286N/A
286N/A /**
286N/A * Gets the allocator used by streams created with this factory
286N/A */
286N/A public abstract XMLEventAllocator getEventAllocator();
286N/A
286N/A}