FileDocCategorySizeDatePackage
ToHTMLSAXHandler.javaAPI DocJava SE 5 API22866Fri Aug 26 14:56:02 BST 2005com.sun.org.apache.xml.internal.serializer

ToHTMLSAXHandler

public class ToHTMLSAXHandler extends ToSAXHandler
This class accepts SAX-like calls, then sends true SAX calls to a wrapped SAX handler. There is optimization done knowing that the ultimate output is HTML.
author
Santiago Pericas-Geertsen
author
G. Todd Miller

Fields Summary
protected boolean
m_escapeSetting
Keeps track of whether output escaping is currently enabled
Constructors Summary
public ToHTMLSAXHandler(ContentHandler handler, String encoding)
A constructor

param
handler the wrapped SAX content handler
param
encoding the encoding of the output HTML document

        super(handler,encoding);
    
public ToHTMLSAXHandler(ContentHandler handler, LexicalHandler lex, String encoding)
A constructor.

param
handler the wrapped SAX content handler
param
lex the wrapped lexical handler
param
encoding the encoding of the output HTML document

        super(handler,lex,encoding);
    
Methods Summary
public voidattributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
Does nothing.

param
eName this parameter is ignored
param
aName this parameter is ignored
param
type this parameter is ignored
param
valueDefault this parameter is ignored
param
value this parameter is ignored
see
org.xml.sax.ext.DeclHandler#attributeDecl(String, String, String,String,String)

    
public voidcharacters(java.lang.String chars)
Receive notification of character data.

param
chars The string of characters to process.
throws
org.xml.sax.SAXException
see
com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#characters(String)

        final int length = chars.length();
        if (length > m_charsBuff.length)
        {
            m_charsBuff = new char[length * 2 + 1];
        }
        chars.getChars(0, length, m_charsBuff, 0);        
        this.characters(m_charsBuff, 0, length);
    
public voidcharacters(char[] ch, int off, int len)
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).

param
ch The characters from the XML document.
param
off The start position in the array.
param
len The number of characters to read from the array.
throws
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
see
#ignorableWhitespace
see
org.xml.sax.Locator
throws
org.xml.sax.SAXException
see
org.xml.sax.ContentHandler#characters(char[], int, int)


        flushPending();
        m_saxHandler.characters(ch, off, len);

        // time to fire off characters event
		if (m_tracer != null)
            super.fireCharEvent(ch, off, len);        
    
public voidclose()
Do nothing.

see
com.sun.org.apache.xml.internal.serializer.SerializationHandler#close()

        return;
    
protected voidcloseStartTag()
This method is called when all the data needed for a call to the SAX handler's startElement() method has been gathered.


        m_elemContext.m_startTagOpen = false;

        // Now is time to send the startElement event
        m_saxHandler.startElement(
            EMPTYSTRING,
            m_elemContext.m_elementName,
            m_elemContext.m_elementName,
            m_attributes);
        m_attributes.clear();       

    
public voidcomment(char[] ch, int start, int length)
Receive notification of a comment anywhere in the document. This callback will be used for comments inside or outside the document element.

param
ch An array holding the characters in the comment.
param
start The starting position in the array.
param
length The number of characters to use from the array.
throws
org.xml.sax.SAXException The application may raise an exception.
see
org.xml.sax.ext.LexicalHandler#comment(char[], int, int)

        flushPending();
        m_lexHandler.comment(ch, start, length);

        // time to fire off comment event
        if (m_tracer != null)
            super.fireCommentEvent(ch, start, length);
        return;
    
public voidelementDecl(java.lang.String name, java.lang.String model)
Does nothing.

see
org.xml.sax.ext.DeclHandler#elementDecl(String, String)

        return;
    
public voidendCDATA()
Does nothing.

see
org.xml.sax.ext.LexicalHandler#endCDATA()

        return;
    
public voidendDTD()
Does nothing.

see
org.xml.sax.ext.LexicalHandler#endDTD()

    
public voidendDocument()
Receive notification of the end of a document.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

throws
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
throws
org.xml.sax.SAXException

        flushPending();

        // Close output document
        m_saxHandler.endDocument();

        if (m_tracer != null)
            super.fireEndDoc();        
    
public voidendElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement() event for every endElement() event (even when the element is empty).

If the element name has a namespace prefix, the prefix will still be attached to the name.

param
namespaceURI The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
param
localName The local name (without prefix), or the empty string if Namespace processing is not being performed.
param
name The qualified name (with prefix), or the empty string if qualified names are not available.
param
name The element type name
throws
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
see
org.xml.sax.ContentHandler#endElement(String, String, String)

        flushPending();
        m_saxHandler.endElement(uri, localName, qName);
        
        // time to fire off endElement event
        if (m_tracer != null)
            super.fireEndElem(qName);
    
public voidendElement(java.lang.String elementName)
Receive notification of the end of an element.

param
elementName The element type name
throws
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
see
com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#endElement(String)

        flushPending();
        m_saxHandler.endElement(EMPTYSTRING, elementName, elementName);

        // time to fire off endElement event
		if (m_tracer != null)
            super.fireEndElem(elementName);        
    
public voidendPrefixMapping(java.lang.String prefix)
Does nothing.

    
public voidexternalEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2)

see
org.xml.sax.ext.DeclHandler#externalEntityDecl(String, String, String)

    
public voidflushPending()
This method flushes any pending events, which can be startDocument() closing the opening tag of an element, or closing an open CDATA section.

		if (m_needToCallStartDocument)
		{
			startDocumentInternal();
			m_needToCallStartDocument = false;
		}       	
        // Close any open element
        if (m_elemContext.m_startTagOpen)
        {
            closeStartTag();
            m_elemContext.m_startTagOpen = false;
        }
    
public java.util.PropertiesgetOutputFormat()
Returns null.

return
null
see
com.sun.org.apache.xml.internal.serializer.Serializer#getOutputFormat()


               
      
    
        return null;
    
public java.io.OutputStreamgetOutputStream()
Reurns null

return
null
see
com.sun.org.apache.xml.internal.serializer.Serializer#getOutputStream()

        return null;
    
public java.io.WritergetWriter()
Returns null

return
null
see
com.sun.org.apache.xml.internal.serializer.Serializer#getWriter()

        return null;
    
public voidignorableWhitespace(char[] ch, int start, int length)
Does nothing.

see
org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)

    
public voidindent(int n)
Does nothing.

    
public voidinternalEntityDecl(java.lang.String name, java.lang.String value)
Does nothing.

see
org.xml.sax.DTDHandler#unparsedEntityDecl

    
public voidnamespaceAfterStartElement(java.lang.String prefix, java.lang.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(). startPrefixMapping(prefix,uri) would be used before the startElement() call.

param
prefix the prefix associated with the given URI.
param
uri the URI of the namespace
see
com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#namespaceAfterStartElement(String, String)

        // hack for XSLTC with finding URI for default namespace
        if (m_elemContext.m_elementURI == null)
        {
            String prefix1 = getPrefixPart(m_elemContext.m_elementName);
            if (prefix1 == null && EMPTYSTRING.equals(prefix))
            {
                // the elements URI is not known yet, and it
                // doesn't have a prefix, and we are currently
                // setting the uri for prefix "", so we have
                // the uri for the element... lets remember it
                m_elemContext.m_elementURI = uri;
            }
        }       
        startPrefixMapping(prefix,uri,false);
    
public voidprocessingInstruction(java.lang.String arg0, java.lang.String arg1)
Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

param
target The processing instruction target.
param
data The processing instruction data, or null if none was supplied.
throws
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
throws
org.xml.sax.SAXException
see
org.xml.sax.ContentHandler#processingInstruction(String, String)

        flushPending();
        m_saxHandler.processingInstruction(arg0,arg1);

		// time to fire off processing instruction event
		
        if (m_tracer != null)		
		    super.fireEscapingEvent(arg0,arg1);        
    
public 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).

return
true if the class was successfuly reset.
see
com.sun.org.apache.xml.internal.serializer.Serializer#reset()

        boolean wasReset = false;
        if (super.reset())
        {
            resetToHTMLSAXHandler();
            wasReset = true;
        }
        return wasReset;
    
private voidresetToHTMLSAXHandler()
Reset all of the fields owned by ToHTMLSAXHandler class

        this.m_escapeSetting = false;
    
public voidserialize(org.w3c.dom.Node node)
Does nothing.

see
com.sun.org.apache.xml.internal.serializer.DOMSerializer#serialize(Node)

        return;
    
public voidsetDocumentLocator(org.xml.sax.Locator arg0)
Does nothing.

see
org.xml.sax.ContentHandler#setDocumentLocator(Locator)

        // do nothing
    
public booleansetEscaping(boolean escape)
Turns special character escaping on/off.

param
excape true if escaping is to be set on.
see
com.sun.org.apache.xml.internal.serializer.SerializationHandler#setEscaping(boolean)

        boolean oldEscapeSetting = m_escapeSetting;
        m_escapeSetting = escape;

        if (escape) {
            processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, "");
        } else {
            processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "");
        }

        return oldEscapeSetting;
    
public voidsetIndent(boolean indent)
Does nothing

param
indent the number of spaces to indent per indentation level (ignored)
see
com.sun.org.apache.xml.internal.serializer.SerializationHandler#setIndent(boolean)

    
public voidsetOutputFormat(java.util.Properties format)
Does nothing.

param
format this parameter is not used
see
com.sun.org.apache.xml.internal.serializer.Serializer#setOutputFormat(Properties)

    
public voidsetOutputStream(java.io.OutputStream output)
Does nothing.

param
output this parameter is ignored
see
com.sun.org.apache.xml.internal.serializer.Serializer#setOutputStream(OutputStream)

    
public voidsetWriter(java.io.Writer writer)
Does nothing.

param
writer this parameter is ignored.
see
com.sun.org.apache.xml.internal.serializer.Serializer#setWriter(Writer)

    
public voidskippedEntity(java.lang.String arg0)
Does nothing.

see
org.xml.sax.ContentHandler#skippedEntity(String)

    
public voidstartCDATA()
Does nothing.

see
org.xml.sax.ext.LexicalHandler#startCDATA()

    
public voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
Receive notification of the beginning of an element, although this is a SAX method additional namespace or attribute information can occur before or after this call, that is associated with this element.

param
namespaceURI The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
param
localName The local name (without prefix), or the empty string if Namespace processing is not being performed.
param
qName The elements name.
param
atts The attributes attached to the element, if any.
throws
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
see
org.xml.sax.ContentHandler#startElement
see
org.xml.sax.ContentHandler#endElement
see
org.xml.sax.AttributeList
throws
org.xml.sax.SAXException
see
org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)

        flushPending();
        super.startElement(namespaceURI, localName, qName, atts);
        m_saxHandler.startElement(namespaceURI, localName, qName, atts);
        m_elemContext.m_startTagOpen = false;
    
public voidstartElement(java.lang.String elementNamespaceURI, java.lang.String elementLocalName, java.lang.String elementName)
An element starts, but attributes are not fully known yet.

param
elementNamespaceURI the URI of the namespace of the element (optional)
param
elementLocalName the element name, but without prefix (optional)
param
elementName the element name, with prefix, if any (required)
see
com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#startElement(String)


        super.startElement(elementNamespaceURI, elementLocalName, elementName);

        flushPending();

        // Handle document type declaration (for first element only)
        if (m_lexHandler != null)
        {
            String doctypeSystem = getDoctypeSystem();
            String doctypePublic = getDoctypePublic();
            if ((doctypeSystem != null) || (doctypePublic != null))
                m_lexHandler.startDTD(
                    elementName,
                    doctypePublic,
                    doctypeSystem);
            m_lexHandler = null;
        }
        m_elemContext = m_elemContext.push(elementNamespaceURI, elementLocalName, elementName);
    
public voidstartElement(java.lang.String elementName)
An element starts, but attributes are not fully known yet.

param
elementName the element name, with prefix, if any
see
com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#startElement(String)

        this.startElement(null,null, elementName);
    
public voidstartEntity(java.lang.String arg0)
Does nothing.

see
org.xml.sax.ext.LexicalHandler#startEntity(String)

    
public booleanstartPrefixMapping(java.lang.String prefix, java.lang.String uri, boolean shouldFlush)
Handle a prefix/uri mapping, which is associated with a startElement() that is soon to follow. Need to close any open start tag to make sure than any name space attributes due to this event are associated wih the up comming element, not the current one.

see
com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#startPrefixMapping
param
prefix The Namespace prefix being declared.
param
uri The Namespace URI the prefix is mapped to.
param
shouldFlush true if any open tags need to be closed first, this will impact which element the mapping applies to (open parent, or its up comming child)
return
returns true if the call made a change to the current namespace information, false if it did not change anything, e.g. if the prefix/namespace mapping was already in scope from before.
throws
org.xml.sax.SAXException The client may throw an exception during processing.

        // no namespace support for HTML
        if (shouldFlush) 
            flushPending();   
        m_saxHandler.startPrefixMapping(prefix,uri);
        return false;
    
public voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)
Begin the scope of a prefix-URI Namespace mapping just before another element is about to start. This call will close any open tags so that the prefix mapping will not apply to the current element, but the up comming child.

see
org.xml.sax.ContentHandler#startPrefixMapping
param
prefix The Namespace prefix being declared.
param
uri The Namespace URI the prefix is mapped to.
throws
org.xml.sax.SAXException The client may throw an exception during processing.

        startPrefixMapping(prefix,uri,true);