List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.gvnix.service.roo.addon.addon.ws.WSConfigServiceImpl.java
/** * Add a wsdl location to import of document type. * <p>//ww w .j a v a 2s . co m * Adds a wsdl location to the axistools plugin configuration. If code * generation plugin configuration not exists, it will be created. * </p> * * @param wsdlLocation WSDL file location * @return Location added to pom ? */ private boolean addImportLocationRpc(String wsdlLocation) { // Get plugin template Element plugin = XmlUtils.findFirstElement("/axistools-plugin/plugin", XmlUtils.getRootElement(this.getClass(), "dependencies-import-axistools-plugin.xml")); // Add plugin getProjectOperations().updateBuildPlugin(getProjectOperations().getFocusedModuleName(), new Plugin(plugin)); getFileManager().commit(); // Get pom.xml String pomPath = getPomFilePath(); Validate.notNull(pomPath, POM_FILE_NOT_FOUND); // Get a mutable pom.xml reference to modify it MutableFile pomMutableFile = getFileManager().updateFile(pomPath); Document pom = getInputDocument(pomMutableFile.getInputStream()); Element root = pom.getDocumentElement(); // Get plugin element Element axistoolsPlugin = XmlUtils.findFirstElement( "/project/build/plugins/plugin[groupId='org.codehaus.mojo' and artifactId='axistools-maven-plugin']", root); // If plugin element not exists, message error Validate.notNull(axistoolsPlugin, "Axistools plugin is not defined in the pom.xml, relaunch again this command."); // Check URL connection and WSDL format Element rootElement = getSecurityService().getWsdl(wsdlLocation).getDocumentElement(); // The wsdl location already exists on old plugin format ? Element wsdlLocationUrl = XmlUtils.findFirstElement( "executions/execution/configuration/urls[url='" + wsdlLocation + "']", axistoolsPlugin); // The wsdl location already exists on new plugin format ? String serviceId = WsdlParserUtils.findFirstCompatibleServiceElementName(rootElement); Element wsdlLocationElement = XmlUtils.findFirstElement("executions/execution[id='" + serviceId + "']", axistoolsPlugin); // If location already added on plugin, do nothing if (wsdlLocationElement != null || wsdlLocationUrl != null) { return false; } // Access configuration > urls element. // Configuration and urls are created if not exists. Element executions = DomUtils.findFirstElementByName(EXECUTIONS, axistoolsPlugin); if (executions == null) { executions = pom.createElement(EXECUTIONS); axistoolsPlugin.appendChild(executions); } Element execution = pom.createElement(EXECUTION); Element id = pom.createElement("id"); id.setTextContent(serviceId); Element phase = pom.createElement(PHASE2); phase.setTextContent("generate-sources"); execution.appendChild(id); execution.appendChild(phase); Element goals = pom.createElement(GOALS2); Element goal = pom.createElement(GOAL2); goal.setTextContent("wsdl2java"); goals.appendChild(goal); execution.appendChild(goals); executions.appendChild(execution); Element configuration = pom.createElement(CONFIGURATION2); execution.appendChild(configuration); Element urls = pom.createElement("urls"); configuration.appendChild(urls); // Configure the packagename to generate client sources Element packageSpace = pom.createElement("packageSpace"); String packageName = WsdlParserUtils.getTargetNamespaceRelatedPackage(rootElement); packageSpace.setTextContent(packageName.substring(0, packageName.length() - 1)); configuration.appendChild(packageSpace); // Create new url element and append it to the XML tree Element url = pom.createElement("url"); url.setTextContent(wsdlLocation); urls.appendChild(url); // Write new XML to disk XmlUtils.writeXml(pomMutableFile.getOutputStream(), pom); return true; }
From source file:org.gvnix.service.roo.addon.addon.ws.WSConfigServiceImpl.java
/** * Add a wsdl location to import of document type. * <p>/*ww w .j a v a2 s . com*/ * Adds a wsdl location to the codegen plugin configuration. If code * generation plugin configuration not exists, it will be created. * </p> * * @param wsdlLocation WSDL file location * @return Location added to pom ? */ private boolean addImportLocationDocument(String wsdlLocation) { // Get plugin template Element pluginTemplate = XmlUtils.findFirstElement("/codegen-plugin/plugin", XmlUtils.getRootElement(this.getClass(), "dependencies-import-codegen-plugin.xml")); // Add plugin getProjectOperations().updateBuildPlugin(getProjectOperations().getFocusedModuleName(), new Plugin(pluginTemplate)); getFileManager().commit(); // Get pom.xml String pomPath = getPomFilePath(); Validate.notNull(pomPath, POM_FILE_NOT_FOUND); // Get a mutable pom.xml reference to modify it MutableFile pomMutableFile = getFileManager().updateFile(pomPath); Document pom = getInputDocument(pomMutableFile.getInputStream()); Element root = pom.getDocumentElement(); // Get plugin element Element plugin = XmlUtils.findFirstElement( "/project/build/plugins/plugin[groupId='org.apache.cxf' and artifactId='cxf-codegen-plugin']", root); // If plugin element not exists, message error Validate.notNull(plugin, "Codegen plugin is not defined in the pom.xml, relaunch again this command."); // Check URL connection and WSDL format Element rootElement = getSecurityService().getWsdl(wsdlLocation).getDocumentElement(); // The wsdl location already exists on old plugin format ? Element wsdlOptionElement = XmlUtils .findFirstElement("executions/execution/configuration/wsdlOptions/wsdlOption[wsdl='" + removeFilePrefix(wsdlLocation) + "']", plugin); // The wsdl location already exists on new plugin format ? String serviceId = WsdlParserUtils.findFirstCompatibleServiceElementName(rootElement); Element execution = XmlUtils.findFirstElement( "executions/execution[phase='generate-sources' and id='" + serviceId + "']", plugin); // If location already added on plugin, do nothing if (execution != null || wsdlOptionElement != null) { return false; } // Create global executions section if not exists already Element executions = DomUtils.findFirstElementByName(EXECUTIONS, plugin); if (executions == null) { executions = pom.createElement(EXECUTIONS); plugin.appendChild(executions); } // Create an execution section for this service execution = pom.createElement(EXECUTION); Element id = pom.createElement("id"); id.setTextContent(serviceId); Element phase = pom.createElement(PHASE2); phase.setTextContent("generate-sources"); execution.appendChild(id); execution.appendChild(phase); Element goals = pom.createElement(GOALS2); Element goal = pom.createElement(GOAL2); goal.setTextContent("wsdl2java"); goals.appendChild(goal); execution.appendChild(goals); executions.appendChild(execution); // Access execution > configuration > sourceRoot, wsdlOptions and // defaultOptions. // Configuration, sourceRoot, wsdlOptions and defaultOptions are // created if not exists. Element configuration = DomUtils.findFirstElementByName(CONFIGURATION2, execution); if (configuration == null) { configuration = pom.createElement(CONFIGURATION2); execution.appendChild(configuration); } Element sourceRoot = DomUtils.findFirstElementByName("sourceRoot", configuration); if (sourceRoot == null) { sourceRoot = pom.createElement("sourceRoot"); sourceRoot.setTextContent("${basedir}/target/generated-sources/client"); configuration.appendChild(sourceRoot); } Element defaultOptions = DomUtils.findFirstElementByName("defaultOptions", configuration); if (defaultOptions == null) { appendDefaultOptions(pom, configuration); } Element wsdlOptions = DomUtils.findFirstElementByName("wsdlOptions", configuration); if (wsdlOptions == null) { wsdlOptions = pom.createElement("wsdlOptions"); configuration.appendChild(wsdlOptions); } // Create new wsdl element and append it to the XML tree Element wsdlOption = pom.createElement("wsdlOption"); Element wsdl = pom.createElement("wsdl"); wsdl.setTextContent(removeFilePrefix(wsdlLocation)); wsdlOption.appendChild(wsdl); // Configure the packagename to generate client sources Element packagenames = pom.createElement("packagenames"); Element packagename = pom.createElement("packagename"); // Add the package name to generate sources String packageName = WsdlParserUtils.getTargetNamespaceRelatedPackage(rootElement); packagename.setTextContent(packageName.substring(0, packageName.length() - 1)); packagenames.appendChild(packagename); wsdlOption.appendChild(packagenames); wsdlOptions.appendChild(wsdlOption); // Write new XML to disk XmlUtils.writeXml(pomMutableFile.getOutputStream(), pom); return true; }
From source file:org.gvnix.service.roo.addon.addon.ws.WSConfigServiceImpl.java
/** * Update web configuration file (web.xml) with CXF configuration. * <ul>/*from ww w . j a v a2 s . co m*/ * <li>Add the CXF servlet declaration and mapping with '/services/*' URL to * access published web services. All added before forst servlet mapping</li> * <li>Configure Spring context to load cxf configuration file</li> * </ul> * <p> * If already installed cxf declaration, nothing to do. * </p> */ protected void updateWebConfigurationFile() { // Get web configuration file document and root XML representation MutableFile file = getFileManager().updateFile(getWebConfigFilePath()); Document web = getInputDocument(file.getInputStream()); Element root = web.getDocumentElement(); // If CXF servlet already installed: nothing to do if (XmlUtils.findFirstElement( "/web-app/servlet[servlet-class='org.apache.cxf.transport.servlet.CXFServlet']", root) != null) { return; } // Get first servlet mapping declaration Element firstMapping = XmlUtils.findRequiredElement("/web-app/servlet-mapping", root); // Add CXF servlet definition before first mapping root.insertBefore(getServletDefinition(web), firstMapping.getPreviousSibling()); // Add CXF servlet mapping before first mapping root.insertBefore(getServletMapping(web), firstMapping); // Add CXF configuration file path to Spring context Element context = XmlUtils .findFirstElement("/web-app/context-param[param-name='contextConfigLocation']/param-value", root); context.setTextContent(getCxfConfigRelativeFilePath().concat(" ").concat(context.getTextContent())); // Write modified web.xml to disk XmlUtils.writeXml(file.getOutputStream(), web); }
From source file:com.photon.phresco.framework.actions.applications.Build.java
public String createAndroidProfile() throws IOException { S_LOGGER.debug("Entering Method Build.createAndroidProfile()"); boolean hasSigning = false; try {//from w w w .j a v a 2 s .c om StringBuilder builder = new StringBuilder(Utility.getProjectHome()); builder.append(projectCode); builder.append(File.separatorChar); builder.append(POM_XML); File pomPath = new File(builder.toString()); AndroidPomProcessor processor = new AndroidPomProcessor(pomPath); hasSigning = processor.hasSigning(); String profileId = PROFILE_ID; String defaultGoal = GOAL_INSTALL; Plugin plugin = new Plugin(); plugin.setGroupId(ANDROID_PROFILE_PLUGIN_GROUP_ID); plugin.setArtifactId(ANDROID_PROFILE_PLUGIN_ARTIFACT_ID); plugin.setVersion(ANDROID_PROFILE_PLUGIN_VERSION); PluginExecution execution = new PluginExecution(); execution.setId(ANDROID_EXECUTION_ID); Goals goal = new Goals(); goal.getGoal().add(GOAL_SIGN); execution.setGoals(goal); execution.setPhase(PHASE_PACKAGE); execution.setInherited(TRUE); AndroidProfile androidProfile = new AndroidProfile(); androidProfile.setKeystore(keystore); androidProfile.setStorepass(storepass); androidProfile.setKeypass(keypass); androidProfile.setAlias(alias); androidProfile.setVerbose(true); androidProfile.setVerify(true); DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.newDocument(); List<Element> executionConfig = new ArrayList<Element>(); executionConfig.add(doc.createElement(ELEMENT_ARCHIVE_DIR)); Element removeExistSignature = doc.createElement(ELEMENT_REMOVE_EXIST_SIGN); Element includeElement = doc.createElement(ELEMENT_INCLUDES); Element doNotCheckInBuildInclude = doc.createElement(ELEMENT_INCLUDE); doNotCheckInBuildInclude.setTextContent(ELEMENT_BUILD); Element doNotCheckinTargetInclude = doc.createElement(ELEMENT_INCLUDE); doNotCheckinTargetInclude.setTextContent(ELEMENT_TARGET); includeElement.appendChild(doNotCheckInBuildInclude); includeElement.appendChild(doNotCheckinTargetInclude); executionConfig.add(includeElement); removeExistSignature.setTextContent(TRUE); executionConfig.add(removeExistSignature); //verboss Element verbos = doc.createElement(ELEMENT_VERBOS); verbos.setTextContent(TRUE); executionConfig.add(verbos); //verify Element verify = doc.createElement(ELEMENT_VERIFY); verbos.setTextContent(TRUE); executionConfig.add(verify); Configuration configValues = new Configuration(); configValues.getAny().addAll(executionConfig); execution.setConfiguration(configValues); List<Element> additionalConfigs = new ArrayList<Element>(); processor.setProfile(profileId, false, defaultGoal, plugin, androidProfile, execution, null, additionalConfigs); processor.save(); profileCreationStatus = true; if (hasSigning) { profileCreationMessage = getText(PROFILE_UPDATE_SUCCESS); } else { profileCreationMessage = getText(PROFILE_CREATE_SUCCESS); } } catch (Exception e) { S_LOGGER.error("Entered into catch block of Build.createAndroidProfile()" + FrameworkUtil.getStackTraceAsString(e)); profileCreationStatus = false; if (hasSigning) { profileCreationMessage = getText(PROFILE_UPDATE_ERROR); } else { profileCreationMessage = getText(PROFILE_CREATE_ERROR); } } return SUCCESS; }
From source file:com.bluexml.xforms.controller.mapping.MappingToolCommon.java
protected void addId(Document xformsDocument, Node element, String alfrescoId) { if (alfrescoId != null) { Element idElement = xformsDocument.createElement(MsgId.INT_INSTANCE_SIDEID.getText()); idElement.setTextContent(alfrescoId); element.appendChild(idElement);//from ww w. ja v a2s. c om } }
From source file:com.bluexml.xforms.controller.mapping.MappingToolCommon.java
/** * Creates an item for inputs that support multiple values, setting the item * value./* w w w.j a v a 2 s . co m*/ * * @param formInstance * @param value * @throws DOMException * @return the DOM node for the item */ protected Element getInputMultipleItemWithValue(Document formInstance, String value) throws DOMException { Element item = formInstance.createElement(MsgId.INT_INSTANCE_INPUT_MULT_ITEM.getText()); Element valueElt = formInstance.createElement(MsgId.INT_INSTANCE_INPUT_MULT_VALUE.getText()); valueElt.setTextContent(value); item.appendChild(valueElt); return item; }
From source file:com.mirth.connect.model.util.ImportConverter.java
private static void updateTransformerFor1_4(Document document, Element transformerRoot, String incoming, String outgoing) {// w w w.j av a2 s.co m String template = ""; Element transformerTemplate = null; if (transformerRoot.getElementsByTagName("template").getLength() > 0) { transformerTemplate = (Element) transformerRoot.getElementsByTagName("template").item(0); if (transformerTemplate != null) template = transformerTemplate.getTextContent(); } Element inboundTemplateElement = null, outboundTemplateElement = null, inboundProtocolElement = null, outboundProtocolElement = null; if (transformerRoot.getElementsByTagName("inboundTemplate").getLength() == 0) inboundTemplateElement = document.createElement("inboundTemplate"); if (transformerRoot.getElementsByTagName("outboundTemplate").getLength() == 0) outboundTemplateElement = document.createElement("outboundTemplate"); if (transformerRoot.getElementsByTagName("inboundProtocol").getLength() == 0) { inboundProtocolElement = document.createElement("inboundProtocol"); inboundProtocolElement.setTextContent(incoming.toString()); } if (transformerRoot.getElementsByTagName("outboundProtocol").getLength() == 0) { outboundProtocolElement = document.createElement("outboundProtocol"); outboundProtocolElement.setTextContent(outgoing.toString()); } if (transformerTemplate != null) { if (incoming.equals(HL7V2) && outgoing.equals(HL7V2)) { inboundTemplateElement.setTextContent(template); } else if (outgoing.equals(HL7V2)) { outboundTemplateElement.setTextContent(template); } } if (transformerRoot.getElementsByTagName("inboundTemplate").getLength() == 0) transformerRoot.appendChild(inboundTemplateElement); if (transformerRoot.getElementsByTagName("outboundTemplate").getLength() == 0) transformerRoot.appendChild(outboundTemplateElement); if (transformerRoot.getElementsByTagName("inboundProtocol").getLength() == 0) transformerRoot.appendChild(inboundProtocolElement); if (transformerRoot.getElementsByTagName("outboundProtocol").getLength() == 0) transformerRoot.appendChild(outboundProtocolElement); // replace HL7 Message builder with Message Builder NodeList steps = getElements(transformerRoot, "step", "com.mirth.connect.model.Step"); for (int i = 0; i < steps.getLength(); i++) { Element step = (Element) steps.item(i); NodeList stepTypesList = step.getElementsByTagName("type"); if (stepTypesList.getLength() > 0) { Element stepType = (Element) stepTypesList.item(0); if (stepType.getTextContent().equals("HL7 Message Builder")) { stepType.setTextContent("Message Builder"); } if (stepType.getTextContent().equals("Message Builder") || stepType.getTextContent().equals("Mapper")) { boolean foundRegex = false, foundDefaultValue = false; Element data = (Element) step.getElementsByTagName("data").item(0); NodeList entries = data.getElementsByTagName("entry"); for (int j = 0; j < entries.getLength(); j++) { NodeList strings = ((Element) entries.item(j)).getElementsByTagName("string"); if (strings.getLength() > 0) { if (strings.item(0).getTextContent().equals("RegularExpressions")) foundRegex = true; else if (strings.item(0).getTextContent().equals("DefaultValue")) foundDefaultValue = true; if (strings.item(0).getTextContent().equals("isGlobal")) { if (strings.item(1).getTextContent().equals("0")) strings.item(1).setTextContent("channel"); else if (strings.item(1).getTextContent().equals("1")) strings.item(1).setTextContent("global"); } } } if (!foundRegex) data.appendChild(createRegexElement(document)); if (!foundDefaultValue) data.appendChild(createDefaultValueElement(document)); } } } if (transformerTemplate != null) transformerRoot.removeChild(transformerTemplate); }
From source file:cc.siara.csv_ml_demo.MultiLevelCSVSwingDemo.java
/** * Evaluates given XPath from Input box against Document generated by * parsing csv_ml in input box and sets value or node list to output box. *///from w w w . java 2 s . c o m private void processXPath() { XPath xpath = XPathFactory.newInstance().newXPath(); Document doc = parseInputToDOM(); if (doc == null) return; StringBuffer out_str = new StringBuffer(); try { XPathExpression expr = xpath.compile(tfXPath.getText()); try { Document outDoc = Util.parseXMLToDOM("<output></output>"); Element rootElement = outDoc.getDocumentElement(); NodeList ret = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < ret.getLength(); i++) { Object o = ret.item(i); if (o instanceof String) { out_str.append(o); } else if (o instanceof Node) { Node n = (Node) o; short nt = n.getNodeType(); switch (nt) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.CDATA_SECTION_NODE: // Only one value gets // evaluated? if (out_str.length() > 0) out_str.append(','); if (nt == Node.ATTRIBUTE_NODE) out_str.append(n.getNodeValue()); else out_str.append(n.getTextContent()); break; case Node.ELEMENT_NODE: rootElement.appendChild(outDoc.importNode(n, true)); break; } } } if (out_str.length() > 0) { rootElement.setTextContent(out_str.toString()); out_str.setLength(0); } out_str.append(Util.docToString(outDoc, true)); } catch (Exception e) { // Thrown most likely because the given XPath evaluates to a // string out_str.append(expr.evaluate(doc)); } } catch (XPathExpressionException e) { e.printStackTrace(); } taOutput.setText(out_str.toString()); tfOutputSize.setText(String.valueOf(out_str.length())); }
From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java
private synchronized String duplicate(final Document originalDom, final Element originalRootElement, final Element patchElement) throws Exception { boolean isdone = false; Element parentElement = null; DuplicateChildElementObject childElementObject = isChildElement(originalRootElement, patchElement); if (!childElementObject.isNeedDuplicate()) { isdone = true;//from w w w .ja va2s . com parentElement = childElementObject.getElement(); } else if (childElementObject.getElement() != null) { parentElement = childElementObject.getElement(); } else { parentElement = originalRootElement; } String son_name = patchElement.getNodeName(); Element subITEM = null; if (!isdone) { subITEM = originalDom.createElement(son_name); if (patchElement.hasChildNodes()) { if (patchElement.getFirstChild().getNodeType() == Node.TEXT_NODE) { subITEM.setTextContent(patchElement.getTextContent()); } } if (patchElement.hasAttributes()) { NamedNodeMap attributes = patchElement.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { String attribute_name = attributes.item(i).getNodeName(); String attribute_value = attributes.item(i).getNodeValue(); subITEM.setAttribute(attribute_name, attribute_value); } } parentElement.appendChild(subITEM); } else { subITEM = parentElement; } NodeList sub_messageItems = patchElement.getChildNodes(); int sub_item_number = sub_messageItems.getLength(); logger.debug("patchEl: " + DomUtils.elementToString(patchElement) + "length: " + sub_item_number); if (sub_item_number == 0) { isdone = true; } else { for (int j = 0; j < sub_item_number; j++) { if (sub_messageItems.item(j).getNodeType() == Node.ELEMENT_NODE) { Element sub_messageItem = (Element) sub_messageItems.item(j); logger.debug("node name: " + DomUtils.elementToString(subITEM) + " node type: " + subITEM.getNodeType()); duplicate(originalDom, subITEM, sub_messageItem); } } } return (parentElement != null) ? DomUtils.elementToString(parentElement) : ""; }
From source file:de.qucosa.webapi.v1.DocumentResource.java
private FileUpdateOperation updateFileNodeWith(Element target, Element update) throws FedoraClientException, IOException, XPathExpressionException { FileUpdateOperation fupo = new FileUpdateOperation(); NodeList updateNodes = update.getChildNodes(); for (int i = 0; i < updateNodes.getLength(); i++) { if (updateNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element updateField = (Element) updateNodes.item(i); String updateFieldLocalName = updateField.getLocalName(); Element targetElement = (Element) target.getElementsByTagName(updateFieldLocalName).item(0); if (targetElement == null) { targetElement = target.getOwnerDocument().createElement(updateFieldLocalName); target.appendChild(targetElement); targetElement.appendChild(target.getOwnerDocument().createTextNode("")); }/* w w w.j ava2 s .c o m*/ String oldVal = targetElement.getTextContent(); String newVal = updateField.getTextContent(); if (!oldVal.equals(newVal)) { switch (updateFieldLocalName) { case "PathName": if (!newVal.isEmpty()) fupo.rename(oldVal, newVal); break; case "Label": fupo.newLabel(updateField.getTextContent()); break; case "FrontdoorVisible": fupo.newState(determineDatastreamState(update)); break; } targetElement.setTextContent(updateField.getTextContent()); } } } return fupo; }