@Override public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws DOMException { return node.replaceChild(newChild, oldChild); }
protected boolean replaceNode(Node[] primaryNodes, Node testNode, List<Node> usedNodes) { boolean foundItem = false; for (int j=0;j<primaryNodes.length;j++){ if (primaryNodes[j].getNodeName().equals(testNode.getNodeName())) { Node newNode = primaryNodes[j].getOwnerDocument().importNode(testNode.cloneNode(true), true); primaryNodes[j].getParentNode().replaceChild(newNode, primaryNodes[j]); usedNodes.add(testNode); foundItem = true; } } return foundItem; } }
protected boolean replaceNode(Node[] primaryNodes, Node testNode, final String attribute, List<Node> usedNodes) { if (testNode.getAttributes().getNamedItem(attribute) == null) { return false; } Node[] filtered = NodeUtil.filterByAttribute(primaryNodes, attribute); int pos = NodeUtil.findNode(filtered, testNode, attribute, true); if (pos >= 0) { Node foundNode = filtered[pos]; Node newNode = foundNode.getOwnerDocument().importNode(testNode.cloneNode(true), true); foundNode.getParentNode().replaceChild(newNode, foundNode); usedNodes.add(testNode); return true; } return false; }
filtered[pos].getParentNode().replaceChild(newNode, filtered[pos]);
Node newTestNode = foundNode.getOwnerDocument().importNode(testNode.cloneNode(true), true); NodeUtil.mergeNodeLists(targetNode, newTestNode.getChildNodes(), foundNode.getChildNodes(), "name"); foundNode.getParentNode().replaceChild(targetNode, foundNode); usedNodes.add(testNode); return true;
@Override public void postSign(Document document) throws MarshalException { // check for XAdES-BES NodeList nl = document.getElementsByTagNameNS(XADES_132_NS, "QualifyingProperties"); if (nl.getLength() != 1) { throw new MarshalException("no XAdES-BES extension present"); } QualifyingPropertiesType qualProps; try { qualProps = QualifyingPropertiesType.Factory.parse(nl.item(0), DEFAULT_XML_OPTIONS); } catch (XmlException e) { throw new MarshalException(e); } // create basic XML container structure UnsignedPropertiesType unsignedProps = qualProps.getUnsignedProperties(); if (unsignedProps == null) { unsignedProps = qualProps.addNewUnsignedProperties(); } UnsignedSignaturePropertiesType unsignedSigProps = unsignedProps.getUnsignedSignatureProperties(); if (unsignedSigProps == null) { /* unsignedSigProps = */ unsignedProps.addNewUnsignedSignatureProperties(); } Node n = document.importNode(qualProps.getDomNode().getFirstChild(), true); nl.item(0).getParentNode().replaceChild(n, nl.item(0)); } }
root.replaceChild(newNode, node); nodeAdded = true; break; root.replaceChild(newNode, node); nodeAdded = true; break;
qualNl.item(0).getParentNode().replaceChild(n, qualNl.item(0));
/** * Recursively apply includes through all SQL fragments. * @param source Include node in DOM tree * @param variablesContext Current context for static variables with values */ private void applyIncludes(Node source, final Properties variablesContext, boolean included) { if (source.getNodeName().equals("include")) { Node toInclude = findSqlFragment(getStringAttribute(source, "refid"), variablesContext); Properties toIncludeContext = getVariablesContext(source, variablesContext); applyIncludes(toInclude, toIncludeContext, true); if (toInclude.getOwnerDocument() != source.getOwnerDocument()) { toInclude = source.getOwnerDocument().importNode(toInclude, true); } source.getParentNode().replaceChild(toInclude, source); while (toInclude.hasChildNodes()) { toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude); } toInclude.getParentNode().removeChild(toInclude); } else if (source.getNodeType() == Node.ELEMENT_NODE) { NodeList children = source.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { applyIncludes(children.item(i), variablesContext, included); } } else if (included && source.getNodeType() == Node.TEXT_NODE && !variablesContext.isEmpty()) { // replace variables ins all text nodes source.setNodeValue(PropertyParser.parse(source.getNodeValue(), variablesContext)); } }
toInclude = source.getOwnerDocument().importNode(toInclude, true); source.getParentNode().replaceChild(toInclude, source); while (toInclude.hasChildNodes()) { toInclude.getParentNode().insertBefore(toInclude.getFirstChild(), toInclude);
XmlUtils.findFirstElement( "//*[@id='" + child.getAttribute("id") + "']", proposed); proposedElementToReplace.getParentNode().replaceChild( proposed.getOwnerDocument().importNode(child, false), proposedElementToReplace); originalElement.getParentNode().replaceChild( original.getOwnerDocument().importNode(proposedElement, false), originalElement);
@Override public void run() { prev.getParentNode().replaceChild(newe, prev); // Note: no warning if it is not possible! } }
/** * Replaces the old node with the new node */ public static void replaceWith(Node oldNode, Node newNode) { Node parentNode = oldNode.getParentNode(); if (parentNode != null) { parentNode.replaceChild(newNode, oldNode); } }
/** * Update style element - invoke this appropriately after any change to the * CSS styles. */ public void updateStyleElement() { // TODO: this should be sufficient - why does Batik occasionally not pick up // the changes unless we actually replace the style element itself? // cssman.updateStyleElement(document, style); Element newstyle = cssman.makeStyleElement(document); style.getParentNode().replaceChild(newstyle, style); style = newstyle; }
/** * Update style element - invoke this appropriately after any change to the * CSS styles. */ public void updateStyleElement() { // TODO: this should be sufficient - why does Batik occasionally not pick up // the changes unless we actually replace the style element itself? // cssman.updateStyleElement(document, style); Element newstyle = cssman.makeStyleElement(document); style.getParentNode().replaceChild(newstyle, style); style = newstyle; }
@Override public void run() { Element olde = plot.getIdElement(id); if(olde != null) { olde.getParentNode().replaceChild(newe, olde); plot.putIdElement(id, newe); } // Note: no warning if it is not possible! } }
@Override public boolean replaceNode(final XPathExpression expression, final Node replacement) throws XPathExpressionException { assertOpen(); final Node node = getNodeByXPath(expression); if (node != null) { final Node parent = node.getParentNode(); parent.replaceChild(replacement, node); return (modified = true); } return false; }
public XMLBuilder replaceNodeAt(String xpath, XMLElement element) { Node target = find(xpath); target.getParentNode().replaceChild(element.toW3C(), target); return this; }
@Override public void run() { Element olde = plot.getIdElement(id); if(olde != null) { olde.getParentNode().replaceChild(newe, olde); plot.putIdElement(id, newe); } // Note: no warning if it is not possible! } }
public DOMNode replaceChild(DOMNode newChild, DOMNode oldChild) throws DOMException { try { return wrap(_delegate.replaceChild( newChild.getDelegate(), oldChild.getDelegate())); } catch (org.w3c.dom.DOMException ex) { throw wrap(ex); } }