net.rim.device.api.xml.jaxp
Class WBXMLWriter

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--net.rim.device.api.xml.jaxp.WBXMLWriter
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, RIMExtendedHandler, WBXMLConstants

public class WBXMLWriter
extends DefaultHandler
implements RIMExtendedHandler, WBXMLConstants

This class implements an XML writer as a SAX parser handler. The writer can be passed to any parser and will write XML to the specified OutputStream.

Since:
JDE 4.0.0

Field Summary
 
Fields inherited from interface net.rim.device.api.xml.WBXMLConstants
CHARSET_ISO_8859_1, CHARSET_UTF_8, END, ENTITY, EXT_0, EXT_1, EXT_2, EXT_I_0, EXT_I_1, EXT_I_2, EXT_T_0, EXT_T_1, EXT_T_2, ISO_8859_1, LITERAL, LITERAL_A, LITERAL_AC, LITERAL_C, OPAQUE, PI, PUBLIC_ID_UNKNOWN, PUBLIC_ID_WML10, PUBLIC_ID_WML11, PUBLIC_ID_WML12, PUBLIC_ID_WML13, STR_I, STR_T, SWITCH_PAGE, UTF_8, WBXML_1_1, WBXML_1_2, WBXML_1_3
 
Constructor Summary
WBXMLWriter(OutputStream out)
          This class implements an XML writer as a SAX parser handler.
 
Method Summary
 void cdataSection(char[] text, int offset, int length)
          Receives notification of a CDATA section.
 void characters(char[] ch, int start, int length)
          DefaultHandler overrides
 void comment(char[] text, int offset, int length)
          Receives notification of a comment.
 void defaultAttribute(String element, String attribute, String defaultValue)
          Receives notification of a default attribute value declaration.
 void endDocument()
          Receive notification of the end of the document.
 void endDTD(String name, String publicIdStr, String systemId, String body)
          Receives notification of the end of the document type definition (DTD).
 void endElement(String uri, String localName, String qName)
          Receive notification of the end of an element.
 void endEntityReference(String name)
          Receives notification of the end of an entity reference.
 void entityDecl(String name, String value)
          Receives notification of a general entity declaration.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
 void processingInstruction(String target, String data)
          Receive notification of a processing instruction.
 InputSource resolveEntity(String publicId, String systemId)
          Resolve an external entity.
 void setAttrStartTable(int page, String[] attrStartTable)
          Sets the attribute start Table for a given page.
 void setAttrValueTable(int page, String[] attrValueTable)
          Sets the attribute value Table for a given page.
 void setCharset(int charset)
          Sets the character set for the written WBXML.
 void setEncoding(String encoding)
          Sets the encoding for the written WBXML.
 void setEntityResolver(EntityResolver entityResolver)
          Sets the entity resolver for this writer.
 void setPublicID(int publicID)
          Sets the written WBXML public ID.
 void setTagTable(int page, String[] tagTable)
          Sets the tag table for a given page.
 void setVersion(int version)
          Sets the version of WBXML to write.
 void startAndEndElement(String eUri, String localName, String qName, Attributes attributes)
          Receives notification of the start and end of an element.
 void startDocument()
          Receive notification of the beginning of the document.
 void startDTD()
          Implementation of RIMExtendedHandler
 void startElement(String eUri, String localName, String qName, Attributes attributes)
          Receive notification of the start of an element.
 void startEntityReference(String name, String publicId, String systemId)
          Receives notification of the start of an entity reference.
 void startPrefixMapping(String prefix, String uri)
          Receive notification of the start of a Namespace mapping.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, notationDecl, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WBXMLWriter

public WBXMLWriter(OutputStream out)
This class implements an XML writer as a SAX parser handler. The writer can be passed to any parser and will write XML to the specified OutputStream.
Parameters:
out - A stream to receive the XML output.
Since:
JDE 4.0.0
Method Detail

cdataSection

public void cdataSection(char[] text,
                         int offset,
                         int length)
                  throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of a CDATA section.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
text - The CDATA characters not including .
offset - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
DefaultHandler overrides
Overrides:
characters in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
ch - The characters.
start - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.characters(char[], int, int)

comment

public void comment(char[] text,
                    int offset,
                    int length)
             throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of a comment.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
text - The comment characters not including .
offset - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

defaultAttribute

public void defaultAttribute(String element,
                             String attribute,
                             String defaultValue)
                      throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of a default attribute value declaration.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
element - The qualified name of the element.
attribute - The qualified name of the attribute.
defaultValue - The default attribute value.
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

endDocument

public void endDocument()
                 throws SAXException
Description copied from class: DefaultHandler
Receive notification of the end of the document.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of a document (such as finalising a tree or closing an output file).

Overrides:
endDocument in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endDocument()

endDTD

public void endDTD(String name,
                   String publicIdStr,
                   String systemId,
                   String body)
            throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of the end of the document type definition (DTD).
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
name - The document name.
publicId - The public ID of the DTD external subset (or null).
systemId - The sytem ID of the DTD external subset (or null of no external subset specified).
body - The body of the DTD. This includes all characters between .
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Description copied from class: DefaultHandler
Receive notification of the end of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

Overrides:
endElement in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

endEntityReference

public void endEntityReference(String name)
                        throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of the end of an entity reference.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
name - The name of the entity.
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

entityDecl

public void entityDecl(String name,
                       String value)
                throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of a general entity declaration.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
name - The name of the entity.
value - The entity's replacement text.
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Description copied from class: DefaultHandler
Receive notification of ignorable whitespace in element content.

By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).

Overrides:
ignorableWhitespace in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
ch - The whitespace characters.
start - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.ignorableWhitespace(char[], int, int)

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Description copied from class: DefaultHandler
Receive notification of a processing instruction.

By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

Overrides:
processingInstruction in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none is supplied.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException,
                                 IOException
Description copied from class: DefaultHandler
Resolve an external entity.

Always return null, so that the parser will use the system identifier provided in the XML document. This method implements the SAX default behaviour: application writers can override it in a subclass to do special translations such as catalog lookups or URI redirection.

Overrides:
resolveEntity in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
publicId - The public identifer, or null if none is available.
systemId - The system identifier provided in the XML document.
Returns:
The new input source, or null to require the default behaviour.
Throws:
IOException - If there is an error setting up the new input source.
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)

setAttrStartTable

public void setAttrStartTable(int page,
                              String[] attrStartTable)
Sets the attribute start Table for a given page. Currently only page 0 is supported. The first string in the array defines attribute 5, the second attribute 6, and so on.
Parameters:
page - The page number.
attrStartTable - The attribute names to define.
Since:
JDE 4.0.0

setAttrValueTable

public void setAttrValueTable(int page,
                              String[] attrValueTable)
Sets the attribute value Table for a given page. Currently only page 0 is supported. The first string in the array defines attribute value 0x85, the second attribute value 0x86, and so on.
Parameters:
page - The page number.
attrValueTable - The attribute names to define.
Since:
JDE 4.0.0

setCharset

public void setCharset(int charset)
Sets the character set for the written WBXML.
Parameters:
charset - The character set must be one of CHARSET_ISO_8859_1 or CHARSET_UTF_8.
Since:
JDE 4.0.0

setEncoding

public void setEncoding(String encoding)
                 throws IOException
Sets the encoding for the written WBXML.
Parameters:
encoding - The encoding must be one of UTF_8 or ISO_8859_1.
Throws:
IllegalArgumentException - Thrown if the encoding is not supported for WBXML.
Since:
JDE 4.0.0

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)
Sets the entity resolver for this writer. If the parser encounters external parsed entities, it asks the writer to resolve them.
Parameters:
entityResolver - The entity resolver.
Since:
JDE 4.0.0

setPublicID

public void setPublicID(int publicID)
Sets the written WBXML public ID.
Parameters:
publicId - The public ID must be one of PUBLIC_ID_WML10, PUBLIC_ID_WML11, PUBLIC_ID_WML12, or PUBLIC_ID_WML13.
Since:
JDE 4.0.0

setTagTable

public void setTagTable(int page,
                        String[] tagTable)
Sets the tag table for a given page. Currently only page 0 is supported The first string in the array defines tag 5, the second tag 6, and so on.
Parameters:
page - The page number.
tagTable - The tags to define.
Since:
JDE 4.0.0

setVersion

public void setVersion(int version)
Sets the version of WBXML to write.
Parameters:
The - version must be one of WBXML_1_1, WBXML_1_2, or WBXML_1_3.
Since:
JDE 4.0.0

startAndEndElement

public void startAndEndElement(String eUri,
                               String localName,
                               String qName,
                               Attributes attributes)
                        throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of the start and end of an element. The element contains no content.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
name - The element type name.
attributes - The specified or defaulted attributes.
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.
See Also:
org.xml.sax.helpers.DefaultHandler.startElement, org.xml.sax.helpers.DefaultHandler.endElement

startDocument

public void startDocument()
                   throws SAXException
Description copied from class: DefaultHandler
Receive notification of the beginning of the document.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the beginning of a document (such as allocating the root node of a tree or creating an output file).

Overrides:
startDocument in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startDocument()

startDTD

public void startDTD()
Implementation of RIMExtendedHandler
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Throws:
SAXException - Thrown if a SAX exception, possibly wrapping another exception, occurs.

startElement

public void startElement(String eUri,
                         String localName,
                         String qName,
                         Attributes attributes)
                  throws SAXException
Description copied from class: DefaultHandler
Receive notification of the start of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

Overrides:
startElement in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

startEntityReference

public void startEntityReference(String name,
                                 String publicId,
                                 String systemId)
                          throws SAXException
Description copied from interface: RIMExtendedHandler
Receives notification of the start of an entity reference.
Since:
JDE 4.0.0

Following copied from interface: RIMExtendedHandler
Parameters:
name - The name of the entity.
publicId - The public ID of the entity.
systemId - The system ID of the entity or null if this is an internal entity
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Description copied from class: DefaultHandler
Receive notification of the start of a Namespace mapping.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).

Overrides:
startPrefixMapping in class DefaultHandler
Since:
JDE 4.0.0

Following copied from class: DefaultHandler
Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI mapped to the prefix.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)



Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.