serializertotext.java
来自「java jdk 1.4的源码」· Java 代码 · 共 555 行 · 第 1/2 页
JAVA
555 行
* @throws org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. */ public void charactersRaw(char ch[], int start, int length) throws org.xml.sax.SAXException { // accum(ch, start, length); try { writeNormalizedChars(ch, start, length, false); } catch(IOException ioe) { throw new SAXException(ioe); } flushWriter(); // flushWriter(); } /** * Once a surrogate has been detected, write the pair as a single * character reference. * * @param c the first part of the surrogate. * @param ch Character array. * @param i position Where the surrogate was detected. * @param end The end index of the significant characters. * @return i+1. * @throws IOException * @throws org.xml.sax.SAXException if invalid UTF-16 surrogate detected. */ protected int writeUTF16Surrogate(char c, char ch[], int i, int end) throws IOException, org.xml.sax.SAXException { // UTF-16 surrogate int surrogateValue = getURF16SurrogateValue(c, ch, i, end); i++; // m_writer.write('x'); m_writer.write(surrogateValue); return i; } /** * Normalize the characters, but don't escape. Different from * SerializerToXML#writeNormalizedChars because it does not attempt to do * XML escaping at all. * * @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. * @param isCData true if a CDATA block should be built around the characters. * * @throws IOException * @throws org.xml.sax.SAXException */ void writeNormalizedChars(char ch[], int start, int length, boolean isCData) throws IOException, org.xml.sax.SAXException { int end = start + length; for (int i = start; i < end; i++) { char c = ch[i]; if (CharInfo.S_LINEFEED == c) { m_writer.write(m_lineSep, 0, m_lineSepLen); } else if (isCData && (c > m_maxCharacter)) { if (i != 0) m_writer.write("]]>"); // This needs to go into a function... if (isUTF16Surrogate(c)) { i = writeUTF16Surrogate(c, ch, i, end); } else { m_writer.write(c); } if ((i != 0) && (i < (end - 1))) m_writer.write("<![CDATA["); } else if (isCData && ((i < (end - 2)) && (']' == c) && (']' == ch[i + 1]) && ('>' == ch[i + 2]))) { m_writer.write("]]]]><![CDATA[>"); i += 2; } else { if (c <= m_maxCharacter) { m_writer.write(c); } else if (isUTF16Surrogate(c)) { i = writeUTF16Surrogate(c, ch, i, end); } else { m_writer.write(c); } } } } /** * 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 */ public void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException { // accum(ch, start, length); try { writeNormalizedChars(ch, start, length, false); } catch(IOException ioe) { throw new SAXException(ioe); } flushWriter(); // flushWriter(); } /** * Receive notification of ignorable whitespace in element content. * * <p>Validating Parsers must use this method to report each chunk * of ignorable whitespace (see the W3C XML 1.0 recommendation, * section 2.10): non-validating parsers may also use this method * if they are capable of parsing and using content models.</p> * * <p>SAX parsers may return all contiguous whitespace 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> * * @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 #characters * * @throws org.xml.sax.SAXException */ public void ignorableWhitespace(char ch[], int start, int length) throws org.xml.sax.SAXException { try { writeNormalizedChars(ch, start, length, false); } catch(IOException ioe) { throw new SAXException(ioe); } flushWriter(); } /** * 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 */ public void processingInstruction(String target, String data) throws org.xml.sax.SAXException { // No action for the moment. } /** * Called when a Comment is to be constructed. * Note that Xalan will normally invoke the other version of this method. * %REVIEW% In fact, is this one ever needed, or was it a mistake? * * @param data The comment data. * @throws org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. */ public void comment(String data) throws org.xml.sax.SAXException { // No action for the moment. } /** * Report an XML comment anywhere in the document. * * This callback will be used for comments inside or outside the * document element, including comments in the external DTD * subset (if read). * * @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. */ public void comment(char ch[], int start, int length) throws org.xml.sax.SAXException { // No action for the moment. } /** * Receive notivication of a entityReference. * * @param name non-null reference to the name of the entity. * * @throws org.xml.sax.SAXException */ public void entityReference(String name) throws org.xml.sax.SAXException { // No action for the moment. }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?