tohtmlstream.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,886 行 · 第 1/5 页
JAVA
1,886 行
* @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 com.sun.org.apache.xml.internal.serializer.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 com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#namespaceAfterStartElement(String, String) */ public void namespaceAfterStartElement(String prefix, String uri) throws SAXException { // hack for XSLTC with finding URI for default namespace if (m_elemContext.m_elementURI == null) { String prefix1 = getPrefixPart(m_elemContext.m_elementName); if (prefix1 == null && EMPTYSTRING.equals(prefix)) { // the elements URI is not known yet, and it // doesn't have a prefix, and we are currently // setting the uri for prefix "", so we have // the uri for the element... lets remember it m_elemContext.m_elementURI = uri; } } startPrefixMapping(prefix,uri,false); } public void startDTD(String name, String publicId, String systemId) throws SAXException { m_inDTD = true; super.startDTD(name, publicId, systemId); } /** * Report the end of DTD declarations. * @throws org.xml.sax.SAXException The application may raise an exception. * @see #startDTD */ public void endDTD() throws org.xml.sax.SAXException { m_inDTD = false; /* for ToHTMLStream the DOCTYPE is entirely output in the * startDocumentInternal() method, so don't do anything here */ } /** * This method does nothing. */ public void attributeDecl( String eName, String aName, String type, String valueDefault, String value) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer } /** * This method does nothing. */ public void elementDecl(String name, String model) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer } /** * This method does nothing. */ public void internalEntityDecl(String name, String value) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer } /** * This method does nothing. */ public void externalEntityDecl( String name, String publicId, String systemId) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer } /** * This method is used to add an attribute to the currently open element. * The caller has guaranted that this attribute is unique, which means that it * not been seen before and will not be seen again. * * @param name the qualified name of the attribute * @param value the value of the attribute which can contain only * ASCII printable characters characters in the range 32 to 127 inclusive. * @param flags the bit values of this integer give optimization information. */ public void addUniqueAttribute(String name, String value, int flags) throws SAXException { try { final java.io.Writer writer = m_writer; if ((flags & NO_BAD_CHARS) > 0 && m_htmlcharInfo.onlyQuotAmpLtGt) { // "flags" has indicated that the characters // '>' '<' '&' and '"' are not in the value and // m_htmlcharInfo has recorded that there are no other // entities in the range 0 to 127 so we write out the // value directly writer.write(' '); writer.write(name); writer.write("=\""); writer.write(value); writer.write('"'); } else if ( (flags & HTML_ATTREMPTY) > 0 && (value.length() == 0 || value.equalsIgnoreCase(name))) { writer.write(' '); writer.write(name); } else { writer.write(' '); writer.write(name); writer.write("=\""); if ((flags & HTML_ATTRURL) > 0) { writeAttrURI(writer, value, m_specialEscapeURLs); } else { writeAttrString(writer, value, this.getEncoding()); } writer.write('"'); } } catch (IOException e) { throw new SAXException(e); } } public void comment(char ch[], int start, int length) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer if (m_inDTD) return; super.comment(ch, start, length); } public boolean reset() { boolean ret = super.reset(); if (!ret) return fa
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?