List of usage examples for org.w3c.dom DOMException WRONG_DOCUMENT_ERR
short WRONG_DOCUMENT_ERR
To view the source code for org.w3c.dom DOMException WRONG_DOCUMENT_ERR.
Click Source Link
Node
is used in a different document than the one that created it (that doesn't support it). From source file:com.gargoylesoftware.htmlunit.html.DomNode.java
/** * Check for insertion errors for a new child node. This is overridden by derived * classes to enforce which types of children are allowed. * * @param newChild the new child node that is being inserted below this node * @throws DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does * not allow children of the type of the newChild node, or if the node to insert is one of * this node's ancestors or this node itself, or if this node is of type Document and the * DOM application attempts to insert a second DocumentType or Element node. * WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the * one that created this node.//from w w w . j a va 2 s . co m */ protected void checkChildHierarchy(final Node newChild) throws DOMException { Node parentNode = this; while (parentNode != null) { if (parentNode == newChild) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Child node is already a parent."); } parentNode = parentNode.getParentNode(); } final Document thisDocument = getOwnerDocument(); final Document childDocument = newChild.getOwnerDocument(); if (childDocument != thisDocument && childDocument != null) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Child node " + newChild.getNodeName() + " is not in the same Document as this " + getNodeName() + "."); } }
From source file:org.structr.web.entity.dom.DOMNode.java
protected void checkSameDocument(Node otherNode) throws DOMException { Document doc = getOwnerDocument(); if (doc != null) { Document otherDoc = otherNode.getOwnerDocument(); // Shadow doc is neutral if (otherDoc != null && !doc.equals(otherDoc) && !(doc instanceof ShadowDocument)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, WRONG_DOCUMENT_ERR_MESSAGE); }// ww w. j av a 2s . com if (otherDoc == null) { ((DOMNode) otherNode).doAdopt((Page) doc); } } }
From source file:org.apache.xml.security.signature.Manifest.java
/** * Constructor Manifest//from w w w .j a v a 2s. co m * * @param element * @param baseURI * @throws XMLSecurityException */ public Manifest(Element element, String baseURI) throws XMLSecurityException { super(element, baseURI); // check out Reference children this.referencesEl = XMLUtils.selectDsNodes(this.constructionElement.getFirstChild(), Constants._TAG_REFERENCE); int le = this.referencesEl.length; if (le == 0) { // At least one Reference must be present. Bad. Object exArgs[] = { Constants._TAG_REFERENCE, Constants._TAG_MANIFEST }; throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, I18n.translate("xml.WrongContent", exArgs)); } // create List this.references = new ArrayList<Reference>(le); for (int i = 0; i < le; i++) { this.references.add(null); } }
From source file:org.exist.dom.ElementImpl.java
/** * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node) *///ww w .ja v a2 s . co m @Override public Node insertBefore(Node newChild, Node refChild) throws DOMException { if (refChild == null) { return appendChild(newChild); } if (!(refChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } final NodeListImpl nl = new NodeListImpl(); nl.add(newChild); final TransactionManager transact = ownerDocument.getBrokerPool().getTransactionManager(); final Txn transaction = transact.beginTransaction(); DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); insertBefore(transaction, nl, refChild); broker.storeXMLResource(transaction, (DocumentImpl) getOwnerDocument()); transact.commit(transaction); return refChild.getPreviousSibling(); } catch (final TransactionException e) { transact.abort(transaction); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, e.getMessage()); } catch (final EXistException e) { transact.abort(transaction); LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) { try { transact.close(transaction); } finally { broker.release(); } } } return null; }
From source file:org.exist.dom.ElementImpl.java
/** * Insert a list of nodes at the position before the reference * child./* w ww. j a v a 2 s .c o m*/ */ @Override public void insertBefore(Txn transaction, NodeList nodes, Node refChild) throws DOMException { if (refChild == null) { //TODO : use NodeImpl.UNKNOWN_NODE_IMPL_GID ? -pb appendChildren(transaction, nodes, -1); return; } if (!(refChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "wrong node type"); } DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); final NodePath path = getPath(); StreamListener listener = null; //May help getReindexRoot() to make some useful things broker.getIndexController().setDocument(ownerDocument); final StoredNode reindexRoot = broker.getIndexController().getReindexRoot(this, path, true, true); broker.getIndexController().setMode(StreamListener.STORE); if (reindexRoot == null) { listener = broker.getIndexController().getStreamListener(); } final StoredNode following = (StoredNode) refChild; final StoredNode previous = (StoredNode) following.getPreviousSibling(); if (previous == null) { // there's no sibling node before the new node final NodeId newId = following.getNodeId().insertBefore(); appendChildren(transaction, newId, following.getNodeId(), new NodeImplRef(this), path, nodes, listener); } else { // insert the new node between the preceding and following sibling final NodeId newId = previous.getNodeId().insertNode(following.getNodeId()); appendChildren(transaction, newId, following.getNodeId(), new NodeImplRef(getLastNode(previous)), path, nodes, listener); } setDirty(true); broker.updateNode(transaction, this, true); broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } }
From source file:org.exist.dom.ElementImpl.java
/** * Insert a list of nodes at the position following the reference * child.//w w w . ja va 2 s. co m */ @Override public void insertAfter(Txn transaction, NodeList nodes, Node refChild) throws DOMException { if (refChild == null) { //TODO : use NodeImpl.UNKNOWN_NODE_IMPL_GID ? -pb appendChildren(null, nodes, -1); return; } if (!(refChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "wrong node type: "); } DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); final NodePath path = getPath(); StreamListener listener = null; //May help getReindexRoot() to make some useful things broker.getIndexController().setDocument(ownerDocument); final StoredNode reindexRoot = broker.getIndexController().getReindexRoot(this, path, true, true); broker.getIndexController().setMode(StreamListener.STORE); if (reindexRoot == null) { listener = broker.getIndexController().getStreamListener(); } final StoredNode previous = (StoredNode) refChild; final StoredNode following = (StoredNode) previous.getNextSibling(); final NodeId followingId = following == null ? null : following.getNodeId(); final NodeId newNodeId = previous.getNodeId().insertNode(followingId); appendChildren(transaction, newNodeId, followingId, new NodeImplRef(getLastNode(previous)), path, nodes, listener); setDirty(true); broker.updateNode(transaction, this, true); broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } }
From source file:org.exist.dom.ElementImpl.java
/** * Update a child node. This method will only update the child node * but not its potential descendant nodes. * * @param oldChild/*ww w .j ava 2 s .c o m*/ * @param newChild * @throws DOMException */ @Override public StoredNode updateChild(Txn transaction, Node oldChild, Node newChild) throws DOMException { if (!(oldChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } if (!(newChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } StoredNode oldNode = (StoredNode) oldChild; final StoredNode newNode = (StoredNode) newChild; if (!oldNode.nodeId.getParentId().equals(nodeId)) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Node is not a child of this element"); } if (newNode.getNodeType() == Node.ATTRIBUTE_NODE) { if (newNode.getQName().equalsSimple(Namespaces.XML_ID_QNAME)) { // an xml:id attribute. Normalize the attribute and set its type to ID final AttrImpl attr = (AttrImpl) newNode; attr.setValue(StringValue.trimWhitespace(StringValue.collapseWhitespace(attr.getValue()))); attr.setType(AttrImpl.ID); } } StoredNode previousNode = (StoredNode) oldNode.getPreviousSibling(); if (previousNode == null) { previousNode = this; } else { previousNode = getLastNode(previousNode); } final NodePath currentPath = getPath(); final NodePath oldPath = oldNode.getPath(currentPath); DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); //May help getReindexRoot() to make some useful things broker.getIndexController().setDocument(ownerDocument); //Check if the change affects any ancestor nodes, which then need to be reindexed later StoredNode reindexRoot = broker.getIndexController().getReindexRoot(oldNode, oldPath, false); //Remove indexes if (reindexRoot == null) { reindexRoot = oldNode; } broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.REMOVE_SOME_NODES); //TODO: fix once range index has been moved to new architecture final StoredNode valueReindexRoot = broker.getValueIndex().getReindexRoot(this, oldPath); broker.getValueIndex().reindex(valueReindexRoot); //Remove the actual node data broker.removeNode(transaction, oldNode, oldPath, null); broker.endRemove(transaction); newNode.nodeId = oldNode.nodeId; //Reinsert the new node data broker.insertNodeAfter(transaction, previousNode, newNode); final NodePath path = newNode.getPath(currentPath); broker.indexNode(transaction, newNode, path); if (newNode.getNodeType() == Node.ELEMENT_NODE) { broker.endElement(newNode, path, null); } broker.updateNode(transaction, this, true); //Recreate indexes on ancestor nodes broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); broker.getValueIndex().reindex(valueReindexRoot); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } return newNode; }
From source file:org.exist.dom.ElementImpl.java
/** * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node) *//* w w w . j a v a 2 s . co m*/ @Override public Node removeChild(Txn transaction, Node oldChild) throws DOMException { if (!(oldChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "wrong node type"); } final StoredNode oldNode = (StoredNode) oldChild; if (!oldNode.nodeId.getParentId().equals(nodeId)) { throw new DOMException(DOMException.NOT_FOUND_ERR, "node is not a child of this element"); } final NodePath oldPath = oldNode.getPath(); StreamListener listener = null; DBBroker broker = null; try { //May help getReindexRoot() to make some useful things broker = ownerDocument.getBrokerPool().get(null); broker.getIndexController().setDocument(ownerDocument); final StoredNode reindexRoot = broker.getIndexController().getReindexRoot(oldNode, oldPath, false); broker.getIndexController().setMode(StreamListener.REMOVE_SOME_NODES); if (reindexRoot == null) { listener = broker.getIndexController().getStreamListener(); } else { broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.REMOVE_SOME_NODES); } broker.removeAllNodes(transaction, oldNode, oldPath, listener); --children; if (oldChild.getNodeType() == Node.ATTRIBUTE_NODE) { --attributes; } broker.endRemove(transaction); setDirty(true); broker.updateNode(transaction, this, false); broker.flush(); if (reindexRoot != null && !reindexRoot.getNodeId().equals(oldNode.getNodeId())) { broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); } } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } return oldNode; }
From source file:org.exist.dom.ElementImpl.java
public void removeAppendAttributes(Txn transaction, NodeList removeList, NodeList appendList) { DBBroker broker = null;//from w ww.j a v a 2 s .c om try { broker = ownerDocument.getBrokerPool().get(null); if (removeList != null) { try { for (int i = 0; i < removeList.getLength(); i++) { final Node oldChild = removeList.item(i); if (!(oldChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } final StoredNode old = (StoredNode) oldChild; if (!old.nodeId.isChildOf(nodeId)) { throw new DOMException(DOMException.NOT_FOUND_ERR, "node " + old.nodeId.getParentId() + " is not a child of element " + nodeId); } final NodePath oldPath = old.getPath(); // remove old custom indexes broker.getIndexController().reindex(transaction, old, StreamListener.REMOVE_SOME_NODES); broker.removeNode(transaction, old, oldPath, null); children--; attributes--; } } finally { broker.endRemove(transaction); } } final NodePath path = getPath(); broker.getIndexController().setDocument(ownerDocument, StreamListener.STORE); final StreamListener listener = broker.getIndexController().getStreamListener(); if (children == 0) { appendChildren(transaction, nodeId.newChild(), null, new NodeImplRef(this), path, appendList, listener); } else { if (attributes == 0) { final StoredNode firstChild = (StoredNode) getFirstChild(); final NodeId newNodeId = firstChild.nodeId.insertBefore(); appendChildren(transaction, newNodeId, firstChild.getNodeId(), new NodeImplRef(this), path, appendList, listener); } else { final AttribVisitor visitor = new AttribVisitor(); accept(visitor); final NodeId firstChildId = visitor.firstChild == null ? null : visitor.firstChild.nodeId; final NodeId newNodeId = visitor.lastAttrib.nodeId.insertNode(firstChildId); appendChildren(transaction, newNodeId, firstChildId, new NodeImplRef(visitor.lastAttrib), path, appendList, listener); } setDirty(true); } attributes += appendList.getLength(); broker.updateNode(transaction, this, true); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } }
From source file:org.exist.dom.ElementImpl.java
/** * Replaces the oldNode with the newChild * /*from ww w . j a va2s . c o m*/ * @param transaction * @param newChild * @param oldChild * * @return The new node (this differs from the {@link org.w3c.dom.Node#replaceChild(Node, Node)} specification) * * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node) */ @Override public Node replaceChild(Txn transaction, Node newChild, Node oldChild) throws DOMException { if (!(oldChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } final StoredNode oldNode = (StoredNode) oldChild; if (!oldNode.nodeId.getParentId().equals(nodeId)) { throw new DOMException(DOMException.NOT_FOUND_ERR, "Node is not a child of this element"); } StoredNode previous = (StoredNode) oldNode.getPreviousSibling(); if (previous == null) { previous = this; } else { previous = getLastNode(previous); } final NodePath oldPath = oldNode.getPath(); StreamListener listener = null; //May help getReindexRoot() to make some useful things Node newNode = null; DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); broker.getIndexController().setDocument(ownerDocument); final StoredNode reindexRoot = broker.getIndexController().getReindexRoot(oldNode, oldPath, false); broker.getIndexController().setMode(StreamListener.REMOVE_SOME_NODES); if (reindexRoot == null) { listener = broker.getIndexController().getStreamListener(); } else { broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.REMOVE_SOME_NODES); } broker.removeAllNodes(transaction, oldNode, oldPath, listener); broker.endRemove(transaction); broker.flush(); broker.getIndexController().setMode(StreamListener.STORE); listener = broker.getIndexController().getStreamListener(); newNode = appendChild(transaction, oldNode.nodeId, new NodeImplRef(previous), getPath(), newChild, listener); //Reindex if required final DocumentImpl owner = (DocumentImpl) getOwnerDocument(); broker.storeXMLResource(transaction, owner); broker.updateNode(transaction, this, false); broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE); broker.flush(); } catch (final EXistException e) { LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) broker.release(); } //return oldChild; // method is spec'd to return the old child, even though that's probably useless in this case return newNode; //returning the newNode is more sensible than returning the oldNode }