elena 2002/12/30 17:16:06 Modified: java/src/org/apache/xerces/dom AttrImpl.java CoreDocumentImpl.java ElementImpl.java Log: Implementation of DOM Level 3 setId* methods. Revision Changes Path 1.48 +9 -2 xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java Index: AttrImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- AttrImpl.java 19 Nov 2002 01:41:36 -0000 1.47 +++ AttrImpl.java 31 Dec 2002 01:16:06 -0000 1.48 @@ -239,8 +239,15 @@ * @param id */ public void setIdAttribute(boolean id){ - this.isIdAttribute(id); + isIdAttribute(id); } + /** DOM Level 3: isId*/ + public boolean getIsId(){ + // REVISIT: should an attribute that is not in the tree return + // isID true? + return isIdAttribute(); + } + // // Node methods 1.37 +21 -12 xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java Index: CoreDocumentImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- CoreDocumentImpl.java 30 Dec 2002 21:31:02 -0000 1.36 +++ CoreDocumentImpl.java 31 Dec 2002 01:16:06 -0000 1.37 @@ -1631,19 +1631,28 @@ * @see #putIdentifier * @see #removeIdentifier */ - public Element getIdentifier(String idName) { + public Element getIdentifier(String idName) { - if (needsSyncData()) { - synchronizeData(); - } + if (needsSyncData()) { + synchronizeData(); + } - if (identifiers == null) { - return null; - } - - return (Element)identifiers.get(idName); - - } // getIdentifier(String):Element + if (identifiers == null) { + return null; + } + Element elem = (Element) identifiers.get(idName); + if (elem != null) { + // check that the element is in the tree + Node parent = elem.getParentNode(); + while (parent != null) { + if (parent == this) { + return elem; + } + parent = parent.getParentNode(); + } + } + return null; + } // getIdentifier(String):Element /** * Removes a previously registered element with the specified 1.56 +108 -39 xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java Index: ElementImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- ElementImpl.java 30 Dec 2002 21:31:02 -0000 1.55 +++ ElementImpl.java 31 Dec 2002 01:16:06 -0000 1.56 @@ -478,33 +478,37 @@ * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is * readonly. */ - public void setAttribute(String name, String value) { + public void setAttribute(String name, String value) { - if (ownerDocument.errorChecking && isReadOnly()) { - String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); - throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); - } + if (ownerDocument.errorChecking && isReadOnly()) { + String msg = + DOMMessageFormatter.formatMessage( + DOMMessageFormatter.DOM_DOMAIN, + "NO_MODIFICATION_ALLOWED_ERR", + null); + throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); + } - if (needsSyncData()) { - synchronizeData(); - } + if (needsSyncData()) { + synchronizeData(); + } - Attr newAttr = getAttributeNode(name); - if (newAttr == null) { - newAttr = getOwnerDocument().createAttribute(name); + Attr newAttr = getAttributeNode(name); + if (newAttr == null) { + newAttr = getOwnerDocument().createAttribute(name); - if (attributes == null) { - attributes = new AttributeMap(this, null); - } + if (attributes == null) { + attributes = new AttributeMap(this, null); + } - newAttr.setNodeValue(value); - attributes.setNamedItem(newAttr); - } - else { - newAttr.setNodeValue(value); - } + newAttr.setNodeValue(value); + attributes.setNamedItem(newAttr); + } + else { + newAttr.setNodeValue(value); + } - } // setAttribute(String,String) + } // setAttribute(String,String) /** * Add a new attribute/value pair, or replace the value of the @@ -669,6 +673,7 @@ } // setAttributeNS(String,String,String) + /** * Introduced in DOM Level 2. <p> * @@ -898,45 +903,109 @@ } return true; } - - // - // Public methods - // - + /** - * NON-DOM: Subclassed to flip the attributes' readonly switch as well. - * @see NodeImpl#setReadOnly + * DOM Level 3: register the given attribute node as an ID attribute */ - public void setReadOnly(boolean readOnly, boolean deep) { - super.setReadOnly(readOnly,deep); - if (attributes != null) { - attributes.setReadOnly(readOnly,true); + public void setIdAttributeNode(Attr at) { + if (needsSyncData()) { + synchronizeData(); + } + if (ownerDocument.errorChecking) { + if (isReadOnly()) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); + throw new DOMException( + DOMException.NO_MODIFICATION_ALLOWED_ERR, + msg); + } + + if (at.getOwnerElement() != this) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); + throw new DOMException(DOMException.NOT_FOUND_ERR, msg); + } + } + ((AttrImpl) at).isIdAttribute(true); + ownerDocument.putIdentifier(at.getValue(), this); + } + + /** + * DOM Level 3: register the given attribute node as an ID attribute + */ + public void setIdAttribute(String name, boolean makeId) { + if (needsSyncData()) { + synchronizeData(); + } + Attr at = getAttributeNode(name); + if (ownerDocument.errorChecking) { + if (isReadOnly()) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); + throw new DOMException( + DOMException.NO_MODIFICATION_ALLOWED_ERR, + msg); + } + + if (at.getOwnerElement() != this) { + String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); + throw new DOMException(DOMException.NOT_FOUND_ERR, msg); + } + } + + ((AttrImpl) at).isIdAttribute(makeId); + if (!makeId) { + ownerDocument.removeIdentifier(at.getValue()); + } + else { + ownerDocument.putIdentifier(at.getValue(), this); } } /** - * NON-DOM: register the given attribute node as an ID attribute + * DOM Level 3: register the given attribute node as an ID attribute */ - public void setIdAttributeNode(Attr at) { + public void setIdAttributeNS(String namespaceURI, String localName, + boolean makeId) { if (needsSyncData()) { synchronizeData(); } - if (ownerDocument.errorChecking) { + Attr at = getAttributeNodeNS(namespaceURI, localName); + if (ownerDocument.errorChecking) { if (isReadOnly()) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException( DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } - + if (at.getOwnerElement() != this) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); throw new DOMException(DOMException.NOT_FOUND_ERR, msg); } } - ((AttrImpl) at).isIdAttribute(true); - ownerDocument.putIdentifier(at.getValue(), this); + ((AttrImpl) at).isIdAttribute(makeId); + if (!makeId) { + ownerDocument.removeIdentifier(at.getValue()); + } + else { + ownerDocument.putIdentifier(at.getValue(), this); + } + } + + + // + // Public methods + // + + /** + * NON-DOM: Subclassed to flip the attributes' readonly switch as well. + * @see NodeImpl#setReadOnly + */ + public void setReadOnly(boolean readOnly, boolean deep) { + super.setReadOnly(readOnly,deep); + if (attributes != null) { + attributes.setReadOnly(readOnly,true); + } } + //
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]