@Override public void setNodeValue(String nodeValue) throws DOMException { node.setNodeValue(nodeValue); }
private static void setProperty (Document doc, Node parent, String name, String value) { Node properties = getFirstChildNodeByName(parent, "properties"); Node property = getFirstChildByNameAttrValue(properties, "property", "name", name); NamedNodeMap attributes = property.getAttributes(); Node valueNode = attributes.getNamedItem("value"); if (valueNode == null) { valueNode = doc.createAttribute("value"); valueNode.setNodeValue(value); attributes.setNamedItem(valueNode); } else { valueNode.setNodeValue(value); } }
private static void setProperty (Document doc, Node parent, String name, String value) { Node properties = getFirstChildNodeByName(parent, "properties"); Node property = getFirstChildByNameAttrValue(properties, "property", "name", name); NamedNodeMap attributes = property.getAttributes(); Node valueNode = attributes.getNamedItem("value"); if (valueNode == null) { valueNode = doc.createAttribute("value"); valueNode.setNodeValue(value); attributes.setNamedItem(valueNode); } else { valueNode.setNodeValue(value); } }
public static void setValue(Element self, String value) { Node firstChild = self.getFirstChild(); if (firstChild == null) { firstChild = self.getOwnerDocument().createTextNode(value); self.appendChild(firstChild); } firstChild.setNodeValue(value); }
/** * Checks if the replacement was properly made to a node. * * @param file File we are searching for value * @param saved boolean on whether we need to save * @param provider Node we are attempting to replace * @return boolean * @throws AndrolibException setting node value failed */ private static boolean isSaved(File file, boolean saved, Node provider) throws AndrolibException { String reference = provider.getNodeValue(); String replacement = pullValueFromStrings(file.getParentFile(), reference); if (replacement != null) { provider.setNodeValue(replacement); saved = true; } return saved; }
/** * Replaces package value with passed packageOriginal string * * @param file File for AndroidManifest.xml * @param packageOriginal Package name to replace * @throws AndrolibException */ public static void renameManifestPackage(File file, String packageOriginal) throws AndrolibException { try { Document doc = loadDocument(file); // Get the manifest line Node manifest = doc.getFirstChild(); // update package attribute NamedNodeMap attr = manifest.getAttributes(); Node nodeAttr = attr.getNamedItem("package"); nodeAttr.setNodeValue(packageOriginal); saveDocument(file, doc); } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) { } }
private static void pushDown(Node p) { long time = 0; Node current = p; while ((current = current.getParentNode()) != null) { if (current.getAttributes() != null && current.getAttributes().getNamedItem("begin") != null) { time += toTime(current.getAttributes().getNamedItem("begin").getNodeValue()); } } if (p.getAttributes() != null && p.getAttributes().getNamedItem("begin") != null) { p.getAttributes().getNamedItem("begin").setNodeValue(toTimeExpression(time + toTime(p.getAttributes().getNamedItem("begin").getNodeValue()))); } if (p.getAttributes() != null && p.getAttributes().getNamedItem("end") != null) { p.getAttributes().getNamedItem("end").setNodeValue(toTimeExpression(time + toTime(p.getAttributes().getNamedItem("end").getNodeValue()))); } }
public static void changeTime(Node p, String attribute, long amount) { if (p.getAttributes() != null && p.getAttributes().getNamedItem(attribute) != null) { String oldValue = p.getAttributes().getNamedItem(attribute).getNodeValue(); long nuTime = toTime(oldValue) + amount; int frames = 0; if (oldValue.contains(".")) { frames = -1; } else { // todo more precision! 44 ~= 23 frames per second. // that should be ok for non high framerate content // actually I'd have to get the ttp:frameRateMultiplier // and the ttp:frameRate attribute to calculate at which frame to show the sub frames = (int) (nuTime - (nuTime / 1000) * 1000) / 44; } p.getAttributes().getNamedItem(attribute).setNodeValue(toTimeExpression(nuTime, frames)); } }
protected void setTextcontent(Node root, String text) { Node textNode = findTextNode(root); if (textNode != null) { //Apache FOP may remove any leading/trailing spaces if //a page-number-citation is at the end of a paragraph //for this reson change the first/last one to a non breaking space. if (text.charAt(text.length() - 1) == ' ') { text = text.substring(0, text.length() - 1) + (char)160; } if (text.charAt(0) == ' ') { if (text.length() > 1) { text = (char)160 + (text.substring(1)); } else { text = Character.toString((char)160); } } textNode.setNodeValue(text); } }
@Override public Node[] merge(List<Node> nodeList1, List<Node> nodeList2, List<Node> exhaustedNodes) { if (CollectionUtils.isEmpty(nodeList1) || CollectionUtils.isEmpty(nodeList2)) { return null; } Node node1 = nodeList1.get(0); Node node2 = nodeList2.get(0); Set<String> finalItems = getMergedNodeValues(node1, node2); StringBuilder sb = new StringBuilder(); Iterator<String> itr = finalItems.iterator(); while (itr.hasNext()) { sb.append(itr.next()); if (itr.hasNext()) { sb.append(getDelimiter()); } } node1.setNodeValue(sb.toString()); node2.setNodeValue(sb.toString()); Node[] response = new Node[nodeList2.size()]; for (int j=0;j<response.length;j++){ response[j] = nodeList2.get(j); } return response; }
protected static List<byte[]> extractImages(Document ttml) throws XPathExpressionException, URISyntaxException, IOException { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile("//*/@backgroundImage"); NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET); LinkedHashMap<String, String> internalNames2Original = new LinkedHashMap<String, String>(); int p = 1; for (int i = 0; i < nl.getLength(); i++) { Node bgImageNode = nl.item(i); String uri = bgImageNode.getNodeValue(); String ext = uri.substring(uri.lastIndexOf(".")); String internalName = internalNames2Original.get(uri); if (internalName == null) { internalName = "urn:mp4parser:" + p++ + ext; internalNames2Original.put(internalName, uri); } bgImageNode.setNodeValue(internalName); } List<byte[]> images = new ArrayList<byte[]>(); if (!internalNames2Original.isEmpty()) { for (Map.Entry<String, String> internalName2Original : internalNames2Original.entrySet()) { URI pic = new URI(ttml.getDocumentURI()).resolve(internalName2Original.getValue()); images.add(streamToByteArray(pic.toURL().openStream())); } } return images; }
private static void substituteSystemProperties(Node node) { Stack<NodeList> nodeLists = new Stack<>(); nodeLists.push(node.getChildNodes()); while (!nodeLists.isEmpty()) { NodeList nodeList = nodeLists.pop(); for (int i = 0; i < nodeList.getLength(); ++i) { Node currentNode = nodeList.item(i); if (currentNode.hasChildNodes()) { nodeLists.push(currentNode.getChildNodes()); } final NamedNodeMap attributes = currentNode.getAttributes(); if (attributes != null) { for (int j = 0; j < attributes.getLength(); ++j) { final Node attributeNode = attributes.item(j); final String newValue = replaceProperties(attributeNode.getNodeValue()); if (newValue != null) { attributeNode.setNodeValue(newValue); } } } if (currentNode.getNodeType() == Node.TEXT_NODE) { final String newValue = replaceProperties(currentNode.getNodeValue()); if (newValue != null) { currentNode.setNodeValue(newValue); } } } } }
private static NodeList getChildElements(Element self, String elementName) { List<Node> result = new ArrayList<Node>(); NodeList nodeList = self.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element child = (Element) node; if ("*".equals(elementName) || child.getTagName().equals(elementName)) { result.add(child); } } else if (node.getNodeType() == Node.TEXT_NODE) { String value = node.getNodeValue(); if ((!isGlobalKeepIgnorableWhitespace() && value.trim().length() == 0) || isGlobalTrimWhitespace()) { value = value.trim(); } if ("*".equals(elementName) && value.length() > 0) { node.setNodeValue(value); result.add(node); } } } return new NodesHolder(result); }
gceNode.appendChild(delayNode); delayNode.setNodeValue(Integer.valueOf(delayMillis / 10).toString()); if (transparencyColorIndex >= 0) { Node transparencyFlagNode = gceNode.getAttributes().getNamedItem(transparencyFlagNodeName); gceNode.appendChild(transparencyFlagNode); transparencyFlagNode.setNodeValue("TRUE"); Node transparencyIndexNode = gceNode.getAttributes().getNamedItem(transparencyIndexNodeName); if (transparencyIndexNode == null) { gceNode.appendChild(transparencyIndexNode); transparencyIndexNode.setNodeValue(Integer.valueOf(transparencyColorIndex).toString());
/** * Parse the DOM tree recursively searching for text containing reference to the old sheet name and replacing it. * * @param dom the XML node in which to perform the replacement. * * Code extracted from: <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=54470">Bug 54470</a> */ private void updateDomSheetReference(Node dom, final String oldName, final String newName) { String value = dom.getNodeValue(); if (value != null) { // make sure the value contains the old sheet and not a similar sheet // (ex: Valid: 'Sheet1'! or Sheet1! ; NotValid: 'Sheet1Test'! or Sheet1Test!) if (value.contains(oldName+"!") || value.contains(oldName+"'!")) { XSSFName temporary = _wb.createName(); temporary.setRefersToFormula(value); updateName(temporary, oldName, newName); dom.setNodeValue(temporary.getRefersToFormula()); _wb.removeName(temporary); } } NodeList nl = dom.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { updateDomSheetReference(nl.item(i), oldName, newName); } }
node.setNodeValue(newNodeValue);
@Test public void testAddedAttributes() { Node node1 = new DummyNode(); node1.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"); Node node2 = new DummyNode(); node2.setNodeValue("http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"); Set<String> mergedVals = merge.getMergedNodeValues(node1, node2); assertArrayEquals(new String[] {"http://www.springframework.org/schema/beans", "http://www.springframework.org/schema/beans/spring-beans.xsd", "http://www.springframework.org/schema/tx", "http://www.springframework.org/schema/tx/spring-tx.xsd"}, mergedVals.toArray()); }
@Test public void testNodeAttributes() { Node node1 = new DummyNode(); node1.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" + "\nhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-8.4.xsd" + "\nhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-9.4.xsd" + "\nhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"); Node node2 = new DummyNode(); node2.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"); Set<String> mergedVals = merge.getMergedNodeValues(node1, node2); assertArrayEquals(new String[] {"http://www.springframework.org/schema/beans", "http://www.springframework.org/schema/beans/spring-beans.xsd", "http://www.springframework.org/schema/tx", "http://www.springframework.org/schema/tx/spring-tx.xsd"}, mergedVals.toArray()); }
@RunTestSetup @Test public void testGeoServerReload() throws Exception { Catalog cat = getCatalog(); FeatureTypeInfo lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertFalse("foo".equals(lakes.getTitle())); GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader()); File info = dd.findResourceFile(lakes); // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml"); FileReader in = new FileReader(info); Element dom = ReaderUtils.parse(in); Element title = ReaderUtils.getChildElement(dom, "title"); title.getFirstChild().setNodeValue("foo"); OutputStream output = new FileOutputStream(info); try { TransformerFactory.newInstance() .newTransformer() .transform(new DOMSource(dom), new StreamResult(output)); } finally { output.close(); } getGeoServer().reload(); lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertEquals("foo", lakes.getTitle()); }
currentElement.setTextContent(value); } else { node.setNodeValue(value);