org.cyberneko.html.filters

Class Writer

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 StringAUGMENTATIONS
Augmentations feature identifier.
protected intfElementDepth
Element depth.
protected StringfEncoding
The encoding.
protected booleanfNormalize
Normalize character content.
protected booleanfPrintChars
Print characters.
protected PrintWriterfPrinter
The print writer used for serializing the document with the appropriate character encoding.
protected booleanfSeenHttpEquiv
Seen http-equiv directive.
protected booleanfSeenRootElement
Seen root element.
protected static StringFILTERS
Filters property identifier.
static StringNOTIFY_CHAR_REFS
Notify character entity references.
static StringNOTIFY_HTML_BUILTIN_REFS
Notify built-in entity references.
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
voidcharacters(XMLString text, Augmentations augs)
Characters.
voidcomment(XMLString text, Augmentations augs)
Comment.
voidemptyElement(QName element, XMLAttributes attributes, Augmentations augs)
Empty element.
voidendElement(QName element, Augmentations augs)
End element.
voidendGeneralEntity(String name, Augmentations augs)
End general entity.
static voidmain(String[] argv)
Main.
protected voidprintAttributeValue(String text)
Print attribute value.
protected voidprintCharacters(XMLString text, boolean normalize)
Print characters.
protected voidprintEndElement(QName element)
Print end element.
protected voidprintEntity(String name)
Print entity.
protected voidprintStartElement(QName element, XMLAttributes attributes)
Print start element.
voidstartDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
Start document.
voidstartDocument(XMLLocator locator, String encoding, Augmentations augs)
Start document.
voidstartElement(QName element, XMLAttributes attributes, Augmentations augs)
Start element.
voidstartGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs)
Start general entity.

Field Detail

AUGMENTATIONS

protected static final String AUGMENTATIONS
Augmentations feature identifier.

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.

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.

Constructor Detail

Writer

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

Writer

public Writer(OutputStream outputStream, String encoding)
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 Detail

characters

public void characters(XMLString text, Augmentations augs)
Characters.

comment

public void comment(XMLString text, Augmentations augs)
Comment.

emptyElement

public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
Empty element.

endElement

public void endElement(QName element, Augmentations augs)
End element.

endGeneralEntity

public void endGeneralEntity(String name, Augmentations augs)
End general entity.

main

public static void main(String[] argv)
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, NamespaceContext nscontext, Augmentations augs)
Start document.

startDocument

public void startDocument(XMLLocator locator, String encoding, Augmentations augs)
Start document.

startElement

public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
Start element.

startGeneralEntity

public void startGeneralEntity(String name, XMLResourceIdentifier id, String encoding, Augmentations augs)
Start general entity.
(C) Copyright 2002-2005, Andy Clark. All rights reserved.