|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.idoox.xml.TokenizerWrapper
This class helps you to wrap Tokenizer
s. If you want to process
XML messages in stream-based manner you need to wrap
Tokenizer
s. With help of this class wrapping of
Tokenizer
s is really simple.
To wrap Tokenizer
you have to subclass this class.
Usually it is sufficient to override only next()
but you can
override any other method.
Here is an example of Tokenizer
that leaves the first
element from the wrapped Tokenizer
.
//overriden next() method - public byte next() throws TokenizerException, IOException { // ask TokenizerWrapper for the next Token byte next = super.next(); switch (next) { // check the start Tokens case START_TOKEN: // if it is first Element, leave it and increment depth if (depth == 0) { depth++; super.next(); } depth++; break; case END_TOKEN: depth--; // if it is last Element, leave it and decrement depth if (depth == 1) { super.next(); } break; } return next; }
Nested Class Summary | |
static class |
TokenizerWrapper.DefaultTokenizerState
This is default implementation of internal tokenizers state. |
static interface |
TokenizerWrapper.TokenizerState
This interface represents internal state of TokenizerWrapper . |
Field Summary |
Fields inherited from interface org.idoox.xml.Tokenizer |
CONTENT, END_DOCUMENT, END_TOKEN, START_TOKEN, typeNames, UNKNOWN |
Constructor Summary | |
TokenizerWrapper(Tokenizer tokenizer)
Creates new wrapper above the specified Tokenizer |
Method Summary | |
byte |
currentState()
Returns the current state of the tokenizer. |
java.util.Map |
getCurrentPrefixMap()
Returns clone of the current prefix map. |
protected TokenizerWrapper.TokenizerState |
getCurrentState()
Returns the current state of the Tokenizer . |
org.w3c.dom.Element |
getDOMRepresentation(org.w3c.dom.Document doc)
Returns DOM representation of the element that is being parsed. |
static org.w3c.dom.Element |
getDOMRepresentation(Tokenizer tokenizer,
org.w3c.dom.Document doc)
|
java.lang.String |
getLocalName()
Returns the local name of the current element. |
java.lang.String |
getNamespace()
Returns the namespace URI of the current element. |
java.lang.String |
getNamespaceForPrefix(java.lang.String prefix)
Returns a namespace URI for a declared prefix. |
protected Tokenizer |
getTokenizer()
Gets underlying Tokenizer . |
byte |
next()
Clears current state of tokenizer wrapper and calls Tokenizer.next() on underlying tokenizer. |
static byte |
nextElement(Tokenizer tokenizer)
Moves Tokenizer to next element - start or end (START_TOKEN, END_TOKEN or END_DOCUMENT). |
static byte |
nextSibling(Tokenizer source)
Moves Tokenizer to next sibling (START_TOKEN). |
QName |
parseQName(java.lang.String qName)
Parses qName in the context of the opened element and returns the pair (namespaceURI, localName). |
int |
pushNewlyDeclaredPrefixes(DeclaredPrefixesStack prefixes)
Adds prefixes newly declared in this token. |
java.lang.String |
readContent()
Reads the content (PCDATA, CDATA). |
void |
readToken(Token stoken)
Reads the start/end of an element. |
protected void |
setCurrentContent(java.lang.String content)
Set current state of tokenizer wrapper. |
protected void |
setCurrentState(TokenizerWrapper.TokenizerState state)
Sets the current state of the Tokenizer . |
protected void |
setCurrentToken(Token currentToken)
Set current state of tokenizer wrapper. |
protected void |
setCurrentToken(Token currentToken,
java.util.Map prefixMap,
java.lang.String[] newPrefixes)
Set current state of tokenizer wrapper. |
protected void |
setTokenizer(Tokenizer tokenizer)
Sets underlying Tokenizer . |
static java.lang.String |
tokenToString(byte token)
|
boolean |
whitespaceContent()
Returns true if the content contains only whitespaces. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TokenizerWrapper(Tokenizer tokenizer)
Tokenizer
tokenizer
- Tokenizer
that will be wrappedMethod Detail |
protected TokenizerWrapper.TokenizerState getCurrentState()
Tokenizer
.
If the state is NULL
TokenizerWrapper
will forward all the functions to the underlying
Tokenizer
. If it is not NULL
it will
be used to implement functions inherited from Tokenizer
.
TokenizerWrapper
protected void setCurrentState(TokenizerWrapper.TokenizerState state)
Tokenizer
.
If the state is NULL
TokenizerWrapper
will forward all the functions to the underlying
Tokenizer
. If it is not NULL
it will
be used to implement functions inherited from Tokenizer
.
state
- new current state of TokenizerWrapper
protected void setCurrentToken(Token currentToken)
setCurrentState(new DefaultTokenizerState(currentToken));
currentToken
- tokenDefaultTokenizerState#DefaultTokenizerState
protected void setCurrentContent(java.lang.String content)
setCurrentState(new DefaultTokenizerState(content));
content
- contentDefaultTokenizerState#DefaultTokenizerState
protected void setCurrentToken(Token currentToken, java.util.Map prefixMap, java.lang.String[] newPrefixes)
setCurrentState(new DefaultTokenizerState(currentToken,prefixMap,newPrefixes));
currentToken
- tokenprefixMap
- namespace declarationsnewPrefixes
- newly declared prefixesDefaultTokenizerState#DefaultTokenizerState
protected Tokenizer getTokenizer()
Tokenizer
.
Tokenizer
.protected void setTokenizer(Tokenizer tokenizer)
Tokenizer
.
tokenizer
- new underlying Tokenizer
.public java.lang.String getLocalName() throws TokenizerException
Tokenizer
getLocalName
in interface Tokenizer
TokenizerException
- if the tokenizer is not on the START_TOKENpublic java.lang.String getNamespace() throws TokenizerException
Tokenizer
getNamespace
in interface Tokenizer
TokenizerException
- if the tokenizer is not on the START_TOKENpublic java.lang.String getNamespaceForPrefix(java.lang.String prefix)
Tokenizer
getNamespaceForPrefix
in interface Tokenizer
prefix
- the declared prefix
public org.w3c.dom.Element getDOMRepresentation(org.w3c.dom.Document doc) throws TokenizerException
Tokenizer
getDOMRepresentation
in interface Tokenizer
doc
- the document within which the element should be created
TokenizerException
- if there is an error in
tokenizing the XML documentpublic static org.w3c.dom.Element getDOMRepresentation(Tokenizer tokenizer, org.w3c.dom.Document doc) throws TokenizerException
TokenizerException
public QName parseQName(java.lang.String qName)
Tokenizer
parseQName
in interface Tokenizer
qName
- the qualified name
public byte next() throws TokenizerException, java.io.IOException
Tokenizer.next()
on underlying tokenizer.
You should override this function to change underlying
tokenizer.
next
in interface Tokenizer
TokenizerException
- if there is an error in the XML
document or the tokenizer is beyond the end of the document (the
previous call to next()
has returned END_DOCUMENT).
java.io.IOException
- if some IOException has occuredpublic static byte nextElement(Tokenizer tokenizer) throws java.io.IOException, TokenizerException
tokenizer
- Tokenizer to move
java.io.IOException
TokenizerException
public static byte nextSibling(Tokenizer source) throws TokenizerException, java.io.IOException, java.lang.IllegalStateException
source
-
TokenizerException
java.io.IOException
java.lang.IllegalStateException
- If Tokenizer is not on the start of an element
(START_TOKEN) IllegalStateException is thrown.public byte currentState()
Tokenizer
Tokenizer.next()
for details.
currentState
in interface Tokenizer
public java.lang.String readContent() throws TokenizerException
Tokenizer
readContent
in interface Tokenizer
TokenizerException
- if the tokenizer is not in CONTENT statepublic void readToken(Token stoken) throws TokenizerException, java.io.IOException
Tokenizer
stoken
. This function may be called only if the tokenizer
is on START_TOKEN or END_TOKEN.
readToken
in interface Tokenizer
stoken
- structure containing name, namespace URI and attribute pairs; holder for result
java.io.IOException
- if there was an error reading the input document
TokenizerException
- if the tokenizer is not in START_TOKEN, END_TOKEN or the document is not a well-formed XML.public boolean whitespaceContent() throws TokenizerException
Tokenizer
whitespaceContent
in interface Tokenizer
TokenizerException
- if the tokenizer is not in CONTENT statepublic java.util.Map getCurrentPrefixMap()
Tokenizer
getCurrentPrefixMap
in interface Tokenizer
public int pushNewlyDeclaredPrefixes(DeclaredPrefixesStack prefixes)
Tokenizer
pushNewlyDeclaredPrefixes
in interface Tokenizer
prefixes
- the newly declared prefixes
public static java.lang.String tokenToString(byte token)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |