Skip to content

Commit 53bb5f6

Browse files
David LiDavid Li
David Li
authored and
David Li
committed
8037259: xerces update: xpointer update
Reviewed-by: lancea, phh
1 parent 054b85b commit 53bb5f6

File tree

7 files changed

+87
-85
lines changed

7 files changed

+87
-85
lines changed

jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ElementSchemePointer.java

+21-28
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* DO NOT REMOVE OR ALTER!
44
*/
55
/*
6-
* Copyright 2005 The Apache Software Foundation.
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
1112
*
1213
* http://www.apache.org/licenses/LICENSE-2.0
1314
*
@@ -19,7 +20,7 @@
1920
*/
2021
package com.sun.org.apache.xerces.internal.xpointer;
2122

22-
import java.util.Hashtable;
23+
import java.util.HashMap;
2324

2425
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
2526
import com.sun.org.apache.xerces.internal.util.SymbolTable;
@@ -38,7 +39,7 @@
3839
* @xerces.internal
3940
*
4041
*/
41-
class ElementSchemePointer implements XPointerPart {
42+
final class ElementSchemePointer implements XPointerPart {
4243

4344
// Fields
4445

@@ -344,15 +345,17 @@ protected boolean matchChildSequence(QName element, int event)
344345

345346
// Donot check for empty elements if the empty element is
346347
// a child of a found parent element
347-
//if (!fIsElementFound) {
348-
if (checkMatch()) {
349-
fIsElementFound = true;
348+
if (checkMatch()) {
349+
if (!fIsElementFound) {
350350
fWasOnlyEmptyElementFound = true;
351351
} else {
352-
fIsElementFound = false;
352+
fWasOnlyEmptyElementFound = false;
353353
}
354-
//}
355-
354+
fIsElementFound = true;
355+
} else {
356+
fIsElementFound = false;
357+
fWasOnlyEmptyElementFound = false;
358+
}
356359
}
357360
}
358361

@@ -523,7 +526,7 @@ private final class Tokens {
523526

524527
private SymbolTable fSymbolTable;
525528

526-
private Hashtable fTokenNames = new Hashtable();
529+
private HashMap<Integer, String> fTokenNames = new HashMap<>();
527530

528531
/**
529532
* Constructor
@@ -545,16 +548,7 @@ private Tokens(SymbolTable symbolTable) {
545548
* @return String The token string
546549
*/
547550
private String getTokenString(int token) {
548-
return (String) fTokenNames.get(new Integer(token));
549-
}
550-
551-
/**
552-
* Returns the token String
553-
* @param token The index of the token
554-
* @return String The token string
555-
*/
556-
private Integer getToken(int token) {
557-
return (Integer) fTokenNames.get(new Integer(token));
551+
return fTokenNames.get(new Integer(token));
558552
}
559553

560554
/**
@@ -563,12 +557,11 @@ private Integer getToken(int token) {
563557
* @param token The token string
564558
*/
565559
private void addToken(String tokenStr) {
566-
Integer tokenInt = (Integer) fTokenNames.get(tokenStr);
567-
if (tokenInt == null) {
568-
tokenInt = new Integer(fTokenNames.size());
560+
if (!fTokenNames.containsValue(tokenStr)) {
561+
Integer tokenInt = new Integer(fTokenNames.size());
569562
fTokenNames.put(tokenInt, tokenStr);
563+
addToken(tokenInt.intValue());
570564
}
571-
addToken(tokenInt.intValue());
572565
}
573566

574567
/**

jaxp/src/com/sun/org/apache/xerces/internal/xpointer/ShortHandPointer.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* DO NOT REMOVE OR ALTER!
44
*/
55
/*
6-
* Copyright 2005 The Apache Software Foundation.
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
1112
*
1213
* http://www.apache.org/licenses/LICENSE-2.0
1314
*
@@ -17,6 +18,7 @@
1718
* See the License for the specific language governing permissions and
1819
* limitations under the License.
1920
*/
21+
2022
package com.sun.org.apache.xerces.internal.xpointer;
2123

2224
import com.sun.org.apache.xerces.internal.impl.Constants;
@@ -37,9 +39,8 @@
3739
* in document order that has a matching NCName as an identifier.
3840
* </p>
3941
*
40-
*
4142
*/
42-
class ShortHandPointer implements XPointerPart {
43+
final class ShortHandPointer implements XPointerPart {
4344

4445
// The name of the ShortHand pointer
4546
private String fShortHandPointer;
@@ -261,7 +262,7 @@ public boolean isFragmentResolved() {
261262
* @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#isChildFragmentResolved()
262263
*/
263264
public boolean isChildFragmentResolved() {
264-
return fIsFragmentResolved & ( fMatchingChildCount > 0);
265+
return fIsFragmentResolved && ( fMatchingChildCount > 0);
265266
}
266267

267268
/**

jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerErrorHandler.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* DO NOT REMOVE OR ALTER!
44
*/
55
/*
6-
* Copyright 2005 The Apache Software Foundation.
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
1112
*
1213
* http://www.apache.org/licenses/LICENSE-2.0
1314
*
@@ -17,6 +18,7 @@
1718
* See the License for the specific language governing permissions and
1819
* limitations under the License.
1920
*/
21+
2022
package com.sun.org.apache.xerces.internal.xpointer;
2123

2224
import java.io.PrintWriter;
@@ -31,7 +33,7 @@
3133
* implementation and reported as resource errors.
3234
*
3335
*/
34-
class XPointerErrorHandler implements XMLErrorHandler {
36+
final class XPointerErrorHandler implements XMLErrorHandler {
3537

3638
//
3739
// Data

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

+27-21
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* DO NOT REMOVE OR ALTER!
44
*/
55
/*
6-
* Copyright 2005 The Apache Software Foundation.
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
1112
*
1213
* http://www.apache.org/licenses/LICENSE-2.0
1314
*
@@ -17,10 +18,11 @@
1718
* See the License for the specific language governing permissions and
1819
* limitations under the License.
1920
*/
21+
2022
package com.sun.org.apache.xerces.internal.xpointer;
2123

22-
import java.util.Hashtable;
23-
import java.util.Vector;
24+
import java.util.ArrayList;
25+
import java.util.HashMap;
2426

2527
import com.sun.org.apache.xerces.internal.impl.Constants;
2628
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
@@ -32,6 +34,7 @@
3234
import com.sun.org.apache.xerces.internal.xni.Augmentations;
3335
import com.sun.org.apache.xerces.internal.xni.QName;
3436
import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
37+
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
3538
import com.sun.org.apache.xerces.internal.xni.XMLString;
3639
import com.sun.org.apache.xerces.internal.xni.XNIException;
3740
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
@@ -64,8 +67,8 @@ public final class XPointerHandler extends XIncludeHandler implements
6467
XPointerProcessor {
6568

6669
// Fields
67-
// A Vector of XPointerParts
68-
protected Vector fXPointerParts = null;
70+
// An ArrayList of XPointerParts
71+
protected ArrayList<XPointerPart> fXPointerParts = null;
6972

7073
// The current XPointerPart
7174
protected XPointerPart fXPointerPart = null;
@@ -102,21 +105,25 @@ public final class XPointerHandler extends XIncludeHandler implements
102105
public XPointerHandler() {
103106
super();
104107

105-
fXPointerParts = new Vector();
108+
fXPointerParts = new ArrayList<>();
106109
fSymbolTable = new SymbolTable();
107110
}
108111

109112
public XPointerHandler(SymbolTable symbolTable,
110113
XMLErrorHandler errorHandler, XMLErrorReporter errorReporter) {
111114
super();
112115

113-
fXPointerParts = new Vector();
116+
fXPointerParts = new ArrayList<>();
114117
fSymbolTable = symbolTable;
115118
fErrorHandler = errorHandler;
116119
fXPointerErrorReporter = errorReporter;
117120
//fErrorReporter = errorReporter; // The XInclude ErrorReporter
118121
}
119122

123+
public void setDocumentHandler(XMLDocumentHandler handler) {
124+
fDocumentHandler = handler;
125+
}
126+
120127
// ************************************************************************
121128
// Implementation of the XPointerProcessor interface.
122129
// ************************************************************************
@@ -300,7 +307,7 @@ public boolean resolveXPointer(QName element, XMLAttributes attributes,
300307
// in the XPointer expression until a matching element is found.
301308
for (int i = 0; i < fXPointerParts.size(); i++) {
302309

303-
fXPointerPart = (XPointerPart) fXPointerParts.get(i);
310+
fXPointerPart = fXPointerParts.get(i);
304311

305312
if (fXPointerPart.resolveXPointer(element, attributes, augs,
306313
event)) {
@@ -430,11 +437,11 @@ protected void init() {
430437
}
431438

432439
/**
433-
* Returns a Vector of XPointerPart objects
440+
* Returns an ArrayList of XPointerPart objects
434441
*
435-
* @return A Vector of XPointerPart objects.
442+
* @return An ArrayList of XPointerPart objects.
436443
*/
437-
public Vector getPointerParts() {
444+
public ArrayList<XPointerPart> getPointerParts() {
438445
return fXPointerParts;
439446
}
440447

@@ -480,7 +487,7 @@ private final class Tokens {
480487

481488
private SymbolTable fSymbolTable;
482489

483-
private Hashtable fTokenNames = new Hashtable();
490+
private HashMap<Integer, String> fTokenNames = new HashMap<>();
484491

485492
/**
486493
* Constructor
@@ -508,7 +515,7 @@ private Tokens(SymbolTable symbolTable) {
508515
* @return String The token string
509516
*/
510517
private String getTokenString(int token) {
511-
return (String) fTokenNames.get(new Integer(token));
518+
return fTokenNames.get(new Integer(token));
512519
}
513520

514521
/**
@@ -517,12 +524,11 @@ private String getTokenString(int token) {
517524
* @param token The token string
518525
*/
519526
private void addToken(String tokenStr) {
520-
Integer tokenInt = (Integer) fTokenNames.get(tokenStr);
521-
if (tokenInt == null) {
522-
tokenInt = new Integer(fTokenNames.size());
527+
if (!fTokenNames.containsValue(tokenStr)) {
528+
Integer tokenInt = new Integer(fTokenNames.size());
523529
fTokenNames.put(tokenInt, tokenStr);
530+
addToken(tokenInt.intValue());
524531
}
525-
addToken(tokenInt.intValue());
526532
}
527533

528534
/**

jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerMessageFormatter.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* DO NOT REMOVE OR ALTER!
44
*/
55
/*
6-
* Copyright 2005 The Apache Software Foundation.
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
1112
*
1213
* http://www.apache.org/licenses/LICENSE-2.0
1314
*
@@ -17,6 +18,7 @@
1718
* See the License for the specific language governing permissions and
1819
* limitations under the License.
1920
*/
21+
2022
package com.sun.org.apache.xerces.internal.xpointer;
2123

2224
import java.util.Locale;
@@ -33,7 +35,7 @@
3335
* @xerces.internal
3436
*
3537
*/
36-
class XPointerMessageFormatter implements MessageFormatter {
38+
final class XPointerMessageFormatter implements MessageFormatter {
3739

3840
public static final String XPOINTER_DOMAIN = "http://www.w3.org/TR/XPTR";
3941

jaxp/src/com/sun/org/apache/xerces/internal/xpointer/XPointerPart.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* DO NOT REMOVE OR ALTER!
44
*/
55
/*
6-
* Copyright 2005 The Apache Software Foundation.
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
* The ASF licenses this file to You under the Apache License, Version 2.0
10+
* (the "License"); you may not use this file except in compliance with
11+
* the License. You may obtain a copy of the License at
1112
*
1213
* http://www.apache.org/licenses/LICENSE-2.0
1314
*
@@ -17,6 +18,7 @@
1718
* See the License for the specific language governing permissions and
1819
* limitations under the License.
1920
*/
21+
2022
package com.sun.org.apache.xerces.internal.xpointer;
2123

2224
import com.sun.org.apache.xerces.internal.xni.Augmentations;
@@ -49,7 +51,7 @@ public interface XPointerPart {
4951
* Provides scheme specific parsing of a XPointer expression i.e.
5052
* the PointerPart or ShortHandPointer.
5153
*
52-
* @param xpointer A String representing the PointerPart or ShortHandPointer.
54+
* @param part A String representing the PointerPart or ShortHandPointer.
5355
* @throws XNIException Thrown if the PointerPart string does not conform to
5456
* the syntax defined by its scheme.
5557
*

0 commit comments

Comments
 (0)