List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:com.bluexml.xforms.actions.GetAction.java
/** * Gets the instance for forms that do not require calling the controller because of how simple * their instance is. The controller acts as a bridge to the mapping; when there's no * information to extract from the mapping, a better option is to serve the instance here. * /*w ww.jav a2s .co m*/ * @param dataType * @param formType * @return the instance */ private Document getInstanceListOrSelector(String dataType, FormTypeEnum formType) { DocumentBuilder docBuilder = null; try { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { if (logger.isErrorEnabled()) { logger.error("Failed to obtain a document builder", e); } return null; } Document instance = docBuilder.newDocument(); Element rootElement = instance.createElement(dataType); instance.appendChild(rootElement); if (formType == FormTypeEnum.SELECTOR) { // the data type in the combo box Element sideData = instance.createElement(MsgId.INT_INSTANCE_SIDE_DATATYPE.getText()); sideData.setTextContent(dataType); rootElement.appendChild(sideData); return instance; } else if (formType == FormTypeEnum.LIST) { // the id of the object whose Edit button was clicked Element editedid = instance.createElement(MsgId.INT_INSTANCE_SIDEEDIT.getText()); rootElement.appendChild(editedid); return instance; } return null; // we never reach here }
From source file:ddf.catalog.services.xsltlistener.XsltResponseQueueTransformer.java
private Element createElement(Document parentDoc, String namespace, String tagName, String elementValue) { Element element = parentDoc.createElementNS(namespace, tagName); element.setTextContent(elementValue); return element; }
From source file:com.photon.phresco.framework.impl.ConfigurationWriter.java
/** * create the properties to the configuration element * @param configNode//from w w w. j a va 2 s . c o m * @param propertyInfos */ private void createProperties(Element configNode, List<PropertyInfo> propertyInfos) { for (PropertyInfo propertyInfo : propertyInfos) { String key = propertyInfo.getKey(); String value = propertyInfo.getValue(); Element propNode = getDocument().createElement(key); propNode.setTextContent(value); configNode.appendChild(propNode); } }
From source file:ml.shifu.shifu.core.pmml.builder.impl.ZscoreLocalTransformCreator.java
/** * Create DerivedField for categorical variable * /*from ww w . j ava 2s . c o m*/ * @param config * - ColumnConfig for categorical variable * @param cutoff * - cutoff for normalization * @param normType * - the normalization method that is used to generate DerivedField * @return DerivedField for variable */ protected List<DerivedField> createCategoricalDerivedField(ColumnConfig config, double cutoff, ModelNormalizeConf.NormType normType) { Document document = null; try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { LOG.error("Fail to create document node.", e); throw new RuntimeException("Fail to create document node.", e); } String defaultValue = Normalizer.normalize(config, "doesn't exist at all...by paypal", cutoff, normType) .get(0).toString(); String missingValue = Normalizer.normalize(config, null, cutoff, normType).get(0).toString(); InlineTable inlineTable = new InlineTable(); for (int i = 0; i < config.getBinCategory().size(); i++) { List<String> catVals = CommonUtils.flattenCatValGrp(config.getBinCategory().get(i)); for (String cval : catVals) { String dval = Normalizer.normalize(config, cval, cutoff, normType).get(0).toString(); Element out = document.createElementNS(NAME_SPACE_URI, ELEMENT_OUT); out.setTextContent(dval); Element origin = document.createElementNS(NAME_SPACE_URI, ELEMENT_ORIGIN); origin.setTextContent(cval); inlineTable.addRows(new Row().addContent(origin).addContent(out)); } } MapValues mapValues = new MapValues("out").setDataType(DataType.DOUBLE).setDefaultValue(defaultValue) .addFieldColumnPairs(new FieldColumnPair(new FieldName(NormalUtils.getSimpleColumnName(config, columnConfigList, segmentExpansions, datasetHeaders)), ELEMENT_ORIGIN)) .setInlineTable(inlineTable).setMapMissingTo(missingValue); List<DerivedField> derivedFields = new ArrayList<DerivedField>(); derivedFields.add(new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE) .setName(FieldName.create( genPmmlColumnName(NormalUtils.getSimpleColumnName(config.getColumnName()), normType))) .setExpression(mapValues)); return derivedFields; }
From source file:no.dusken.barweb.view.XListView.java
private Element createPersonElement(BarPerson p, Document dom, Integer lowLimit) { Element personEle = dom.createElement("barPerson"); Boolean enoughMoney = p.getMoney() >= lowLimit; personEle.setAttribute("enoughmoney", enoughMoney.toString()); personEle.setTextContent(p.getName()); return personEle; }
From source file:com.twinsoft.convertigo.engine.admin.services.database_objects.Set.java
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception { Element root = document.getDocumentElement(); Document post = null;/*from w ww . j av a 2 s. co m*/ Element response = document.createElement("response"); try { Map<String, DatabaseObject> map = com.twinsoft.convertigo.engine.admin.services.projects.Get .getDatabaseObjectByQName(request); xpath = new TwsCachedXPathAPI(); post = XMLUtils.parseDOM(request.getInputStream()); postElt = document.importNode(post.getFirstChild(), true); String objectQName = xpath.selectSingleNode(postElt, "./@qname").getNodeValue(); DatabaseObject object = map.get(objectQName); // String comment = getPropertyValue(object, "comment").toString(); // object.setComment(comment); if (object instanceof Project) { Project project = (Project) object; String objectNewName = getPropertyValue(object, "name").toString(); Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName); map.remove(objectQName); map.put(project.getQName(), project); } BeanInfo bi = CachedIntrospector.getBeanInfo(object.getClass()); PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); Method setter = propertyDescriptor.getWriteMethod(); Class<?> propertyTypeClass = propertyDescriptor.getReadMethod().getReturnType(); if (propertyTypeClass.isPrimitive()) { propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass); } try { String propertyValue = getPropertyValue(object, propertyName).toString(); Object oPropertyValue = createObject(propertyTypeClass, propertyValue); if (object.isCipheredProperty(propertyName)) { Method getter = propertyDescriptor.getReadMethod(); String initialValue = (String) getter.invoke(object, (Object[]) null); if (oPropertyValue.equals(initialValue) || DatabaseObject.encryptPropertyValue(initialValue).equals(oPropertyValue)) { oPropertyValue = initialValue; } else { object.hasChanged = true; } } if (oPropertyValue != null) { Object args[] = { oPropertyValue }; setter.invoke(object, args); } } catch (IllegalArgumentException e) { } } Engine.theApp.databaseObjectsManager.exportProject(object.getProject()); response.setAttribute("state", "success"); response.setAttribute("message", "Project have been successfully updated!"); } catch (Exception e) { Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage()); response.setAttribute("state", "error"); response.setAttribute("message", "Error during saving the properties!"); Element stackTrace = document.createElement("stackTrace"); stackTrace.setTextContent(e.getMessage()); root.appendChild(stackTrace); } finally { xpath.resetCache(); } root.appendChild(response); }
From source file:org.openmrs.module.xforms.aop.XformsConceptAdvisor.java
private void setItemValueText(Element parentElement, String valueText) { NodeList elements = parentElement.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "value"); if (elements.getLength() > 0) { Element valueElement = (Element) elements.item(0); valueElement.setTextContent(valueText); }// w ww . jav a 2 s . co m }
From source file:com.photon.phresco.framework.impl.ConfigurationWriter.java
public void updateTestConfiguration(SettingsInfo settingsInfo, String browser, String resultConfigXml) throws PhrescoException { try {//from w w w .j a va 2 s. c o m Node configNode = getNode("environment"); Node node = getNode("environment/" + settingsInfo.getType()); Node browserNode = getNode("environment/Browser"); if (node != null) { configNode.removeChild(node); } if (browserNode != null) { browserNode.setTextContent(browser); } else { Element browserEle = getDocument().createElement("Browser"); browserEle.setTextContent(browser); configNode.appendChild(browserEle); } configNode.appendChild(createConfigElement(settingsInfo)); } catch (Exception e) { throw new PhrescoException("Configuration not found to delete"); } }
From source file:org.gvnix.dynamic.configuration.roo.addon.PomManagerImpl.java
/** * Write a configurations into POM profile. * //from w w w .j a v a 2 s .co m * @param doc Pom document * @param dynConf * @return New configuration element */ protected Element exportConfiguration(Document doc, DynConfiguration dynConf) { Element root = doc.getDocumentElement(); // <project> // <profiles> // <profile> // <id>test</id> // <activation> // <activeByDefault>true</activeByDefault> // </activation> // </profile> // </profiles> // </project> // Profiles section: find or create if not exists Element profs = XmlUtils.findFirstElement("/project/profiles", root); if (profs == null) { profs = doc.createElement("profiles"); root.appendChild(profs); } // Remove profile if already exists Element prof = XmlUtils.findFirstElement("profile/id[text()='" + dynConf.getName() + "']/..", profs); if (prof != null) { profs.removeChild(prof); } // Create a profile section for this dynamic configuration prof = doc.createElement("profile"); profs.appendChild(prof); // Create an identifier for profile Element id = doc.createElement("id"); id.setTextContent(dynConf.getName()); prof.appendChild(id); // If dynamic configuration is active: profile active by default if (dynConf.isActive()) { // Create an activation section Element activation = doc.createElement("activation"); prof.appendChild(activation); Element active = doc.createElement("activeByDefault"); active.setTextContent("true"); activation.appendChild(active); } return prof; }
From source file:com.photon.phresco.framework.impl.ServerPluginUtil.java
private void addTomcatPlugin(File pomFile) throws PhrescoException { try {// ww w. j a v a2s . com PomProcessor pomProcessor = new PomProcessor(pomFile); Plugin plugin = pomProcessor.getPlugin("org.codehaus.mojo", "tomcat-maven-plugin"); if (plugin != null) { return; } pomProcessor.addPlugin("org.codehaus.mojo", "tomcat-maven-plugin", "1.1"); List<Element> configList = new ArrayList<Element>(); DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element userNameElem = doc.createElement("username"); userNameElem.setTextContent("${server.username}"); Element passwordElem = doc.createElement("password"); passwordElem.setTextContent("${server.password}"); Element urlElem = doc.createElement("url"); urlElem.setTextContent("http://${server.host}:${server.port}/manager/html"); Element pathElem = doc.createElement("path"); pathElem.setTextContent("/${project.build.finalName}"); Element argLineElem = doc.createElement("argLine"); argLineElem.setTextContent("-Xmx512m"); configList.add(userNameElem); configList.add(passwordElem); configList.add(urlElem); configList.add(pathElem); configList.add(argLineElem); pomProcessor.addConfiguration("org.codehaus.mojo", "tomcat-maven-plugin", configList); pomProcessor.save(); } catch (ParserConfigurationException e) { throw new PhrescoException(e); } catch (PhrescoPomException e) { throw new PhrescoException(e); } catch (JAXBException e) { throw new PhrescoException(e); } catch (IOException e) { throw new PhrescoException(e); } }