@Override public void setTextContent(String textContent) throws DOMException { node.setTextContent(textContent); }
public static void trimWhitespace(Node node) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { child.setTextContent(child.getTextContent().trim()); } trimWhitespace(child); } }
protected Node wrap(AbstractWmlConversionContext context, String result, Document doc) { RPr rPr = null; Node node = null; if (result != null) { node = createNode(doc); if (result.length() > 0) { node.setTextContent(result); } } return node; }
public InputStream sanitize(InputStream in) throws Exception { byte [] content = IOUtils.toByteArray(in); try { // storing the entire file in memory in case we need to bail. Document doc = builder.parse(new ByteArrayInputStream(content)); doc.setXmlStandalone(true); Object result = expression.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { nodes.item(i).setTextContent(""); } DOMSource source = new DOMSource(doc); ByteArrayOutputStream output = new ByteArrayOutputStream(); StreamResult outStream = new StreamResult(output); transformer.transform(source, outStream); return new ByteArrayInputStream(output.toByteArray()); } catch (Exception e) { ROOT_LOGGER.debug("Error while sanitizing an xml document", e); return new ByteArrayInputStream(content); } } }
n.setTextContent(resolvedValue);
public static void testXmlClusteredCache(OsgiTestUtils.Cluster cluster) throws Exception { File config = cluster.getWorkingArea().resolve("ehcache.xml").toFile(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(TestMethods.class.getResourceAsStream("ehcache-clustered-osgi.xml")); XPath xpath = XPathFactory.newInstance().newXPath(); Node clusterUriAttribute = (Node) xpath.evaluate("//config/service/cluster/connection/@url", doc, XPathConstants.NODE); clusterUriAttribute.setTextContent(cluster.getConnectionUri().toString() + "/cache-manager"); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(new DOMSource(doc), new StreamResult(config)); try (PersistentCacheManager cacheManager = (PersistentCacheManager) CacheManagerBuilder.newCacheManager( new XmlConfiguration(config.toURI().toURL(), TestMethods.class.getClassLoader()) )) { cacheManager.init(); final Cache<Long, Person> cache = cacheManager.getCache("clustered-cache", Long.class, Person.class); cache.put(1L, new Person("Brian")); assertThat(cache.get(1L).name, is("Brian")); } }
private boolean setConfigElement(Element parent, String tagName, String textContent) { Node element = parent.getElementsByTagName(tagName).item(0); if (element == null) { element = mConfig.createElement(tagName); parent.appendChild(element); } if (!textContent.equals(element.getTextContent())) { element.setTextContent(textContent); return true; } return false; }
public static void deleteInjectionPoint(Document doc, Node node) { NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { //calls this method for all the children which is Element SoapUtil.deleteInjectionPoint(doc, currentNode); } else if (currentNode.getNodeType() == Node.TEXT_NODE) { currentNode.setTextContent(currentNode.getTextContent().replaceAll(Pattern.quote(InjectionModel.STAR) +"$", "")); } } }
try { String filePath = Environment.getExternalStorageDirectory()+"/Trip/"+tripID+".trip"; File file = new File(filePath); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(file); // Change the content of node Node nodes = doc.getElementsByTagName("RouteName").item(0); // I changed the below line form nodes.setNodeValue to nodes.setTextContent nodes.setTextContent(newname); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // initialize StreamResult with File object to save to file StreamResult result = new StreamResult(file); DOMSource source = new DOMSource(doc); transformer.transform(source, result); } catch (Exception e) { e.printStackTrace(); }
mapElement.setTextContent(entry.getValue()); rootElement.appendChild(mapElement);
/** * Gets database dependency from config file and adds it with test scope * * @param moduleName * the module which dependency should be added * @param databaseConfigPrefix * the prefix name for choosing the dependency to add * @param configuration * the configuration file with the dependencies to copy from */ private void addTestScopedDependency(String moduleName, String databaseConfigPrefix, final Element configuration) { final List<Element> databaseDependencies = XmlUtils.findElements(databaseConfigPrefix + "/dependencies/dependency", configuration); for (final Element dependencyElement : databaseDependencies) { // Change scope from provided to test NodeList childNodes = dependencyElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { final Node node = childNodes.item(i); if (node != null && node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("scope")) { node.setTextContent("test"); } } // Add dependency getProjectOperations().addDependency(moduleName, new Dependency(dependencyElement)); } }
Node diskNodeAttribute = diskNodeAttributes.getNamedItem("type"); diskNodeAttribute.setTextContent(migrateDiskInfo.getDiskType().toString()); Node driverNodeAttribute = driverNodeAttributes.getNamedItem("type"); driverNodeAttribute.setTextContent(migrateDiskInfo.getDriverType().toString()); } else if ("source".equals(diskChildNode.getNodeName())) { diskNode.removeChild(diskChildNode);
SoapUtil.deleteInjectionPoint(doc, doc.getDocumentElement()); currentNode.setTextContent(currentNode.getTextContent() + InjectionModel.STAR);
password.setTextContent(BCrypt.hashpw(apikey, BCrypt.gensalt(4))); changed = true;
private void setBundleInformation(String group, String artifact, String version) { this.bundleElement.getElementsByTagName(GROUP_ELEMENT_NAME).item(0).setTextContent(group); this.bundleElement.getElementsByTagName(ARTIFACT_ELEMENT_NAME).item(0).setTextContent(artifact); this.bundleElement.getElementsByTagName(VERSION_ELEMENT_NAME).item(0).setTextContent(version); }
private Node clickAndWaitCommand(final Document document, final String linkTarget) { final Node tr = document.createElement("tr"); final Node td1 = tr.appendChild(document.createElement("td")); td1.setTextContent("clickAndWait"); final Node td2 = tr.appendChild(document.createElement("td")); td2.setTextContent(linkTarget); final Node td3 = tr.appendChild(document.createElement("td")); td3.setTextContent(" "); return tr; }
public void setUrl(String url) { NodeList addrList = _eprElmt.getElementsByTagNameNS(Namespaces.WS_ADDRESSING_NS, "Address"); if (addrList.getLength() > 0) addrList.item(0).setTextContent(url); else { Element addrElmt = _eprElmt.getOwnerDocument().createElementNS(Namespaces.WS_ADDRESSING_NS, "Address"); addrElmt.setTextContent(url); _eprElmt.appendChild(addrElmt); } }
private static void trimWhitespace(Node node) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { child.setTextContent(child.getTextContent().trim()); } trimWhitespace(child); } }
private static void setText(final Node node, final String text) { if (node instanceof SelectableTextInput) { ((SelectableTextInput) node).setText(text); } else { node.setTextContent(text); } }
@Override protected Map<XPathExpression, Node> getReplacements(final XPath xPath, final ElementFactory elemFactory) throws ParserConfigurationException, XPathExpressionException { final XPathExpression key = xPath.compile(autoDiscoverParamExpression); final Element value = elemFactory.createElement("init-param"); value.appendChild(elemFactory.createElement("param-name")).setTextContent("auto-discover-services"); value.appendChild(elemFactory.createElement("param-value")).setTextContent("false"); final Map<XPathExpression, Node> replacements = new HashMap<XPathExpression, Node>(1); replacements.put(key, value); return replacements; }