< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/TreeWalker.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. --- 1,7 ---- /* ! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership.
*** 15,29 **** * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package com.sun.org.apache.xml.internal.utils; ! import com.sun.org.apache.xalan.internal.utils.SecuritySupport; ! import java.io.File; import org.w3c.dom.Comment; import org.w3c.dom.Element; import org.w3c.dom.EntityReference; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; --- 15,29 ---- * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ ! package com.sun.org.apache.xml.internal.utils; + import com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler; + import javax.xml.transform.Result; import org.w3c.dom.Comment; import org.w3c.dom.Element; import org.w3c.dom.EntityReference; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node;
*** 45,60 **** { /** Local reference to a ContentHandler */ private ContentHandler m_contentHandler = null; - // ARGHH!! JAXP Uses Xerces without setting the namespace processing to ON! - // DOM2Helper m_dh = new DOM2Helper(); - - /** DomHelper for this TreeWalker */ - protected DOMHelper m_dh; - /** Locator object for this TreeWalker */ private LocatorImpl m_locator = new LocatorImpl(); /** * Get the ContentHandler used for the tree walk. --- 45,54 ----
*** 80,123 **** * Constructor. * @param contentHandler The implementation of the * @param systemId System identifier for the document. * contentHandler operation (toXMLString, digest, ...) */ ! public TreeWalker(ContentHandler contentHandler, DOMHelper dh, String systemId) { this.m_contentHandler = contentHandler; m_contentHandler.setDocumentLocator(m_locator); if (systemId != null) { m_locator.setSystemId(systemId); } - m_dh = dh; - } - - /** - * Constructor. - * @param contentHandler The implementation of the - * contentHandler operation (toXMLString, digest, ...) - */ - public TreeWalker(ContentHandler contentHandler, DOMHelper dh) - { - this.m_contentHandler = contentHandler; - m_contentHandler.setDocumentLocator(m_locator); - m_dh = dh; } /** * Constructor. * @param contentHandler The implementation of the * contentHandler operation (toXMLString, digest, ...) */ public TreeWalker(ContentHandler contentHandler) { ! this.m_contentHandler = contentHandler; ! if (m_contentHandler != null) { ! m_contentHandler.setDocumentLocator(m_locator); ! } ! m_dh = new DOM2Helper(); } /** * Perform a pre-order traversal non-recursive style. * --- 74,102 ---- * Constructor. * @param contentHandler The implementation of the * @param systemId System identifier for the document. * contentHandler operation (toXMLString, digest, ...) */ ! public TreeWalker(ContentHandler contentHandler, String systemId) { this.m_contentHandler = contentHandler; + if (m_contentHandler != null) { m_contentHandler.setDocumentLocator(m_locator); + } if (systemId != null) { m_locator.setSystemId(systemId); } } /** * Constructor. * @param contentHandler The implementation of the * contentHandler operation (toXMLString, digest, ...) */ public TreeWalker(ContentHandler contentHandler) { ! this(contentHandler, null); } /** * Perform a pre-order traversal non-recursive style. *
*** 237,258 **** pos = nextNode; } this.m_contentHandler.endDocument(); } ! /** Flag indicating whether following text to be processed is raw text */ boolean nextIsRaw = false; /** * Optimized dispatch of characters. */ private final void dispatachChars(Node node) throws org.xml.sax.SAXException { ! if(m_contentHandler instanceof com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler) { ! ((com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)m_contentHandler).characters(node); } else { String data = ((Text) node).getData(); this.m_contentHandler.characters(data.toCharArray(), 0, data.length()); --- 216,237 ---- pos = nextNode; } this.m_contentHandler.endDocument(); } ! // Flag indicating whether following text to be processed is raw text boolean nextIsRaw = false; /** * Optimized dispatch of characters. */ private final void dispatachChars(Node node) throws org.xml.sax.SAXException { ! if(m_contentHandler instanceof CharacterNodeHandler) { ! ((CharacterNodeHandler)m_contentHandler).characters(node); } else { String data = ((Text) node).getData(); this.m_contentHandler.characters(data.toCharArray(), 0, data.length());
*** 311,331 **** break; case Node.ELEMENT_NODE : NamedNodeMap atts = ((Element) node).getAttributes(); int nAttrs = atts.getLength(); - // System.out.println("TreeWalker#startNode: "+node.getNodeName()); for (int i = 0; i < nAttrs; i++) { Node attr = atts.item(i); String attrName = attr.getNodeName(); - // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue()); if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) { - // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue()); int index; // Use "" instead of null, as Xerces likes "" for the // name of the default namespace. Fix attributed // to "Steven Murray" <smurray@ebt.com>. String prefix = (index = attrName.indexOf(":")) < 0 --- 290,307 ----
*** 335,353 **** attr.getNodeValue()); } } ! // System.out.println("m_dh.getNamespaceOfNode(node): "+m_dh.getNamespaceOfNode(node)); ! // System.out.println("m_dh.getLocalNameOfNode(node): "+m_dh.getLocalNameOfNode(node)); ! String ns = m_dh.getNamespaceOfNode(node); if(null == ns) ns = ""; this.m_contentHandler.startElement(ns, ! m_dh.getLocalNameOfNode(node), node.getNodeName(), ! new AttList(atts, m_dh)); break; case Node.PROCESSING_INSTRUCTION_NODE : { ProcessingInstruction pi = (ProcessingInstruction) node; String name = pi.getNodeName(); --- 311,327 ---- attr.getNodeValue()); } } ! String ns = DOM2Helper.getNamespaceOfNode(node); if(null == ns) ns = ""; this.m_contentHandler.startElement(ns, ! DOM2Helper.getLocalNameOfNode(node), node.getNodeName(), ! new AttList(atts)); break; case Node.PROCESSING_INSTRUCTION_NODE : { ProcessingInstruction pi = (ProcessingInstruction) node; String name = pi.getNodeName();
*** 391,403 **** if (nextIsRaw) { nextIsRaw = false; ! m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, ""); dispatachChars(node); ! m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, ""); } else { dispatachChars(node); } --- 365,377 ---- if (nextIsRaw) { nextIsRaw = false; ! m_contentHandler.processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, ""); dispatachChars(node); ! m_contentHandler.processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, ""); } else { dispatachChars(node); }
*** 438,452 **** { case Node.DOCUMENT_NODE : break; case Node.ELEMENT_NODE : ! String ns = m_dh.getNamespaceOfNode(node); if(null == ns) ns = ""; this.m_contentHandler.endElement(ns, ! m_dh.getLocalNameOfNode(node), node.getNodeName()); NamedNodeMap atts = ((Element) node).getAttributes(); int nAttrs = atts.getLength(); --- 412,426 ---- { case Node.DOCUMENT_NODE : break; case Node.ELEMENT_NODE : ! String ns = DOM2Helper.getNamespaceOfNode(node); if(null == ns) ns = ""; this.m_contentHandler.endElement(ns, ! DOM2Helper.getLocalNameOfNode(node), node.getNodeName()); NamedNodeMap atts = ((Element) node).getAttributes(); int nAttrs = atts.getLength();
< prev index next >