nu.xom.samples
Class TextSerializer

java.lang.Object
  extended by nu.xom.Serializer
      extended by nu.xom.samples.TextSerializer

public class TextSerializer
extends nu.xom.Serializer

This Serializer subclass outputs raw, unescaped text from the text nodes, but no markup of any kind. In essence, it converts XML into plain text.

Version:
1.0
Author:
Elliotte Rusty Harold

Constructor Summary
TextSerializer(java.io.OutputStream out)
           Create a new text serializer that uses the UTF-8 encoding.
TextSerializer(java.io.OutputStream out, java.lang.String encoding)
           Create a new serializer that uses a specified encoding.
 
Method Summary
static void main(java.lang.String[] args)
           
protected  void write(nu.xom.Comment comment)
           Writes a comment onto the output stream using the current options.
protected  void write(nu.xom.DocType doctype)
           Writes a DocType object onto the output stream using the current options.
protected  void write(nu.xom.ProcessingInstruction instruction)
           Writes a processing instruction onto the output stream using the current options.
protected  void writeEmptyElementTag(nu.xom.Element element)
           Writes an empty-element tag for the element including all its namespace declarations and attributes.
protected  void writeEndTag(nu.xom.Element element)
           Writes the end-tag for an element in the form </name>.
protected  void writeStartTag(nu.xom.Element element)
           Writes the start-tag for the element including all its namespace declarations and attributes.
protected  void writeText(nu.xom.Text text)
           
protected  void writeXMLDeclaration()
           Writes the XML declaration onto the output stream, followed by a line break.
 
Methods inherited from class nu.xom.Serializer
breakLine, flush, getColumnNumber, getEncoding, getIndent, getLineSeparator, getMaxLength, getPreserveBaseURI, getUnicodeNormalizationFormC, setIndent, setLineSeparator, setMaxLength, setOutputStream, setPreserveBaseURI, setUnicodeNormalizationFormC, write, write, write, write, writeAttributes, writeAttributeValue, writeChild, writeEscaped, writeNamespaceDeclaration, writeNamespaceDeclarations, writeRaw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextSerializer

public TextSerializer(java.io.OutputStream out)

Create a new text serializer that uses the UTF-8 encoding.

Parameters:
out - the output stream to write the document on
Throws:
java.lang.NullPointerException - if out is null

TextSerializer

public TextSerializer(java.io.OutputStream out,
                      java.lang.String encoding)
               throws java.io.UnsupportedEncodingException

Create a new serializer that uses a specified encoding. The encoding must be recognized by the Java virtual machine.

Parameters:
out - the output stream to write the document on
encoding - the character encoding for the serialization
Throws:
java.lang.NullPointerException - if out or encoding is null
java.io.UnsupportedEncodingException - if the VM does not support the requested encoding
Method Detail

writeStartTag

protected void writeStartTag(nu.xom.Element element)
Description copied from class: nu.xom.Serializer

Writes the start-tag for the element including all its namespace declarations and attributes.

The writeAttributes method is called to write all the non-namespace-declaration attributes. The writeNamespaceDeclarations method is called to write all the namespace declaration attributes.

Overrides:
writeStartTag in class nu.xom.Serializer
Parameters:
element - the element whose start-tag is written

writeEmptyElementTag

protected void writeEmptyElementTag(nu.xom.Element element)
Description copied from class: nu.xom.Serializer

Writes an empty-element tag for the element including all its namespace declarations and attributes.

The writeAttributes method is called to write all the non-namespace-declaration attributes. The writeNamespaceDeclarations method is called to write all the namespace declaration attributes.

If subclasses don't wish empty-element tags to be used, they can override this method to simply invoke writeStartTag followed by writeEndTag.

Overrides:
writeEmptyElementTag in class nu.xom.Serializer
Parameters:
element - the element whose empty-element tag is written

writeEndTag

protected void writeEndTag(nu.xom.Element element)
Description copied from class: nu.xom.Serializer

Writes the end-tag for an element in the form </name>.

Overrides:
writeEndTag in class nu.xom.Serializer
Parameters:
element - the element whose end-tag is written

writeXMLDeclaration

protected void writeXMLDeclaration()
Description copied from class: nu.xom.Serializer

Writes the XML declaration onto the output stream, followed by a line break.

Overrides:
writeXMLDeclaration in class nu.xom.Serializer

write

protected void write(nu.xom.Comment comment)
Description copied from class: nu.xom.Serializer

Writes a comment onto the output stream using the current options. Since character and entity references are not resolved in comments, comments can only be serialized when all characters they contain are available in the current encoding.

Overrides:
write in class nu.xom.Serializer
Parameters:
comment - the Comment to serialize

write

protected void write(nu.xom.ProcessingInstruction instruction)
Description copied from class: nu.xom.Serializer

Writes a processing instruction onto the output stream using the current options. Since character and entity references are not resolved in processing instructions, processing instructions can only be serialized when all characters they contain are available in the current encoding.

Overrides:
write in class nu.xom.Serializer
Parameters:
instruction - the ProcessingInstruction to serialize

write

protected void write(nu.xom.DocType doctype)
Description copied from class: nu.xom.Serializer

Writes a DocType object onto the output stream using the current options.

Overrides:
write in class nu.xom.Serializer
Parameters:
doctype - the document type declaration to serialize

writeText

protected void writeText(nu.xom.Text text)
                  throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)


Copyright 2002-2005 Elliotte Rusty Harold
elharo@metalab.unc.edu