You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2006/11/03 23:43:26 UTC
svn commit: r471030 -
/xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java
Author: mrglavas
Date: Fri Nov 3 14:43:26 2006
New Revision: 471030
URL: http://svn.apache.org/viewvc?view=rev&rev=471030
Log:
Fixing JIRA Issue #1207:
http://issues.apache.org/jira/browse/XERCESJ-1207
To match the NCName:* node test in an XPath a given QName must have the same
namespace as the one specified by the node test. We were treating these as if
they were unrestricted wildcards.
Modified:
xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java
Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java?view=diff&rev=471030&r1=471029&r2=471030
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/XPathMatcher.java Fri Nov 3 14:43:26 2006
@@ -203,7 +203,7 @@
*
* @throws SAXException Thrown by handler to signal an error.
*/
- public void startElement(QName element, XMLAttributes attributes){
+ public void startElement(QName element, XMLAttributes attributes) {
if (DEBUG_METHODS2) {
System.out.println(toString()+"#startElement("+
"element={"+element+"},"+
@@ -211,7 +211,7 @@
")");
}
- for(int i = 0; i < fLocationPaths.length; i++) {
+ for (int i = 0; i < fLocationPaths.length; i++) {
// push context
int startStep = fCurrentStep[i];
fStepIndexes[i].push(startStep);
@@ -279,18 +279,16 @@
if (DEBUG_MATCH) {
System.out.println(toString()+" [CHILD] before");
}
- if (nodeTest.type == XPath.NodeTest.QNAME) {
- if (!nodeTest.name.equals(element)) {
- if(fCurrentStep[i] > descendantStep) {
- fCurrentStep[i] = descendantStep;
- continue;
- }
- fNoMatchDepth[i]++;
- if (DEBUG_MATCH) {
- System.out.println(toString()+" [CHILD] after NO MATCH");
- }
+ if (!matches(nodeTest, element)) {
+ if (fCurrentStep[i] > descendantStep) {
+ fCurrentStep[i] = descendantStep;
continue;
}
+ fNoMatchDepth[i]++;
+ if (DEBUG_MATCH) {
+ System.out.println(toString()+" [CHILD] after NO MATCH");
+ }
+ continue;
}
fCurrentStep[i]++;
if (DEBUG_MATCH) {
@@ -298,10 +296,11 @@
}
}
if (fCurrentStep[i] == steps.length) {
- if(sawDescendant) {
+ if (sawDescendant) {
fCurrentStep[i] = descendantStep;
fMatched[i] = MATCHED_DESCENDANT;
- } else {
+ }
+ else {
fMatched[i] = MATCHED;
}
continue;
@@ -319,14 +318,13 @@
for (int aIndex = 0; aIndex < attrCount; aIndex++) {
attributes.getName(aIndex, fQName);
- if (nodeTest.type != XPath.NodeTest.QNAME ||
- nodeTest.name.equals(fQName)) {
+ if (matches(nodeTest, fQName)) {
fCurrentStep[i]++;
if (fCurrentStep[i] == steps.length) {
fMatched[i] = MATCHED_ATTRIBUTE;
- int j=0;
- for(; j<i && ((fMatched[j] & MATCHED) != MATCHED); j++);
- if(j==i) {
+ int j = 0;
+ for(; j < i && ((fMatched[j] & MATCHED) != MATCHED); j++);
+ if (j == i) {
AttributePSVI attrPSVI = (AttributePSVI)attributes.getAugmentations(aIndex).getItem(Constants.ATTRIBUTE_PSVI);
fMatchedString = attrPSVI.getActualNormalizedValue();
matched(fMatchedString, attrPSVI.getActualNormalizedValueType(), attrPSVI.getItemValueTypes(), false);
@@ -376,7 +374,7 @@
"element={"+element+"},"+
")");
}
- for(int i = 0; i<fLocationPaths.length; i++) {
+ for (int i = 0; i < fLocationPaths.length; i++) {
// go back a step
fCurrentStep[i] = fStepIndexes[i].pop();
@@ -387,9 +385,9 @@
// signal match, if appropriate
else {
- int j=0;
- for(; j<i && ((fMatched[j] & MATCHED) != MATCHED); j++);
- if ((j<i) || (fMatched[j] == 0) ||
+ int j = 0;
+ for(; j < i && ((fMatched[j] & MATCHED) != MATCHED); j++);
+ if ((j < i) || (fMatched[j] == 0) ||
((fMatched[j] & MATCHED_ATTRIBUTE) == MATCHED_ATTRIBUTE)) {
continue;
}
@@ -467,6 +465,18 @@
}
return str.toString();
} // normalize(String):String
+
+ /** Returns true if the given QName matches the node test. **/
+ private static boolean matches(XPath.NodeTest nodeTest, QName value) {
+ if (nodeTest.type == XPath.NodeTest.QNAME) {
+ return nodeTest.name.equals(value);
+ }
+ if (nodeTest.type == XPath.NodeTest.NAMESPACE) {
+ return nodeTest.name.uri == value.uri;
+ }
+ // XPath.NodeTest.WILDCARD
+ return true;
+ } // matches(XPath.NodeTest,QName):boolean
//
// MAIN
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org