@Parallelizable(comment="Factory configuration should be performed sequentially.") public interface XMLInputFactory extends Cloneable
The OSGi factory service to create XMLStreamReader instances.
For each bundle, a distinct factory instance is returned and can be
individually configured (if not enough the factory can be
cloned).
import javolution.xml.stream.*; public class Activator implements BundleActivator { public void start(BundleContext bc) throws Exception { // Configures factory. ServiceTracker<XMLInputFactory, XMLInputFactory> tracker = new ServiceTracker<>(bc, XMLInputFactory.class, null); tracker.open(); tracker.getService().setProperty(IS_COALESCING, true); // Instantiates a reader. String xml = "<test>This is a test</test>"; CharSequenceReader in = new CharSequenceReader().setInput(xml); XMLStreamReader reader = tracker.getService().createXMLStreamReader(in); // Parses XML. while (reader.hasNext()) { int eventType = reader.next(); if (eventType == XMLStreamConstants.CHARACTERS) { System.out.println(reader.getText()); } } // Closes the reader which may be recycled back to the factory. reader.close(); } }
| Modifier and Type | Field and Description |
|---|---|
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.
|
static String |
IS_VALIDATING
The property that requires the parser to validate the input data.
|
| Modifier and Type | Method and Description |
|---|---|
XMLInputFactory |
clone()
Returns a clone of this factory which can be independently configured.
|
XMLStreamReader |
createXMLStreamReader(InputStream stream)
Returns a XML stream reader for the specified input stream
(encoding autodetected).
|
XMLStreamReader |
createXMLStreamReader(InputStream stream,
String encoding)
Returns a XML stream reader for the specified input stream using the
specified encoding.
|
XMLStreamReader |
createXMLStreamReader(Reader reader)
Returns a XML stream reader for the specified I/O reader.
|
Object |
getProperty(String name)
Gets the value of a feature/property from the underlying implementation.
|
boolean |
isPropertySupported(String name)
Queries the set of properties that this factory supports.
|
void |
setProperty(String name,
Object value)
Allows the user to set specific feature/property on the underlying
implementation.
|
static final String IS_COALESCING
static final String IS_VALIDATING
static final 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 = factoryRef.getService();
factory.setProperty(ENTITIES, HTML_ENTITIES);
XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException
reader - the XML data to read from.XMLStreamExceptionXMLStreamReader createXMLStreamReader(InputStream stream) throws XMLStreamException
stream - the input stream to read from.XMLStreamExceptionXMLStreamReader createXMLStreamReader(InputStream stream, String encoding) throws XMLStreamException
stream - the input stream to read from.encoding - the character encoding of the stream.XMLStreamExceptionvoid 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.Object getProperty(String name) throws IllegalArgumentException
name - the name of the property (may not be null).IllegalArgumentException - if the property is not supported.boolean isPropertySupported(String name)
name - the name of the property.true if the property is supported;
false otherwise.XMLInputFactory clone()
Copyright © 2005-2013 Javolution. All Rights Reserved.