serializerbase.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,289 行 · 第 1/3 页
JAVA
1,289 行
for (int i = 0; i < nAtts; i++) { String uri = atts.getURI(i); if (null == uri) uri = ""; // Ignore ns decls as attributes in the "" namespace (see javadoc) String qname = atts.getQName(i); if (qname.startsWith("xmlns:") && uri.equals(EMPTYSTRING)) { continue; } addAttributeAlways( uri, atts.getLocalName(i), atts.getQName(i), atts.getType(i), atts.getValue(i)); } } /** * Return a {@link ContentHandler} interface into this serializer. * If the serializer does not support the {@link ContentHandler} * interface, it should return null. * * @return A {@link ContentHandler} interface into this serializer, * or null if the serializer is not SAX 2 capable * @throws IOException An I/O exception occured */ public ContentHandler asContentHandler() throws IOException { return this; } /** * Report the end of an entity. * * @param name The name of the entity that is ending. * @throws org.xml.sax.SAXException The application may raise an exception. * @see #startEntity */ public void endEntity(String name) throws org.xml.sax.SAXException { if (name.equals("[dtd]")) m_inExternalDTD = false; m_inEntityRef = false; if (m_tracer != null) this.fireEndEntity(name); } /** * Flush and close the underlying java.io.Writer. This method applies to * ToStream serializers, not ToSAXHandler serializers. * @see com.sun.org.apache.xml.internal.serializer.ToStream */ public void close() { // do nothing (base behavior) } /** * Initialize global variables */ protected void initCDATA() { // CDATA stack // _cdataStack = new Stack(); // _cdataStack.push(new Integer(-1)); // push dummy value } /** * Returns the character encoding to be used in the output document. * @return the character encoding to be used in the output document. */ public String getEncoding() { return m_encoding; } /** * Sets the character encoding coming from the xsl:output encoding stylesheet attribute. * @param encoding the character encoding */ public void setEncoding(String m_encoding) { this.m_encoding = m_encoding; } /** * Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute * @param b true if the XML declaration is to be omitted from the output * document. */ public void setOmitXMLDeclaration(boolean b) { this.m_shouldNotWriteXMLHeader = b; } /** * @return true if the XML declaration is to be omitted from the output * document. */ public boolean getOmitXMLDeclaration() { return m_shouldNotWriteXMLHeader; } /** * Returns the previously set value of the value to be used as the public * identifier in the document type declaration (DTD). * *@return the public identifier to be used in the DOCTYPE declaration in the * output document. */ public String getDoctypePublic() { return m_doctypePublic; } /** Set the value coming from the xsl:output doctype-public stylesheet attribute. * @param doctypePublic the public identifier to be used in the DOCTYPE * declaration in the output document. */ public void setDoctypePublic(String doctypePublic) { this.m_doctypePublic = doctypePublic; } /** * Returns the previously set value of the value to be used * as the system identifier in the document type declaration (DTD). * @return the system identifier to be used in the DOCTYPE declaration in * the output document. * */ public String getDoctypeSystem() { return m_doctypeSystem; } /** Set the value coming from the xsl:output doctype-system stylesheet attribute. * @param doctypeSystem the system identifier to be used in the DOCTYPE * declaration in the output document. */ public void setDoctypeSystem(String doctypeSystem) { this.m_doctypeSystem = doctypeSystem; } /** Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties * @param doctypeSystem the system identifier to be used in the DOCTYPE * declaration in the output document. * @param doctypePublic the public identifier to be used in the DOCTYPE * declaration in the output document. */ public void setDoctype(String doctypeSystem, String doctypePublic) { this.m_doctypeSystem = doctypeSystem; this.m_doctypePublic = doctypePublic; } /** * Sets the value coming from the xsl:output standalone stylesheet attribute. * @param standalone a value of "yes" indicates that the * <code>standalone</code> delaration is to be included in the output * document. This method remembers if the value was explicitly set using * this method, verses if the value is the default value. */ public void setStandalone(String standalone) { if (standalone != null) { m_standaloneWasSpecified = true; setStandaloneInternal(standalone); } } /** * Sets the XSL standalone attribute, but does not remember if this is a * default or explicite setting. * @param standalone "yes" | "no" */ protected void setStandaloneInternal(String standalone) { if ("yes".equals(standalone)) m_standalone = "yes"; else m_standalone = "no"; } /** * Gets the XSL standalone attribute * @return a value of "yes" if the <code>standalone</code> delaration is to * be included in the output document. * @see com.sun.org.apache.xml.internal.serializer.XSLOutputAttributes#getStandalone() */ public String getStandalone() { return m_standalone; } /** * @return true if the output document should be indented to visually * indicate its structure. */ public boolean getIndent() { return m_doIndent; } /** * Gets the mediatype the media-type or MIME type associated with the output * document. * @return the mediatype the media-type or MIME type associated with the * output document. */ public String getMediaType() { return m_mediatype; } /** * Gets the version of the output format. * @return the version of the output format. */ public String getVersion() { return m_version; } /** * Sets the value coming from the xsl:output version attribute. * @param version the version of the output format. * @see com.sun.org.apache.xml.internal.serializer.SerializationHandler#setVersion(String) */ public void setVersion(String version) { m_version = version; } /** * Sets the value coming from the xsl:output media-type stylesheet attribute. * @param mediaType the non-null media-type or MIME type associated with the * output document. * @see javax.xml.transform.OutputKeys#MEDIA_TYPE * @see com.sun.org.apache.xml.internal.serializer.SerializationHandler#setMediaType(String) */ public void setMediaType(String mediaType) { m_mediatype = mediaType; } /** * @return the number of spaces to indent for each indentation level. */ public int getIndentAmount() { return m_indentAmount; } /** * Sets the indentation amount. * @param m_indentAmount The m_indentAmount to set */ public void setIndentAmount(int m_indentAmount) { this.m_indentAmount = m_indentAmount; } /** * Sets the value coming from the xsl:output indent stylesheet * attribute. * @param doIndent true if the output document should be indented to * visually indicate its structure. * @see com.sun.org.apache.xml.internal.serializer.XSLOutputAttributes#setIndent(boolean) */ public void setIndent(boolean doIndent) { m_doIndent = doIndent; } /** * 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 uri, String prefix) throws SAXException { // default behavior is to do nothing } /** * Return a {@link DOMSerializer} interface into this serializer. If the * serializer does not support the {@link DOMSerializer} interface, it should * return null. * * @return A {@link DOMSerializer} interface into this serializer, or null * if the serializer is not DOM capable * @throws IOException An I/O exception occured * @see com.sun.org.apache.xml.internal.serializer.Serializer#asDOMSerializer() */ public DOMSerializer asDOMSerializer() throws IOException { return this; } /** * Push a boolean state based on if the name of the element * is found in the list of qnames. A state is only pushed if * there were some cdata-section-names were specified. * * @param namespaceURI Should be a non-null reference to the namespace URL * of the element that owns the state, or empty string. * @param localName Should be a non-null reference to the local name * of the element that owns the state. * * Hidden parameters are the vector of qualified elements specified in * cdata-section-names attribute, and the m_cdataSectionStates stack * onto which whether the current element is in the list is pushed (true or * false). Other hidden parameters are the current elements namespaceURI, * localName and qName */ protected boolean isCdataSection() { boolean b = false; if (null != m_cdataSectionElements) { if (m_elemContext.m_elementLocalName == null) m_elemContext.m_elementLocalName = getLocalName(m_elemContext.m_elementName); if (m_elemContext.m_elementURI == null) { String prefix = getPrefixPart(m_elemContext.m_elementName); if (prefix != null) m_elemContext.m_elementURI = m_prefixMap.lookupNamespace(prefix); } if ((null != m_elemContext.m_elementURI) && m_elemContext.m_elementURI.length() == 0) m_elemContext.m_elementURI = null; int nElems = m_cdataSectionElements.size(); // loop through 2 at a time, as these are pairs of URI and localName for (int i = 0; i < nElems; i += 2) { String uri = (String) m_cdataSectionElements.elementAt(i); String loc = (String) m_cdataSectionElements.elementAt(i + 1); if (loc.equals(m_elemContext.m_elementLocalName) && subPartMatch(m_elemContext.m_elementURI, uri)) { b = true; break; } } } return b; } /** * Tell if two strings are equal, without worry if the first string is null. * * @param p String reference, which may be null. * @param t String reference, which may be null. * * @return true if strings are equal. */ private static final boolean subPartMatch(String p, String t) { return (p == t) || ((null != p) && (p.equals(t))); } /** * Returns the local name of a qualified name. * If the name has no prefix, * then it works as the identity (SAX2). * * @param qname a qualified name * @return returns the prefix of the qualified name, * or null if there is no prefix. */ protected static final String getPrefixPart(String qname) { final int col = qname.indexOf(':'); return (col > 0) ? qname.substring(0, col) : null; //return (col > 0) ? qname.substring(0,col) : ""; } /** * Some users of the serializer may need the current namespace mappings * @return the current namespace mappings (prefix/uri) * @see com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#getNamespaceMappings() */ public NamespaceMappings getNamespaceMappings() { return m_prefixMap; } /** * Returns the prefix currently pointing to the given URI (if any). * @param namespaceURI the uri of the namespace in question * @return a prefix pointing to the given URI (if any). * @see com.sun.org.apache.xml.internal.serializer.ExtendedContentHandler#getPrefix(String) */ public String getPrefix(String namespaceURI) { String prefix = m_prefixMap.lookupPrefix(namespaceURI); return prefix; } /** * Returns the URI of an element or attribute. Note that default namespaces
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?