8037259: xerces update: xpointer update
authordli
Tue, 15 Apr 2014 10:36:23 -0700
changeset 23955 67c850464591
parent 23954 1161e065d446
child 23956 933717886959
child 24054 1fc636fbd7cf
8037259: xerces update: xpointer update Reviewed-by: lancea Contributed-by: david.x.li@oracle.com
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ElementSchemePointer.java
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ShortHandPointer.java
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerErrorHandler.java
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerHandler.java
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerMessageFormatter.java
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerPart.java
jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerProcessor.java
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ElementSchemePointer.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ElementSchemePointer.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -19,7 +20,7 @@
  */
 package com.sun.org.apache.xerces.internal.xpointer;
 
-import java.util.Hashtable;
+import java.util.HashMap;
 
 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
 import com.sun.org.apache.xerces.internal.util.SymbolTable;
@@ -38,9 +39,8 @@
  * @xerces.internal
  *
  * @version $Id: ElementSchemePointer.java,v 1.4 2009/06/11 23:51:50 joehw Exp $
- *
  */
-class ElementSchemePointer implements XPointerPart {
+final class ElementSchemePointer implements XPointerPart {
 
     // Fields
 
@@ -346,15 +346,17 @@
 
                 // Donot check for empty elements if the empty element is
                 // a child of a found parent element
-                //if (!fIsElementFound) {
-                    if (checkMatch()) {
-                        fIsElementFound = true;
+                if (checkMatch()) {
+                    if (!fIsElementFound) {
                         fWasOnlyEmptyElementFound = true;
                     } else {
-                        fIsElementFound = false;
+                        fWasOnlyEmptyElementFound = false;
                     }
-                //}
-
+                    fIsElementFound = true;
+                } else {
+                    fIsElementFound = false;
+                    fWasOnlyEmptyElementFound = false;
+                }
             }
         }
 
@@ -526,7 +528,7 @@
 
         private SymbolTable fSymbolTable;
 
-        private Hashtable fTokenNames = new Hashtable();
+        private HashMap<Integer, String> fTokenNames = new HashMap<>();
 
         /**
          * Constructor
@@ -548,16 +550,7 @@
          * @return String The token string
          */
         private String getTokenString(int token) {
-            return (String) fTokenNames.get(new Integer(token));
-        }
-
-        /**
-         * Returns the token String
-         * @param token The index of the token
-         * @return String The token string
-         */
-        private Integer getToken(int token) {
-            return (Integer) fTokenNames.get(new Integer(token));
+            return fTokenNames.get(new Integer(token));
         }
 
         /**
@@ -566,12 +559,11 @@
          * @param token The token string
          */
         private void addToken(String tokenStr) {
-            Integer tokenInt = (Integer) fTokenNames.get(tokenStr);
-            if (tokenInt == null) {
-                tokenInt = new Integer(fTokenNames.size());
+            if (!fTokenNames.containsValue(tokenStr)) {
+                Integer tokenInt = new Integer(fTokenNames.size());
                 fTokenNames.put(tokenInt, tokenStr);
+                addToken(tokenInt.intValue());
             }
-            addToken(tokenInt.intValue());
         }
 
         /**
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ShortHandPointer.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ShortHandPointer.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,6 +18,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package com.sun.org.apache.xerces.internal.xpointer;
 
 import com.sun.org.apache.xerces.internal.impl.Constants;
@@ -37,9 +39,8 @@
  * in document order that has a matching NCName as an identifier.
  * </p>
  *
- *
  */
-class ShortHandPointer implements XPointerPart {
+final class ShortHandPointer implements XPointerPart {
 
     // The name of the ShortHand pointer
     private String fShortHandPointer;
@@ -261,7 +262,7 @@
      * @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#isChildFragmentResolved()
      */
     public boolean isChildFragmentResolved() {
-        return fIsFragmentResolved & ( fMatchingChildCount >  0);
+        return fIsFragmentResolved && ( fMatchingChildCount >  0);
     }
 
     /**
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerErrorHandler.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerErrorHandler.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,6 +18,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package com.sun.org.apache.xerces.internal.xpointer;
 
 import java.io.PrintWriter;
@@ -31,7 +33,7 @@
  * implementation and reported as resource errors.
  *
  */
-class XPointerErrorHandler implements XMLErrorHandler {
+final class XPointerErrorHandler implements XMLErrorHandler {
 
     //
     // Data
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerHandler.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerHandler.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,10 +18,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package com.sun.org.apache.xerces.internal.xpointer;
 
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.HashMap;
 
 import com.sun.org.apache.xerces.internal.impl.Constants;
 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
@@ -32,6 +34,7 @@
 import com.sun.org.apache.xerces.internal.xni.Augmentations;
 import com.sun.org.apache.xerces.internal.xni.QName;
 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
+import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
 import com.sun.org.apache.xerces.internal.xni.XMLString;
 import com.sun.org.apache.xerces.internal.xni.XNIException;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
@@ -64,8 +67,8 @@
         XPointerProcessor {
 
     // Fields
-    // A Vector of XPointerParts
-    protected Vector fXPointerParts = null;
+    // An ArrayList of XPointerParts
+    protected ArrayList<XPointerPart> fXPointerParts = null;
 
     // The current XPointerPart
     protected XPointerPart fXPointerPart = null;
@@ -102,7 +105,7 @@
     public XPointerHandler() {
         super();
 
-        fXPointerParts = new Vector();
+        fXPointerParts = new ArrayList<>();
         fSymbolTable = new SymbolTable();
     }
 
@@ -110,13 +113,17 @@
             XMLErrorHandler errorHandler, XMLErrorReporter errorReporter) {
         super();
 
-        fXPointerParts = new Vector();
+        fXPointerParts = new ArrayList<>();
         fSymbolTable = symbolTable;
         fErrorHandler = errorHandler;
         fXPointerErrorReporter = errorReporter;
         //fErrorReporter = errorReporter; // The XInclude ErrorReporter
     }
 
+    public void setDocumentHandler(XMLDocumentHandler handler) {
+        fDocumentHandler = handler;
+    }
+
     // ************************************************************************
     //  Implementation of the XPointerProcessor interface.
     // ************************************************************************
@@ -300,7 +307,7 @@
             // in the XPointer expression until a matching element is found.
             for (int i = 0; i < fXPointerParts.size(); i++) {
 
-                fXPointerPart = (XPointerPart) fXPointerParts.get(i);
+                fXPointerPart = fXPointerParts.get(i);
 
                 if (fXPointerPart.resolveXPointer(element, attributes, augs,
                         event)) {
@@ -430,11 +437,11 @@
     }
 
     /**
-     * Returns a Vector of XPointerPart objects
+     * Returns an ArrayList of XPointerPart objects
      *
-     * @return A Vector of XPointerPart objects.
+     * @return An ArrayList of XPointerPart objects.
      */
-    public Vector getPointerParts() {
+    public ArrayList<XPointerPart> getPointerParts() {
         return fXPointerParts;
     }
 
@@ -480,7 +487,7 @@
 
         private SymbolTable fSymbolTable;
 
-        private Hashtable fTokenNames = new Hashtable();
+        private HashMap<Integer, String> fTokenNames = new HashMap<>();
 
         /**
          * Constructor
@@ -508,7 +515,7 @@
          * @return String The token string
          */
         private String getTokenString(int token) {
-            return (String) fTokenNames.get(new Integer(token));
+            return fTokenNames.get(new Integer(token));
         }
 
         /**
@@ -517,12 +524,11 @@
          * @param token The token string
          */
         private void addToken(String tokenStr) {
-            Integer tokenInt = (Integer) fTokenNames.get(tokenStr);
-            if (tokenInt == null) {
-                tokenInt = new Integer(fTokenNames.size());
+            if (!fTokenNames.containsValue(tokenStr)) {
+                Integer tokenInt = new Integer(fTokenNames.size());
                 fTokenNames.put(tokenInt, tokenStr);
+                addToken(tokenInt.intValue());
             }
-            addToken(tokenInt.intValue());
         }
 
         /**
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerMessageFormatter.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerMessageFormatter.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,6 +18,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package com.sun.org.apache.xerces.internal.xpointer;
 
 import java.util.Locale;
@@ -34,7 +36,7 @@
  *
  * @version $Id: XPointerMessageFormatter.java,v 1.5 2010-11-01 04:40:26 joehw Exp $
  */
-class XPointerMessageFormatter implements MessageFormatter {
+final class XPointerMessageFormatter implements MessageFormatter {
 
     public static final String XPOINTER_DOMAIN = "http://www.w3.org/TR/XPTR";
 
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerPart.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerPart.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,6 +18,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package com.sun.org.apache.xerces.internal.xpointer;
 
 import com.sun.org.apache.xerces.internal.xni.Augmentations;
@@ -49,7 +51,7 @@
      * Provides scheme specific parsing of a XPointer expression i.e.
      * the PointerPart or ShortHandPointer.
      *
-     * @param  xpointer A String representing the PointerPart or ShortHandPointer.
+     * @param  part A String representing the PointerPart or ShortHandPointer.
      * @throws XNIException Thrown if the PointerPart string does not conform to
      *         the syntax defined by its scheme.
      *
--- a/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerProcessor.java	Wed Jan 08 10:49:54 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerProcessor.java	Tue Apr 15 10:36:23 2014 -0700
@@ -3,11 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -34,7 +35,6 @@
  *
  * @xerces.internal
  *
- *
  */
 public interface XPointerProcessor {
 
@@ -56,7 +56,6 @@
      * @throws XNIException Thrown if the xpointer string does not conform to
      *         the XPointer Framework syntax or the syntax of the pointer part does
      *         not conform to its definition for its scheme.
-     *
      */
     public void parseXPointer(String xpointer) throws XNIException;
 
@@ -74,7 +73,6 @@
      *                2 - An empty element call
      * @return true if the element was resolved by the xpointer
      * @throws XNIException Thrown to signal an error
-     *
      */
     public boolean resolveXPointer(QName element, XMLAttributes attributes,
             Augmentations augs, int event) throws XNIException;
@@ -86,7 +84,6 @@
      * @return True if the xpointer expression matches a node/fragment in the resource
      *         else returns false.
      * @throws XNIException Thrown to signal an error
-     *
      */
     public boolean isFragmentResolved() throws XNIException;
 
@@ -97,7 +94,6 @@
      * @return True if the xpointer expression matches a fragment in the resource
      *         else returns false.
      * @throws XNIException Thrown to signal an error
-     *
      */
     public boolean isXPointerResolved() throws XNIException;