tohtmlstream.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,886 行 · 第 1/5 页

JAVA
1,886
字号
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("MULTIPLE", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("OPTGROUP");        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("OPTION");        elemDesc.setAttr("SELECTED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("TEXTAREA");        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("READONLY", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("BUTTON");        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("SCRIPT");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc.setAttr("FOR", ElemDesc.ATTRURL);        elemDesc.setAttr("DEFER", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("IMG");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);        elemDesc.setAttr("USEMAP", ElemDesc.ATTRURL);        elemDesc.setAttr("ISMAP", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("OBJECT");        elemDesc.setAttr("CLASSID", ElemDesc.ATTRURL);        elemDesc.setAttr("CODEBASE", ElemDesc.ATTRURL);        elemDesc.setAttr("DATA", ElemDesc.ATTRURL);        elemDesc.setAttr("ARCHIVE", ElemDesc.ATTRURL);        elemDesc.setAttr("USEMAP", ElemDesc.ATTRURL);        elemDesc.setAttr("DECLARE", ElemDesc.ATTREMPTY);        elemDesc = (ElemDesc) m_elementFlags.get("FORM");        elemDesc.setAttr("ACTION", ElemDesc.ATTRURL);        elemDesc = (ElemDesc) m_elementFlags.get("HEAD");        elemDesc.setAttr("PROFILE", ElemDesc.ATTRURL);        // Attribution to: "Voytenko, Dimitry" <DVoytenko@SECTORBASE.COM>        elemDesc = (ElemDesc) m_elementFlags.get("FRAME");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);        // HTML 4.0, section 16.5        elemDesc = (ElemDesc) m_elementFlags.get("IFRAME");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);        // NS4 extensions        elemDesc = (ElemDesc) m_elementFlags.get("LAYER");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc = (ElemDesc) m_elementFlags.get("ILAYER");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc = (ElemDesc) m_elementFlags.get("DIV");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);    }    /**     * Dummy element for elements not found.     */    static private final ElemDesc m_dummy = new ElemDesc(0 | ElemDesc.BLOCK);    /** True if URLs should be specially escaped with the %xx form. */    private boolean m_specialEscapeURLs = true;    /** True if the META tag should be omitted. */    private boolean m_omitMetaTag = false;    /**     * Tells if the formatter should use special URL escaping.     *     * @param bool True if URLs should be specially escaped with the %xx form.     */    public void setSpecialEscapeURLs(boolean bool)    {        m_specialEscapeURLs = bool;    }    /**     * Tells if the formatter should omit the META tag.     *     * @param bool True if the META tag should be omitted.     */    public void setOmitMetaTag(boolean bool)    {        m_omitMetaTag = bool;    }    /**     * 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.     *     * @param format The output format to use     */    public void setOutputFormat(Properties format)    {         m_specialEscapeURLs =            OutputPropertyUtils.getBooleanProperty(                OutputPropertiesFactory.S_USE_URL_ESCAPING,                format);        m_omitMetaTag =            OutputPropertyUtils.getBooleanProperty(                OutputPropertiesFactory.S_OMIT_META_TAG,                format);        super.setOutputFormat(format);    }    /**     * Tells if the formatter should use special URL escaping.     *     * @return True if URLs should be specially escaped with the %xx form.     */    private final boolean getSpecialEscapeURLs()    {        return m_specialEscapeURLs;    }    /**     * Tells if the formatter should omit the META tag.     *     * @return True if the META tag should be omitted.     */    private final boolean getOmitMetaTag()    {        return m_omitMetaTag;    }    /**     * Get a description of the given element.     *     * @param name non-null name of element, case insensitive.     *     * @return non-null reference to ElemDesc, which may be m_dummy if no      *         element description matches the given name.     */    public static final ElemDesc getElemDesc(String name)    {        /* this method used to return m_dummy  when name was null         * but now it doesn't check and and requires non-null name.         */        Object obj = m_elementFlags.get(name);        if (null != obj)            return (ElemDesc)obj;        return m_dummy;    }    /**     * Default constructor.     */    public ToHTMLStream()    {        super();        m_charInfo = m_htmlcharInfo;        // initialize namespaces        m_prefixMap = new NamespaceMappings();    }    /** The name of the current element. *///    private String m_currentElementName = null;    /**     * Receive notification of the beginning of a document.     *     * @throws org.xml.sax.SAXException Any SAX exception, possibly     *            wrapping another exception.     *     * @throws org.xml.sax.SAXException     */    protected void startDocumentInternal() throws org.xml.sax.SAXException    {        super.startDocumentInternal();        m_needToCallStartDocument = false;         m_needToOutputDocTypeDecl = true;        m_startNewLine = false;        setOmitXMLDeclaration(true);        if (true == m_needToOutputDocTypeDecl)        {            String doctypeSystem = getDoctypeSystem();            String doctypePublic = getDoctypePublic();            if ((null != doctypeSystem) || (null != doctypePublic))            {                final java.io.Writer writer = m_writer;                try                {                writer.write("<!DOCTYPE HTML");                if (null != doctypePublic)                {                    writer.write(" PUBLIC \"");                    writer.write(doctypePublic);                    writer.write('"');                }                if (null != doctypeSystem)                {                    if (null == doctypePublic)                        writer.write(" SYSTEM \"");                    else                        writer.write('"');                    writer.write(doctypeSystem);                    writer.write('"');                }                writer.write('>');                outputLineSep();                }                catch(IOException e)                {                    throw new SAXException(e);                }            }        }        m_needToOutputDocTypeDecl = false;    }    /**     * Receive notification of the end of a document.      *     * @throws org.xml.sax.SAXException Any SAX exception, possibly     *            wrapping another exception.     *     * @throws org.xml.sax.SAXException     */    public final void endDocument() throws org.xml.sax.SAXException    {                flushPending();        if (m_doIndent && !m_isprevtext)        {            try            {            outputLineSep();            }            catch(IOException e)            {                throw new SAXException(e);            }        }        flushWriter();        if (m_tracer != null)            super.fireEndDoc();    }    /**     *  Receive notification of the beginning of an element.     *     *     *  @param namespaceURI     *  @param localName     *  @param name The element type name.     *  @param atts The attributes attached to the element, if any.     *  @throws org.xml.sax.SAXException Any SAX exception, possibly     *             wrapping another exception.     *  @see #endElement     *  @see org.xml.sax.AttributeList     */    public void startElement(        String namespaceURI,        String localName,        String name,        Attributes atts)        throws org.xml.sax.SAXException    {        ElemContext elemContext = m_elemContext;        // clean up any pending things first        if (elemContext.m_startTagOpen)        {            closeStartTag();            elemContext.m_startTagOpen = false;        }        else if (m_cdataTagOpen)        {            closeCDATA();            m_cdataTagOpen = false;        }        else if (m_needToCallStartDocument)        {            startDocumentInternal();            m_needToCallStartDocument = false;        }        // if this element has a namespace then treat it like XML        if (null != namespaceURI && namespaceURI.length() > 0)        {            super.startElement(namespaceURI, localName, name, atts);            return;        }                try        {            ElemDesc elemDesc = getElemDesc(name);            int elemFlags = elemDesc.getFlags();            // deal with indentation issues first            if (m_doIndent)            {                boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0;                if (m_ispreserve)                    m_ispreserve = false;                else if (                    (null != elemContext.m_elementName)                    && (!m_inBlockElem                        || isBlockElement) /* && !isWhiteSpaceSensitive */                    )                {                    m_startNewLine = true;                    indent();                }                m_inBlockElem = !isBlockElement;            }            // save any attributes for later processing            if (atts != null)                addAttributes(atts);                        m_isprevtext = false;            final java.io.Writer writer = m_writer;            writer.write('<');            writer.write(name);            if (m_tracer != null)                firePseudoAttributes();                        if ((elemFlags & ElemDesc.EMPTY) != 0)              {                // an optimization for elements which are expected                // to be empty.                m_elemContext = elemContext.push();                /* XSLTC sometimes calls namespaceAfterStartElement()                 * so we need to remember the name                 */                m_elemContext.m_elementName = name;                m_elemContext.m_elementDesc = elemDesc;                return;                            }             else

⌨️ 快捷键说明

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