Author: mrglavas
Date: Sun Jun 18 15:44:11 2006
New Revision: 415211
URL: http://svn.apache.org/viewvc?rev=415211&view=rev
Log:
Fixing JIRA Bug #1123:
http://issues.apache.org/jira/browse/XERCESJ-1123
We need to take special care of schema defaulted attributes. Calling the
non-namespace
aware setAttributeNode() method could overwrite another attribute with the same
local name. Since we know all of the attributes in the document which were not
defaulted
from the schema will have unique qualified names and that all of the schema
defaults will
be at the end of the list we can add them to the element with
setAttributeNode(). Schema
defaults are added with setAttributeNodeNS(). Normally its unwise to mix these
methods but
the implementation of setAttributeNode() in Xerces is much more efficient
[O(log n) instead
of O(n)] than setAttributeNodeNS(), it would hurt performance if we switched
over in all
cases.
Modified:
xerces/java/trunk/src/org/apache/xerces/dom/AttributeMap.java
xerces/java/trunk/src/org/apache/xerces/dom/DeferredElementNSImpl.java
xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java
Modified: xerces/java/trunk/src/org/apache/xerces/dom/AttributeMap.java
URL:
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/AttributeMap.java?rev=415211&r1=415210&r2=415211&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/AttributeMap.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/AttributeMap.java Sun Jun 18
15:44:11 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2002,2004,2005 The Apache Software Foundation.
+ * Copyright 2000-2002,2004-2006 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.
@@ -21,7 +21,6 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
-
/**
* AttributeMap inherits from NamedNodeMapImpl and extends it to deal with the
* specifics of storing attributes. These are:
@@ -102,7 +101,7 @@
argn.ownerNode = ownerNode;
argn.isOwned(true);
- int i = findNamePoint(arg.getNodeName(),0);
+ int i = findNamePoint(argn.getNodeName(),0);
AttrImpl previous = null;
if (i >= 0) {
previous = (AttrImpl) nodes.elementAt(i);
@@ -571,14 +570,14 @@
argn.ownerNode = ownerNode;
argn.isOwned(true);
- int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
+ int i = findNamePoint(argn.getNamespaceURI(), argn.getLocalName());
if (i >= 0) {
nodes.setElementAt(arg,i);
}
else {
// If we can't find by namespaceURI, localName, then we find by
// nodeName so we know where to insert.
- i = findNamePoint(arg.getNodeName(),0);
+ i = findNamePoint(argn.getNodeName(),0);
if (i >= 0) {
nodes.insertElementAt(arg,i);
}
Modified: xerces/java/trunk/src/org/apache/xerces/dom/DeferredElementNSImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/DeferredElementNSImpl.java?rev=415211&r1=415210&r2=415211&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/DeferredElementNSImpl.java
(original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/DeferredElementNSImpl.java Sun
Jun 18 15:44:11 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2002,2004 The Apache Software Foundation.
+ * Copyright 1999-2002,2004,2006 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.
@@ -117,9 +117,18 @@
if (attrIndex != -1) {
NamedNodeMap attrs = getAttributes();
do {
- NodeImpl attr =
- (NodeImpl)ownerDocument.getNodeObject(attrIndex);
- attrs.setNamedItem(attr);
+ AttrImpl attr = (AttrImpl)
ownerDocument.getNodeObject(attrIndex);
+ // Take special care of schema defaulted attributes. Calling
the
+ // non-namespace aware setAttributeNode() method could
overwrite
+ // another attribute with the same local name.
+ if (!attr.getSpecified() &&
+ attr.getNamespaceURI() != null &&
+ attr.getName().indexOf(':') < 0) {
+ attrs.setNamedItemNS(attr);
+ }
+ else {
+ attrs.setNamedItem(attr);
+ }
attrIndex = ownerDocument.getPrevSibling(attrIndex);
} while (attrIndex != -1);
}
Modified: xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java
URL:
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java?rev=415211&r1=415210&r2=415211&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java
(original)
+++ xerces/java/trunk/src/org/apache/xerces/parsers/AbstractDOMParser.java Sun
Jun 18 15:44:11 2006
@@ -922,9 +922,17 @@
((PSVIAttrNSImpl) attr).setPSVI (attrPSVI);
}
-
attr.setValue (attrValue);
- el.setAttributeNode (attr);
+ boolean specified = attributes.isSpecified(i);
+ // Take special care of schema defaulted attributes. Calling
the
+ // non-namespace aware setAttributeNode() method could
overwrite
+ // another attribute with the same local name.
+ if (!specified && fAttrQName.uri != null && fAttrQName.prefix
== null) {
+ el.setAttributeNodeNS(attr);
+ }
+ else {
+ el.setAttributeNode(attr);
+ }
// NOTE: The specified value MUST be set after you set
// the node value because that turns the "specified"
// flag to "true" which may overwrite a "false"
@@ -971,7 +979,7 @@
((ElementImpl) el).setIdAttributeNode (attr, true);
}
- attrImpl.setSpecified (attributes.isSpecified (i));
+ attrImpl.setSpecified (specified);
// REVISIT: Handle entities in attribute value.
}
}
@@ -1037,7 +1045,9 @@
element.rawname,
type);
int attrCount = attributes.getLength ();
- for (int i = 0; i < attrCount; i++) {
+ // Need to loop in reverse order so that the attributes
+ // are processed in document order when the DOM is expanded.
+ for (int i = attrCount - 1; i >= 0; --i) {
// set type information
AttributePSVI attrPSVI =
(AttributePSVI)attributes.getAugmentations (i).getItem
(Constants.ATTRIBUTE_PSVI);
boolean id = false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]