src/com/sun/org/apache/xerces/internal/xpointer/XPointerHandler.java

Print this page

        

@@ -1,28 +1,30 @@
 /*
  * reserved comment block
  * 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
  *
  * Unless required by applicable law or agreed to in writing, software
  * 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.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;
 import com.sun.org.apache.xerces.internal.util.SymbolTable;
 import com.sun.org.apache.xerces.internal.util.XMLChar;

@@ -30,10 +32,11 @@
 import com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler;
 import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport;
 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;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
 

@@ -62,12 +65,12 @@
  */
 public final class XPointerHandler extends XIncludeHandler implements
         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;
 
     // Has the fXPointerPart resolved successfully

@@ -100,25 +103,29 @@
      *
      */
     public XPointerHandler() {
         super();
 
-        fXPointerParts = new Vector();
+        fXPointerParts = new ArrayList<>();
         fSymbolTable = new SymbolTable();
     }
 
     public XPointerHandler(SymbolTable symbolTable,
             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.
     // ************************************************************************
 
     /**

@@ -298,11 +305,11 @@
 
             // for each element, attempt to resolve it against each pointer part
             // 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)) {
                     fFoundMatchingPtrPart = true;
                     resolved = true;

@@ -428,15 +435,15 @@
 
         initErrorReporter();
     }
 
     /**
-     * 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;
     }
 
     /**
      * List of XPointer Framework tokens.

@@ -478,11 +485,11 @@
         // Current token position
         private int fCurrentTokenIndex;
 
         private SymbolTable fSymbolTable;
 
-        private Hashtable fTokenNames = new Hashtable();
+        private HashMap<Integer, String> fTokenNames = new HashMap<>();
 
         /**
          * Constructor
          *
          * @param symbolTable SymbolTable

@@ -506,26 +513,25 @@
          * Returns the token String
          * @param token The index of the token
          * @return String The token string
          */
         private String getTokenString(int token) {
-            return (String) fTokenNames.get(new Integer(token));
+            return fTokenNames.get(new Integer(token));
         }
 
         /**
          * Add the specified string as a token
          *
          * @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());
         }
+        }
 
         /**
          * Add the specified int token
          *
          * @param token The int specifying the token