| |
|
| java.lang.Object javolution.xml.stream.XMLStreamReaderImpl
XMLStreamReaderImpl | final public class XMLStreamReaderImpl implements XMLStreamReader,Reusable(Code) | | This class represents a
javolution.lang.Reusable reusable implementation of
XMLStreamWriter .
Except for the types being used (
CharArray CharArray /
CharSequence CharSequence instead of
String ) the
parsing behavior is about the same as for the standard
javax.xml.stream.XMLStreamReader (although several times
faster).
The
CharArray CharArray instances returned by this reader
supports fast primitive conversions as illustrated below:[code]
// Creates reader for an input sream with unknown encoding.
XMLStreamReaderImpl xmlReader = new XMLStreamReaderImpl().setInput(inputStream);
// Parses.
for (int e=xmlReader.next(); e != XMLStreamConstants.END_DOCUMENT; e = xmlReader.next()) {
switch (e) { // Event.
case XMLStreamConstants.START_ELEMENT:
if (xmlReader.getLocalName().equals("Time")) {
// Reads primitive types (int) attributes directly.
int hour = xmlReader.getAttributeValue("hour").toInt();
int minute = xmlReader.getAttributeValue("minute").toInt();
int second = xmlReader.getAttributeValue("second").toInt();
...
}
...
break;
}
}
// Closes reader, it is automatically reset() and can be reused!
xmlReader.close();
[/code]
This reader returns all contiguous character data in a single
chunk (always coalescing). It is non-validating (DTD is returned
unparsed). Although, users may define custom entities mapping using
the
XMLStreamReaderImpl.setEntities method (e.g. after parsing/resolving
external entities).
author: Jean-Marie Dautelle version: 4.0, September 4, 2006 |
Method Summary | |
public void | close() | public int | getAttributeCount() | public CharArray | getAttributeLocalName(int index) | public CharArray | getAttributeNamespace(int index) | public CharArray | getAttributePrefix(int index) | public CharArray | getAttributeType(int index) | public CharArray | getAttributeValue(CharSequence uri, CharSequence localName) | public CharArray | getAttributeValue(int index) | public Attributes | getAttributes() Returns the current attributes (SAX2-Like). | public CharArray | getCharacterEncodingScheme() | public int | getDepth() Returns the current depth of the element. | public CharArray | getElementText() | public String | getEncoding() | public int | getEventType() | public CharArray | getLocalName() | public Location | getLocation() | public NamespaceContext | getNamespaceContext() | public int | getNamespaceCount() | public CharArray | getNamespacePrefix(int index) | public CharArray | getNamespaceURI(CharSequence prefix) | public CharArray | getNamespaceURI(int index) | public CharArray | getNamespaceURI() | public CharArray | getPIData() | public CharArray | getPITarget() | public CharArray | getPrefix() | public Object | getProperty(String name) | public CharArray | getQName() Returns the qualified name of the current event. | public CharArray | getText() | public char[] | getTextCharacters() | public int | getTextCharacters(int sourceStart, char[] target, int targetStart, int length) | public int | getTextLength() | public int | getTextStart() | public CharArray | getVersion() | public boolean | hasName() | public boolean | hasNext() | public boolean | hasText() | public boolean | isAttributeSpecified(int index) | public boolean | isCharacters() | public boolean | isEndElement() | public boolean | isStandalone() | public boolean | isStartElement() | public boolean | isWhiteSpace() | public int | next() | public int | nextTag() | public void | require(int type, CharSequence namespaceURI, CharSequence localName) | public void | reset() | public void | setEntities(Map entities) Defines a custom entities to replacement text mapping for this reader.
For example:[code]
FastMap HTML_ENTITIES = new FastMap();
HTML_ENTITIES.put("nbsp", " ");
HTML_ENTITIES.put("copy", "©");
HTML_ENTITIES.put("eacute", "é");
...
XMLStreamReaderImpl reader = new XMLStreamReaderImpl();
reader.setEntities(HTML_ENTITIES);
[/code]
The entities mapping may be changed dynamically (e.g. | public void | setInput(InputStream in) Sets the input stream source for this XML stream reader
(encoding retrieved from XML prolog if any). | public void | setInput(InputStream in, String encoding) Sets the input stream source and encoding for this XML stream reader. | public void | setInput(Reader reader) Sets the reader input source for this XML stream reader. | public boolean | standaloneSet() | public String | toString() Returns the textual representation of this reader current state. |
NAMES_OF_EVENTS | final static String[] NAMES_OF_EVENTS(Code) | | Holds the textual representation for events.
|
READER_BUFFER_CAPACITY | final static int READER_BUFFER_CAPACITY(Code) | | Holds the reader buffer capacity.
|
_charactersPending | boolean _charactersPending(Code) | | Indicates if characters are pending for potential coalescing.
|
XMLStreamReaderImpl | public XMLStreamReaderImpl()(Code) | | Default constructor.
|
getAttributeCount | public int getAttributeCount()(Code) | | |
getAttributeLocalName | public CharArray getAttributeLocalName(int index)(Code) | | |
getAttributeNamespace | public CharArray getAttributeNamespace(int index)(Code) | | |
getAttributes | public Attributes getAttributes()(Code) | | Returns the current attributes (SAX2-Like).
returns the number of attributes. throws: IllegalStateException - if not a START_ELEMENT. |
getCharacterEncodingScheme | public CharArray getCharacterEncodingScheme()(Code) | | |
getDepth | public int getDepth()(Code) | | Returns the current depth of the element. Outside the root element,
the depth is 0. The depth is incremented by 1 when a start tag is
reached. The depth is decremented AFTER the end tag event was observed.
[code]
0
1
sometext 1
2
2
1
0 [/code]
the nesting depth. |
getEventType | public int getEventType()(Code) | | |
getNamespaceCount | public int getNamespaceCount()(Code) | | |
getQName | public CharArray getQName()(Code) | | Returns the qualified name of the current event.
the qualified name. throws: IllegalStateException - if this not a START_ELEMENT or END_ELEMENT. |
getTextCharacters | public char[] getTextCharacters()(Code) | | |
getTextCharacters | public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException(Code) | | |
getTextLength | public int getTextLength()(Code) | | |
getTextStart | public int getTextStart()(Code) | | |
hasName | public boolean hasName()(Code) | | |
hasText | public boolean hasText()(Code) | | |
isAttributeSpecified | public boolean isAttributeSpecified(int index)(Code) | | |
isCharacters | public boolean isCharacters()(Code) | | |
isEndElement | public boolean isEndElement()(Code) | | |
isStandalone | public boolean isStandalone()(Code) | | |
isStartElement | public boolean isStartElement()(Code) | | |
isWhiteSpace | public boolean isWhiteSpace()(Code) | | |
reset | public void reset()(Code) | | |
setEntities | public void setEntities(Map entities)(Code) | | Defines a custom entities to replacement text mapping for this reader.
For example:[code]
FastMap HTML_ENTITIES = new FastMap();
HTML_ENTITIES.put("nbsp", " ");
HTML_ENTITIES.put("copy", "©");
HTML_ENTITIES.put("eacute", "é");
...
XMLStreamReaderImpl reader = new XMLStreamReaderImpl();
reader.setEntities(HTML_ENTITIES);
[/code]
The entities mapping may be changed dynamically (e.g.
after reading the DTD and all external entities references are resolved).
Parameters: entities - the entities to replacement texts mapping (both must be CharSequence instances). |
setInput | public void setInput(InputStream in) throws XMLStreamException(Code) | | Sets the input stream source for this XML stream reader
(encoding retrieved from XML prolog if any).
Parameters: in - the input source with unknown encoding. |
setInput | public void setInput(InputStream in, String encoding) throws XMLStreamException(Code) | | Sets the input stream source and encoding for this XML stream reader.
Parameters: in - the input source. Parameters: encoding - the associated encoding. |
standaloneSet | public boolean standaloneSet()(Code) | | |
toString | public String toString()(Code) | | Returns the textual representation of this reader current state.
the textual representation of the current state. |
|
|
|