tohtmlstream.java

来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 1,824 行 · 第 1/5 页

JAVA
1,824
字号
        elemDesc = (ElemDesc) m_elementFlags.get("BLOCKQUOTE");        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);        // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("DEL");        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);             // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("DIR");        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);                   // ----------------------------------------------                elemDesc = (ElemDesc) m_elementFlags.get("DIV");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL); // Netscape 4 extension        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY); // Internet-Explorer extension           // ----------------------------------------------                elemDesc = (ElemDesc) m_elementFlags.get("DL");        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);                   // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("FORM");        elemDesc.setAttr("ACTION", 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);        elemDesc.setAttr("NORESIZE",ElemDesc.ATTREMPTY);        // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("HEAD");        elemDesc.setAttr("PROFILE", ElemDesc.ATTRURL);        // ----------------------------------------------                elemDesc = (ElemDesc) m_elementFlags.get("HR");        elemDesc.setAttr("NOSHADE", ElemDesc.ATTREMPTY);                // ----------------------------------------------        // HTML 4.0, section 16.5        elemDesc = (ElemDesc) m_elementFlags.get("IFRAME");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);        // ----------------------------------------------        // Netscape 4 extension        elemDesc = (ElemDesc) m_elementFlags.get("ILAYER");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        // ----------------------------------------------        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("INPUT");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        elemDesc.setAttr("USEMAP", ElemDesc.ATTRURL);        elemDesc.setAttr("CHECKED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("ISMAP", ElemDesc.ATTREMPTY);        elemDesc.setAttr("READONLY", ElemDesc.ATTREMPTY);                // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("INS");        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);        // ----------------------------------------------        // Netscape 4 extension        elemDesc = (ElemDesc) m_elementFlags.get("LAYER");        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);        // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("LINK");        elemDesc.setAttr("HREF", ElemDesc.ATTRURL);               // ----------------------------------------------               elemDesc = (ElemDesc) m_elementFlags.get("MENU");        elemDesc.setAttr("COMPACT", 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("OL");        elemDesc.setAttr("COMPACT", 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("Q");        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);        // ----------------------------------------------        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("SELECT");        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("MULTIPLE", ElemDesc.ATTREMPTY);        // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("TABLE");        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY); // Internet-Explorer extension                // ----------------------------------------------                elemDesc = (ElemDesc) m_elementFlags.get("TD");        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY);        // ----------------------------------------------        elemDesc = (ElemDesc) m_elementFlags.get("TEXTAREA");        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);        elemDesc.setAttr("READONLY", ElemDesc.ATTREMPTY);               // ----------------------------------------------                        elemDesc = (ElemDesc) m_elementFlags.get("TH");        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY);                // ----------------------------------------------        // The nowrap attribute of a tr element is both        // a Netscape and Internet-Explorer extension                        elemDesc = (ElemDesc) m_elementFlags.get("TR");        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY);                // ----------------------------------------------                elemDesc = (ElemDesc) m_elementFlags.get("UL");        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);    }    /**     * 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.     *      * 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!)      *     * @param format The output format or serialzation parameters     * 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;    }        /**     * A Trie that is just a copy of the "static" one.     * We need this one to be able to use the faster, but not thread-safe     * method Trie.get2(name)     */    private Trie m_htmlInfo = new Trie(m_elementFlags);    /**     * Calls to this method could be replaced with calls to     * getElemDesc(name), but this one should be faster.     */    private ElemDesc getElemDesc2(String name)    {        Object obj = m_htmlInfo.get2(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);

⌨️ 快捷键说明

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