List of usage examples for org.w3c.dom Node getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:org.jboss.tools.aerogear.hybrid.core.plugin.CordovaPluginManager.java
private List<IPluginInstallationAction> getSourceFilesActionsForPlatform(Node node, AbstractPluginInstallationActionsFactory factory) { ArrayList<IPluginInstallationAction> list = new ArrayList<IPluginInstallationAction>(); NodeList sourceFiles = getSourceFileNodes(node); for (int i = 0; i < sourceFiles.getLength(); i++) { Node current = sourceFiles.item(i); String src = getAttributeValue(current, "src"); String targetDir = getAttributeValue(current, "target-dir"); String framework = getAttributeValue(current, "framework"); String compilerFlags = getAttributeValue(current, "compiler-flags"); String id = CordovaPluginXMLHelper.getAttributeValue(node.getOwnerDocument().getDocumentElement(), "id"); IPluginInstallationAction action = factory.getSourceFileAction(src, targetDir, framework, id, compilerFlags);//from www .j a va 2 s . c om list.add(action); } return list; }
From source file:org.kalypso.model.hydrology.util.optimize.NAOptimizingJob.java
private void saveOptimizeConfig(final File file) { try {// www. j a va 2 s .com final TransformerFactory factory = TransformerFactory.newInstance(); final Transformer t = factory.newTransformer(); t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$ t.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ final Node naOptimizeDom = m_data.getOptimizeData().getOptimizeDom(); final Document ownerDocument = naOptimizeDom instanceof Document ? (Document) naOptimizeDom : naOptimizeDom.getOwnerDocument(); final String encoding = ownerDocument.getInputEncoding(); t.setOutputProperty(OutputKeys.ENCODING, encoding); t.transform(new DOMSource(ownerDocument), new StreamResult(file)); } catch (final Exception e) { e.printStackTrace(); } }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * copies one node to another node (of a different dom document). *//* ww w . jav a 2 s . c o m*/ public static Node copyNode(final Node source, final Node dest) { // Debug.debugMethodBegin( "XMLTools", "copyNode" ); if (source.getNodeType() == Node.TEXT_NODE) { final Text tn = dest.getOwnerDocument().createTextNode(source.getNodeValue()); return tn; } final NamedNodeMap attr = source.getAttributes(); if (attr != null) { for (int i = 0; i < attr.getLength(); i++) { ((Element) dest).setAttribute(attr.item(i).getNodeName(), attr.item(i).getNodeValue()); } } final NodeList list = source.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (!(list.item(i) instanceof Text)) { final Element en = dest.getOwnerDocument().createElementNS(list.item(i).getNamespaceURI(), list.item(i).getNodeName()); if (list.item(i).getNodeValue() != null) { en.setNodeValue(list.item(i).getNodeValue()); } final Node n = copyNode(list.item(i), en); dest.appendChild(n); } else if (list.item(i) instanceof CDATASection) { final CDATASection cd = dest.getOwnerDocument().createCDATASection(list.item(i).getNodeValue()); dest.appendChild(cd); } else { final Text tn = dest.getOwnerDocument().createTextNode(list.item(i).getNodeValue()); dest.appendChild(tn); } } // Debug.debugMethodEnd(); return dest; }
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * inserts a node into a dom element (of a different dom document) *///from www. ja v a2s . c o m public static Node insertNodeInto(final Node source, final Node dest) { Document dDoc = null; final Document sDoc = source.getOwnerDocument(); if (dest instanceof Document) { dDoc = (Document) dest; } else { dDoc = dest.getOwnerDocument(); } if (dDoc.equals(sDoc)) { dest.appendChild(source); } else { final Element element = dDoc.createElementNS(source.getNamespaceURI(), source.getNodeName()); dest.appendChild(element); copyNode(source, element); } return dest; }
From source file:org.kitodo.production.plugin.importer.massimport.PicaMassImport.java
/** * If the record contains a volume of a serial publication, then the series * data will be prepended to it./*from ww w. j a v a 2s . c o m*/ * * @param volumeRecord * hitlist with one hit which will may be a volume of a serial * publication * @return hitlist that may have been extended to contain two hits, first * the series record and second the volume record * @throws ImportPluginException * if something goes wrong in {@link #getOpacAddress()} */ private Node addParentDataForVolume(Node volumeRecord) throws ImportPluginException { try { org.jdom.Document volumeAsJDOMDoc = new DOMBuilder().build(volumeRecord.getOwnerDocument()); Element volumeAsJDOM = volumeAsJDOMDoc.getRootElement().getChild("record"); String parentPPN = getFieldValueFromRecord(volumeAsJDOM, SERIAL_TOTALITY_IDENTIFIER_FIELD); if (parentPPN.isEmpty()) { parentPPN = getFieldValueFromRecord(volumeAsJDOM, TOTALITY_IDENTIFIER_FIELD); } if (!parentPPN.isEmpty()) { Node parentRecord = SRUHelper.parseResult(SRUHelper.search(parentPPN, getOpacAddress())); if (parentRecord == null) { String mess = "Could not retrieve superordinate record " + parentPPN; logger.error(mess); throw new ImportPluginException(mess); } org.jdom.Document resultAsJDOM = new DOMBuilder().build(parentRecord.getOwnerDocument()); volumeAsJDOM.getParent().removeContent(volumeAsJDOM); resultAsJDOM.getRootElement().addContent(volumeAsJDOM); return new DOMOutputter().output(resultAsJDOM).getFirstChild(); } } catch (ParserConfigurationException | JDOMException | IOException e) { throw new ImportPluginException(e.getMessage(), e); } return volumeRecord; }
From source file:org.kitodo.production.plugin.opac.pica.ConfigOpacCatalogue.java
@SuppressWarnings("unchecked") Node executeBeautifier(Node myHitlist) { /* Ausgabe des Opac-Ergebnissen in Datei */ if (!PicaPlugin.getTempDir().equals("") && new File(PicaPlugin.getTempDir()).canWrite()) { debugMyNode(myHitlist, FilenameUtils.concat(PicaPlugin.getTempDir(), "opacBeautifyBefore.xml")); }// w ww .ja va2 s. c o m /* * aus dem Dom-Node ein JDom-Object machen */ Document doc = new DOMBuilder().build(myHitlist.getOwnerDocument()); /* * Im JDom-Object alle Felder durchlaufen und die notwendigen * Ersetzungen vornehmen */ /* alle Records durchlaufen */ List<Element> elements = doc.getRootElement().getChildren(); for (Element el : elements) { // Element el = (Element) it.next(); /* in jedem Record den Beautifier anwenden */ executeBeautifierForElement(el); } /* * aus dem JDom-Object wieder ein Dom-Node machen */ DOMOutputter doutputter = new DOMOutputter(); try { myHitlist = doutputter.output(doc); myHitlist = myHitlist.getFirstChild(); } catch (JDOMException e) { logger.error("JDOMException in executeBeautifier(Node)", e); } /* Ausgabe des berarbeiteten Opac-Ergebnisses */ if (!PicaPlugin.getTempDir().equals("") && new File(PicaPlugin.getTempDir()).canWrite()) { debugMyNode(myHitlist, FilenameUtils.concat(PicaPlugin.getTempDir(), "opacBeautifyAfter.xml")); } return myHitlist; }
From source file:org.kitodo.production.plugin.opac.pica.ConfigOpacCatalogue.java
/** * Print given DomNode to defined File.//w w w . j a v a2 s . c o m */ private void debugMyNode(Node inNode, String fileName) { try (FileOutputStream output = new FileOutputStream(fileName)) { XMLOutputter outputter = new XMLOutputter(); Document tempDoc = new DOMBuilder().build(inNode.getOwnerDocument()); outputter.output(tempDoc.getRootElement(), output); } catch (IOException e) { logger.error("debugMyNode(Node, String)", e); } }
From source file:org.kuali.rice.core.api.util.xml.XmlHelper.java
public static void appendXml(Node parentNode, String xml) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false);/*from w w w .j av a 2 s . co m*/ org.w3c.dom.Document xmlDocument = factory.newDocumentBuilder() .parse(new InputSource(new StringReader(xml))); org.w3c.dom.Element xmlDocumentElement = xmlDocument.getDocumentElement(); Node importedNode = parentNode.getOwnerDocument().importNode(xmlDocumentElement, true); parentNode.appendChild(importedNode); }
From source file:org.omg.bpmn.miwg.util.xml.XPathUtil.java
/** * Builds an absolute XPath string from the given node. * /*from w w w . j a v a 2 s . c o m*/ * @param node * @param context namespace context used to determine correct namespace prefixes, see * {@link SignavioNamespaceContext} * @return an XPath string or null (if no node was given) */ public static String getXPathString(Node node, NamespaceContext context) { if (node == null) { return null; } LinkedList<String> xpathSteps = new LinkedList<String>(); String string = getNodeString(node, context); xpathSteps.add(string); Node current; if (node instanceof Attr) current = ((Attr) node).getOwnerElement(); else current = node.getParentNode(); while (current != node.getOwnerDocument()) { xpathSteps.add(getNodeString(current, context)); current = current.getParentNode(); } StringBuffer buff = new StringBuffer(); Iterator<String> it = xpathSteps.descendingIterator(); while (it.hasNext()) { buff.append("/" + it.next()); } return buff.toString(); }
From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.DocumentFactory.java
/** * Updates the Target Element of the given Policy * // w w w . j a va2 s. c om * @param policy */ private void updatePolicyTargets(Node policy) { Node target = policy.getChildNodes().item(1); while (target.hasChildNodes()) { target.removeChild(target.getFirstChild()); } Vector<Node> resourceListFromRules = new Vector<Node>(); for (int i = 0; i < policy.getChildNodes().getLength(); i++) { Node n = policy.getChildNodes().item(i); if (n.getNodeName().equalsIgnoreCase("Rule")) { resourceListFromRules.add(n); } } Vector<Node> resourceListFromTarget = new Vector<Node>(); for (int i = 0; i < resourceListFromRules.size(); i++) { Node n = resourceListFromRules.elementAt(i); boolean matches = false; for (int k = 0; k < resourceListFromTarget.size(); k++) { if (n.getChildNodes().item(3).getChildNodes().item(3).getChildNodes().item(1).getChildNodes() .item(1).getChildNodes().item(1).getTextContent() .equalsIgnoreCase(resourceListFromTarget.elementAt(k).getChildNodes().item(3) .getChildNodes().item(3).getChildNodes().item(1).getChildNodes().item(1) .getChildNodes().item(1).getTextContent())) { matches = true; } } if (!matches) { resourceListFromTarget.add(n.cloneNode(true)); } } Document ress = null; try { ress = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(new java.io.StringReader("<Resources></Resources>"))); } catch (Exception e) { Logger.getLogger(this.getClass()).error(e); } if (resourceListFromTarget.size() != 0) { Node copy = target.getOwnerDocument().importNode(ress.getDocumentElement(), true); target.appendChild(copy); for (int f = 0; f < resourceListFromTarget.size(); f++) { Node res = policy.getOwnerDocument().importNode(resourceListFromTarget.elementAt(f).getChildNodes() .item(3).getChildNodes().item(3).getChildNodes().item(1), true); copy.appendChild(res); } } }