tohtmlstream.java

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

JAVA
1,824
字号
     *     * @param chars The characters from the XML document.     * @param start The start position in the array.     * @param length 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     */    public final void characters(char chars[], int start, int length)        throws org.xml.sax.SAXException    {        if (m_elemContext.m_isRaw)        {            try            {                if (m_elemContext.m_startTagOpen)                {                    closeStartTag();                    m_elemContext.m_startTagOpen = false;                }                m_ispreserve = true;                //              With m_ispreserve just set true it looks like shouldIndent()//              will always return false, so drop any possible indentation.//              if (shouldIndent())//                  indent();                // writer.write("<![CDATA[");                // writer.write(chars, start, length);                writeNormalizedChars(chars, start, length, false, m_lineSepUse);                // writer.write("]]>");                                // time to generate characters event                if (m_tracer != null)                    super.fireCharEvent(chars, start, length);                                return;            }            catch (IOException ioe)            {                throw new org.xml.sax.SAXException(                    Utils.messages.createMessage(                        MsgKey.ER_OIERROR,                        null),                    ioe);                //"IO error", ioe);            }        }        else        {            super.characters(chars, start, length);        }    }    /**     *  Receive notification of cdata.     *     *  <p>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.</p>     *     *  <p>The application must not attempt to read from the array     *  outside of the specified range.</p>     *     *  <p>Note that some parsers will report whitespace using the     *  ignorableWhitespace() method rather than this one (validating     *  parsers must do so).</p>     *     *  @param ch The characters from the XML document.     *  @param start The start position in the array.     *  @param length 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     */    public final void cdata(char ch[], int start, int length)        throws org.xml.sax.SAXException    {        if ((null != m_elemContext.m_elementName)            && (m_elemContext.m_elementName.equalsIgnoreCase("SCRIPT")                || m_elemContext.m_elementName.equalsIgnoreCase("STYLE")))        {            try            {                if (m_elemContext.m_startTagOpen)                {                    closeStartTag();                    m_elemContext.m_startTagOpen = false;                }                m_ispreserve = true;                if (shouldIndent())                    indent();                // writer.write(ch, start, length);                writeNormalizedChars(ch, start, length, true, m_lineSepUse);            }            catch (IOException ioe)            {                throw new org.xml.sax.SAXException(                    Utils.messages.createMessage(                        MsgKey.ER_OIERROR,                        null),                    ioe);                //"IO error", ioe);            }        }        else        {            super.cdata(ch, start, length);        }    }    /**     *  Receive notification of a processing instruction.     *     *  @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     */    public void processingInstruction(String target, String data)        throws org.xml.sax.SAXException    {        // Process any pending starDocument and startElement first.        flushPending();                 // Use a fairly nasty hack to tell if the next node is supposed to be         // unescaped text.        if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))        {            startNonEscaping();        }        else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))        {            endNonEscaping();        }        else        {            try            {            if (m_elemContext.m_startTagOpen)            {                closeStartTag();                m_elemContext.m_startTagOpen = false;            }            else if (m_needToCallStartDocument)                startDocumentInternal();            if (shouldIndent())                indent();            final java.io.Writer writer = m_writer;            //writer.write("<?" + target);            writer.write("<?");            writer.write(target);            if (data.length() > 0 && !Character.isSpaceChar(data.charAt(0)))                writer.write(' ');             //writer.write(data + ">"); // different from XML            writer.write(data); // different from XML            writer.write('>'); // different from XML            // Always output a newline char if not inside of an             // element. The whitespace is not significant in that            // case.            if (m_elemContext.m_currentElemDepth <= 0)                outputLineSep();            m_startNewLine = true;            }            catch(IOException e)            {                throw new SAXException(e);            }        }                       // now generate the PI event        if (m_tracer != null)            super.fireEscapingEvent(target, data);     }    /**     * Receive notivication of a entityReference.     *     * @param name non-null reference to entity name string.     *     * @throws org.xml.sax.SAXException     */    public final void entityReference(String name)        throws org.xml.sax.SAXException    {        try        {        final java.io.Writer writer = m_writer;        writer.write('&');        writer.write(name);        writer.write(';');                } catch(IOException e)        {            throw new SAXException(e);        }    }    /**     * @see ExtendedContentHandler#endElement(String)     */    public final void endElement(String elemName) throws SAXException    {        endElement(null, null, elemName);    }    /**     * Process the attributes, which means to write out the currently     * collected attributes to the writer. The attributes are not     * cleared by this method     *      * @param writer the writer to write processed attributes to.     * @param nAttrs the number of attributes in m_attributes      * to be processed     *     * @throws org.xml.sax.SAXException     */    public void processAttributes(java.io.Writer writer, int nAttrs)        throws IOException,SAXException    {            /*              * process the collected attributes             */            for (int i = 0; i < nAttrs; i++)            {                processAttribute(                    writer,                    m_attributes.getQName(i),                    m_attributes.getValue(i),                    m_elemContext.m_elementDesc);            }    }    /**     * For the enclosing elements starting tag write out out any attributes     * followed by ">"     *     *@throws org.xml.sax.SAXException     */    protected void closeStartTag() throws SAXException    {            try            {            // finish processing attributes, time to fire off the start element event            if (m_tracer != null)                super.fireStartElem(m_elemContext.m_elementName);                          int nAttrs = m_attributes.getLength();               if (nAttrs>0)            {                processAttributes(m_writer, nAttrs);                // clear attributes object for re-use with next element                m_attributes.clear();            }            m_writer.write('>');            /* whether Xalan or XSLTC, we have the prefix mappings now, so             * lets determine if the current element is specified in the cdata-             * section-elements list.             */            if (m_cdataSectionElements != null)                 m_elemContext.m_isCdataSection = isCdataSection();            if (m_doIndent)            {                m_isprevtext = false;                m_preserves.push(m_ispreserve);            }                        }            catch(IOException e)            {                throw new SAXException(e);            }    }    /**     * Initialize the serializer with the specified output stream and output     * format. Must be called before calling any of the serialize methods.     *     * @param output The output stream to use     * @param format The output format     * @throws UnsupportedEncodingException The encoding specified   in the     * output format is not supported     */    protected synchronized void init(OutputStream output, Properties format)        throws UnsupportedEncodingException    {        if (null == format)        {            format = OutputPropertiesFactory.getDefaultMethodProperties(Method.HTML);         }        super.init(output,format, false);    }            /**         * Specifies an output stream to which the document should be         * serialized. This method should not be called while the         * serializer is in the process of serializing a document.         * <p>         * The encoding specified in the output properties is used, or         * if no encoding was specified, the default for the selected         * output method.         *         * @param output The output stream         */        public void setOutputStream(OutputStream output)        {            try            {                Properties format;                if (null == m_format)                    format = OutputPropertiesFactory.getDefaultMethodProperties(Method.HTML);                else                    format = m_format;                init(output, format, true);            }            catch (UnsupportedEncodingException uee)            {                // Should have been warned in init, I guess...            }        }            /**         * 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 uri the URI of the namespace         * @param prefix the prefix associated with the given URI.         *         * @see ExtendedContentHandler#namespaceAfterStartElement(String, String)         */        public void namespaceAfterStartElement(String prefix, String uri)            throws SAXException        {            // hack for XSLTC with 

⌨️ 快捷键说明

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