|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fi.iki.hsivonen.xml.HtmlSerializer
public class HtmlSerializer
Serializes a sequence of SAX events representing an XHTML 1.0 Strict document
to an OutputStream
as a UTF-8-encoded HTML 4.01 Strict
document. The SAX events must represent a valid XHTML 1.0 document, except
the namespace prefixes don't matter and there may be
startElement
and endElement
calls for elements
from other namespaces. The startElement
and
endElement
calls for non-XHTML elements are ignored. No
validity checking is performed. Hence, the emitter of the SAX events is
responsible for making sure the events represent a document that meets the
above requirements. The OutputStream
is closed when the end of
the document is seen.
Field Summary | |
---|---|
private static String[] |
booleanAttributes
Minimized "boolean" HTML attributes |
private int |
doctype
|
static int |
DOCTYPE_HTML401_STRICT
|
static int |
DOCTYPE_HTML401_TRANSITIONAL
|
static int |
DOCTYPE_HTML5
|
private boolean |
emitMeta
|
private static String[] |
emptyElements
HTML 4.01 elements which don't have an end tag |
private String |
encoding
|
static int |
NO_DOCTYPE
|
protected Writer |
writer
The writer used for output |
private static String |
XHTML_NS
The XHTML namespace URI |
Constructor Summary | |
---|---|
HtmlSerializer(OutputStream out)
Creates a new instance of HtmlSerializer in the HTML 4.01 doctype mode with the UTF-8 encoding and no charset meta. |
|
HtmlSerializer(OutputStream out,
int doctype,
boolean emitMeta)
|
|
HtmlSerializer(OutputStream out,
int doctype,
boolean emitMeta,
String enc)
|
Method Summary | |
---|---|
void |
characters(char[] ch,
int start,
int length)
Writes out characters. |
void |
endDocument()
Must be called in the end. |
void |
endElement(String namespaceURI,
String localName,
String qName)
Writes an end tag if the element is an XHTML element and is not an empty element in HTML 4.01 Strict. |
void |
endPrefixMapping(String str)
Does nothing. |
void |
ignorableWhitespace(char[] values,
int param,
int param2)
Does nothing. |
static void |
main(String[] args)
Used for testing. |
void |
processingInstruction(String str,
String str1)
Does nothing. |
void |
setDocumentLocator(Locator locator)
Does nothing. |
void |
skippedEntity(String str)
Does nothing. |
void |
startDocument()
Must be called first. |
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes atts)
Writes a start tag if the element is an XHTML element. |
void |
startPrefixMapping(String str,
String str1)
Does nothing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NO_DOCTYPE
public static final int DOCTYPE_HTML401_TRANSITIONAL
public static final int DOCTYPE_HTML401_STRICT
public static final int DOCTYPE_HTML5
private static final String XHTML_NS
private static final String[] emptyElements
private static final String[] booleanAttributes
protected Writer writer
private int doctype
private String encoding
private boolean emitMeta
Constructor Detail |
---|
public HtmlSerializer(OutputStream out)
out
- the stream to which the output is writtenpublic HtmlSerializer(OutputStream out, int doctype, boolean emitMeta)
public HtmlSerializer(OutputStream out, int doctype, boolean emitMeta, String enc)
Method Detail |
---|
public void characters(char[] ch, int start, int length) throws SAXException
characters
in interface ContentHandler
ch
- the source arraystart
- the index of the first character to be writtenlength
- the number of characters to write
SAXException
- if there are IO problemspublic void endDocument() throws SAXException
endDocument
in interface ContentHandler
SAXException
- if there are IO problemspublic void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement
in interface ContentHandler
namespaceURI
- the XML namespacelocalName
- the element name in the namespaceqName
- ignored
SAXException
- if there are IO problemspublic void startDocument() throws SAXException
startDocument
in interface ContentHandler
SAXException
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
startElement
in interface ContentHandler
namespaceURI
- the XML namespacelocalName
- the element name in the namespaceqName
- ignoredatts
- the attribute list
SAXException
- if there are IO problemspublic static void main(String[] args)
public void endPrefixMapping(String str) throws SAXException
endPrefixMapping
in interface ContentHandler
SAXException
public void ignorableWhitespace(char[] values, int param, int param2) throws SAXException
ignorableWhitespace
in interface ContentHandler
SAXException
public void processingInstruction(String str, String str1) throws SAXException
processingInstruction
in interface ContentHandler
SAXException
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
public void skippedEntity(String str) throws SAXException
skippedEntity
in interface ContentHandler
SAXException
public void startPrefixMapping(String str, String str1) throws SAXException
startPrefixMapping
in interface ContentHandler
SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |