You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by fe...@apache.org on 2002/09/09 20:31:39 UTC
cvs commit: xml-xindice/java/src/org/apache/xindice/xml/dom ElementImpl.java
fern 2002/09/09 11:31:39
Modified: java/src/org/apache/xindice/xml/dom ElementImpl.java
Log:
- The removeAttribute method was throwing a NPE if the attribute did not exist.
- The remoteAttributeNS method was not setting the removed attribute's parent.
Revision Changes Path
1.5 +32 -22 xml-xindice/java/src/org/apache/xindice/xml/dom/ElementImpl.java
Index: ElementImpl.java
===================================================================
RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/xml/dom/ElementImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ElementImpl.java 3 Aug 2002 15:49:08 -0000 1.4
+++ ElementImpl.java 9 Sep 2002 18:31:39 -0000 1.5
@@ -201,16 +201,20 @@
}
/**
- * Removes an attribute by name. If the removed attribute has a default
- * value it is immediately replaced.
+ * Removes an attribute by name. If the removed attribute has a
+ * default value it is immediately replaced. If the named
+ * attribute does not exist, this method has no effect.
+ *
* @param name The name of the attribute to remove.
* @exception DOMException
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
- */
- public void removeAttribute(String name) throws DOMException {
+ **/
+ public void removeAttribute( String name ) throws DOMException {
checkReadOnly();
- AttrImpl attr = (AttrImpl)attributes.removeNamedItem(name);
- ((AttrImpl)attr).setParentNode((NodeImpl)this.getOwnerDocument());
+ AttrImpl attr = (AttrImpl) attributes.removeNamedItem(name);
+ if ( attr != null ) {
+ attr.setParentNode( (NodeImpl)this.getOwnerDocument() );
+ }
setDirty();
}
@@ -315,14 +319,14 @@
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
* <br>NOT_FOUND_ERR: Raised if <code>oldAttr</code> is not an attribute
* of the element.
- */
- public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
+ **/
+ public Attr removeAttributeNode( Attr oldAttr ) throws DOMException {
checkReadOnly();
- DocumentImpl doc = (DocumentImpl)getOwnerDocument();
- if ( oldAttr.getParentNode() != this )
- throw EX_NOT_FOUND;
- attributes.remove(oldAttr.getName());
- ((AttrImpl)oldAttr).setParentNode((NodeImpl)this.getOwnerDocument());
+ if ( oldAttr.getParentNode() != this ) {
+ throw EX_NOT_FOUND;
+ }
+ attributes.remove( oldAttr.getName() );
+ ((AttrImpl)oldAttr).setParentNode( (NodeImpl)this.getOwnerDocument() );
setDirty();
return oldAttr;
}
@@ -387,20 +391,26 @@
}
/**
- * Removes an attribute by local name and namespace URI. If the removed
- * attribute has a default value it is immediately replaced. The
- * replacing attribute has the same namespace URI and local name, as well
- * as the original prefix.
- * <br> HTML-only DOM implementations do not need to implement this method.
+ * Removes an attribute by local name and namespace URI. If the
+ * removed attribute has a default value it is immediately
+ * replaced. The replacing attribute has the same namespace URI
+ * and local name, as well as the original prefix.
+ *
+ * <br> HTML-only DOM implementations do not need to implement this
+ * method.
+ *
* @param namespaceURI The namespace URI of the attribute to remove.
* @param localName The local name of the attribute to remove.
* @exception DOMException
* NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
* @since DOM Level 2
- */
- public void removeAttributeNS(String namespaceURI, String localName) {
+ **/
+ public void removeAttributeNS( String namespaceURI, String localName ) {
checkReadOnly();
- attributes.removeNamedItemNS(namespaceURI, localName);
+ AttrImpl attr = (AttrImpl) attributes.removeNamedItemNS( namespaceURI, localName );
+ if ( attr != null ) {
+ attr.setParentNode( (NodeImpl)this.getOwnerDocument() );
+ }
setDirty();
}