List of usage examples for org.w3c.dom Node getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:de.betterform.xml.xforms.xpath.saxon.function.XFormsFunction.java
protected Container getContainer(XPathContext xpathContext) { Item item = xpathContext.getContextItem(); Node n = (Node) ((NodeWrapper) item).getUnderlyingNode(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("context node: " + n.getNodeName()); }/* w w w . jav a 2 s. c om*/ Element root = n.getOwnerDocument().getDocumentElement(); Object container = root.getUserData("container"); if (container instanceof Container) { return (Container) container; } else { return null; } }
From source file:com.zacwolf.commons.wbxcon.WBXCONorg.java
/** * This is a helper method that correctly handles setting the text content * for a given tag in a DOM <code>Document</code> * // w w w . j av a2s. c o m * @param tagName DOM tag to create and add to the parent node. * @param value The text value to be assigned to the tag * @param parent The parent Node that the tag/text will be added to */ final static void documentSetTextContentOfNode(final String tagName, final String value, final Node parent) { final Document dom = parent.getOwnerDocument(); final Node node = dom.createElement(tagName); final Text nodeVal = dom.createTextNode(value); node.appendChild(nodeVal); parent.appendChild(node); }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
private void copyParing(Document paring, Node response) throws Exception { Node paringElement = response.appendChild(response.getOwnerDocument().createElement("paring")); Node kehaNode = response.getOwnerDocument().importNode(paring.getDocumentElement(), true); NamedNodeMap attrs = kehaNode.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { paringElement.getAttributes().setNamedItem(attrs.item(i).cloneNode(true)); }/*from w w w. j a v a2 s . c o m*/ while (kehaNode.hasChildNodes()) { paringElement.appendChild(kehaNode.getFirstChild()); } }
From source file:Sax2Dom.java
public Sax2Dom(Node root) throws ParserConfigurationException { _root = root;//from ww w.ja va 2s . com if (root instanceof Document) { _document = (Document) root; } else if (root != null) { _document = root.getOwnerDocument(); } else { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); _document = factory.newDocumentBuilder().newDocument(); _root = _document; } }
From source file:ch.entwine.weblounge.bridge.oaipmh.util.XmlGen.java
/** * Append node <code>n</code> to element <code>e</code> respecting different * node types like attributes and elements. *//* w ww .j a v a2s . com*/ private void appendTo(Element e, Node n) { Node toAppend = ObjectUtils.equals(n.getOwnerDocument(), document) ? n : document.importNode(n, true); if (toAppend instanceof Attr) { e.setAttributeNode((Attr) toAppend); } else { e.appendChild(toAppend); } }
From source file:cz.muni.fi.mir.mathmlunificator.utils.DOMBuilderTest.java
@Test public void testCloneNodeToNewDoc() { try {// w w w . ja v a 2 s. c o m String xmlString = "<math xmlns:uni=\"http://mir.fi.muni.cz/mathml-unification/\"\n" + " uni:unification-level=\"2\" uni:unification-max-level=\"4\" xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" + " <msup>\n" + " <mi>a</mi>\n" + " <mi>b</mi>\n" + " </msup>\n" + " <mo>+</mo>\n" + " <mfrac>\n" + " <mi>c</mi>\n" + " <mi>d</mi>\n" + " </mfrac>\n" + "</math>"; Document originalDoc = DOMBuilder.buildDoc(xmlString); Document doc = DOMBuilder.buildDoc(xmlString); // deep == true NodeList deepNodeList = doc.getElementsByTagNameNS("http://www.w3.org/1998/Math/MathML", "mo"); assertEquals(deepNodeList.getLength(), 1); Node deepNode = deepNodeList.item(0); Node newDeepNode = DOMBuilder.cloneNodeToNewDoc(deepNode, true); System.out.println("testCloneNodeToNewDoc deep output:\n" + XMLOut.xmlStringSerializer(newDeepNode.getOwnerDocument())); testXML("Deep clonning failed", DOMBuilder.buildDoc("<mo xmlns=\"http://www.w3.org/1998/Math/MathML\">+</mo>"), newDeepNode.getOwnerDocument()); newDeepNode.setTextContent("deep different content"); System.out.println("testCloneNodeToNewDoc input document DOM after non-deep processing:\n" + XMLOut.xmlStringSerializer(doc)); testXML("Original document DOM changed after processing", originalDoc, doc); // deep == false NodeList noDeepNodeList = doc.getElementsByTagNameNS("http://www.w3.org/1998/Math/MathML", "mfrac"); assertEquals(noDeepNodeList.getLength(), 1); Node noDeepNode = noDeepNodeList.item(0); Node newNoDeepNode = DOMBuilder.cloneNodeToNewDoc(noDeepNode, false); System.out.println("testCloneNodeToNewDoc non-deep output:\n" + XMLOut.xmlStringSerializer(newNoDeepNode.getOwnerDocument())); testXML("Non-deep clonning failed", DOMBuilder.buildDoc("<mfrac xmlns=\"http://www.w3.org/1998/Math/MathML\"/>"), newNoDeepNode.getOwnerDocument()); newNoDeepNode.setTextContent("non-deep different content"); System.out.println("testCloneNodeToNewDoc input document DOM after non-deep processing:\n" + XMLOut.xmlStringSerializer(doc)); testXML("Original document DOM changed after processing", originalDoc, doc); } catch (ParserConfigurationException | SAXException | IOException ex) { fail(ex.getMessage()); } }
From source file:net.sourceforge.ajaxtags.tags.AjaxAnchorsTag.java
/** * Rewrite link. Change (or create) "onclick" attribute, set "href" attribute to * "javascript://nop/"./* w ww . j av a 2s . c om*/ * * @param link * node of document with link * @param target * target of request */ protected final void rewriteLink(final Node link, final String target) { final NamedNodeMap map = link.getAttributes(); final Attr href = (Attr) map.getNamedItem("href"); if (href != null) { Attr onclick = (Attr) map.getNamedItem("onclick"); if (onclick == null) { onclick = link.getOwnerDocument().createAttribute("onclick"); map.setNamedItem(onclick); } onclick.setValue(getOnclickAjax(target, href.getValue(), getOptionsBuilder())); href.setValue("javascript://nop/"); } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static Document getDocument(Node node) { if (node instanceof Document) { return (Document) node; }// w w w . ja va2 s . com return node.getOwnerDocument(); }
From source file:de.betterform.xml.xforms.xpath.saxon.function.Changed.java
/** * Evaluate in a general context//from ww w . j a v a 2 s. co m */ public Item evaluateItem(XPathContext xpathContext) throws XPathException { Item item = argument[0].evaluateItem(xpathContext); if (item != null) { Node node = (Node) ((NodeWrapper) item).getUnderlyingNode(); String xpath = DOMUtil.getCanonicalPath(node); // String currentValue = (String) argument[0].evaluateAsString(xpathContext); String currentValue = DOMUtil.getTextNodeAsString(node); de.betterform.xml.xforms.model.Instance owner = (de.betterform.xml.xforms.model.Instance) node .getOwnerDocument().getDocumentElement().getUserData("instance"); String initialValue = null; try { Document initial = owner.getInitialInstance(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Initial Instance: START:"); DOMUtil.prettyPrintDOM(initial); LOGGER.debug("\nInitial Instance: STOP"); } initialValue = XPathUtil.evaluateAsString(initial, xpath); } catch (XFormsException e) { throw new XPathException("initial Instance couldn't be fetched", e); } if (currentValue.equals(initialValue)) { return BooleanValue.FALSE; } else { return BooleanValue.TRUE; } } else { LOGGER.warn("Item for " + xpathContext.toString() + " couldn't be found"); return BooleanValue.FALSE; } }
From source file:com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI.java
private boolean shouldReset(Node current) { boolean shouldReset = lastDocument == null || xpathApi == null; if (!shouldReset) { Document doc = current instanceof Document ? (Document) current : current.getOwnerDocument(); shouldReset = !lastDocument.equals(doc); }/*from w ww . j a va 2 s . c o m*/ return shouldReset; }