serializerbase.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,289 行 · 第 1/3 页
JAVA
1,289 行
* do not apply directly to attributes. * @param qname a qualified name * @param isElement true if the qualified name is the name of * an element. * @return returns the namespace URI associated with the qualified name. */ public String getNamespaceURI(String qname, boolean isElement) { String uri = EMPTYSTRING; int col = qname.lastIndexOf(':'); final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING; if (!EMPTYSTRING.equals(prefix) || isElement) { if (m_prefixMap != null) { uri = m_prefixMap.lookupNamespace(prefix); if (uri == null && !prefix.equals(XMLNS_PREFIX)) { throw new RuntimeException( XMLMessages.createXMLMessage( XMLErrorResources.ER_NAMESPACE_PREFIX, new Object[] { qname.substring(0, col) } )); } } } return uri; } /** * Returns the URI of prefix (if any) * * @param prefix the prefix whose URI is searched for * @return the namespace URI currently associated with the * prefix, null if the prefix is undefined. */ public String getNamespaceURIFromPrefix(String prefix) { String uri = null; if (m_prefixMap != null) uri = m_prefixMap.lookupNamespace(prefix); return uri; } /** * Entity reference event. * * @param name Name of entity * * @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 com.sun.org.apache.xml.internal.serializer.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 com.sun.org.apache.xml.internal.serializer.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. Historically Xalan has not always called a startDocument() * although it always calls endDocument() on the serializer. * So the serializer must be flexible for that. 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 is used to set the source locator, which might be used to * generated an error message. * @param locator the source locator * * @see com.sun.org.apache.xml.internal.serializer.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 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; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?