public abstract class XMLInputFactory
extends java.lang.Object
The class represents the factory for getting XMLStreamReader
intances.
The default implementation
automatically
recycles
any reader which has been
closed
.
Usage example:
// 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.
Modifier and Type | Field and Description |
---|---|
static Configurable<java.lang.Class<? extends XMLInputFactory>> |
CLASS
Holds the XMLInputFactory implementation (configurable).
|
static java.lang.String |
ENTITIES
Property used to specify additional entities to be recognized by the
readers (type:
java.util.Map , default: null ). |
static java.lang.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(java.io.InputStream stream)
Returns a XML stream reader for the specified input stream
(encoding autodetected).
|
abstract XMLStreamReader |
createXMLStreamReader(java.io.InputStream stream,
java.lang.String encoding)
Returns a XML stream reader for the specified input stream using the
specified encoding.
|
abstract XMLStreamReader |
createXMLStreamReader(java.io.Reader reader)
Returns a XML stream reader for the specified I/O reader.
|
abstract java.lang.Object |
getProperty(java.lang.String name)
Gets the value of a feature/property from the underlying implementation.
|
abstract boolean |
isPropertySupported(java.lang.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(java.lang.String name,
java.lang.Object value)
Allows the user to set specific feature/property on the underlying
implementation.
|
public static final Configurable<java.lang.Class<? extends XMLInputFactory>> CLASS
public static final java.lang.String IS_COALESCING
Boolean
, default: FALSE
)public static final java.lang.String ENTITIES
java.util.Map
, default: null
).
For example:
FastMap<String, String> HTML_ENTITIES = new FastMap<String, String>();
HTML_ENTITIES.put("nbsp", " ");
HTML_ENTITIES.put("copy", "©");
HTML_ENTITIES.put("eacute", "é");
...
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(ENTITIES, HTML_ENTITIES);
public 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(java.io.Reader reader) throws XMLStreamException
reader
- the XML data to read from.XMLStreamException
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream) throws XMLStreamException
stream
- the input stream to read from.XMLStreamException
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream, java.lang.String encoding) throws XMLStreamException
stream
- the input stream to read from.encoding
- the character encoding of the stream.XMLStreamException
public abstract void setProperty(java.lang.String name, java.lang.Object value) throws java.lang.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 propertyjava.lang.IllegalArgumentException
- if the property is not supported.public abstract java.lang.Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException
name
- the name of the property (may not be null).java.lang.IllegalArgumentException
- if the property is not supported.public abstract boolean isPropertySupported(java.lang.String name)
name
- the name of the property.true
if the property is supported;
false
otherwise.Copyright © 2005 - 2007 Javolution.