< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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,15 +15,15 @@
  * 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;
+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,16 +45,10 @@
 {
 
   /** 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.

@@ -80,44 +74,29 @@
    * 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)
+  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);
     }
-    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();
+      this(contentHandler, null);
   }
 
   /**
    * Perform a pre-order traversal non-recursive style.
    *

@@ -237,22 +216,22 @@
       pos = nextNode;
     }
     this.m_contentHandler.endDocument();
   }
 
-  /** Flag indicating whether following text to be processed is raw text          */
+  // 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)
+    if(m_contentHandler instanceof CharacterNodeHandler)
     {
-      ((com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)m_contentHandler).characters(node);
+      ((CharacterNodeHandler)m_contentHandler).characters(node);
     }
     else
     {
       String data = ((Text) node).getData();
       this.m_contentHandler.characters(data.toCharArray(), 0, data.length());

@@ -311,21 +290,18 @@
 
       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

@@ -335,19 +311,17 @@
                                                    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);
+      String ns = DOM2Helper.getNamespaceOfNode(node);
       if(null == ns)
         ns = "";
       this.m_contentHandler.startElement(ns,
-                                         m_dh.getLocalNameOfNode(node),
+                                         DOM2Helper.getLocalNameOfNode(node),
                                          node.getNodeName(),
-                                         new AttList(atts, m_dh));
+                                         new AttList(atts));
       break;
     case Node.PROCESSING_INSTRUCTION_NODE :
     {
       ProcessingInstruction pi = (ProcessingInstruction) node;
       String name = pi.getNodeName();

@@ -391,13 +365,13 @@
 
       if (nextIsRaw)
       {
         nextIsRaw = false;
 
-        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
+        m_contentHandler.processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "");
         dispatachChars(node);
-        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
+        m_contentHandler.processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, "");
       }
       else
       {
         dispatachChars(node);
       }

@@ -438,15 +412,15 @@
     {
     case Node.DOCUMENT_NODE :
       break;
 
     case Node.ELEMENT_NODE :
-      String ns = m_dh.getNamespaceOfNode(node);
+      String ns = DOM2Helper.getNamespaceOfNode(node);
       if(null == ns)
         ns = "";
       this.m_contentHandler.endElement(ns,
-                                         m_dh.getLocalNameOfNode(node),
+              DOM2Helper.getLocalNameOfNode(node),
                                          node.getNodeName());
 
       NamedNodeMap atts = ((Element) node).getAttributes();
       int nAttrs = atts.getLength();
 
< prev index next >