List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java
private Element toEnumPropertyElement(ODataProperty prop, Document doc, boolean setType) { final Element element = doc.createElement(ODataConstants.PREFIX_DATASERVICES + prop.getName()); if (setType) { element.setAttribute(ODataConstants.ATTR_M_TYPE, prop.getEnumValue().getTypeName()); }/*from w ww . ja v a2 s .c o m*/ element.setTextContent(prop.getEnumValue().toString()); return element; }
From source file:com.evolveum.midpoint.prism.schema.SchemaToDomProcessor.java
/** * Add generic annotation element./*from w w w .j a v a 2 s .c o m*/ * @param qname QName of the element * @param value string value of the element * @param parent element under which the definition will be added * @return created XSD element */ public Element addAnnotation(QName qname, String value, Element parent) { Element annotation = createElement(qname); parent.appendChild(annotation); if (value != null) { annotation.setTextContent(value); } return annotation; }
From source file:com.photon.phresco.util.ProjectUtils.java
private void addWebLogicPlugin(File pomFile, String pluginVersion) throws PhrescoException { try {/*from w w w .j av a 2 s.c o m*/ PomProcessor pomProcessor = new PomProcessor(pomFile); pomProcessor.addPlugin("com.oracle.weblogic", "weblogic-maven-plugin", pluginVersion); List<Element> configList = new ArrayList<Element>(); DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element adminUrl = doc.createElement("adminurl"); adminUrl.setTextContent("t3://${server.host}:${server.port}"); Element user = doc.createElement("user"); user.setTextContent("${server.username}"); Element password = doc.createElement("password"); password.setTextContent("${server.password}"); Element upload = doc.createElement("upload"); upload.setTextContent("true"); Element action = doc.createElement("action"); action.setTextContent("deploy"); Element remote = doc.createElement("remote"); remote.setTextContent("true"); Element verbose = doc.createElement("verbose"); verbose.setTextContent("false"); Element source = doc.createElement("source"); source.setTextContent("${project.basedir}/do_not_checkin/build/temp/${project.build.finalName}.war"); Element name = doc.createElement("name"); name.setTextContent("${project.build.finalName}"); Element argLineElem = doc.createElement("argLine"); argLineElem.setTextContent("-Xmx512m"); configList.add(adminUrl); configList.add(user); configList.add(password); configList.add(upload); configList.add(action); configList.add(remote); configList.add(verbose); configList.add(source); configList.add(name); configList.add(argLineElem); pomProcessor.addConfiguration("com.oracle.weblogic", "weblogic-maven-plugin", configList); pomProcessor.save(); } catch (ParserConfigurationException e) { throw new PhrescoException(e); } catch (PhrescoPomException e) { throw new PhrescoException(e); } }
From source file:de.topobyte.livecg.core.painting.backend.svg.SvgPainter.java
@Override public void drawString(String text, double x, double y) { Element element = doc.createElementNS(svgNS, "text"); element.setAttributeNS(null, "style", "fill:" + getCurrentColor() + ";stroke:none;fill-opacity:" + color.getAlpha() + ";font-family:Sans;font-size:12px"); element.setAttributeNS(null, "x", Double.toString(x)); element.setAttributeNS(null, "y", Double.toString(y)); element.setTextContent(text); append(element);//from w w w . j a va 2s .c o m }
From source file:chat.viska.xmpp.HandshakerPipe.java
private void initiateResourceBinding() { if (pipeline == null) { throw new IllegalStateException(); }//from w w w. j av a 2 s . c om this.resourceBindingIqId = UUID.randomUUID().toString(); final Document iq = XmlWrapperStanza.createIq(Stanza.IqType.SET, resourceBindingIqId, Jid.EMPTY, Jid.EMPTY); final Element bind = (Element) iq.getDocumentElement() .appendChild(iq.createElementNS(CommonXmlns.RESOURCE_BINDING, "bind")); if (!this.presetResource.isEmpty()) { final Element resource = (Element) bind.appendChild(iq.createElement("resource")); resource.setTextContent(this.presetResource); } this.pipeline.write(iq); }
From source file:com.bluexml.xforms.controller.mapping.MappingToolClassFormsToAlfresco.java
/** * Process remove reference.//from w w w.j a v a 2 s .c o m * * @param relementId * the relement id * @param elementsToRemove * the elements to remove * @param associationType * the association type * @param associationElement * the association element * @param multiple * the multiple */ private void processRemoveReference(String relementId, List<Element> elementsToRemove, AssociationType associationType, Element associationElement, boolean multiple) { String targetId = null; Element targetNode = null; targetNode = associationElement; if (targetNode != null) { targetId = getId(targetNode); if (StringUtils.equals(targetId, relementId)) { if (multiple) { elementsToRemove.add(associationElement); } else { Element eltTargetId = DOMUtil.getOneElementByTagName(DOMUtil.getAllChildren(targetNode), MsgId.INT_INSTANCE_SIDEID.getText()); Element eltTargetLabel = DOMUtil.getOneElementByTagName(DOMUtil.getAllChildren(targetNode), MsgId.INT_INSTANCE_SIDELABEL.getText()); eltTargetId.setTextContent(""); eltTargetLabel.setTextContent(""); } } else if (isInline(associationType)) { removeReference(targetNode, relementId); } } }
From source file:betullam.xmlmodifier.XMLmodifier.java
/** * @param args/*from w w w .j a va 2 s . co m*/ * @throws ParserConfigurationException * @throws IOException * @throws SAXException * @throws XPathExpressionException * @throws TransformerException */ public void modify(String mdFolder, String fileName, String condStructureType, String condMdNameFile, String condMdValueFile, String condMdNameElement, String condMdValueElement, String newMdName, String newMdValue) { // Get the files that should be modified: Set<File> filesToModify = getFilesToModify(mdFolder, fileName, condStructureType, condMdNameFile, condMdValueFile); // Backup XML-files before modifing them: makeBackupFiles(filesToModify); // Iterate over all files in given directory and it's subdirectories. Works with Apache commons-io library (FileUtils). for (File xmlFile : filesToModify) { // DOM Parser: String filePath = xmlFile.getAbsolutePath(); DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); Document xmlDoc = null; try { DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder(); xmlDoc = documentBuilder.parse(filePath); // Get the elements to change. The name-attribute of the <goobi:metadata ...>-tag is important. // E. g. to change metadata "AccessLicense", the value of "mdName" must be the same as the name-attribute: <goobi:metadata name="AccessLicense"> List<Node> nodeArrayList = getElementsToModify(condMdNameElement, condMdValueElement, xmlDoc); // Set the metadata (modMdName) to the given value (modMdValue): //for (int i = 0; i < node.getLength(); i++) { for (Node node : nodeArrayList) { Element xmlElement = (Element) node; // Change element text content: if (!newMdValue.equals("null")) { xmlElement.setTextContent(newMdValue); } // Change element content if (!newMdName.equals("null")) { NamedNodeMap attributes = xmlElement.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { //Element attributeElement = (Attribute)attributes.item(j); //xmlElement.setAttribute(attributes.item(j).getNodeName(), newMdName); xmlElement.setAttribute("name", newMdName); } } } // Save modifications to XML file: TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(xmlDoc); StreamResult streamResult = new StreamResult(new File(filePath)); transformer.transform(domSource, streamResult); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } System.out.println("File modified: " + xmlFile.getAbsoluteFile()); } }
From source file:com.mirth.connect.server.servlets.WebStartServlet.java
private Document getAdministratorJnlp(HttpServletRequest request) throws Exception { InputStream is = ResourceUtil.getResourceStream(this.getClass(), "mirth-client.jnlp"); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is); IOUtils.closeQuietly(is);/*from w w w .j a va 2 s . c o m*/ Element jnlpElement = document.getDocumentElement(); // Change the title to include the version of Mirth Connect PropertiesConfiguration versionProperties = new PropertiesConfiguration(); versionProperties.setDelimiterParsingDisabled(true); versionProperties.load(ResourceUtil.getResourceStream(getClass(), "version.properties")); String version = versionProperties.getString("mirth.version"); Element informationElement = (Element) jnlpElement.getElementsByTagName("information").item(0); Element title = (Element) informationElement.getElementsByTagName("title").item(0); String titleText = title.getTextContent() + " " + version; // If a server name is set, prepend the application title with it String serverName = configurationController.getServerSettings().getServerName(); if (StringUtils.isNotBlank(serverName)) { titleText = serverName + " - " + titleText; } title.setTextContent(titleText); String scheme = request.getScheme(); String serverHostname = request.getServerName(); int serverPort = request.getServerPort(); String contextPath = request.getContextPath(); String codebase = scheme + "://" + serverHostname + ":" + serverPort + contextPath; PropertiesConfiguration mirthProperties = new PropertiesConfiguration(); mirthProperties.setDelimiterParsingDisabled(true); mirthProperties.load(ResourceUtil.getResourceStream(getClass(), "mirth.properties")); String server = null; if (StringUtils.isNotBlank(mirthProperties.getString("server.url"))) { server = mirthProperties.getString("server.url"); } else { int httpsPort = mirthProperties.getInt("https.port", 8443); String contextPathProp = mirthProperties.getString("http.contextpath", ""); // Add a starting slash if one does not exist if (!contextPathProp.startsWith("/")) { contextPathProp = "/" + contextPathProp; } // Remove a trailing slash if one exists if (contextPathProp.endsWith("/")) { contextPathProp = contextPathProp.substring(0, contextPathProp.length() - 1); } server = "https://" + serverHostname + ":" + httpsPort + contextPathProp; } jnlpElement.setAttribute("codebase", codebase); Element resourcesElement = (Element) jnlpElement.getElementsByTagName("resources").item(0); String maxHeapSize = request.getParameter("maxHeapSize"); if (StringUtils.isBlank(maxHeapSize)) { maxHeapSize = mirthProperties.getString("administrator.maxheapsize"); } if (StringUtils.isNotBlank(maxHeapSize)) { Element j2se = (Element) resourcesElement.getElementsByTagName("j2se").item(0); j2se.setAttribute("max-heap-size", maxHeapSize); } List<String> defaultClientLibs = new ArrayList<String>(); defaultClientLibs.add("mirth-client.jar"); defaultClientLibs.add("mirth-client-core.jar"); defaultClientLibs.add("mirth-crypto.jar"); defaultClientLibs.add("mirth-vocab.jar"); for (String defaultClientLib : defaultClientLibs) { Element jarElement = document.createElement("jar"); jarElement.setAttribute("download", "eager"); jarElement.setAttribute("href", "webstart/client-lib/" + defaultClientLib); if (defaultClientLib.equals("mirth-client.jar")) { jarElement.setAttribute("main", "true"); } resourcesElement.appendChild(jarElement); } List<String> clientLibs = ControllerFactory.getFactory().createExtensionController().getClientLibraries(); for (String clientLib : clientLibs) { if (!defaultClientLibs.contains(clientLib)) { Element jarElement = document.createElement("jar"); jarElement.setAttribute("download", "eager"); jarElement.setAttribute("href", "webstart/client-lib/" + clientLib); resourcesElement.appendChild(jarElement); } } List<MetaData> allExtensions = new ArrayList<MetaData>(); allExtensions .addAll(ControllerFactory.getFactory().createExtensionController().getConnectorMetaData().values()); allExtensions .addAll(ControllerFactory.getFactory().createExtensionController().getPluginMetaData().values()); // we are using a set so that we don't have duplicates Set<String> extensionPathsToAddToJnlp = new HashSet<String>(); for (MetaData extension : allExtensions) { if (doesExtensionHaveClientOrSharedLibraries(extension)) { extensionPathsToAddToJnlp.add(extension.getPath()); } } for (String extensionPath : extensionPathsToAddToJnlp) { Element extensionElement = document.createElement("extension"); extensionElement.setAttribute("href", "webstart/extensions/" + extensionPath + ".jnlp"); resourcesElement.appendChild(extensionElement); } Element applicationDescElement = (Element) jnlpElement.getElementsByTagName("application-desc").item(0); Element serverArgumentElement = document.createElement("argument"); serverArgumentElement.setTextContent(server); applicationDescElement.appendChild(serverArgumentElement); Element versionArgumentElement = document.createElement("argument"); versionArgumentElement.setTextContent(version); applicationDescElement.appendChild(versionArgumentElement); String[] protocols = configurationController.getHttpsClientProtocols(); String[] cipherSuites = configurationController.getHttpsCipherSuites(); // Only add arguments for the protocols / cipher suites if they are non-default if (!Arrays.areEqual(protocols, MirthSSLUtil.DEFAULT_HTTPS_CLIENT_PROTOCOLS) || !Arrays.areEqual(cipherSuites, MirthSSLUtil.DEFAULT_HTTPS_CIPHER_SUITES)) { Element sslArgumentElement = document.createElement("argument"); sslArgumentElement.setTextContent("-ssl"); applicationDescElement.appendChild(sslArgumentElement); Element protocolsArgumentElement = document.createElement("argument"); protocolsArgumentElement.setTextContent(StringUtils.join(protocols, ',')); applicationDescElement.appendChild(protocolsArgumentElement); Element cipherSuitesArgumentElement = document.createElement("argument"); cipherSuitesArgumentElement.setTextContent(StringUtils.join(cipherSuites, ',')); applicationDescElement.appendChild(cipherSuitesArgumentElement); } return document; }
From source file:com.mirth.connect.model.util.ImportConverter.java
private static void updateFilterFor1_7(Document document) { // add data element to Rules NodeList rules = getElements(document, "rule", "com.mirth.connect.model.Rule"); for (int i = 0; i < rules.getLength(); i++) { Element rule = (Element) rules.item(i); if (rule.getElementsByTagName("type").getLength() == 0) { Element typeElement = document.createElement("type"); typeElement.setTextContent("JavaScript"); rule.appendChild(typeElement); }//from ww w . j a v a 2s.co m if (rule.getElementsByTagName("data").getLength() == 0) { Element dataElement = document.createElement("data"); dataElement.setAttribute("class", "map"); Element entryElement = document.createElement("entry"); Element keyElement = document.createElement("string"); Element valueElement = document.createElement("string"); keyElement.setTextContent("Script"); valueElement.setTextContent(rule.getElementsByTagName("script").item(0).getTextContent()); entryElement.appendChild(keyElement); entryElement.appendChild(valueElement); dataElement.appendChild(entryElement); rule.appendChild(dataElement); } } }
From source file:es.upm.fi.dia.oeg.sitemap4rdf.Generator.java
/** * Generates the SitemapsSection of the sitemap index file * @param doc the XML Document/*from ww w.j a v a 2 s.co m*/ * @param elem the Element for the sitemapindex element */ protected void generateSitemapsSection(Element root, Document doc) { try { DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATEFORMAT); Iterator<String> iterator = (Iterator<String>) files.keySet().iterator();// Iterate on keys while (iterator.hasNext()) { String fileName = (String) iterator.next(); if (gzip != null && gzip.equals(TRUE)) fileName = fileName + zipFileExtension; Element sitemap = doc.createElement(siteMapTag); Element loc = doc.createElement(locTag); Element lastMod = doc.createElement(lastmodTag); loc.setTextContent(siteroot + fileName); Date date = new Date(); lastMod.setTextContent(dateFormat.format(date)); sitemap.appendChild(loc); sitemap.appendChild(lastMod); root.appendChild(sitemap); } } catch (DOMException e) { logger.debug("DOMException ", e); System.err.println(e.getMessage()); System.exit(3); } }