List of usage examples for org.w3c.dom Node setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Sets the kerberos configs//from ww w.j a v a2 s . c om * * @param kerberosConfig kerbeos config */ private void setKerberosRampartConfig(Node kerberosConfig, Map<String, String> carbonSecKerberosDataMap) { NodeList list = kerberosConfig.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (SecurityFormConstants.RAMPART_PROPERTY.equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute(SecurityFormConstants.PROPERTY_NAME); if (StringUtils.isNotBlank(attribute)) { node.setTextContent(carbonSecKerberosDataMap.get(attribute)); } } } }
From source file:org.xwiki.officeimporter.internal.filter.ListFilter.java
/** * {@inheritDoc}//from ww w . j av a 2 s . c o m */ public void filter(Document document, Map<String, String> cleaningParams) { List<Element> listItems = filterDescendants(document.getDocumentElement(), new String[] { TAG_LI }); for (Element listItem : listItems) { Node nextChild = listItem.getFirstChild(); while (nextChild != null) { if (nextChild.getNodeType() == Node.TEXT_NODE) { String trimmed = StringUtils.stripStart(nextChild.getTextContent(), WHITE_SPACE_CHARS); nextChild.setTextContent(trimmed); if (trimmed.equals("")) { nextChild = nextChild.getNextSibling(); continue; } } else if (nextChild.getNodeName().equals(TAG_P)) { replaceWithChildren((Element) nextChild); } break; } } }
From source file:org.zaproxy.zap.extension.saml.SAMLMessage.java
/** Update XML document with any attributes that were changed */ private void updateXMLDocument() { XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); for (Attribute attribute : attributeMap.values()) { try {// www . j a va2s .c o m Node node = (Node) xpath.compile(attribute.getxPath()).evaluate(xmlDocument, XPathConstants.NODE); if (node != null) { // the attributes that aren't available will be giving null // values if (node instanceof Element) { node.setTextContent(attribute.getValue().toString()); } else if (node instanceof Attr) { ((Attr) node).setValue(attribute.getValue().toString()); } else { node.setNodeValue(attribute.getValue().toString()); } } } catch (XPathExpressionException e) { log.warn(attribute.getxPath() + " is not a valid XPath", e); } } if (SAMLConfiguration.getInstance().getXSWEnabled()) { try { NodeList nodeList = (NodeList) xpath.compile("/Response//Signature").evaluate(xmlDocument, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { Node item = nodeList.item(i); if (item instanceof Element) { item.getParentNode().removeChild(item); } } } catch (XPathExpressionException e) { log.warn("'/Response//Signature' is not a valid XPath", e); } } }
From source file:revaligner.service.FileAligner.java
private String createglpfile(String prjid) throws Exception { this.tempfolder = (this.prjfolder + File.separator + "temp"); File temp = new File(this.tempfolder); if (temp.exists()) { FileUtils.cleanDirectory(temp);//from w ww. j a v a 2 s . c om } else { temp.mkdirs(); } InputStream contentfile = FileAligner.class.getClassLoader().getResourceAsStream("content.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder(); org.w3c.dom.Document document = builder.parse(contentfile); org.w3c.dom.Element root = document.getDocumentElement(); org.w3c.dom.Node sourcelang = root.getElementsByTagName("sourceLanguage").item(0); sourcelang.getAttributes().getNamedItem("localeCode").setTextContent(this.sourcelanguage); org.w3c.dom.Node targetlang = root.getElementsByTagName("targetLanguage").item(0); targetlang.getAttributes().getNamedItem("localeCode").setTextContent(this.targetlanguage); org.w3c.dom.Node xliffpath = root.getElementsByTagName("__xliffFile").item(0); xliffpath.getAttributes().getNamedItem("archivePath") .setTextContent(this.targetlanguage + "/txlf/" + new File(this.populatedsourcetxlf).getName()); org.w3c.dom.Node sourcepath = root.getElementsByTagName("__storable").item(0); sourcepath.getAttributes().getNamedItem("archivePath") .setTextContent("source/" + new File(this.backupsourcefile).getName()); org.w3c.dom.Node projectname = root.getElementsByTagName("projectName").item(0); projectname.setTextContent(prjid); TransformerFactory tf = TransformerFactory.newInstance(); Transformer m = tf.newTransformer(); DOMSource source = new DOMSource(document); File dest = new File(temp + File.separator + "content.xml"); StreamResult result = new StreamResult(new FileOutputStream(dest)); m.transform(source, result); File sourcefolder = new File(temp + File.separator + "source"); sourcefolder.mkdir(); FileUtils.copyFileToDirectory(new File(this.backupsourcefile), sourcefolder); File targetlangfolder = new File(temp + File.separator + this.targetlanguage); targetlangfolder.mkdir(); File txlffolder = new File(targetlangfolder + File.separator + "txlf"); txlffolder.mkdir(); FileUtils.copyFileToDirectory(new File(this.populatedsourcetxlf), txlffolder); ZipFile zf = new ZipFile(); String glpfile = this.tempfolder + File.separator + prjid + ".glp"; zf.ZipIt(glpfile, this.tempfolder); contentfile.close(); result.getOutputStream().close(); return glpfile; }
From source file:wsattacker.library.signatureFaking.SignatureFakingOracle.java
private void appendCertificate(Node keyInfo, String certificate) { keyInfo.setTextContent(""); String prefix = keyInfo.getPrefix(); if (prefix == null) { prefix = ""; } else {/*from w w w .j ava 2s. co m*/ prefix = prefix + ":"; } Node data = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Data"); keyInfo.appendChild(data); Node cert = keyInfo.getOwnerDocument().createElementNS(NamespaceConstants.URI_NS_DS, prefix + "X509Certificate"); data.appendChild(cert); cert.setTextContent(certificate); log.debug("Appending Certificate \r\n" + certificate + "\r\nto the" + prefix + "X509Certificate element"); }
From source file:xquery4j.TestEvaluator.java
@Test public void testDomUpdate() throws Exception { XQueryEvaluator evaluator = buildQueryEvaluator(); final String select = IOUtils.toString(getClass().getResourceAsStream("/select.xq")); final Document employees = DOMUtils.parse(getClass().getResourceAsStream("/employees.xml")); Node result = (Node) evaluator.evaluateExpression(select, employees).get(0); result.setTextContent("newValue"); Node result2 = (Node) evaluator.evaluateExpression(select, employees).get(0); Assert.assertEquals("newValue", result2.getTextContent()); LOGGER.debug(DOMUtils.domToString(result2)); }