List of usage examples for org.w3c.dom Node setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:com.photon.phresco.framework.commons.QualityUtil.java
public static void changeTestName(String performancePath, String testName) throws Exception { File buildPathXml = null;/*from ww w. j a va2s .c om*/ S_LOGGER.debug("Entering Method QualityUtil.testSuite() performance path and TestName " + performancePath + " " + testName); buildPathXml = new File(performancePath + buildFileName); Document document = com.photon.phresco.framework.impl.util.FrameworkUtil.getDocument(buildPathXml); String fileNameNode = "project/target[@name='init']/property[@name='jmeter.result.file']"; NodeList nodelist = org.apache.xpath.XPathAPI.selectNodeList(document, fileNameNode); if (nodelist != null && nodelist.getLength() > 0) { Node stringProp = nodelist.item(0); NamedNodeMap attributes = stringProp.getAttributes(); Node valueAttr = attributes.getNamedItem("value"); String valueAttrTxt = valueAttr.getTextContent(); S_LOGGER.debug("Load test xml name " + valueAttrTxt.substring(0, valueAttrTxt.indexOf("/") + 1).concat(testName + ".xml")); valueAttr.setTextContent( valueAttrTxt.substring(0, valueAttrTxt.indexOf("/") + 1).concat(testName + ".xml")); } saveDocument(buildPathXml, document); }
From source file:com.occamlab.te.parsers.ImageParser.java
private static Document parse(InputStream source, Element instruction, PrintWriter logger) throws Exception { ImageReader reader;/*www .j a v a 2 s.c om*/ try { ImageInputStream iis = ImageIO.createImageInputStream(source); reader = ImageIO.getImageReaders(iis).next(); reader.setInput(iis); } catch (Exception e) { logger.println("No image handlers available for the data stream. " + e.getMessage()); throw e; } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(instruction), new DOMResult(doc)); Element new_instruction = doc.getDocumentElement(); int framesRead = 0; boolean containsFrames = false; Element framesElement = null; Element metadataElement = null; NodeList nodes = new_instruction.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { // System.out.println(node.getLocalName()); if (node.getLocalName().equals("type")) { node.setTextContent(reader.getFormatName().toLowerCase()); } else if (node.getLocalName().equals("frames")) { framesElement = (Element) node; containsFrames = true; } else if (node.getLocalName().equals("metadata")) { metadataElement = (Element) node; } else if (node.getLocalName().equals("frame")) { int frame; String frameStr = ((Element) node).getAttribute("num"); if (frameStr.length() == 0) { frame = framesRead; framesRead++; ((Element) node).setAttribute("num", Integer.toString(frame)); } else { frame = Integer.parseInt(frameStr); framesRead = frame + 1; } processFrame(reader, frame, node.getChildNodes(), logger); containsFrames = true; } } } if (containsFrames) { if (metadataElement != null) { IIOMetadata metadata = reader.getStreamMetadata(); if (metadata != null) { String format = metadataElement.getAttribute("format"); if (format.length() == 0) { format = metadata.getNativeMetadataFormatName(); } Node tree = metadata.getAsTree(format); t.transform(new DOMSource(tree), new DOMResult(metadataElement)); } } if (framesElement != null) { boolean allowSearch = !reader.isSeekForwardOnly(); int frames = reader.getNumImages(allowSearch); if (frames == -1) { try { while (true) { reader.read(framesRead); framesRead++; } } catch (Exception e) { jlogger.log(Level.SEVERE, "", e); frames = framesRead + 1; } } framesElement.setTextContent(Integer.toString(frames)); } } else { processFrame(reader, 0, nodes, logger); framesRead = 1; } // t.transform(new DOMSource(doc), new StreamResult(System.out)); return doc; }
From source file:com.occamlab.te.parsers.ImageParser.java
private static Node processFrame(ImageReader reader, int frame, NodeList nodes, PrintWriter logger) throws Exception { if (nodes.getLength() == 0) { return null; }/*from w w w . ja v a2 s . c om*/ String formatName = reader.getFormatName().toLowerCase(); // 2011-09-08 // PwD BufferedImage image = reader.read(frame); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { // System.out.println(node.getLocalName()); if (node.getLocalName().equals("type")) { node.setTextContent(formatName); // 2011-09-08 PwD was // reader.getFormatName().toLowerCase() } else if (node.getLocalName().equals("height")) { node.setTextContent(Integer.toString(image.getHeight())); } else if (node.getLocalName().equals("width")) { node.setTextContent(Integer.toString(image.getWidth())); } else if (node.getLocalName().equals("metadata")) { try { // 2011--08-23 PwD IIOMetadata metadata = reader.getImageMetadata(frame); if (metadata != null) { String format = ((Element) node).getAttribute("format"); if (format.length() == 0) { format = metadata.getNativeMetadataFormatName(); } Node tree = metadata.getAsTree(format); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(tree), new DOMResult(node)); } } catch (javax.imageio.IIOException e) { // 2011--08-23 PwD DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); String format = reader.getFormatName().toLowerCase(); String formatEltName = "javax_imageio_" + format + "_1.0"; Element formatElt = doc.createElement(formatEltName); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(formatElt), new DOMResult(node)); } } else if (node.getLocalName().equals("model")) { int imagetype = -1; String model = ((Element) node).getAttribute("value"); if (model.equals("MONOCHROME")) { imagetype = BufferedImage.TYPE_BYTE_BINARY; } else if (model.equals("GRAY")) { imagetype = BufferedImage.TYPE_BYTE_GRAY; } else if (model.equals("RGB")) { imagetype = BufferedImage.TYPE_3BYTE_BGR; } else if (model.equals("ARGB")) { imagetype = BufferedImage.TYPE_4BYTE_ABGR; } else { model = "CUSTOM"; } ((Element) node).setAttribute("value", model); BufferedImage buffImage = image; if (image.getType() != imagetype && imagetype != -1) { buffImage = new BufferedImage(image.getWidth(), image.getHeight(), imagetype); Graphics2D g2 = buffImage.createGraphics(); ImageTracker tracker = new ImageTracker(); boolean done = g2.drawImage(image, 0, 0, tracker); if (!done) { while (!tracker.done) { sleep(50); } } } processBufferedImage(buffImage, formatName, node.getChildNodes()); } else if (node.getLocalName().equals("transparency")) { // 2011-08-24 // PwD int transparency = image.getTransparency(); String transparencyName = null; switch (transparency) { case Transparency.OPAQUE: { transparencyName = "Opaque"; break; } case Transparency.BITMASK: { transparencyName = "Bitmask"; break; } case Transparency.TRANSLUCENT: { transparencyName = "Translucent"; break; } default: { transparencyName = "Unknown"; } } node.setTextContent(transparencyName); } else if (node.getLocalName().equals("base64Data")) { // 2011-09-08 // PwD String base64Data = getBase64Data(image, formatName, node); node.setTextContent(base64Data); } else { logger.println("ImageParser Error: Invalid tag " + node.getNodeName()); } } } return null; }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void appendHeaderManagerCollectionProp(Document document, Node elementProp, Map<String, String> headersMap) { Node collectionProp = document.createElement("collectionProp"); NamedNodeMap attributes = collectionProp.getAttributes(); attributes.setNamedItem(createAttribute(document, "name", "HeaderManager.headers")); createHeaderElementProp(document, headersMap, collectionProp); elementProp.setTextContent(null); elementProp.appendChild(collectionProp); }
From source file:com.intel.podm.redfish.resources.MetadataResourceProvider.java
private void updateUris(Document xmlDocument) { NodeList list = xmlDocument.getElementsByTagName("edmx:Reference"); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); Node uri = item.getAttributes().getNamedItem("Uri"); uri.setTextContent("/redfish/v1/metadata/" + uri.getTextContent()); }// w ww. j ava 2s. c om }
From source file:com.amalto.core.history.accessor.ManyFieldAccessor.java
public void set(String value) { Node collectionItemNode = getCollectionItemNode(); collectionItemNode.setTextContent(value); }
From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java
private void appendCertificate(Node keyInfo, String certificate) { String prefix = keyInfo.getPrefix(); if (replaceAll == true) { keyInfo.setTextContent(""); if (prefix == null) { prefix = ""; } else {// ww w. j a v a2 s . 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); } else { List<Element> l = DomUtilities.findChildren(keyInfo, "X509Certificate", NamespaceConstants.URI_NS_DS, true); Node cert = l.get(0); cert.setTextContent(certificate); } Logging.getInstance().log(getClass(), "Appending Certificate \r\n" + certificate + "\r\nto the" + prefix + "X509Certificate element", Logging.DEBUG); }
From source file:net.frontlinesms.plugins.forms.FormsPluginController.java
/** * Fabaris_a.zanchi This method inserts the designer software version number * in the outgoing xform It also creates an empty tag for the client version * * @param xmlContent the string representation of the xform *///from ww w .j a va 2s . co m public static String insertSoftwareVersionNumber(String xmlContent, Form form) throws Exception { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); InputSource inStream = new InputSource(); inStream.setCharacterStream(new StringReader(xmlContent)); org.w3c.dom.Document xmlDoc = docBuilder.parse(inStream); xmlDoc.getDocumentElement().normalize(); Node versionNode = xmlDoc.getElementsByTagName(DefaultComponentDescriptor.DESINGER_VERSION_TAGNAME + "_" + DefaultComponentDescriptor.DESIGNER_VERSION_INDEX).item(0); if (versionNode != null) { versionNode.setTextContent(form.getDesignerVersion()); } /* * NodeList nodeList = xmlDoc.getElementsByTagName("h:head"); Node * headNode = nodeList.item(0); Node modelNode = * xmlDoc.getElementsByTagName("model").item(0); Element newElemDesigner * = xmlDoc.createElement("designer_version"); Element newElemClient = * xmlDoc.createElement("client_version"); Node newNodeDesigner = (Node) * newElemDesigner; Node newNodeClient = (Node) newElemClient; String * designerVersion = form.getDesignerVersion(); if (designerVersion == * null) designerVersion = ""; * newNodeDesigner.appendChild(xmlDoc.createTextNode(designerVersion)); * newNodeClient.appendChild(xmlDoc.createTextNode("")); * headNode.insertBefore(newNodeDesigner, modelNode); * headNode.insertBefore(newNodeClient, modelNode); */ TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer trans = tFactory.newTransformer(); trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); StringWriter sWriter = new StringWriter(); Result result = new StreamResult(sWriter); trans.transform(new DOMSource(xmlDoc), result); String result2 = sWriter.getBuffer().toString(); System.out.println("-------- inserting version ------------"); System.out.println(result2); return result2; }
From source file:chat.viska.xmpp.plugins.webrtc.WebRtcPlugin.java
@Nonnull public Completable sendSdp(@Nonnull final Jid recipient, @Nonnull final String id, @Nonnull final SessionDescription sdp, final boolean creating) { final Document iq = Stanza.getIqTemplate(Stanza.IqType.SET, UUID.randomUUID().toString(), getSession().getNegotiatedJid(), recipient); final Element webrtcElement = (Element) iq.getDocumentElement() .appendChild(iq.createElementNS(XMLNS, "webrtc")); webrtcElement.setAttribute("id", id); if (creating) { webrtcElement.setAttribute("action", "create"); }//from www . jav a 2 s . c om final Element sdpElement = (Element) webrtcElement.appendChild(iq.createElement("sdp")); if (sdp.type != null) { sdpElement.setAttribute("type", sdp.type.canonicalForm()); } for (String line : sdp.description.split(REGEX_LINE_BREAK)) { final Node node = sdpElement.appendChild(iq.createElement("line")); node.setTextContent(line); } return this.context.sendIq(new XmlWrapperStanza(iq)).getResponse().toSingle().toCompletable(); }
From source file:org.opencastproject.loadtest.impl.IngestJob.java
/** * Parse and change the manifest.xml's id to match the mediapackage id we will be ingesting. * //www. j a v a 2 s. c om * @param filepath * The path to the manifest.xml file. */ private void changeManifestID(String filepath) { try { logger.info("Filepath for changing the manifest id is " + filepath); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(filepath); // Get the mediapackage XPath xPath = XPathFactory.newInstance().newXPath(); Node mediapackage = ((NodeList) xPath.evaluate("//*[local-name() = 'mediapackage']", doc, XPathConstants.NODESET)).item(0); // update mediapackage attribute NamedNodeMap attr = mediapackage.getAttributes(); Node nodeAttr = attr.getNamedItem("id"); nodeAttr.setTextContent(id); // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(filepath)); transformer.transform(source, result); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (TransformerException tfe) { tfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (SAXException sae) { sae.printStackTrace(); } catch (XPathExpressionException xpe) { xpe.printStackTrace(); } }