org.idoox.xml
Interface TokenWriter

All Known Implementing Classes:
XMLWriterReader

public interface TokenWriter

Writes a stream of XML tokens into XML stream. This interface enables to write (serialize) sequence of XML tokens (elements).

Since:
4.0
Component:
Core

Method Summary
 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.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.
 void setPrefixForNamespace(java.lang.String prefix, java.lang.String namespace)
          Sets prefix for specified namespace URI.
 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.
 

Method Detail

flush

public void flush()
           throws java.io.IOException
Flushes the internal caches.

Throws:
java.io.IOException

enter

public void enter(java.lang.String namespace,
                  java.lang.String name)
           throws java.io.IOException,
                  java.lang.IllegalStateException
Create new element, namespace can be null for unqualified. When all the attributes and content of the element was written leave() MUST be called.

Parameters:
name - name of the element
namespace - namespace URI of the element
Throws:
java.io.IOException - if IOException occurs
java.lang.IllegalStateException - if called in an invalid place

writeAttribute

public void writeAttribute(java.lang.String namespace,
                           java.lang.String name,
                           java.lang.String value)
                    throws java.io.IOException,
                           java.lang.IllegalStateException
Can be called only when inside new element, not after outputting some content.

Parameters:
name - name of the attribute
namespace - namespace URI of the attribute
value - value of the attribute
Throws:
java.io.IOException - if IOException occurs
java.lang.IllegalStateException - if called in an invalid place

writeXmlAttribute

public void writeXmlAttribute(java.lang.String name,
                              java.lang.String value)
                       throws java.io.IOException,
                              java.lang.IllegalStateException
Outputs XML attribute, i.e. the one starting with 'xml:', such as xml:lang or xml:space. Can be called only when inside new element, not after outputting some content.

Parameters:
name - name of the attribute, without 'xml:' prefix
value - value of the attribute
Throws:
java.io.IOException - if IOException occurs
java.lang.IllegalStateException - if called in an invalid place

writeContent

public void writeContent(java.lang.String content)
                  throws java.io.IOException,
                         java.lang.IllegalStateException
Writes text content to a XML stream.

Parameters:
content - the content to be written
Throws:
java.io.IOException - if IOException occurs
java.lang.IllegalStateException - if called in an invalid place

leave

public void leave()
           throws java.io.IOException,
                  java.lang.IllegalStateException
Terminate current element. Called when all attributes and all content of the element was written. Each enter(java.lang.String, java.lang.String) call MUST has corresponding leave() call.

Throws:
java.io.IOException
java.lang.IllegalStateException

getPrefixForNamespace

public java.lang.String getPrefixForNamespace(java.lang.String namespace)
                                       throws java.io.IOException,
                                              java.lang.IllegalStateException
Returns prefix for a namespace URI, if prefix for namespace URI doesn't exist it will be automatically created as ns[:digit:]+.

Parameters:
namespace - the namespace URI for which prefix is returned
Returns:
the appropriate prefix
Throws:
java.io.IOException - if an IOException occurs
java.lang.IllegalStateException - if not called at the start of the element and some definition is required

setPrefixForNamespace

public void setPrefixForNamespace(java.lang.String prefix,
                                  java.lang.String namespace)
                           throws java.io.IOException,
                                  java.lang.IllegalStateException
Sets prefix for specified namespace URI.

Note: Prefixes that look like ns[:digit:]+ are used by automatic prefix generation and MUST NOT be used by user.

Note: There are no internal checks for validity of namespace prefix mapping. The caller must ensure that the mapping is valid.

Parameters:
prefix - prefix to be registered
namespace - the namespace URI to be registered with the prefix
Throws:
java.io.IOException - if an IOException occurs
java.lang.IllegalStateException - if not called at the start of element