com.openharbor.beck.write
Class XMLWriter

java.lang.Object
  extended byjava.io.Writer
      extended bycom.openharbor.beck.write.XMLWriter
Direct Known Subclasses:
AxisWriter, FastXMLWriter, OHXPathCollector, TentativeXMLWriter

public abstract class XMLWriter
extends java.io.Writer

Generates an XML document via a stream-style interface. The document is generated in fragments by a sequence of method calls. This interface is similar to SAX2, by design; this interface could easily be implemented by delegation to an org.xml.sax.ContentHandler.


Nested Class Summary
static class XMLWriter.MapKey
          A key for use with a Map in an XMLWriter's document state or element stack.
 
Field Summary
static XMLWriter.MapKey CYCLES
           
static XMLWriter.MapKey DECLARED_NAMESPACES
           
static XMLWriter.MapKey ELEMENT_NAME
           
 Prefixer prefixer
           
static XMLWriter.MapKey SOURCE
           
static XMLWriter.MapKey TEXT_IS_SIGNIFICANT
           
static java.lang.String XSI
           
static XMLName XSI_TYPE
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
XMLWriter()
           
 
Method Summary
 void attribute(XMLName name, java.lang.String value)
          Add an attribute to the current element.
 void attributes(java.util.Map map)
           
protected  java.lang.String choosePrefix(java.lang.String namespace, java.util.Map declared)
           
protected abstract  void declareNamespace(java.lang.String prefix, java.lang.String namespaceURI)
           
 void endElement()
           
 java.util.HashMap getDocumentState()
           
 java.util.List getElementStack()
           
 java.util.HashMap getElementStackTop()
           
 java.lang.String namespace(java.lang.String uri)
          Add a namespace declaration to the current element.
 java.lang.String namespace(java.lang.String prefix, java.lang.String uri)
          Add a namespace declaration to the current element.
static XMLWriter.MapKey newMapKey(java.lang.String description)
          Allocate a key for getDocumentState() or the elements of getElementStack().
protected  java.lang.String prefixToNamespace(java.lang.String prefix)
          Find the namespace URI for a given XML name prefix.
protected  XMLName resolveNamespace(java.lang.String qname, boolean isAttribute)
          Convert an XML-style name <prefix:local> to its namespace URI and local part.
protected  void setDocumentState(java.util.HashMap documentState)
           
protected  void startElement(XMLName name)
           
 void startElement(XMLThing tag)
           
abstract  void write(char[] content, int off, int len)
          Add text content to the current element.
 void write(java.lang.String str)
           
 void write(java.lang.String str, int off, int len)
           
 
Methods inherited from class java.io.Writer
close, flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefixer

public Prefixer prefixer

ELEMENT_NAME

public static final XMLWriter.MapKey ELEMENT_NAME

SOURCE

public static final XMLWriter.MapKey SOURCE

CYCLES

public static final XMLWriter.MapKey CYCLES

DECLARED_NAMESPACES

public static final XMLWriter.MapKey DECLARED_NAMESPACES

TEXT_IS_SIGNIFICANT

public static final XMLWriter.MapKey TEXT_IS_SIGNIFICANT

XSI

public static final java.lang.String XSI
See Also:
Constant Field Values

XSI_TYPE

public static final XMLName XSI_TYPE
Constructor Detail

XMLWriter

public XMLWriter()
Method Detail

startElement

public void startElement(XMLThing tag)
                  throws java.io.IOException
Throws:
java.io.IOException

startElement

protected void startElement(XMLName name)
                     throws java.io.IOException
Throws:
java.io.IOException

attribute

public void attribute(XMLName name,
                      java.lang.String value)
               throws java.io.IOException
Add an attribute to the current element. If it's an xsi:type attribute, set the Type of the current element accordingly.

Throws:
java.io.IOException - if text or sub-elements have already been written in this element.

attributes

public void attributes(java.util.Map map)
                throws java.io.IOException
Throws:
java.io.IOException

namespace

public java.lang.String namespace(java.lang.String uri)
                           throws java.io.IOException
Add a namespace declaration to the current element.

Returns:
the prefix assigned to the given uri.
Throws:
java.io.IOException - if text or sub-elements have already been written in this element.

namespace

public java.lang.String namespace(java.lang.String prefix,
                                  java.lang.String uri)
                           throws java.io.IOException
Add a namespace declaration to the current element. The given prefix will be used unless it's null or conflicts with a previous request; in which case another prefix will be used.

Returns:
the prefix assigned to the given uri.
Throws:
java.io.IOException - if text or sub-elements have already been written in this element.

choosePrefix

protected java.lang.String choosePrefix(java.lang.String namespace,
                                        java.util.Map declared)
                                 throws java.io.IOException
Throws:
java.io.IOException

declareNamespace

protected abstract void declareNamespace(java.lang.String prefix,
                                         java.lang.String namespaceURI)
                                  throws java.io.IOException
Throws:
java.io.IOException

resolveNamespace

protected XMLName resolveNamespace(java.lang.String qname,
                                   boolean isAttribute)
                            throws UnknownNamespaceException
Convert an XML-style name <prefix:local> to its namespace URI and local part.

Throws:
UnknownNamespaceException

prefixToNamespace

protected java.lang.String prefixToNamespace(java.lang.String prefix)
                                      throws UnknownNamespaceException
Find the namespace URI for a given XML name prefix.

Throws:
UnknownNamespaceException

write

public abstract void write(char[] content,
                           int off,
                           int len)
                    throws java.io.IOException
Add text content to the current element. Do nothing if len <= 0.

Throws:
java.io.IOException

write

public void write(java.lang.String str)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

endElement

public void endElement()
                throws java.io.IOException
Throws:
java.io.IOException

getDocumentState

public final java.util.HashMap getDocumentState()
Returns:
the HashMap allocated to the current document.

setDocumentState

protected final void setDocumentState(java.util.HashMap documentState)

getElementStackTop

public java.util.HashMap getElementStackTop()
Returns:
the HashMap at the top of the element stack, or null if the stack is empty.

getElementStack

public java.util.List getElementStack()
Returns:
a List of HashMaps, one for each element that has been started but not ended. The first element (index 0) of this list corresponds to the XML document root element; the last element corresponds to the most recently started element. The last element is removed from the stack as a side-effect of this.endElement(). This List is a read-only view (although its element HashMaps are mutable).

Callers should access the HashMaps using a key statically allocated by newMapKey (below). In this way, independent callers can avoid interfering with each other's use of the Map.


newMapKey

public static XMLWriter.MapKey newMapKey(java.lang.String description)
Allocate a key for getDocumentState() or the elements of getElementStack().

Returns:
a different key each time this method is called