List of usage examples for org.w3c.dom Node setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:com.mirth.connect.model.util.ImportConverter.java
private static void setBooleanNode(Node parent, String elementName, boolean value) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeName().equals(elementName)) { child.setTextContent(Boolean.toString(value)); }/*w ww. ja va 2 s. com*/ } }
From source file:com.crawljax.plugins.adi.Report.java
/** * Taken from ErrorReport.//w w w . j a v a 2 s . co m */ private Document addMarker(String id, Document doc, String xpath) { try { String prefixMarker = "###BEGINMARKER" + id + "###"; String suffixMarker = "###ENDMARKER###"; NodeList nodeList = XPathHelper.evaluateXpathExpression(doc, xpath); if (nodeList.getLength() == 0 || nodeList.item(0) == null) { return doc; } Node element = nodeList.item(0); if (element.getNodeType() == Node.ELEMENT_NODE) { Node beginNode = doc.createTextNode(prefixMarker); Node endNode = doc.createTextNode(suffixMarker); element.getParentNode().insertBefore(beginNode, element); if (element.getNextSibling() == null) { element.getParentNode().appendChild(endNode); } else { element.getParentNode().insertBefore(endNode, element.getNextSibling()); } } else if (element.getNodeType() == Node.TEXT_NODE && element.getTextContent() != null) { element.setTextContent(prefixMarker + element.getTextContent() + suffixMarker); } else if (element.getNodeType() == Node.ATTRIBUTE_NODE) { element.setNodeValue(prefixMarker + element.getTextContent() + suffixMarker); } return doc; } catch (Exception e) { return doc; } }
From source file:edu.clemson.lph.civet.xml.StdeCviXmlBuilder.java
/** * Used to add address to Veterinarian, Origin and Destination * @param e//from ww w. j a va 2 s . com * @param sStreet * @param sCity * @param sState * @param sZip * @return */ public Element setAddress(Element e, String sStreet, String sCity, String sState, String sZip) { if (!isValidDoc()) return null; Element address = null; if (e != null) { address = getAddress(e, sStreet, sCity, sState, sZip); if (address != null) return address; address = childElementByName(e, "Address"); if (address == null) { String sElement = e.getTagName(); Node nPerson = null; if (!"Veterinarian".equals(sElement)) { nPerson = childNodeByName(e, "Person"); } address = doc.createElement("Address"); e.insertBefore(address, nPerson); } Node line1 = childNodeByName(address, "Line1"); if (line1 == null) { line1 = doc.createElement("Line1"); address.appendChild(line1); } if (sStreet != null) { line1.setTextContent(sStreet.trim()); } else { line1.setTextContent(""); } Node town = childNodeByName(address, "Town"); if (town == null) { town = doc.createElement("Town"); address.appendChild(town); } if (sCity != null) { town.setTextContent(sCity.trim()); } else { town.setTextContent("Not Provided"); } Node state = childNodeByName(address, "State"); if (state == null) { state = doc.createElement("State"); address.appendChild(state); } if (sState != null) { state.setTextContent(sState.trim()); } else { logger.error("Attempt to add address with no state.", new Exception()); state.setTextContent("ERROR"); } Node zip = childNodeByName(address, "ZIP"); if (zip == null) { zip = doc.createElement("ZIP"); address.appendChild(zip); } if (sZip != null && sZip.trim().length() > 0) { zip.setTextContent(sZip.trim()); } else { zip.setTextContent("00000"); } Node country = childNodeByName(address, "Country"); if (country == null) { country = doc.createElement("Country"); address.appendChild(country); } country.setTextContent("USA"); } return address; }
From source file:de.escidoc.core.test.aa.UserAccountTestBase.java
/** * Inserts the given values into the provided document . * * @param document The document./*from ww w . java 2 s . c om*/ * @param name The name. * @param loginname The loginname. * @throws Exception If anything fails. */ protected void insertUserAccountValues(final Document document, final String name, final String loginname) throws Exception { assertXmlExists("No login-name found in template data. ", document, "/user-account/properties/login-name"); assertXmlExists("No name found in template data. ", document, "/user-account/properties/name"); if (loginname != null) { final Node loginNameNode = selectSingleNode(document, "/user-account/properties/login-name"); loginNameNode.setTextContent(loginname); } if (name != null) { final Node nameNode = selectSingleNode(document, "/user-account/properties/name"); nameNode.setTextContent(name); } }
From source file:de.escidoc.core.test.aa.UserGroupTestBase.java
/** * Inserts the given values into the provided document . * * @param document The document./*from w w w. j a va2 s. co m*/ * @param email The email. * @param name The name. * @param label The label. * @param description The description. * @throws Exception If anything fails. */ protected void insertUserGroupValues(final Document document, final String email, final String name, final String label, final String description) throws Exception { assertXmlExists("No email found in template data. ", document, "/user-group/properties/email"); assertXmlExists("No name found in template data. ", document, "/user-group/properties/name"); assertXmlExists("No label found in template data. ", document, "/user-group/properties/label"); assertXmlExists("No description found in template data. ", document, "/user-group/properties/description"); if (email != null) { final Node emailNode = selectSingleNode(document, "/user-group/properties/email"); emailNode.setTextContent(email); } if (name != null) { final Node nameNode = selectSingleNode(document, "/user-group/properties/name"); nameNode.setTextContent(name); } if (label != null) { final Node labelNode = selectSingleNode(document, "/user-group/properties/label"); labelNode.setTextContent(label); } if (description != null) { final Node descriptionNode = selectSingleNode(document, "/user-group/properties/description"); descriptionNode.setTextContent(description); } }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void appendCollectionProp(Document document, Node elementProp, String contextType, String contextPostData) { // collection append in prop String argumentValue = null;//ww w . j a v a2 s .com if (contextType.equals(FrameworkConstants.POST)) { argumentValue = contextPostData; } Node collectionProp = document.createElement("collectionProp"); NamedNodeMap attributes = collectionProp.getAttributes(); attributes.setNamedItem(createAttribute(document, "name", "Arguments.arguments")); Node subElementProp = document.createElement("elementProp"); NamedNodeMap subElementAttributes = subElementProp.getAttributes(); subElementAttributes.setNamedItem(createAttribute(document, "name", "")); subElementAttributes.setNamedItem(createAttribute(document, "elementType", "HTTPArgument")); collectionProp.appendChild(subElementProp); appendTypeProp(document, subElementProp, "boolProp", "HTTPArgument.always_encode", "false"); appendTypeProp(document, subElementProp, "stringProp", "Argument.value", argumentValue); appendTypeProp(document, subElementProp, "stringProp", "Argument.metadata", "="); appendTypeProp(document, subElementProp, "boolProp", "HTTPArgument.use_equals", "true"); elementProp.setTextContent(null); elementProp.appendChild(collectionProp); }
From source file:au.com.ors.rest.dao.JobAppDAO.java
/** * Update an existing job application<br/> * //ww w .j a va 2 s .c o m * @param application * job application to be updated * @throws JobApplicationNotFoundException * @throws TransformerException */ public JobApplication update(JobApplication application) throws JobApplicationNotFoundException, TransformerException { int jobIndex = -1; for (int i = 0; i < jobAppList.size(); ++i) { if (jobAppList.get(i).get_appId().equals(application.get_appId())) { // found jobIndex = i; break; } } if (jobIndex < 0) { throw new JobApplicationNotFoundException("Application with _appId=" + application.get_appId() + " not found in database while updating."); } jobAppList.set(jobIndex, application); // update section to XML Element root = dom.getDocumentElement(); NodeList nodeList = root.getChildNodes(); for (int i = 0; i < nodeList.getLength(); ++i) { Node node = nodeList.item(i); if (!node.getNodeName().equals("JobApplication")) { continue; } NodeList appInfoList = node.getChildNodes(); for (int j = 0; j < appInfoList.getLength(); ++j) { Node current = appInfoList.item(j); // _appId, _jobId cannot be updated after the application // created already if (current.getNodeType() == Node.ELEMENT_NODE) { if (current.getNodeName().equals("_appId")) { if (!current.getTextContent().equals(application.get_appId())) { break; // not the right application ID } } else if (current.getNodeName().equals("_jobId")) { continue; } else if (current.getNodeName().equals("driverLicenseNumber")) { current.setTextContent(application.getDriverLicenseNumber()); } else if (current.getNodeName().equals("fullName")) { current.setTextContent(application.getFullName()); } else if (current.getNodeName().equals("postCode")) { current.setTextContent(application.getPostCode()); } else if (current.getNodeName().equals("textCoverLetter")) { current.setTextContent(application.getTextCoverLetter()); } else if (current.getNodeName().equals("textBriefResume")) { current.setTextContent(application.getTextBriefResume()); } else if (current.getNodeName().equals("status")) { current.setTextContent(application.getStatus()); } } } } // write dom DOMSource source = new DOMSource(dom); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); StreamResult result = new StreamResult(dataUrl); transformer.transform(source, result); return application; }
From source file:org.gvnix.dynamic.configuration.roo.addon.ConfigurationsImpl.java
/** * {@inheritDoc}/*from www.j a va 2 s .c o m*/ */ public DynProperty updateProperty(String configuration, String property, String value) { // Get the required property element to update Element prop = getProperty(configuration, property); if (prop == null) { return null; } // Get the property value element Node valueElem = getValueElement(prop); if (value == null) { if (valueElem != null) { // Undefined property value: remove property value element prop.removeChild(valueElem); } } else { if (valueElem == null) { // Undo undefined property value: Create property value element valueElem = prop.getOwnerDocument().createElement(VALUE_ELEMENT_NAME); prop.appendChild(valueElem); } // Set property value valueElem.setTextContent(value); } saveConfiguration(prop); return parseProperty(prop); }
From source file:de.escidoc.core.test.aa.UserAccountTestBase.java
/** * Inserts a unique loginname into the provided document by adding the current timestamp to the contained * loginname.//w w w. ja v a 2 s . c o m * * @param document The document. * @return The inserted login name. * @throws Exception If anything fails. */ protected String insertUniqueLoginName(final Document document) throws Exception { assertXmlExists("No login-name found in template data. ", document, "/user-account/properties/login-name"); final Node loginNameNode = selectSingleNode(document, "/user-account/properties/login-name"); String loginname = loginNameNode.getTextContent().trim(); loginname += System.currentTimeMillis(); loginNameNode.setTextContent(loginname); return loginname; }
From source file:de.escidoc.core.test.aa.UserGroupTestBase.java
/** * Creates a new user group.//from ww w.jav a 2 s .c o m * * @param templateName name of the usergroup-template to use. * @param nameModification modified name of the user group. * @return The inserted user group. * @throws Exception If anything fails. */ public Document createSuccessfully(final String templateName, final String nameModification) throws Exception { if (nameModification == null) { return createSuccessfully(templateName); } else { final Document toBeCreatedDocument = getTemplateAsFixedUserGroupDocument(TEMPLATE_USER_GROUP_PATH, templateName); final Node nameNode = selectSingleNode(toBeCreatedDocument, "/user-group/properties/name"); String name = nameNode.getTextContent().trim(); name += nameModification; nameNode.setTextContent(name); insertUniqueLabel(toBeCreatedDocument); final String toBeCreatedXml = toString(toBeCreatedDocument, false); assertXmlValidUserGroup(toBeCreatedXml); final String beforeCreationTimestamp = getNowAsTimestamp(); String createdUserGroupXml = null; try { createdUserGroupXml = create(toBeCreatedXml); } catch (final Exception e) { EscidocAbstractTest.failException(e); } return assertActiveUserGroup(createdUserGroupXml, toBeCreatedXml, beforeCreationTimestamp, beforeCreationTimestamp, false); } }