|
||||||||||
| 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 Tokenizers. If you want to process
XML messages in stream-based manner you need to wrap
Tokenizers. With help of this class wrapping of
Tokenizers 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 wrapped| Method 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.
TokenizerWrapperprotected 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 TokenizerWrapperprotected void setCurrentToken(Token currentToken)
setCurrentState(new DefaultTokenizerState(currentToken));
currentToken - tokenDefaultTokenizerState#DefaultTokenizerStateprotected 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#DefaultTokenizerStateprotected 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 TokenizerTokenizerException - if the tokenizer is not on the START_TOKEN
public java.lang.String getNamespace()
throws TokenizerException
Tokenizer
getNamespace in interface TokenizerTokenizerException - if the tokenizer is not on the START_TOKENpublic java.lang.String getNamespaceForPrefix(java.lang.String prefix)
Tokenizer
getNamespaceForPrefix in interface Tokenizerprefix - the declared prefix
public org.w3c.dom.Element getDOMRepresentation(org.w3c.dom.Document doc)
throws TokenizerException
Tokenizer
getDOMRepresentation in interface Tokenizerdoc - the document within which the element should be created
TokenizerException - if there is an error in
tokenizing the XML document
public static org.w3c.dom.Element getDOMRepresentation(Tokenizer tokenizer,
org.w3c.dom.Document doc)
throws TokenizerException
TokenizerExceptionpublic QName parseQName(java.lang.String qName)
Tokenizer
parseQName in interface TokenizerqName - 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 TokenizerTokenizerException - 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 occured
public 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()
TokenizerTokenizer.next() for details.
currentState in interface Tokenizer
public java.lang.String readContent()
throws TokenizerException
Tokenizer
readContent in interface TokenizerTokenizerException - if the tokenizer is not in CONTENT state
public void readToken(Token stoken)
throws TokenizerException,
java.io.IOException
Tokenizerstoken. This function may be called only if the tokenizer
is on START_TOKEN or END_TOKEN.
readToken in interface Tokenizerstoken - 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 TokenizerTokenizerException - if the tokenizer is not in CONTENT statepublic java.util.Map getCurrentPrefixMap()
Tokenizer
getCurrentPrefixMap in interface Tokenizerpublic int pushNewlyDeclaredPrefixes(DeclaredPrefixesStack prefixes)
Tokenizer
pushNewlyDeclaredPrefixes in interface Tokenizerprefixes - 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 | |||||||||