APIdia Launch Partner
Top Description Fields Constructors Methods
javax.xml.stream

public abstract Class XMLOutputFactory

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.xml.internal.stream.XMLOutputFactoryImpl
Imports
com.sun.xml.internal.stream.XMLOutputFactoryImpl, javax.xml.transform.Result

Defines an abstract implementation of a factory for getting XMLEventWriters and XMLStreamWriters. The following table defines the standard properties of this specification. Each property varies in the level of support required by each implementation. The level of support required is described in the 'Required' column.
Configuration Parameters
Property Name Behavior Return type Default Value Required
javax.xml.stream.isRepairingNamespacesdefaults prefixes on the output sideBooleanFalseYes

The following paragraphs describe the namespace and prefix repair algorithm:

The property can be set with the following code line: setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);

This property specifies that the writer default namespace prefix declarations. The default value is false.

If a writer isRepairingNamespaces it will create a namespace declaration on the current StartElement for any attribute that does not currently have a namespace declaration in scope. If the StartElement has a uri but no prefix specified a prefix will be assigned, if the prefix has not been declared in a parent of the current StartElement it will be declared on the current StartElement. If the defaultNamespace is bound and in scope and the default namespace matches the URI of the attribute or StartElement QName no prefix will be assigned.

If an element or attribute name has a prefix, but is not bound to any namespace URI, then the prefix will be removed during serialization.

If element and/or attribute names in the same start or empty-element tag are bound to different namespace URIs and are using the same prefix then the element or the first occurring attribute retains the original prefix and the following attributes have their prefixes replaced with a new prefix that is bound to the namespace URIs of those attributes.

If an element or attribute name uses a prefix that is bound to a different URI than that inherited from the namespace context of the parent of that element and there is no namespace declaration in the context of the current element then such a namespace declaration is added.

If an element or attribute name is bound to a prefix and there is a namespace declaration that binds that prefix to a different URI then that namespace declaration is either removed if the correct mapping is inherited from the parent context of that element, or changed to the namespace URI of the element or attribute using that prefix.

Author
Copyright (c) 2009, 2015 by Oracle Corporation. All Rights Reserved.
Since
1.6
Version
1.2
See Also
XMLInputFactory, XMLEventWriter, XMLStreamWriter

Field Summary

Modifier and TypeField and Description
pack-priv static final String
public static final String
IS_REPAIRING_NAMESPACES

Property used to set prefix defaulting on the output side

Constructor Summary

AccessConstructor and Description
protected
XMLOutputFactory()

Protected constructor to prevent instantiation.

Method Summary

Modifier and TypeMethod and Description
public abstract XMLEventWriter

Returns:

instance of the XMLEventWriter
createXMLEventWriter
(Result
the result to write to
result
)

Create a new XMLEventWriter that writes to a JAXP result.

public abstract XMLEventWriter

Returns:

instance of the XMLEventWriter
createXMLEventWriter
(OutputStream
the stream to write to
stream
)

Create a new XMLEventWriter that writes to a stream

public abstract XMLEventWriter

Returns:

instance of the XMLEventWriter
createXMLEventWriter
(OutputStream
the stream to write to
stream
,
String
the encoding to use
encoding
)

Create a new XMLEventWriter that writes to a stream

public abstract XMLEventWriter

Returns:

instance of the XMLEventWriter
createXMLEventWriter
(Writer
the stream to write to
stream
)

Create a new XMLEventWriter that writes to a writer

public abstract XMLStreamWriter

Returns:

instance of the XMLStreamWriter
createXMLStreamWriter
(Writer
the writer to write to
stream
)

Create a new XMLStreamWriter that writes to a writer

public abstract XMLStreamWriter

Returns:

instance of the XMLStreamWriter
createXMLStreamWriter
(OutputStream
the stream to write to
stream
)

Create a new XMLStreamWriter that writes to a stream

public abstract XMLStreamWriter

Returns:

instance of the XMLStreamWriter
createXMLStreamWriter
(OutputStream
the stream to write to
stream
,
String
the encoding to use
encoding
)

Create a new XMLStreamWriter that writes to a stream

public abstract XMLStreamWriter

Returns:

instance of the XMLStreamWriter
createXMLStreamWriter
(Result
the result to write to
result
)

Create a new XMLStreamWriter that writes to a JAXP result.

public abstract Object

Returns:

The value of the property
getProperty
(String
The name of the property
name
)

Get a feature/property on the underlying implementation

public abstract boolean

Returns:

true if the property is supported and false otherwise
isPropertySupported
(String
The name of the property (may not be null)
name
)

Query the set of properties that this factory supports.

public static XMLOutputFactory

Returns:

A new instance of the XMLOutputFactory builtin system-default implementation.
newDefaultFactory
()

Creates a new instance of the XMLOutputFactory builtin system-default implementation.

public static XMLOutputFactory

Returns:

an instance of the XMLOutputFactory
newFactory
()

Creates a new instance of the factory.

public static XMLOutputFactory

Returns:

the factory implementation
newFactory
(String
Name of the factory to find, same as a property name
factoryId
,
ClassLoader
classLoader to use
classLoader
)

Create a new instance of the factory.

public static XMLOutputFactory

Returns:

an instance of the XMLOutputFactory
newInstance
()

Creates a new instance of the factory in exactly the same manner as the newFactory() method.

public static XMLInputFactory

Returns:

the factory implementation
newInstance
(String
Name of the factory to find, same as a property name
factoryId
,
ClassLoader
classLoader to use
classLoader
)
Deprecated since 1.7. This method has been deprecated because it returns an instance of XMLInputFactory, which is of the wrong class.

Create a new instance of the factory.

public abstract void
setProperty(String
The name of the property
name
,
Object
The value of the property
value
)

Allows the user to set specific features/properties on the underlying implementation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULIMPLback to summary
pack-priv static final String DEFAULIMPL
IS_REPAIRING_NAMESPACESback to summary
public static final String IS_REPAIRING_NAMESPACES

Property used to set prefix defaulting on the output side

Constructor Detail

XMLOutputFactoryback to summary
protected XMLOutputFactory()

Protected constructor to prevent instantiation. Use newFactory() instead.

Method Detail

createXMLEventWriterback to summary
public abstract XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException

Create a new XMLEventWriter that writes to a JAXP result. This method is optional.

Parameters
result:Result

the result to write to

Returns:XMLEventWriter

instance of the XMLEventWriter

Exceptions
XMLStreamException:
if an error occurs
UnsupportedOperationException:
if this method is not supported by this XMLOutputFactory
createXMLEventWriterback to summary
public abstract XMLEventWriter createXMLEventWriter(OutputStream stream) throws XMLStreamException

Create a new XMLEventWriter that writes to a stream

Parameters
stream:OutputStream

the stream to write to

Returns:XMLEventWriter

instance of the XMLEventWriter

Exceptions
XMLStreamException:
if an error occurs
createXMLEventWriterback to summary
public abstract XMLEventWriter createXMLEventWriter(OutputStream stream, String encoding) throws XMLStreamException

Create a new XMLEventWriter that writes to a stream

Parameters
stream:OutputStream

the stream to write to

encoding:String

the encoding to use

Returns:XMLEventWriter

instance of the XMLEventWriter

Exceptions
XMLStreamException:
if an error occurs
createXMLEventWriterback to summary
public abstract XMLEventWriter createXMLEventWriter(Writer stream) throws XMLStreamException

Create a new XMLEventWriter that writes to a writer

Parameters
stream:Writer

the stream to write to

Returns:XMLEventWriter

instance of the XMLEventWriter

Exceptions
XMLStreamException:
if an error occurs
createXMLStreamWriterback to summary
public abstract XMLStreamWriter createXMLStreamWriter(Writer stream) throws XMLStreamException

Create a new XMLStreamWriter that writes to a writer

Parameters
stream:Writer

the writer to write to

Returns:XMLStreamWriter

instance of the XMLStreamWriter

Exceptions
XMLStreamException:
if an error occurs
createXMLStreamWriterback to summary
public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream) throws XMLStreamException

Create a new XMLStreamWriter that writes to a stream

Parameters
stream:OutputStream

the stream to write to

Returns:XMLStreamWriter

instance of the XMLStreamWriter

Exceptions
XMLStreamException:
if an error occurs
createXMLStreamWriterback to summary
public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding) throws XMLStreamException

Create a new XMLStreamWriter that writes to a stream

Parameters
stream:OutputStream

the stream to write to

encoding:String

the encoding to use

Returns:XMLStreamWriter

instance of the XMLStreamWriter

Exceptions
XMLStreamException:
if an error occurs
createXMLStreamWriterback to summary
public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException

Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.

Parameters
result:Result

the result to write to

Returns:XMLStreamWriter

instance of the XMLStreamWriter

Exceptions
XMLStreamException:
if an error occurs
UnsupportedOperationException:
if this method is not supported by this XMLOutputFactory
getPropertyback to summary
public abstract Object getProperty(String name) throws IllegalArgumentException

Get a feature/property on the underlying implementation

Parameters
name:String

The name of the property

Returns:Object

The value of the property

Exceptions
IllegalArgumentException:
if the property is not supported
isPropertySupportedback to summary
public abstract boolean isPropertySupported(String name)

Query the set of properties that this factory supports.

Parameters
name:String

The name of the property (may not be null)

Returns:boolean

true if the property is supported and false otherwise

newDefaultFactoryback to summary
public static XMLOutputFactory newDefaultFactory()

Creates a new instance of the XMLOutputFactory builtin system-default implementation.

Returns:XMLOutputFactory

A new instance of the XMLOutputFactory builtin system-default implementation.

Since
9
newFactoryback to summary
public static XMLOutputFactory newFactory() throws FactoryConfigurationError

Creates a new instance of the factory. This method uses the JAXP Lookup Mechanism to determine the XMLOutputFactory implementation class to load.

Once an application has obtained a reference to a XMLOutputFactory, it can use the factory to configure and obtain stream instances.

Returns:XMLOutputFactory

an instance of the XMLOutputFactory

Exceptions
FactoryConfigurationError:
in case of service configuration error or if the implementation is not available or cannot be instantiated.
newFactoryback to summary
public static XMLOutputFactory newFactory(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError

Create a new instance of the factory. If the classLoader argument is null, then the ContextClassLoader is used.

This method uses the following ordered lookup procedure to determine the XMLOutputFactory implementation class to load:

  • Use the value of the system property identified by factoryId.
  • Use the value of the property factoryId set in the configuration file, jaxp.properties by default. If the file exists and the property factoryId is specified in the file, its value will be used as the implementation class.

  • If factoryId is "javax.xml.stream.XMLOutputFactory", use the service-provider loading facility, defined by the java.util.ServiceLoader class, to attempt to locate and load an implementation of the service using the specified ClassLoader. If classLoader is null, the default loading mechanism will apply: That is, the service-provider loading facility will use the current thread's context class loader to attempt to load the service. If the context class loader is null, the system class loader will be used.

  • Otherwise, throws a FactoryConfigurationError.

API Note

The parameter factoryId defined here is inconsistent with that of other JAXP factories where the first parameter is fully qualified factory class name that provides implementation of the factory.

Note that this is a new method that replaces the deprecated newInstance(String factoryId, ClassLoader classLoader) method. The original method was incorrectly defined to return XMLInputFactory.

Parameters
factoryId:String

Name of the factory to find, same as a property name

classLoader:ClassLoader

classLoader to use

Returns:XMLOutputFactory

the factory implementation

Exceptions
FactoryConfigurationError:
in case of service configuration error or if the implementation is not available or cannot be instantiated.
newInstanceback to summary
public static XMLOutputFactory newInstance() throws FactoryConfigurationError

Creates a new instance of the factory in exactly the same manner as the newFactory() method.

Returns:XMLOutputFactory

an instance of the XMLOutputFactory

Exceptions
FactoryConfigurationError:
if an instance of this factory cannot be loaded
newInstanceback to summary
public static XMLInputFactory newInstance(String factoryId, ClassLoader classLoader) throws FactoryConfigurationError

Deprecated

since 1.7.

This method has been deprecated because it returns an instance of XMLInputFactory, which is of the wrong class. Use the new method newFactory(java.lang.String, java.lang.ClassLoader) instead.

Create a new instance of the factory.

Parameters
factoryId:String

Name of the factory to find, same as a property name

classLoader:ClassLoader

classLoader to use

Returns:XMLInputFactory

the factory implementation

Annotations
@Deprecated
since:1.7
Exceptions
FactoryConfigurationError:
if an instance of this factory cannot be loaded
setPropertyback to summary
public abstract void setProperty(String name, Object value) throws IllegalArgumentException

Allows the user to set specific features/properties on the underlying implementation.

Parameters
name:String

The name of the property

value:Object

The value of the property

Exceptions
IllegalArgumentException:
if the property is not supported