List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:eu.apenet.dpt.standalone.gui.hgcreation.LevelTreeActions.java
private Node createTree(Document doc, TreeModel model, Object node, HashMap<String, String> paramMap) { CLevelTreeObject obj = (CLevelTreeObject) ((DefaultMutableTreeNode) node).getUserObject(); if (obj.isFile()) { File file = obj.getFile(); try {// w w w . j a v a 2 s .c o m File outputFileTmp = new File(Utilities.TEMP_DIR + ".temp_HG.xml"); FileWriter fileWriter = new FileWriter(outputFileTmp); InputStream xslIs = TransformationTool.class.getResourceAsStream("/xsl/fa2hg.xsl"); Source xsltSource = new StreamSource(xslIs); StringWriter stringWriter = new StringWriter(); StringWriter xslMessages = TransformationTool.createTransformation( fileUtil.readFileAsInputStream(file), stringWriter, xsltSource, paramMap); fileWriter.write(stringWriter.toString()); fileWriter.close(); List<String> filesWithoutEadid = new ArrayList<String>(); if (xslMessages != null && xslMessages.toString().contains("NO_EADID_IN_FILE")) { filesWithoutEadid.add(file.getName()); } else { Reader reader = new FileReader(outputFileTmp); ReaderInputStream readerInputStream = new ReaderInputStream(reader, "UTF-8"); Node fileLevel = stringToNode(doc, readerInputStream); return fileLevel; // el.getParentNode().appendChild(fileLevel); } outputFileTmp.delete(); } catch (Exception e) { LOG.error("Could not create HG part for file: " + file.getName(), e); // createErrorOrWarningPanel(e, true, "Could not create HG"); } } else { Element el = doc.createElement("c"); Element did = doc.createElement("did"); if (!obj.getId().equals("")) { Element unitid = doc.createElement("unitid"); unitid.setAttribute("encodinganalog", "3.1.1"); unitid.setTextContent(obj.getId()); did.appendChild(unitid); } Element title = doc.createElement("unittitle"); title.setAttribute("encodinganalog", "3.1.2"); title.setTextContent(obj.getName()); did.appendChild(title); el.appendChild(did); if (!obj.getDescription().equals("")) { Element scopecontent = doc.createElement("scopecontent"); scopecontent.setAttribute("encodinganalog", "summary"); Element pElt = doc.createElement("p"); pElt.setTextContent(obj.getDescription()); scopecontent.appendChild(pElt); el.appendChild(scopecontent); } for (int i = 0; i < model.getChildCount(node); i++) { Object child = model.getChild(node, i); el.appendChild(createTree(doc, model, child, paramMap)); } return el; } return null; }
From source file:bpsperf.modelgen.BPMNGenerator.java
public void generateRESTTaskSequence(int numNodes, String serviceURL) throws Exception { Element start = addNode(startEvent, "startEvent"); Element rtaskS = null;//w ww .j ava 2s . c o m for (int i = 1; i <= numNodes; i++) { Element rtask = addNode(serviceTask, "rt" + i); rtask.setAttributeNS(activitins, "class", "org.wso2.carbon.bpmn.extensions.rest.SyncInvokeTask"); Element extensions = addElement(rtask, ns, "extensionElements"); Element serviceURLField = addElement(extensions, activitins, "field"); serviceURLField.setAttribute("name", "serviceURL"); Element expression1 = addElement(serviceURLField, activitins, "expression"); expression1.setTextContent(serviceURL); Element methodField = addElement(extensions, activitins, "field"); methodField.setAttribute("name", "method"); Element expression2 = addElement(methodField, activitins, "string"); CDATASection postData = doc.createCDATASection("POST"); expression2.appendChild(postData); Element inputField = addElement(extensions, activitins, "field"); inputField.setAttribute("name", "input"); Element expression3 = addElement(inputField, activitins, "expression"); expression3.setTextContent("Message sent from: rt" + i); Element voutField = addElement(extensions, activitins, "field"); voutField.setAttribute("name", "vout"); Element expression4 = addElement(voutField, activitins, "string"); CDATASection outvarData = doc.createCDATASection("outvar1"); expression4.appendChild(outvarData); if (rtaskS == null) { connect(start, rtask); } else { connect(rtaskS, rtask); } rtaskS = rtask; } Element end = addNode(endEvent, "endEvent"); connect(rtaskS, end); }
From source file:com.hydroLibCreator.action.Creator.java
private Node createLayerNode(Document document, String audioFilename) { Element filename = document.createElement("filename"); filename.setTextContent(audioFilename); Element min = document.createElement("min"); min.setTextContent("0"); Element max = document.createElement("max"); max.setTextContent("1"); Element gain = document.createElement("gain"); gain.setTextContent("1"); Element pitch = document.createElement("pitch"); pitch.setTextContent("0"); Element layer = document.createElement("layer"); layer.appendChild(filename);/*from w ww . j a v a 2s . co m*/ layer.appendChild(min); layer.appendChild(max); layer.appendChild(gain); layer.appendChild(pitch); return layer; }
From source file:com.codebutler.farebot.card.felica.FelicaCard.java
@Override public Element toXML() throws Exception { Element root = super.toXML(); Document doc = root.getOwnerDocument(); Element idmElement = doc.createElement("idm"); idmElement.setTextContent(Base64.encodeToString(mIDm.getBytes(), Base64.DEFAULT)); root.appendChild(idmElement);/* ww w . j a v a2 s.co m*/ Element pmmElement = doc.createElement("pmm"); pmmElement.setTextContent(Base64.encodeToString(mPMm.getBytes(), Base64.DEFAULT)); root.appendChild(pmmElement); Element systemsElement = doc.createElement("systems"); for (FelicaSystem system : mSystems) { Element systemElement = doc.createElement("system"); systemElement.setAttribute("code", String.valueOf(system.getCode())); Element servicesElement = doc.createElement("services"); for (FelicaService service : system.getServices()) { Element serviceElement = doc.createElement("service"); serviceElement.setAttribute("code", String.valueOf(service.getServiceCode())); Element blocksElement = doc.createElement("blocks"); for (FelicaBlock block : service.getBlocks()) { Element blockElement = doc.createElement("block"); blockElement.setAttribute("address", String.valueOf(block.getAddress())); blockElement.setTextContent(Base64.encodeToString(block.getData(), Base64.DEFAULT)); blocksElement.appendChild(blockElement); } serviceElement.appendChild(blocksElement); servicesElement.appendChild(serviceElement); } systemElement.appendChild(servicesElement); systemsElement.appendChild(systemElement); } root.appendChild(systemsElement); return root; }
From source file:com.evolveum.midpoint.prism.marshaller.JaxbDomHack.java
/** * Serializes prism value to JAXB "any" format as returned by JAXB getAny() methods. */// w ww .ja v a2s .c o m public Object toAny(PrismValue value) throws SchemaException { if (value == null) { return null; } Itemable parent = value.getParent(); if (parent == null) { throw new IllegalStateException("Couldn't convert parent-less prism value to xsd:any: " + value); } QName elementName = parent.getElementName(); if (value instanceof PrismPropertyValue) { PrismPropertyValue<Object> pval = (PrismPropertyValue) value; if (pval.isRaw() && parent.getDefinition() == null) { XNode rawElement = pval.getRawElement(); if (rawElement instanceof MapXNode) { return domParser.serializeXMapToElement((MapXNode) rawElement, elementName); } else if (rawElement instanceof PrimitiveXNode<?>) { PrimitiveXNode<?> xprim = (PrimitiveXNode<?>) rawElement; String stringValue = xprim.getStringValue(); Element element = DOMUtil.createElement(DOMUtil.getDocument(), elementName); element.setTextContent(stringValue); DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations()); return element; } else { throw new IllegalArgumentException("Cannot convert raw element " + rawElement + " to xsd:any"); } } else { Object realValue = pval.getValue(); if (XmlTypeConverter.canConvert(realValue.getClass())) { // Always record xsi:type. This is FIXME, but should work OK for now (until we put definition into deltas) return XmlTypeConverter.toXsdElement(realValue, elementName, DOMUtil.getDocument(), true); } else { return wrapIfNeeded(realValue, elementName); } } } else if (value instanceof PrismReferenceValue) { return prismContext.domSerializer().serialize(value, elementName); } else if (value instanceof PrismContainerValue<?>) { PrismContainerValue<?> pval = (PrismContainerValue<?>) value; if (pval.getParent().getCompileTimeClass() == null) { // This has to be runtime schema without a compile-time representation. // We need to convert it to DOM return prismContext.domSerializer().serialize(pval, elementName); } else { return wrapIfNeeded(pval.asContainerable(), elementName); } } else { throw new IllegalArgumentException("Unknown type " + value); } }
From source file:de.mpg.escidoc.services.transformation.Util.java
public static Node getSize(String url) { DocumentBuilder documentBuilder; HttpClient httpClient = new HttpClient(); HeadMethod headMethod = new HeadMethod(url); try {/*from ww w.jav a 2 s. c om*/ logger.info("Getting size of " + url); ProxyHelper.executeMethod(httpClient, headMethod); if (headMethod.getStatusCode() != 200) { logger.warn("Wrong status code " + headMethod.getStatusCode() + " at " + url); } documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element element = document.createElement("size"); document.appendChild(element); Header header = headMethod.getResponseHeader("Content-Length"); logger.info("HEAD Request to " + url + " returned Content-Length: " + (header != null ? header.getValue() : null)); if (header != null) { element.setTextContent(header.getValue()); return document; } else { //did not get length via HEAD request, try to do a GET request //workaround for biomed central, where HEAD requests sometimes return Content-Length, sometimes not logger.info("GET request to " + url + " did not return any Content-Length. Trying GET request."); httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(url); ProxyHelper.executeMethod(httpClient, getMethod); if (getMethod.getStatusCode() != 200) { logger.warn("Wrong status code " + getMethod.getStatusCode() + " at " + url); } InputStream is = getMethod.getResponseBodyAsStream(); long size = 0; while (is.read() != -1) { size++; } is.close(); logger.info("GET request to " + url + " returned a file with length: " + size); element.setTextContent(String.valueOf(size)); return document; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.piraso.maven.WebXmlPirasoModifier.java
private Element createElementNameValue(String node, String nameNode, String valueNode, String name, String value, int loadOnStartup) { Element mainEl = document.createElement(node); Element paramName = document.createElement(nameNode); Element paramValue = document.createElement(valueNode); Element loadOnStartUpEl = document.createElement("load-on-startup"); paramName.setTextContent(name); paramValue.setTextContent(value);/*from ww w. j av a2 s. c o m*/ if (loadOnStartup >= 0) { loadOnStartUpEl.setTextContent(String.valueOf(loadOnStartup)); } mainEl.appendChild(document.createTextNode("\n ")); mainEl.appendChild(paramName); mainEl.appendChild(document.createTextNode("\n ")); mainEl.appendChild(paramValue); mainEl.appendChild(document.createTextNode("\n ")); if (loadOnStartup >= 0) { mainEl.appendChild(document.createTextNode(" ")); mainEl.appendChild(loadOnStartUpEl); mainEl.appendChild(document.createTextNode("\n ")); } return mainEl; }
From source file:clus.statistic.RegressionStatBinaryNomiss.java
@Override public Element getPredictElement(Document doc) { Element stats = doc.createElement("RegressionStatBinaryNomiss"); NumberFormat fr = ClusFormat.SIX_AFTER_DOT; Attr examples = doc.createAttribute("examples"); examples.setValue(fr.format(m_SumWeight)); stats.setAttributeNode(examples);// w ww . j a v a2 s . com for (int i = 0; i < m_NbAttrs; i++) { Element attr = doc.createElement("Target"); Attr name = doc.createAttribute("name"); name.setValue(m_Attrs[i].getName()); attr.setAttributeNode(name); attr.setTextContent(fr.format(getMean(i))); stats.appendChild(attr); } return stats; }
From source file:com.mirth.connect.server.servlets.WebStartServlet.java
private Document getExtensionJnlp(String extensionPath) throws Exception { List<MetaData> allExtensions = new ArrayList<MetaData>(); allExtensions//from w ww .ja va 2s. com .addAll(ControllerFactory.getFactory().createExtensionController().getConnectorMetaData().values()); allExtensions .addAll(ControllerFactory.getFactory().createExtensionController().getPluginMetaData().values()); Set<String> librariesToAddToJnlp = new HashSet<String>(); List<String> extensionsWithThePath = new ArrayList<String>(); for (MetaData metaData : allExtensions) { if (metaData.getPath().equals(extensionPath)) { extensionsWithThePath.add(metaData.getName()); for (ExtensionLibrary library : metaData.getLibraries()) { if (library.getType().equals(ExtensionLibrary.Type.CLIENT) || library.getType().equals(ExtensionLibrary.Type.SHARED)) { librariesToAddToJnlp.add(library.getPath()); } } } } if (extensionsWithThePath.isEmpty()) { throw new Exception("Extension metadata could not be located for the path: " + extensionPath); } Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element jnlpElement = document.createElement("jnlp"); Element informationElement = document.createElement("information"); Element titleElement = document.createElement("title"); titleElement .setTextContent("Mirth Connect Extension - [" + StringUtils.join(extensionsWithThePath, ",") + "]"); informationElement.appendChild(titleElement); Element vendorElement = document.createElement("vendor"); vendorElement.setTextContent("Mirth Corporation"); informationElement.appendChild(vendorElement); jnlpElement.appendChild(informationElement); Element securityElement = document.createElement("security"); securityElement.appendChild(document.createElement("all-permissions")); jnlpElement.appendChild(securityElement); Element resourcesElement = document.createElement("resources"); for (String library : librariesToAddToJnlp) { Element jarElement = document.createElement("jar"); jarElement.setAttribute("download", "eager"); // this path is relative to the servlet path jarElement.setAttribute("href", "libs/" + extensionPath + "/" + library); resourcesElement.appendChild(jarElement); } jnlpElement.appendChild(resourcesElement); jnlpElement.appendChild(document.createElement("component-desc")); document.appendChild(jnlpElement); return document; }