mrglavas 2005/06/22 22:38:35
Modified: java/src/org/apache/xerces/util NamespaceSupport.java
java/src/org/apache/xerces/jaxp/validation
DOMValidatorHelper.java
Log:
Fixing a couple bugs with respect to managing the NamespaceContext during DOM
validation.
1) When a namespace is unbound the URI in the NamespaceContext
should be stored as null instead of the empty string.
2) If a namespace was unbound in the scope of the validation root,
we must not look at the ancestors for a binding.
Revision Changes Path
1.19 +26 -1
xml-xerces/java/src/org/apache/xerces/util/NamespaceSupport.java
Index: NamespaceSupport.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/util/NamespaceSupport.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- NamespaceSupport.java 24 Feb 2004 23:15:53 -0000 1.18
+++ NamespaceSupport.java 23 Jun 2005 05:38:35 -0000 1.19
@@ -260,6 +260,31 @@
return new Prefixes(fPrefixes, count);
}
+ /*
+ * non-NamespaceContext methods
+ */
+
+ /**
+ * Checks whether a binding or unbinding for
+ * the given prefix exists in the context.
+ *
+ * @param prefix The prefix to look up.
+ *
+ * @return true if the given prefix exists in the context
+ */
+ public boolean containsPrefix(String prefix) {
+
+ // find prefix in current context
+ for (int i = fNamespaceSize; i > 0; i -= 2) {
+ if (fNamespace[i - 2] == prefix) {
+ return true;
+ }
+ }
+
+ // prefix not found
+ return false;
+ }
+
protected final class Prefixes implements Enumeration {
private String[] prefixes;
private int counter = 0;
1.5 +12 -8
xml-xerces/java/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java
Index: DOMValidatorHelper.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMValidatorHelper.java 18 Jun 2005 22:59:06 -0000 1.4
+++ DOMValidatorHelper.java 23 Jun 2005 05:38:35 -0000 1.5
@@ -34,6 +34,7 @@
import org.apache.xerces.impl.validation.ValidationManager;
import org.apache.xerces.impl.xs.XMLSchemaValidator;
import org.apache.xerces.impl.xs.util.SimpleLocator;
+import org.apache.xerces.util.NamespaceSupport;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.XMLAttributesImpl;
import org.apache.xerces.util.XMLSymbols;
@@ -102,7 +103,7 @@
private XMLErrorReporter fErrorReporter;
/** The namespace context of this document: stores namespaces in scope.
**/
- private NamespaceContext fNamespaceContext;
+ private NamespaceSupport fNamespaceContext;
/** The namespace context of the DOMSource, includes context from
ancestor nodes. **/
private DOMNamespaceContext fDOMNamespaceContext = new
DOMNamespaceContext();
@@ -152,7 +153,7 @@
public DOMValidatorHelper(XMLSchemaValidatorComponentManager
componentManager) {
fComponentManager = componentManager;
fErrorReporter = (XMLErrorReporter)
fComponentManager.getProperty(ERROR_REPORTER);
- fNamespaceContext = (NamespaceContext)
fComponentManager.getProperty(NAMESPACE_CONTEXT);
+ fNamespaceContext = (NamespaceSupport)
fComponentManager.getProperty(NAMESPACE_CONTEXT);
fSchemaValidator = (XMLSchemaValidator)
fComponentManager.getProperty(SCHEMA_VALIDATOR);
fSymbolTable = (SymbolTable)
fComponentManager.getProperty(SYMBOL_TABLE);
fValidationManager = (ValidationManager)
fComponentManager.getProperty(VALIDATION_MANAGER);
@@ -421,10 +422,10 @@
if (fAttributeQName.uri == NamespaceContext.XMLNS_URI) {
// process namespace attribute
if (fAttributeQName.prefix == XMLSymbols.PREFIX_XMLNS) {
-
fNamespaceContext.declarePrefix(fAttributeQName.localpart,
fSymbolTable.addSymbol(value));
+
fNamespaceContext.declarePrefix(fAttributeQName.localpart, value.length() != 0
? fSymbolTable.addSymbol(value) : null);
}
else {
- fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING,
fSymbolTable.addSymbol(value));
+ fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING,
value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
}
}
}
@@ -500,7 +501,10 @@
fillNamespaceContext();
fDOMContextBuilt = true;
}
- uri = getURI0(prefix);
+ if (fNamespaceSize > 0 &&
+ !fNamespaceContext.containsPrefix(prefix)) {
+ uri = getURI0(prefix);
+ }
}
return uri;
}
@@ -546,10 +550,10 @@
if (fAttributeQName.uri ==
NamespaceContext.XMLNS_URI) {
// process namespace attribute
if (fAttributeQName.prefix ==
XMLSymbols.PREFIX_XMLNS) {
-
declarePrefix0(fAttributeQName.localpart, fSymbolTable.addSymbol(value));
+
declarePrefix0(fAttributeQName.localpart, value.length() != 0 ?
fSymbolTable.addSymbol(value) : null);
}
else {
- declarePrefix0(XMLSymbols.EMPTY_STRING,
fSymbolTable.addSymbol(value));
+ declarePrefix0(XMLSymbols.EMPTY_STRING,
value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]