com.ricebridge.xmlman.in
Class XmlWriter

java.lang.Object
  extended bycom.ricebridge.xmlman.in.XmlWriter

public class XmlWriter
extends Object

Outputs well-formed XML to an OutputStream, using a specified encoding.

You can subclass this class to customize the creation of XML text by XML Manager. Call the XmlManagerStore.setXmlWriterClass(java.lang.Class) method to set the class of your own XmlWriter. Note that subclasses are required to have a empty constructor, so that new instances can be created from the class object.

See Also:
XmlOutputHandler

Field Summary
protected  boolean iClose
           
protected  boolean iFirstElement
           
protected  boolean iFlush
           
protected  boolean iIndent
           
protected  int iIndentCount
           
protected  int iIndentOfText
           
protected  String iIndentString
           
protected  String iLastElement
           
protected  int iNumIndentSpaces
           
protected  OutputStreamWriter iOutputStreamWriter
           
protected  boolean iVerbatimText
           
 
Constructor Summary
XmlWriter()
          Create a new XmlWriter instance.
 
Method Summary
static String encodeAttr(String pText)
          Encode XML attribute content.
static String encodeText(String pText)
          Encode XML text content.
 void endDocument(String pFooter)
          End XML document by flushing and closing stream.
 void endElement(String pQName)
          Output the end tag of an element.
protected  void flush()
          Flush output, and handle exceptions.
 String formatAttrs(List pAttrPairs)
          Create XML attribute content.
 String formatNamespaces(Map pNamespaceMap)
          Create XML Namespace declaration attributes.
protected  String indent()
          Make current indent string.
protected  String indentText(String pText)
          Indent XML text content so that it is aligned with start tag.
 void setClose(boolean pClose)
          Close the OutputStream specified with setOutput(java.io.OutputStream, java.lang.String) when finished.
 void setFlush(boolean pFlush)
          Flush output after the start and end of each element, and after outputting text.
 void setIndent(boolean pIndent)
          Indent XML so that it is human readable.
 void setOutput(OutputStream pOutputStream, String pCharsetName)
          Set the OutputStream and character encoding to use.
 void startDocument(String pHeader)
          Start XML document by outputting header.
 void startElement(String pQName, List pAttrPairs, Map pNamespaceMap)
          Output the start tag of an element, including attributes and namespace declarations, if present.
 void text(String pText)
          Output XML text content for current tag.
protected  String trimContent(String pContent)
          Trim text content to a small example extract for error reporting.
protected  void write(String pContent)
          Write content to output, and handle exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iOutputStreamWriter

protected OutputStreamWriter iOutputStreamWriter

iFlush

protected boolean iFlush

iVerbatimText

protected boolean iVerbatimText

iIndent

protected boolean iIndent

iClose

protected boolean iClose

iFirstElement

protected boolean iFirstElement

iLastElement

protected String iLastElement

iNumIndentSpaces

protected int iNumIndentSpaces

iIndentOfText

protected int iIndentOfText

iIndentCount

protected int iIndentCount

iIndentString

protected String iIndentString
Constructor Detail

XmlWriter

public XmlWriter()
Create a new XmlWriter instance.

Method Detail

setOutput

public void setOutput(OutputStream pOutputStream,
                      String pCharsetName)
Set the OutputStream and character encoding to use.

The OutputStream is wrapped in a OutputStreamWriter which uses the specified character encoding to create the correct stream of output bytes. See the documentation for Charset for a discussion of Java character encoding. Note that XML should generally be encoding as UTF-8 or UTF-16 for guaranteed interoperability.

Parameters:
pOutputStream - OutputStream to recieve XML content
pCharsetName - character encoding for the XML content

setFlush

public void setFlush(boolean pFlush)
Flush output after the start and end of each element, and after outputting text.

Parameters:
pFlush - flush OutputStream after each element
See Also:
XmlSpec.setFlush(boolean)

setIndent

public void setIndent(boolean pIndent)
Indent XML so that it is human readable.

If the XML is not indented, then it is output in a compact format with no newlines or unnecessary whitespace.

Parameters:
pIndent - indent output
See Also:
XmlSpec.setIndent(boolean)

setClose

public void setClose(boolean pClose)
Close the OutputStream specified with setOutput(java.io.OutputStream, java.lang.String) when finished.

Parameters:
pClose - close OutputStream

startDocument

public void startDocument(String pHeader)
Start XML document by outputting header.

Parameters:
pHeader - header content

endDocument

public void endDocument(String pFooter)
End XML document by flushing and closing stream.


startElement

public void startElement(String pQName,
                         List pAttrPairs,
                         Map pNamespaceMap)
Output the start tag of an element, including attributes and namespace declarations, if present.

Note that the list of attributes is a flat list with even elements as names and odd elements as values.

Parameters:
pQName - prefix qualified name of element
pAttrPairs - list of attr, value elements, may be null
pNamespaceMap - prefix to uri mappings, may be null

formatNamespaces

public String formatNamespaces(Map pNamespaceMap)
Create XML Namespace declaration attributes.

Parameters:
pNamespaceMap - prefix to uri mappings

formatAttrs

public String formatAttrs(List pAttrPairs)
Create XML attribute content.

Parameters:
pAttrPairs - list of name, value elements

text

public void text(String pText)
Output XML text content for current tag.

Parameters:
pText - text content to output

endElement

public void endElement(String pQName)
Output the end tag of an element.

Parameters:
pQName - prefix qualified name of element

encodeText

public static String encodeText(String pText)
Encode XML text content.

Parameters:
pText - text content

encodeAttr

public static String encodeAttr(String pText)
Encode XML attribute content.

Parameters:
pText - attribute content

indent

protected String indent()
Make current indent string.


indentText

protected String indentText(String pText)
Indent XML text content so that it is aligned with start tag.

Parameters:
pText - text content

write

protected void write(String pContent)
Write content to output, and handle exceptions.

Parameters:
pContent - content to output

flush

protected void flush()
Flush output, and handle exceptions.


trimContent

protected String trimContent(String pContent)
Trim text content to a small example extract for error reporting.

Parameters:
pContent - text content


Copyright © 2004-2005 Ricebridge