public abstract class XMLInputFactory extends Object
The class represents the factory for getting XMLStreamReader
intances.
The default implementation
automatically
recycles
any reader which has been
closed
.
Usage example:[code] // Lets read a CharSequence input. String xml = "..."; CharSequenceReader in = new CharSequenceReader().setInput(xml); // Creates a factory of readers coalescing adjacent character data. XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); // Creates a new reader (potentially recycled). XMLStreamReader reader = factory.createXMLStreamReader(in); // Parses XML. for (int e=reader.next(); e != XMLStreamConstants.END_DOCUMENT; e = reader.next()) { switch (e) { // Event. ... } } reader.close(); // Automatically recycles this writer. in.close(); // Underlying input should be closed explicitly. [/code]
Modifier and Type | Field and Description |
---|---|
static Configurable |
CLASS
Holds the XMLInputFactory implementation (configurable).
|
static String |
ENTITIES
Property used to specify additional entities to be recognized by the
readers (type:
java.util.Map , default: null ). |
static String |
IS_COALESCING
The property that requires the parser to coalesce adjacent character data
sections (type:
Boolean , default: FALSE ) |
Modifier | Constructor and Description |
---|---|
protected |
XMLInputFactory()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract XMLStreamReader |
createXMLStreamReader(InputStream stream)
Returns a XML stream reader for the specified input stream
(encoding autodetected).
|
abstract XMLStreamReader |
createXMLStreamReader(InputStream stream,
String encoding)
Returns a XML stream reader for the specified input stream using the
specified encoding.
|
abstract XMLStreamReader |
createXMLStreamReader(Reader reader)
Returns a XML stream reader for the specified I/O reader.
|
abstract Object |
getProperty(String name)
Gets the value of a feature/property from the underlying implementation.
|
abstract boolean |
isPropertySupported(String name)
Queries the set of properties that this factory supports.
|
static XMLInputFactory |
newInstance()
Returns a new instance of the
CLASS input factory
implementation which may be configurated by the user
(see setProperty(String, Object) ). |
abstract void |
setProperty(String name,
Object value)
Allows the user to set specific feature/property on the underlying
implementation.
|
public static final Configurable CLASS
public static final String IS_COALESCING
Boolean
, default: FALSE
)public static final String ENTITIES
java.util.Map
, default: null
).
For example:[code]
FastMappublic static XMLInputFactory newInstance()
CLASS
input factory
implementation which may be configurated by the user
(see setProperty(String, Object)
). The input factory
instance is allocated through ObjectFactory.getInstance(Class)
.public abstract XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException
reader
- the XML data to read from.XMLStreamException
public abstract XMLStreamReader createXMLStreamReader(InputStream stream) throws XMLStreamException
stream
- the input stream to read from.XMLStreamException
public abstract XMLStreamReader createXMLStreamReader(InputStream stream, String encoding) throws XMLStreamException
stream
- the input stream to read from.encoding
- the character encoding of the stream.XMLStreamException
public abstract void setProperty(String name, Object value) throws IllegalArgumentException
IllegalArgumentException
to signal that an unsupported
property may not be set with the specified value.name
- the name of the property.value
- the value of the propertyIllegalArgumentException
- if the property is not supported.public abstract Object getProperty(String name) throws IllegalArgumentException
name
- the name of the property (may not be null).IllegalArgumentException
- if the property is not supported.public abstract boolean isPropertySupported(String name)
name
- the name of the property.true
if the property is supported;
false
otherwise.Copyright © 2005–2017 Javolution. All rights reserved.