From: Wolfgang M. M. <wol...@us...> - 2004-09-21 14:42:15
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/dom In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5047/src/org/exist/dom Modified Files: ElementImpl.java Log Message: * Added missing support for xupdate:if * Fixed xupdate:value-of * Prohibit duplicate attributes Index: ElementImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/dom/ElementImpl.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** ElementImpl.java 18 Sep 2004 15:22:57 -0000 1.47 --- ElementImpl.java 21 Sep 2004 14:42:06 -0000 1.48 *************** *** 276,279 **** --- 276,280 ---- DocumentImpl prevDoc = new DocumentImpl(ownerDocument); Node node = null; + NodeImpl lastAttrib = checkDupAttributes(attribs); if (children == 0) { // no children: append a new child *************** *** 281,285 **** } else { - NodeImpl lastAttrib = getLastAttribute(); if (lastAttrib != null && lastAttrib.gid == lastChildID()) node = appendChildren(lastChildID() + 1, lastAttrib, getPath(), attribs, true); --- 282,285 ---- *************** *** 318,321 **** --- 318,322 ---- public Node appendChildren(NodeList nodes, int child) throws DOMException { + // attributes are handled differently. Call checkForAttributes to extract them. nodes = checkForAttributes(nodes); if (nodes == null || nodes.getLength() == 0) *************** *** 566,581 **** } ! private AttrImpl getLastAttribute() { long start = firstChildID(); AttrImpl attr = null; for (long i = start; i < start + children; i++) { Node child = ownerDocument.getNode(i); ! if (child != null ! && child.getNodeType() == Node.ATTRIBUTE_NODE) ! attr = (AttrImpl) child; } return attr; } /** * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String) --- 567,609 ---- } ! /** ! * Check if an attribute is already present in the node's attribute list. Throws a ! * DOMException if yes. Otherwise, returns the last attribute in the attribute list. ! * ! * @param attrs ! * @return ! * @throws DOMException ! */ ! private AttrImpl checkDupAttributes(NodeList attrs) throws DOMException { long start = firstChildID(); AttrImpl attr = null; for (long i = start; i < start + children; i++) { Node child = ownerDocument.getNode(i); ! checkAttribute(child, attrs); ! if (child != null) { ! if(child.getNodeType() == Node.ATTRIBUTE_NODE) ! attr = (AttrImpl) child; ! } else ! break; } return attr; } + private void checkAttribute(Node child, NodeList attrs) throws DOMException { + String childNS = child.getNamespaceURI(); + if(childNS == null) + childNS = ""; + for(int i = 0; i < attrs.getLength(); i++) { + Attr current = (Attr) attrs.item(i); + String currentNS = current.getNamespaceURI(); + if(currentNS == null) + currentNS = ""; + if(child.getLocalName().equals(current.getLocalName()) && + childNS.equals(currentNS)) + throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, + "Attribute " + child.getNodeName() + " is already present."); + } + } + /** * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String) *************** *** 1287,1291 **** appendChildren(firstChildID(), this, getPath(), appendList, true); } else { ! NodeImpl lastAttrib = getLastAttribute(); if (lastAttrib != null && lastAttrib.gid == lastChildID()) appendChildren(lastChildID() + 1, lastAttrib, getPath(), appendList, true); --- 1315,1319 ---- appendChildren(firstChildID(), this, getPath(), appendList, true); } else { ! NodeImpl lastAttrib = checkDupAttributes(appendList); if (lastAttrib != null && lastAttrib.gid == lastChildID()) appendChildren(lastChildID() + 1, lastAttrib, getPath(), appendList, true); |