serializerbase.java
来自「JAVA 所有包」· Java 代码 · 共 1,384 行 · 第 1/3 页
JAVA
1,384 行
* @throws org.xml.sax.SAXException */ public void entityReference(String name) throws org.xml.sax.SAXException { flushPending(); startEntity(name); endEntity(name); if (m_tracer != null) fireEntityReference(name); } /** * Sets the transformer associated with this serializer * @param t the transformer associated with this serializer. * @see SerializationHandler#setTransformer(Transformer) */ public void setTransformer(Transformer t) { m_transformer = t; // If this transformer object implements the SerializerTrace interface // then assign m_tracer to the transformer object so it can be used // to fire trace events. if ((m_transformer instanceof SerializerTrace) && (((SerializerTrace) m_transformer).hasTraceListeners())) { m_tracer = (SerializerTrace) m_transformer; } else { m_tracer = null; } } /** * Gets the transformer associated with this serializer * @return returns the transformer associated with this serializer. * @see SerializationHandler#getTransformer() */ public Transformer getTransformer() { return m_transformer; } /** * This method gets the nodes value as a String and uses that String as if * it were an input character notification. * @param node the Node to serialize * @throws org.xml.sax.SAXException */ public void characters(org.w3c.dom.Node node) throws org.xml.sax.SAXException { flushPending(); String data = node.getNodeValue(); if (data != null) { final int length = data.length(); if (length > m_charsBuff.length) { m_charsBuff = new char[length * 2 + 1]; } data.getChars(0, length, m_charsBuff, 0); characters(m_charsBuff, 0, length); } } /** * @see org.xml.sax.ErrorHandler#error(SAXParseException) */ public void error(SAXParseException exc) throws SAXException { } /** * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException) */ public void fatalError(SAXParseException exc) throws SAXException { m_elemContext.m_startTagOpen = false; } /** * @see org.xml.sax.ErrorHandler#warning(SAXParseException) */ public void warning(SAXParseException exc) throws SAXException { } /** * To fire off start entity trace event * @param name Name of entity */ protected void fireStartEntity(String name) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENTITYREF, name); } } /** * Report the characters event * @param chars content of characters * @param start starting index of characters to output * @param length number of characters to output */// protected void fireCharEvent(char[] chars, int start, int length)// throws org.xml.sax.SAXException// {// if (m_tracer != null)// m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CHARACTERS, chars, start,length); // }// /** * This method is only used internally when flushing the writer from the * various fire...() trace events. Due to the writer being wrapped with * SerializerTraceWriter it may cause the flush of these trace events: * EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS * EVENTTYPE_OUTPUT_CHARACTERS * which trace the output written to the output stream. * */ private void flushMyWriter() { if (m_writer != null) { try { m_writer.flush(); } catch(IOException ioe) { } } } /** * Report the CDATA trace event * @param chars content of CDATA * @param start starting index of characters to output * @param length number of characters to output */ protected void fireCDATAEvent(char[] chars, int start, int length) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CDATA, chars, start,length); } } /** * Report the comment trace event * @param chars content of comment * @param start starting index of comment to output * @param length number of characters to output */ protected void fireCommentEvent(char[] chars, int start, int length) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_COMMENT, new String(chars, start, length)); } } /** * To fire off end entity trace event * @param name Name of entity */ public void fireEndEntity(String name) throws org.xml.sax.SAXException { if (m_tracer != null) flushMyWriter(); // we do not need to handle this. } /** * To fire off start document trace event */ protected void fireStartDoc() throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_STARTDOCUMENT); } } /** * To fire off end document trace event */ protected void fireEndDoc() throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENDDOCUMENT); } } /** * Report the start element trace event. This trace method needs to be * called just before the attributes are cleared. * * @param elemName the qualified name of the element * */ protected void fireStartElem(String elemName) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_STARTELEMENT, elemName, m_attributes); } } /** * To fire off the end element event * @param name Name of element */// protected void fireEndElem(String name)// throws org.xml.sax.SAXException// {// if (m_tracer != null)// m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENDELEMENT,name, (Attributes)null); // } /** * To fire off the PI trace event * @param name Name of PI */ protected void fireEscapingEvent(String name, String data) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_PI,name, data); } } /** * To fire off the entity reference trace event * @param name Name of entity reference */ protected void fireEntityReference(String name) throws org.xml.sax.SAXException { if (m_tracer != null) { flushMyWriter(); m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENTITYREF,name, (Attributes)null); } } /** * Receive notification of the beginning of a document. * This method is never a self generated call, * but only called externally. * * <p>The SAX parser will invoke this method only once, before any * other methods in this interface or in DTDHandler (except for * setDocumentLocator).</p> * * @throws org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception. * * @throws org.xml.sax.SAXException */ public void startDocument() throws org.xml.sax.SAXException { // if we do get called with startDocument(), handle it right away startDocumentInternal(); m_needToCallStartDocument = false; return; } /** * This method handles what needs to be done at a startDocument() call, * whether from an external caller, or internally called in the * serializer. For historical reasons the serializer is flexible to * startDocument() not always being called. * Even if no external call is * made into startDocument() this method will always be called as a self * generated internal startDocument, it handles what needs to be done at a * startDocument() call. * * This method exists just to make sure that startDocument() is only ever * called from an external caller, which in principle is just a matter of * style. * * @throws SAXException */ protected void startDocumentInternal() throws org.xml.sax.SAXException { if (m_tracer != null) this.fireStartDoc(); } /* This method extracts version and encoding information from SAX events. */ protected void setDocumentInfo() { if (m_locator == null) return; try{ String strVersion = ((Locator2)m_locator).getXMLVersion(); if (strVersion != null) setVersion(strVersion); /*String strEncoding = ((Locator2)m_locator).getEncoding(); if (strEncoding != null) setEncoding(strEncoding); */ }catch(ClassCastException e){} } /** * This method is used to set the source locator, which might be used to * generated an error message. * @param locator the source locator * * @see ExtendedContentHandler#setSourceLocator(javax.xml.transform.SourceLocator) */ public void setSourceLocator(SourceLocator locator) { m_sourceLocator = locator; } /** * Used only by TransformerSnapshotImpl to restore the serialization * to a previous state. * * @param mappings NamespaceMappings */ public void setNamespaceMappings(NamespaceMappings mappings) { m_prefixMap = mappings; } public boolean reset() { resetSerializerBase(); return true; } /** * Reset all of the fields owned by SerializerBase * */ private void resetSerializerBase() { this.m_attributes.clear(); this.m_cdataSectionElements = null; this.m_elemContext = new ElemContext(); this.m_doctypePublic = null; this.m_doctypeSystem = null; this.m_doIndent = false; this.m_encoding = null; this.m_indentAmount = 0; this.m_inEntityRef = false; this.m_inExternalDTD = false; this.m_mediatype = null; this.m_needToCallStartDocument = true; this.m_needToOutputDocTypeDecl = false; if (this.m_prefixMap != null) this.m_prefixMap.reset(); this.m_shouldNotWriteXMLHeader = false; this.m_sourceLocator = null; this.m_standalone = null; this.m_standaloneWasSpecified = false; this.m_tracer = null; this.m_transformer = null; this.m_version = null; // don't set writer to null, so that it might be re-used //this.m_writer = null; } /** * Returns true if the serializer is used for temporary output rather than * final output. * * This concept is made clear in the XSLT 2.0 draft. */ final boolean inTemporaryOutputState() { /* This is a hack. We should really be letting the serializer know * that it is in temporary output state with an explicit call, but * from a pragmatic point of view (for now anyways) having no output * encoding at all, not even the default UTF-8 indicates that the serializer * is being used for temporary RTF. */ return (getEncoding() == null); } /** * This method adds an attribute the the current element, * but should not be used for an xsl:attribute child. * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ public void addAttribute(String uri, String localName, String rawName, String type, String value) throws SAXException { if (m_elemContext.m_startTagOpen) { addAttributeAlways(uri, localName, rawName, type, value, false); } } /** * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String) */ public void notationDecl(String arg0, String arg1, String arg2) throws SAXException { // This method just provides a definition to satisfy the interface // A particular sub-class of SerializerBase provides the implementation (if desired) } /** * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ public void unparsedEntityDecl( String arg0, String arg1, String arg2, String arg3) throws SAXException { // This method just provides a definition to satisfy the interface // A particular sub-class of SerializerBase provides the implementation (if desired) } /** * If set to false the serializer does not expand DTD entities, * but leaves them as is, the default value is true. */ public void setDTDEntityExpansion(boolean expand) { // This method just provides a definition to satisfy the interface // A particular sub-class of SerializerBase provides the implementation (if desired) }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?