Class ToHTMLStream
- All Implemented Interfaces:
DOMSerializer,ExtendedContentHandler,ExtendedLexicalHandler,SerializationHandler,Serializer,ContentHandler,DTDHandler,ErrorHandler,DeclHandler,LexicalHandler
public class ToHTMLStream extends ToStream
-
Field Summary
Fields Modifier and Type Field Description static StringCDATA_CONTINUETo insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >static StringCDATA_DELIMITER_CLOSEThe constant "]]>"static StringCDATA_DELIMITER_OPENstatic StringDEFAULT_SAX_SERIALIZERstatic StringEMPTYSTRINGstatic StringENTITY_AMPstatic StringENTITY_CRLFstatic StringENTITY_GTstatic StringENTITY_LTstatic StringENTITY_QUOTprotected booleanm_inDTDThis flag is set while receiving events from the DTDstatic StringXML_PREFIXstatic StringXMLNS_PREFIXstatic StringXMLNS_URIstatic StringXMLVERSION10static StringXMLVERSION11Define the XML version.Fields inherited from class org.apache.xml.serializer.ToStream
m_cdataStartCalled, m_charInfo, m_disableOutputEscapingStates, m_escaping, m_inDoctype, m_ispreserve, m_isprevtext, m_lineSep, m_lineSepLen, m_lineSepUse, m_preserves, m_spaceBeforeCloseFields inherited from class org.apache.xml.serializer.SerializerBase
m_attrBuff, m_attributes, m_CdataElems, m_cdataTagOpen, m_charsBuff, m_doctypePublic, m_doctypeSystem, m_doIndent, m_elemContext, m_indentAmount, m_inEntityRef, m_inExternalDTD, m_mediatype, m_needToCallStartDocument, m_prefixMap, m_shouldNotWriteXMLHeader, m_sourceLocator, m_standaloneWasSpecified, m_StringOfCDATASections, m_tracer, m_version, m_writer, PKG_NAME, PKG_PATHFields inherited from interface org.apache.xml.serializer.ExtendedContentHandler
HTML_ATTREMPTY, HTML_ATTRURL, NO_BAD_CHARS -
Constructor Summary
Constructors Constructor Description ToHTMLStream()Default constructor. -
Method Summary
Modifier and Type Method Description voidaddUniqueAttribute(String name, String value, int flags)This method is used to add an attribute to the currently open element.voidattributeDecl(String eName, String aName, String type, String valueDefault, String value)This method does nothing.voidcdata(char[] ch, int start, int length)Receive notification of cdata.voidcharacters(char[] chars, int start, int length)Receive notification of character data.protected voidcloseStartTag()For the enclosing elements starting tag write out out any attributes followed by ">".voidcomment(char[] ch, int start, int length)Receive notification of an XML comment anywhere in the document.voidelementDecl(String name, String model)This method does nothing.voidendDocument()Receive notification of the end of a document.voidendDTD()Report the end of DTD declarations.voidendElement(String elemName)Receive notification of the end of an element.voidendElement(String namespaceURI, String localName, String name)Receive notification of the end of an element.voidentityReference(String name)Receive notivication of a entityReference.voidexternalEntityDecl(String name, String publicId, String systemId)This method does nothing.static ElemDescgetElemDesc(String name)Get a description of the given element.voidinternalEntityDecl(String name, String value)This method does nothing.voidnamespaceAfterStartElement(String prefix, String uri)This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement().protected voidprocessAttribute(Writer writer, String name, String value, ElemDesc elemDesc)Process an attribute.voidprocessAttributes(Writer writer, int nAttrs)Process the attributes, which means to write out the currently collected attributes to the writer.voidprocessingInstruction(String target, String data)Receive notification of a processing instruction.booleanreset()Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).voidsetOmitMetaTag(boolean bool)Tells if the formatter should omit the META tag.voidsetOutputFormat(Properties format)Specifies an output format for this serializer.voidsetSpecialEscapeURLs(boolean bool)Tells if the formatter should use special URL escaping.protected voidstartDocumentInternal()Receive notification of the beginning of a document.voidstartDTD(String name, String publicId, String systemId)Report the start of DTD declarations, if any.voidstartElement(String namespaceURI, String localName, String name, Attributes atts)Receive notification of the beginning of an element.voidwriteAttrString(Writer writer, String string, String encoding)Writes the specified string after substituting specials, and UTF-16 surrogates for character references&#xnn.voidwriteAttrURI(Writer writer, String string, boolean doURLEscaping)Write the specified string after substituting non ASCII characters, with%HH, where HH is the hex of the byte value.Methods inherited from class org.apache.xml.serializer.ToStream
addAttributeAlways, addCdataSectionElements, characters, charactersRaw, closeCDATA, endCDATA, endNonEscaping, endPrefixMapping, ensureAttributesNamespaceIsDeclared, escapingNotNeeded, firePseudoAttributes, flushPending, flushWriter, getIndentAmount, getOutputFormat, getOutputStream, getWriter, ignorableWhitespace, indent, indent, notationDecl, outputLineSep, serialize, setCdataSectionElements, setContentHandler, setDTDEntityExpansion, setEncoding, setEscaping, setIndentAmount, setLineSepUse, setNewLine, setOutputStream, setTransformer, setWriter, shouldIndent, skippedEntity, startCDATA, startElement, startElement, startEntity, startNonEscaping, startPrefixMapping, startPrefixMapping, unparsedEntityDecl, writeUTF16SurrogateMethods inherited from class org.apache.xml.serializer.SerializerBase
addAttribute, addAttribute, addAttribute, addAttributes, addXSLAttribute, asContentHandler, asDOM3Serializer, asDOMSerializer, characters, close, comment, documentIsEmpty, endEntity, error, fatalError, fireCDATAEvent, fireCharEvent, fireCommentEvent, fireEndDoc, fireEndElem, fireEndEntity, fireEntityReference, fireEscapingEvent, fireStartDoc, fireStartElem, fireStartEntity, getDoctypePublic, getDoctypeSystem, getEncoding, getIndent, getLocalName, getMediaType, getNamespaceMappings, getNamespaceURI, getNamespaceURIFromPrefix, getOmitXMLDeclaration, getOutputProperty, getOutputPropertyDefault, getOutputPropertyNonDefault, getPrefix, getPrefixPart, getStandalone, getTransformer, getVersion, initCDATA, isCdataSection, patchName, setDoctype, setDoctypePublic, setDoctypeSystem, setDocumentLocator, setIndent, setMediaType, setNamespaceMappings, setOmitXMLDeclaration, setOutputProperty, setOutputPropertyDefault, setSourceLocator, setStandalone, setStandaloneInternal, setVersion, startDocument, warning
-
Field Details
-
m_inDTD
protected boolean m_inDTDThis flag is set while receiving events from the DTD -
CDATA_CONTINUE
To insert ]]> in a CDATA section by ending the last CDATA section with ]] and starting the next CDATA section with >- See Also:
- Constant Field Values
-
CDATA_DELIMITER_CLOSE
The constant "]]>"- See Also:
- Constant Field Values
-
CDATA_DELIMITER_OPEN
- See Also:
- Constant Field Values
-
EMPTYSTRING
- See Also:
- Constant Field Values
-
ENTITY_AMP
- See Also:
- Constant Field Values
-
ENTITY_CRLF
- See Also:
- Constant Field Values
-
ENTITY_GT
- See Also:
- Constant Field Values
-
ENTITY_LT
- See Also:
- Constant Field Values
-
ENTITY_QUOT
- See Also:
- Constant Field Values
-
XML_PREFIX
- See Also:
- Constant Field Values
-
XMLNS_PREFIX
- See Also:
- Constant Field Values
-
XMLNS_URI
- See Also:
- Constant Field Values
-
DEFAULT_SAX_SERIALIZER
-
XMLVERSION11
Define the XML version.- See Also:
- Constant Field Values
-
XMLVERSION10
- See Also:
- Constant Field Values
-
-
Constructor Details
-
ToHTMLStream
public ToHTMLStream()Default constructor.
-
-
Method Details
-
setSpecialEscapeURLs
public void setSpecialEscapeURLs(boolean bool)Tells if the formatter should use special URL escaping.- Parameters:
bool- True if URLs should be specially escaped with the %xx form.
-
setOmitMetaTag
public void setOmitMetaTag(boolean bool)Tells if the formatter should omit the META tag.- Parameters:
bool- True if the META tag should be omitted.
-
setOutputFormat
Specifies an output format for this serializer. It the serializer has already been associated with an output format, it will switch to the new format. This method should not be called while the serializer is in the process of serializing a document. This method can be called multiple times before starting the serialization of a particular result-tree. In principle all serialization parameters can be changed, with the exception of method="html" (it must be method="html" otherwise we shouldn't even have a ToHTMLStream object here!)- Specified by:
setOutputFormatin interfaceSerializer- Overrides:
setOutputFormatin classToStream- Parameters:
format- The output format or serialzation parameters to use.
-
getElemDesc
Get a description of the given element.- Parameters:
name- non-null name of element, case insensitive.- Returns:
- non-null reference to ElemDesc, which may be m_dummy if no element description matches the given name.
-
startDocumentInternal
Receive notification of the beginning of a document.- Overrides:
startDocumentInternalin classSerializerBase- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.SAXException
-
endDocument
Receive notification of the end of a document.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.SAXException- See Also:
ContentHandler.startDocument()
-
startElement
public void startElement(String namespaceURI, String localName, String name, Attributes atts) throws SAXExceptionReceive notification of the beginning of an element.- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classToStream- Parameters:
namespaceURI-localName-name- The element type name.atts- The attributes attached to the element, if any.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
endElement(java.lang.String, java.lang.String, java.lang.String),AttributeList
-
endElement
public final void endElement(String namespaceURI, String localName, String name) throws SAXExceptionReceive notification of the end of an element.- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classToStream- Parameters:
namespaceURI-localName-name- The element type name- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.
-
processAttribute
protected void processAttribute(Writer writer, String name, String value, ElemDesc elemDesc) throws IOExceptionProcess an attribute.- Parameters:
writer- The writer to write the processed output to.name- The name of the attribute.value- The value of the attribute.elemDesc- The description of the HTML element that has this attribute.- Throws:
SAXExceptionIOException
-
writeAttrURI
Write the specified string after substituting non ASCII characters, with%HH, where HH is the hex of the byte value.- Parameters:
string- String to convert to XML format.doURLEscaping- True if we should try to encode as per http://www.ietf.org/rfc/rfc2396.txt.- Throws:
SAXException- if a bad surrogate pair is detected.IOException
-
writeAttrString
Writes the specified string after substituting specials, and UTF-16 surrogates for character references&#xnn.- Overrides:
writeAttrStringin classToStream- Parameters:
string- String to convert to XML format.encoding- CURRENTLY NOT IMPLEMENTED.- Throws:
SAXExceptionIOException
-
characters
Receive notification of character data.The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).
- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classToStream- Parameters:
chars- The characters from the XML document.start- The start position in the array.length- The number of characters to read from the array.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.SAXException- See Also:
ToStream.ignorableWhitespace(char[], int, int),Locator
-
cdata
Receive notification of cdata.The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).
- Overrides:
cdatain classToStream- Parameters:
ch- The characters from the XML document.start- The start position in the array.length- The number of characters to read from the array.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.SAXException- See Also:
ToStream.ignorableWhitespace(char[], int, int),Locator
-
processingInstruction
Receive notification of a processing instruction.- Parameters:
target- The processing instruction target.data- The processing instruction data, or null if none was supplied.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.SAXException
-
entityReference
Receive notivication of a entityReference.- Specified by:
entityReferencein interfaceExtendedContentHandler- Overrides:
entityReferencein classSerializerBase- Parameters:
name- non-null reference to entity name string.- Throws:
SAXException
-
endElement
Description copied from class:ToStreamReceive notification of the end of an element.- Specified by:
endElementin interfaceExtendedContentHandler- Overrides:
endElementin classToStream- Parameters:
elemName- The element type name- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
ExtendedContentHandler.endElement(String)
-
processAttributes
Process the attributes, which means to write out the currently collected attributes to the writer. The attributes are not cleared by this method- Overrides:
processAttributesin classToStream- Parameters:
writer- the writer to write processed attributes to.nAttrs- the number of attributes in m_attributes to be processed- Throws:
SAXExceptionIOException
-
closeStartTag
For the enclosing elements starting tag write out out any attributes followed by ">". At this point we also mark if this element is a cdata-section-element.- Overrides:
closeStartTagin classToStream- Throws:
SAXException
-
namespaceAfterStartElement
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call.- Specified by:
namespaceAfterStartElementin interfaceExtendedContentHandler- Overrides:
namespaceAfterStartElementin classSerializerBase- Parameters:
uri- the URI of the namespaceprefix- the prefix associated with the given URI.- Throws:
SAXException- See Also:
ExtendedContentHandler.namespaceAfterStartElement(String, String)
-
startDTD
Description copied from class:ToStreamReport the start of DTD declarations, if any. Any declarations are assumed to be in the internal subset unless otherwise indicated.- Specified by:
startDTDin interfaceLexicalHandler- Overrides:
startDTDin classToStream- Parameters:
name- The document type name.publicId- The declared public identifier for the external DTD subset, or null if none was declared.systemId- The declared system identifier for the external DTD subset, or null if none was declared.- Throws:
SAXException- The application may raise an exception.- See Also:
ToStream.endDTD(),ToStream.startEntity(java.lang.String)
-
endDTD
Report the end of DTD declarations.- Specified by:
endDTDin interfaceLexicalHandler- Overrides:
endDTDin classToStream- Throws:
SAXException- The application may raise an exception.- See Also:
startDTD(java.lang.String, java.lang.String, java.lang.String)
-
attributeDecl
public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXExceptionThis method does nothing.- Specified by:
attributeDeclin interfaceDeclHandler- Overrides:
attributeDeclin classToStream- Parameters:
eName- The name of the associated element.aName- The name of the attribute.type- A string representing the attribute type.valueDefault- A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.value- A string representing the attribute's default value, or null if there is none.- Throws:
SAXException- The application may raise an exception.
-
elementDecl
This method does nothing.- Specified by:
elementDeclin interfaceDeclHandler- Overrides:
elementDeclin classToStream- Parameters:
name- The element type name.model- The content model as a normalized string.- Throws:
SAXException- The application may raise an exception.
-
internalEntityDecl
This method does nothing.- Specified by:
internalEntityDeclin interfaceDeclHandler- Overrides:
internalEntityDeclin classToStream- Parameters:
name- The name of the entity. If it is a parameter entity, the name will begin with '%'.value- The replacement text of the entity.- Throws:
SAXException- The application may raise an exception.- See Also:
ToStream.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String),DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
externalEntityDecl
This method does nothing.- Specified by:
externalEntityDeclin interfaceDeclHandler- Overrides:
externalEntityDeclin classToStream- Parameters:
name- The name of the entity. If it is a parameter entity, the name will begin with '%'.publicId- The declared public identifier of the entity, or null if none was declared.systemId- The declared system identifier of the entity.- Throws:
SAXException- The application may raise an exception.- See Also:
ToStream.internalEntityDecl(java.lang.String, java.lang.String),DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
addUniqueAttribute
This method is used to add an attribute to the currently open element. The caller has guaranted that this attribute is unique, which means that it not been seen before and will not be seen again.- Parameters:
name- the qualified name of the attributevalue- the value of the attribute which can contain only ASCII printable characters characters in the range 32 to 127 inclusive.flags- the bit values of this integer give optimization information.- Throws:
SAXException
-
comment
Description copied from class:ToStreamReceive notification of an XML comment anywhere in the document. This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).- Specified by:
commentin interfaceLexicalHandler- Overrides:
commentin classToStream- Parameters:
ch- An array holding the characters in the comment.start- The starting position in the array.length- The number of characters to use from the array.- Throws:
SAXException- The application may raise an exception.
-
reset
public boolean reset()Description copied from class:ToStreamTry's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons).- Specified by:
resetin interfaceSerializer- Overrides:
resetin classToStream- Returns:
- true if the class was successfuly reset.
-