|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.idoox.xml.XMLWriterReader
This class represents XMLWriter (TokenWriter) which can be also used as XMLReader (Tokenizer). You can write XML tokens to this class and them they can read back (acts like a buffer).
This class is used in the protocol level Message implementation to allow processing of the header processors, which use Tokenizer instead of TokenWriter.
Field Summary | |
java.util.Map |
namespaceMap
Stores mapping of namespaces to their prefixes |
java.util.Map |
prefixMap
Stores mapping of prefixes to their namespace URIs |
Fields inherited from interface org.idoox.xml.Tokenizer |
CONTENT, END_DOCUMENT, END_TOKEN, START_TOKEN, typeNames, UNKNOWN |
Constructor Summary | |
XMLWriterReader()
Constructs an emty XMLWriterReader |
Method Summary | |
byte |
currentState()
Returns the current state of the tokenizer. |
void |
enter(java.lang.String namespace,
java.lang.String name)
Create new element, namespace can be null for unqualified. |
void |
flush()
Flushes the internal caches. |
java.util.Map |
getCurrentPrefixMap()
Returns clone of the current prefix map. |
org.w3c.dom.Element |
getDOMRepresentation(org.w3c.dom.Document doc)
Returns DOM representation of the element that is being parsed. |
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. |
java.lang.String |
getPrefixForNamespace(java.lang.String namespace)
Returns prefix for a namespace URI, if prefix for namespace URI doesn't exist it will be automatically created as ns[:digit:]+. |
void |
leave()
Terminate current element. |
byte |
next()
Parses next part of the input XML document and returns the state of the tokenizer (one of UNKNOWN, START_TOKEN, END_TOKEN, CONTENT, END_DOCUMENT). |
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 token)
Reads the start/end of an element. |
void |
setPrefixForNamespace(java.lang.String prefix,
java.lang.String namespace)
Sets prefix for specified namespace URI. |
boolean |
whitespaceContent()
Returns true if the content contains only whitespaces. |
void |
writeAttribute(java.lang.String namespace,
java.lang.String name,
java.lang.String value)
Can be called only when inside new element, not after outputting some content. |
void |
writeContent(java.lang.String content)
Writes text content to a XML stream. |
void |
writeXmlAttribute(java.lang.String name,
java.lang.String value)
Outputs XML attribute, i.e. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public java.util.Map namespaceMap
public java.util.Map prefixMap
Constructor Detail |
public XMLWriterReader()
XMLWriterReader
Method Detail |
public void flush()
TokenWriter
flush
in interface TokenWriter
public void enter(java.lang.String namespace, java.lang.String name)
TokenWriter
namespace
can be null
for unqualified.
When all the attributes and content of the element was written TokenWriter.leave()
MUST be called.
enter
in interface TokenWriter
name
- name of the elementnamespace
- namespace URI of the elementpublic void writeAttribute(java.lang.String namespace, java.lang.String name, java.lang.String value) throws java.lang.IllegalStateException
TokenWriter
writeAttribute
in interface TokenWriter
name
- name of the attributenamespace
- namespace URI of the attributevalue
- value of the attribute
java.lang.IllegalStateException
- if called in an invalid placepublic void writeXmlAttribute(java.lang.String name, java.lang.String value) throws java.lang.IllegalStateException
TokenWriter
writeXmlAttribute
in interface TokenWriter
name
- name of the attribute, without 'xml:' prefixvalue
- value of the attribute
java.lang.IllegalStateException
- if called in an invalid placepublic void writeContent(java.lang.String content) throws java.io.IOException, java.lang.IllegalStateException
TokenWriter
writeContent
in interface TokenWriter
content
- the content to be written
java.io.IOException
- if IOException occurs
java.lang.IllegalStateException
- if called in an invalid placepublic void leave() throws java.io.IOException, java.lang.IllegalStateException
TokenWriter
TokenWriter.enter(java.lang.String, java.lang.String)
call MUST has corresponding TokenWriter.leave()
call.
leave
in interface TokenWriter
java.lang.IllegalStateException
java.io.IOException
public java.lang.String getPrefixForNamespace(java.lang.String namespace) throws java.lang.IllegalStateException
TokenWriter
getPrefixForNamespace
in interface TokenWriter
namespace
- the namespace URI for which prefix is returned
java.lang.IllegalStateException
- if not called at the start of the element
and some definition is requiredpublic void setPrefixForNamespace(java.lang.String prefix, java.lang.String namespace) throws java.lang.IllegalStateException
TokenWriter
setPrefixForNamespace
in interface TokenWriter
prefix
- prefix to be registerednamespace
- the namespace URI to be registered with the prefix
java.lang.IllegalStateException
- if not called at the start of elementpublic 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 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
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 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 token) throws TokenizerException
Tokenizer
stoken
. This function may be called only if the tokenizer
is on START_TOKEN or END_TOKEN.
readToken
in interface Tokenizer
token
- structure containing name, namespace URI and attribute pairs; holder for result
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 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 document
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |