tohtmlsaxhandler.java

来自「JAVA 所有包」· Java 代码 · 共 744 行 · 第 1/2 页

JAVA
744
字号
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: ToHTMLSAXHandler.java,v 1.3 2005/09/28 13:49:07 pvedula Exp $ */package com.sun.org.apache.xml.internal.serializer;import java.io.IOException;import java.io.OutputStream;import java.io.Writer;import java.util.Properties;import javax.xml.transform.Result;import org.w3c.dom.Node;import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.Locator;import org.xml.sax.SAXException;import org.xml.sax.ext.LexicalHandler;/** * 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. *  * This class is not a public API. *  * @xsl.usage internal */public final class ToHTMLSAXHandler extends ToSAXHandler{	/**	 *  Handle document type declaration (for first element only)	 */	private boolean m_dtdHandled = false;	    /**     * Keeps track of whether output escaping is currently enabled     */    protected boolean m_escapeSetting = false;    /**     * Returns null.     * @return null     * @see Serializer#getOutputFormat()     */    public Properties getOutputFormat()    {        return null;    }    /**     * Reurns null     * @return null     * @see Serializer#getOutputStream()     */    public OutputStream getOutputStream()    {        return null;    }    /**     * Returns null     * @return null     * @see Serializer#getWriter()     */    public Writer getWriter()    {        return null;    }    /**     * Does nothing.     *     */    public void indent(int n) throws SAXException    {    }    /**     * Does nothing.     * @see DOMSerializer#serialize(Node)     */    public void serialize(Node node) throws IOException    {        return;    }    /**     * Turns special character escaping on/off.     *     *     * @param escape true if escaping is to be set on.     *     * @see SerializationHandler#setEscaping(boolean)     */    public boolean setEscaping(boolean escape) throws SAXException    {        boolean oldEscapeSetting = m_escapeSetting;        m_escapeSetting = escape;        if (escape) {            processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, "");        } else {            processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "");        }        return oldEscapeSetting;    }    /**     * Does nothing     * @param indent the number of spaces to indent per indentation level     * (ignored)     * @see SerializationHandler#setIndent(boolean)     */    public void setIndent(boolean indent)    {    }    /**     * Does nothing.     * @param format this parameter is not used     * @see Serializer#setOutputFormat(Properties)     */    public void setOutputFormat(Properties format)    {    }    /**     * Does nothing.     * @param output this parameter is ignored     * @see Serializer#setOutputStream(OutputStream)     */    public void setOutputStream(OutputStream output)    {    }    /**     * Does nothing.     * @param writer this parameter is ignored.     * @see Serializer#setWriter(Writer)     */    public void setWriter(Writer writer)    {    }    /**     * @see org.xml.sax.ext.DeclHandler#attributeDecl(String, String, String, String, String)     */    /**     * 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 void attributeDecl(        String eName,        String aName,        String type,        String valueDefault,        String value)        throws SAXException    {    }    /**     * Does nothing.     * @see org.xml.sax.ext.DeclHandler#elementDecl(String, String)     */        public void elementDecl(String name, String model) throws SAXException    {        return;    }    /**     * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(String, String, String)     */    public void externalEntityDecl(String arg0, String arg1, String arg2)        throws SAXException    {    }    /**     * Does nothing.     *     * @see org.xml.sax.DTDHandler#unparsedEntityDecl     */    public void internalEntityDecl(String name, String value)        throws SAXException    {    }    /**     * Receive notification of the end of an element.     *     * <p>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).</p>     *     * <p>If the element name has a namespace prefix, the prefix will     * still be attached to the name.</p>     *     *     * @param uri 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 qualified name (with prefix), or the     *        empty string if qualified names are not available.     * @throws org.xml.sax.SAXException Any SAX exception, possibly     *            wrapping another exception.     * @see org.xml.sax.ContentHandler#endElement(String, String, String)     */    public void endElement(String uri, String localName, String qName)        throws SAXException    {        flushPending();        m_saxHandler.endElement(uri, localName, qName);                // time to fire off endElement event        if (m_tracer != null)            super.fireEndElem(qName);    }    /**     * Does nothing.     */    public void endPrefixMapping(String prefix) throws SAXException    {    }    /**     * Does nothing.     * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)     */    public void ignorableWhitespace(char[] ch, int start, int length)        throws SAXException    {    }        /**     * Receive notification of a processing instruction.     *     * <p>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.</p>     *     * <p>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.</p>     *     * @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)     */    public void processingInstruction(String target, String data)        throws SAXException    {        flushPending();        m_saxHandler.processingInstruction(target,data);		// time to fire off processing instruction event		        if (m_tracer != null)				    super.fireEscapingEvent(target,data);            }    /**     * Does nothing.       * @see org.xml.sax.ContentHandler#setDocumentLocator(Locator)     */    public void setDocumentLocator(Locator arg0)    {        super.setDocumentLocator(arg0);    }    /**     * Does nothing.     * @see org.xml.sax.ContentHandler#skippedEntity(String)     */    public void skippedEntity(String arg0) throws SAXException    {    }    /**     * 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)     */    public void startElement(        String namespaceURI,        String localName,        String qName,        Attributes atts)        throws SAXException    {        flushPending();        super.startElement(namespaceURI, localName, qName, atts);        m_saxHandler.startElement(namespaceURI, localName, qName, atts);        m_elemContext.m_startTagOpen = false;    }    /**     * 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)     */    public void comment(char[] ch, int start, int length) throws SAXException    {        flushPending();        if (m_lexHandler != null)            m_lexHandler.comment(ch, start, length);        // time to fire off comment event        if (m_tracer != null)            super.fireCommentEvent(ch, start, length);        return;    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?