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

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--net.rim.device.api.xml.jaxp.XMLWriter
All Implemented Interfaces:
RIMExtendedHandler

public class XMLWriter
extends DefaultHandler
implements RIMExtendedHandler

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. It for example, and XML pretty-printer can be written as follows:
XMLWriter writer = new XMLWriter( outStream );
writer.setPrettyPrint( true );
SAXParser parser
parser.parse( inputStream, writer );

Since:
JDE 4.0.0

Constructor Summary
XMLWriter(OutputStream out)
          create an XMLWriter
 
Method Summary
 void cdataSection(char[] text, int offset, int length)
          Receive notification of a CDATA section.
 void characters(char[] ch, int start, int length)
          Receive notification of character data inside an element.
 void comment(char[] text, int offset, int length)
          Receive notification of a comment
 void defaultAttribute(String element, String attribute, String defaultValue)
          Receive notification of a default attribute value declaration
 void endDocument()
          Receive notification of the end of the document.
 void endDTD(String name, String publicId, String systemId, String body)
          Receive notification of the end of the document type definition
 void endElement(String uri, String localName, String qName)
          Receive notification of the end of an element.
 void endEntityReference(String name)
          Receive notification of the end of an entity reference
 void entityDecl(String name, String value)
          Receive 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 setEntityResolver(EntityResolver entityResolver)
          Set the entity resolver for this writer.
 void setExpandingEntities(boolean expannnd)
          Indicate whether this writer should expand entities, or print them as entity references like &ent;
 void setPreserveSpacing()
          Configure this writer to print XML as close to the original as possible.
 void setPrettyPrint()
          Configure this writer to pretty-print the XML.
 void setPrintCompressedOutput()
          Configure this writer to print XML with no unneccessary whitespace.
 void startAndEndElement(String uri, String localName, String qName, Attributes attributes)
          Receive notification of the start and end of an element.
 void startDocument()
          Receive notification of the beginning of the document.
 void startDTD()
          Receive notification of the start of the document type definition
 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)
          Receive 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

XMLWriter

public XMLWriter(OutputStream out)
create an XMLWriter
Parameters:
out - A stream to receive the XML output
Since:
JDE 4.0.0
Method Detail

setPrettyPrint

public void setPrettyPrint()
Configure this writer to pretty-print the XML.
Since:
JDE 4.0.0

setPrintCompressedOutput

public void setPrintCompressedOutput()
Configure this writer to print XML with no unneccessary whitespace.
Since:
JDE 4.0.0

setPreserveSpacing

public void setPreserveSpacing()
Configure this writer to print XML as close to the original as possible. This is the default.
Since:
JDE 4.0.0

setEntityResolver

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

setExpandingEntities

public void setExpandingEntities(boolean expannnd)
Indicate whether this writer should expand entities, or print them as entity references like &ent;
Parameters:
expand - Should entities be expanded?
Since:
JDE 4.0.2

startDTD

public void startDTD()
Description copied from interface: RIMExtendedHandler
Receive notification of the start of the document type definition
Since:
JDE 4.0.0

endDTD

public void endDTD(String name,
                   String publicId,
                   String systemId,
                   String body)
            throws SAXException
Description copied from interface: RIMExtendedHandler
Receive notification of the end of the document type definition
Since:
JDE 4.0.2

comment

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

cdataSection

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

startEntityReference

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

endEntityReference

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

entityDecl

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

defaultAttribute

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

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Description copied from class: DefaultHandler
Receive notification of character data inside an element.

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

Overrides:
characters in class DefaultHandler
Since:
JDE 4.0.2

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.2

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.2

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

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

startAndEndElement

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

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.2

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.2

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.2

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.2


Copyright 1999-2004 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.