com.lotus.xsl
Class FormatterToXML

java.lang.Object
  |
  +--com.lotus.xsl.FormatterToXML
Direct Known Subclasses:
FormatterToHTML

public class FormatterToXML
extends java.lang.Object
implements FormatterListener

FormatterToXML formats SAX-style events into XML.


Field Summary
 int indent
           
 java.lang.String m_attrSpecialChars
          These are characters that will be escaped in the output.
 boolean m_escapeCData
          If true, characters in cdata sections are escaped, instead of being writted out as cdata sections.
 boolean m_shouldWriteXMLHeader
           
 boolean m_stripCData
          If true, cdata sections are simply stripped of their CDATA brackets, without escaping.
 
Constructor Summary
FormatterToXML(java.io.Writer writer)
          Constructor for default encoding.
FormatterToXML(java.io.Writer writer, java.lang.String encoding)
          Constructor for customized encoding.
FormatterToXML(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype, boolean doIndent, int indent)
          Constructor for customized encoding and doctype.
 
Method Summary
 void cdata(char[] ch, int start, int length)
          Receive notification of cdata.
 void characters(char[] chars, int start, int length)
          Receive notification of character data.
 void comment(java.lang.String data)
          Called when a Comment is to be constructed.
 void endDocument()
          Receive notification of the end of a document.
 void endElement(java.lang.String name)
          Receive notification of the end of an element.
 void entityReference(java.lang.String name)
          Receive notivication of a entityReference.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
 void indent(java.io.Writer pw, int n)
          Prints a newline character and n spaces.
static java.lang.String prepAttrString(java.lang.String string, java.lang.String specials, java.lang.String encoding)
          Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
static void printSpace(java.io.Writer pw, int n)
          Prints n spaces.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
 void setDocumentLocator(com.lotus.xsl.Locator locator)
          Receive an object for locating the origin of SAX document events.
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(java.lang.String name, com.lotus.xsl.AttributeList atts)
          Receive notification of the beginning of an element.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_stripCData

public boolean m_stripCData
If true, cdata sections are simply stripped of their CDATA brackets, without escaping.

m_escapeCData

public boolean m_escapeCData
If true, characters in cdata sections are escaped, instead of being writted out as cdata sections.

m_shouldWriteXMLHeader

public boolean m_shouldWriteXMLHeader

indent

public int indent

m_attrSpecialChars

public java.lang.String m_attrSpecialChars
These are characters that will be escaped in the output.
Constructor Detail

FormatterToXML

public FormatterToXML(java.io.Writer writer,
                      java.lang.String encoding)
Constructor for customized encoding.
Parameters:
writer - The character output stream to use.
encoding - Java character encoding in use by writer.

FormatterToXML

public FormatterToXML(java.io.Writer writer)
Constructor for default encoding.
Parameters:
writer - The character output stream to use.

FormatterToXML

public FormatterToXML(java.io.Writer writer,
                      java.lang.String encoding,
                      java.lang.String doctype,
                      boolean doIndent,
                      int indent)
Constructor for customized encoding and doctype.
Parameters:
writer - The character output stream to use.
encoding - Java character encoding in use by writer.
doctype - String to be printed at the top of the document.
indent - Number of spaces to indent at each nesting level.
Method Detail

setDocumentLocator

public void setDocumentLocator(com.lotus.xsl.Locator locator)
Receive an object for locating the origin of SAX document events.
Parameters:
locator - An object that can return the location of any SAX document event.
See Also:
org.xml.sax.Locator

startDocument

public void startDocument()
                   throws com.lotus.xsl.SAXException
Receive notification of the beginning of a document.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

endDocument

public void endDocument()
                 throws com.lotus.xsl.SAXException
Receive notification of the end of a document.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

startElement

public void startElement(java.lang.String name,
                         com.lotus.xsl.AttributeList atts)
                  throws com.lotus.xsl.SAXException
Receive notification of the beginning of an element.
Parameters:
name - The element type name.
atts - The attributes attached to the element, if any.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(java.lang.String), org.xml.sax.AttributeList

endElement

public void endElement(java.lang.String name)
                throws com.lotus.xsl.SAXException
Receive notification of the end of an element.
Parameters:
name - The element type name
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws com.lotus.xsl.SAXException
Receive notification of a processing instruction.
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

comment

public void comment(java.lang.String data)
             throws com.lotus.xsl.SAXException
Called when a Comment is to be constructed.
Specified by:
comment in interface FormatterListener
Parameters:
data - The comment data.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

cdata

public void cdata(char[] ch,
                  int start,
                  int length)
           throws com.lotus.xsl.SAXException
Receive notification of cdata.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

Specified by:
cdata in interface FormatterListener
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ignorableWhitespace(char[], int, int), org.xml.sax.Locator

characters

public void characters(char[] chars,
                       int start,
                       int length)
                throws com.lotus.xsl.SAXException
Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).

Parameters:
chars - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ignorableWhitespace(char[], int, int), org.xml.sax.Locator

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws com.lotus.xsl.SAXException
Receive notification of ignorable whitespace in element content. Not sure how to get this invoked quite yet.
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
characters(char[], int, int)

entityReference

public void entityReference(java.lang.String name)
                     throws com.lotus.xsl.SAXException
Receive notivication of a entityReference.
Specified by:
entityReference in interface FormatterListener

prepAttrString

public static java.lang.String prepAttrString(java.lang.String string,
                                              java.lang.String specials,
                                              java.lang.String encoding)
                                       throws com.lotus.xsl.SAXException
Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
Parameters:
string - String to convert to XML format.
specials - Chracters, should be represeted in chracter referenfces.
encoding - CURRENTLY NOT IMPLEMENTED.
Returns:
XML-formatted string.
See Also:
#backReference

printSpace

public static void printSpace(java.io.Writer pw,
                              int n)
                       throws com.lotus.xsl.SAXException
Prints n spaces.
Parameters:
pw - The character output stream to use.
n - Number of spaces to print.
Throws:
java.io.IOException - Thrown if pw is invalid.

indent

public void indent(java.io.Writer pw,
                   int n)
            throws com.lotus.xsl.SAXException
Prints a newline character and n spaces.
Parameters:
pw - The character output stream to use.
n - Number of spaces to print.
Throws:
java.io.IOException - Thrown if pw is invalid.