org.cyberneko.html.filters

Class Writer

Implemented Interfaces:
XMLComponent, XMLDocumentFilter, HTMLComponent

public class Writer
extends DefaultFilter

An HTML writer written as a filter. Besides serializing the HTML event stream, the writer also passes the document events to the next stage in the pipeline. This allows applications to insert writer filters between other custom filters for debugging purposes.

Since an HTML document may have specified its encoding using the <META> tag and http-equiv/content attributes, the writer will automatically change any character set specified in this tag to match the encoding of the output stream. Therefore, the character encoding name used to construct the writer should be an official IANA encoding name and not a Java encoding name.

Note: The modified character set in the <META> tag is not propagated to the next stage in the pipeline. The changed value is only output to the stream; the original value is sent to the next stage in the pipeline.

Version:
$Id: Writer.java,v 1.7 2005/02/14 04:01:33 andyc Exp $
Author:
Andy Clark

Field Summary

protected static String
AUGMENTATIONS
Augmentations feature identifier.
protected static String
FILTERS
Filters property identifier.
static String
NOTIFY_CHAR_REFS
Notify character entity references.
static String
NOTIFY_HTML_BUILTIN_REFS
Notify built-in entity references.
protected int
fElementDepth
Element depth.
protected String
fEncoding
The encoding.
protected boolean
fNormalize
Normalize character content.
protected boolean
fPrintChars
Print characters.
protected PrintWriter
fPrinter
The print writer used for serializing the document with the appropriate character encoding.
protected boolean
fSeenHttpEquiv
Seen http-equiv directive.
protected boolean
fSeenRootElement
Seen root element.

Fields inherited from class org.cyberneko.html.filters.DefaultFilter

fDocumentHandler, fDocumentSource

Constructor Summary

Writer()
Constructs a writer filter that prints to standard out.
Writer(OutputStream outputStream, String encoding)
Constructs a writer filter using the specified output stream and encoding.
Writer(Writer writer, String encoding)
Constructs a writer filter using the specified Java writer and encoding.

Method Summary

void
characters(XMLString text, Augmentations augs)
Characters.
void
comment(XMLString text, Augmentations augs)
Comment.
void
emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
Empty element.
void
endElement(QName element, Augmentations augs)
End element.
void
endGeneralEntity(String name, Augmentations augs)
End general entity.
static void
main(String[] argv)
Main.
protected void
printAttributeValue(String text)
Print attribute value.
protected void
printCharacters(XMLString text, boolean normalize)
Print characters.
protected void
printEndElement(QName element)
Print end element.
protected void
printEntity(String name)
Print entity.
protected void
printStartElement(QName element, XMLAttributes attributes)
Print start element.
void
startDocument(XMLLocator locator, String encoding, Augmentations augs)
Start document.
void
startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
Start document.
void
startElement(QName element, XMLAttributes attributes, Augmentations augs)
Start element.
void
startGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs)
Start general entity.

Methods inherited from class org.cyberneko.html.filters.DefaultFilter

characters, comment, doctypeDecl, emptyElement, endCDATA, endDocument, endElement, endGeneralEntity, endPrefixMapping, getDocumentHandler, getDocumentSource, getFeatureDefault, getPropertyDefault, getRecognizedFeatures, getRecognizedProperties, ignorableWhitespace, merge, processingInstruction, reset, setDocumentHandler, setDocumentSource, setFeature, setProperty, startCDATA, startDocument, startDocument, startElement, startGeneralEntity, startPrefixMapping, textDecl, xmlDecl

Field Details

AUGMENTATIONS

protected static final String AUGMENTATIONS
Augmentations feature identifier.

FILTERS

protected static final String FILTERS
Filters property identifier.

NOTIFY_CHAR_REFS

public static final String NOTIFY_CHAR_REFS
Notify character entity references.

NOTIFY_HTML_BUILTIN_REFS

public static final String NOTIFY_HTML_BUILTIN_REFS
Notify built-in entity references.

fElementDepth

protected int fElementDepth
Element depth.

fEncoding

protected String fEncoding
The encoding.

fNormalize

protected boolean fNormalize
Normalize character content.

fPrintChars

protected boolean fPrintChars
Print characters.

fPrinter

protected PrintWriter fPrinter
The print writer used for serializing the document with the appropriate character encoding.

fSeenHttpEquiv

protected boolean fSeenHttpEquiv
Seen http-equiv directive.

fSeenRootElement

protected boolean fSeenRootElement
Seen root element.

Constructor Details

Writer

public Writer()
Constructs a writer filter that prints to standard out.

Writer

public Writer(OutputStream outputStream,
              String encoding)
            throws UnsupportedEncodingException
Constructs a writer filter using the specified output stream and encoding.
Parameters:
outputStream - The output stream to write to.
encoding - The encoding to be used for the output. The encoding name should be an official IANA encoding name.

Writer

public Writer(Writer writer,
              String encoding)
Constructs a writer filter using the specified Java writer and encoding.
Parameters:
writer - The Java writer to write to.
encoding - The encoding to be used for the output. The encoding name should be an official IANA encoding name.

Method Details

characters

public void characters(XMLString text,
                       Augmentations augs)
            throws XNIException
Characters.
Overrides:
characters in interface DefaultFilter

comment

public void comment(XMLString text,
                    Augmentations augs)
            throws XNIException
Comment.
Overrides:
comment in interface DefaultFilter

emptyElement

public void emptyElement(QName element,
                         XMLAttributes attributes,
                         Augmentations augs)
            throws XNIException
Empty element.
Overrides:
emptyElement in interface DefaultFilter

endElement

public void endElement(QName element,
                       Augmentations augs)
            throws XNIException
End element.
Overrides:
endElement in interface DefaultFilter

endGeneralEntity

public void endGeneralEntity(String name,
                             Augmentations augs)
            throws XNIException
End general entity.
Overrides:
endGeneralEntity in interface DefaultFilter

main

public static void main(String[] argv)
            throws Exception
Main.

printAttributeValue

protected void printAttributeValue(String text)
Print attribute value.

printCharacters

protected void printCharacters(XMLString text,
                               boolean normalize)
Print characters.

printEndElement

protected void printEndElement(QName element)
Print end element.

printEntity

protected void printEntity(String name)
Print entity.

printStartElement

protected void printStartElement(QName element,
                                 XMLAttributes attributes)
Print start element.

startDocument

public void startDocument(XMLLocator locator,
                          String encoding,
                          Augmentations augs)
            throws XNIException
Start document.
Overrides:
startDocument in interface DefaultFilter

startDocument

public void startDocument(XMLLocator locator,
                          String encoding,
                          NamespaceContext nscontext,
                          Augmentations augs)
            throws XNIException
Start document.
Overrides:
startDocument in interface DefaultFilter

startElement

public void startElement(QName element,
                         XMLAttributes attributes,
                         Augmentations augs)
            throws XNIException
Start element.
Overrides:
startElement in interface DefaultFilter

startGeneralEntity

public void startGeneralEntity(String name,
                               XMLResourceIdentifier id,
                               String encoding,
                               Augmentations augs)
            throws XNIException
Start general entity.
Overrides:
startGeneralEntity in interface DefaultFilter

(C) Copyright 2002-2005, Andy Clark. All rights reserved.