Java Code Examples for org.w3c.dom.Element#setTextContent()

The following examples show how to use org.w3c.dom.Element#setTextContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VsmCommand.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
private static Element deletePortProfileDetails(Document doc, String name) {
    Element configure = doc.createElementNS(s_ciscons, "nxos:configure");
    Element modeConfigure = doc.createElement("nxos:" + s_configuremode);
    configure.appendChild(modeConfigure);

    // Command and name for the port profile to be deleted.
    Element deletePortProfile = doc.createElement("no");
    modeConfigure.appendChild(deletePortProfile);

    Element portProfile = doc.createElement("port-profile");
    deletePortProfile.appendChild(portProfile);

    Element portDetails = doc.createElement("name");
    portProfile.appendChild(portDetails);

    // Name of the profile to delete.
    Element value = doc.createElement(s_paramvalue);
    value.setAttribute("isKey", "true");
    value.setTextContent(name);
    portDetails.appendChild(value);

    // Persist the configuration across reboots.
    modeConfigure.appendChild(persistConfiguration(doc));

    return configure;
}
 
Example 2
Source File: LaunchControl.java    From SB_Elsinore_Server with MIT License 6 votes vote down vote up
/******
 * Save the volume information for an onboard Analogue Input.
 *
 * @param name
 *            Device name
 * @param volumeAIN
 *            Analogue input pin
 * @param volumeUnit
 *            The units for the volume (free text string)
 * @param concurrentHashMap
 *            Hashmap of the volume ranges and readings
 */
public static void saveVolume(final String name, final String volumeAIN,
        final String volumeUnit,
        final ConcurrentHashMap<BigDecimal, BigDecimal> concurrentHashMap) {

    BrewServer.LOG.info("Saving volume for " + name);

    // save any changes
    Element device = saveVolumeMeasurements(name, concurrentHashMap,
            volumeUnit);

    Element tElement = getFirstElement(device, "volume-pin");
    if (tElement == null) {
        tElement = addNewElement(device, "volume-pin");
    }

    tElement.setTextContent(volumeAIN);

}
 
Example 3
Source File: QuikitServlet.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void error( Document dom, Throwable exception )
{
    Element root = dom.getDocumentElement();
    dom.removeChild( root );
    Element preElement = (Element) dom.appendChild( dom.createElementNS( Page.XHTML, "html" ) )
        .appendChild( dom.createElementNS( Page.XHTML, "body" ) )
        .appendChild( dom.createElementNS( Page.XHTML, "code" ) )
        .appendChild( dom.createElementNS( Page.XHTML, "pre" ) );

    StringWriter stringWriter = new StringWriter( 2000 );
    PrintWriter writer = new PrintWriter( stringWriter );
    exception.printStackTrace( writer );
    writer.close();
    String content = stringWriter.getBuffer().toString();
    preElement.setTextContent( content );
}
 
Example 4
Source File: StandardFlowSerializer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static void addBundle(final Element parentElement, final BundleCoordinate coordinate) {
    // group
    final Element groupElement = parentElement.getOwnerDocument().createElement("group");
    groupElement.setTextContent(CharacterFilterUtils.filterInvalidXmlCharacters(coordinate.getGroup()));

    // artifact
    final Element artifactElement = parentElement.getOwnerDocument().createElement("artifact");
    artifactElement.setTextContent(CharacterFilterUtils.filterInvalidXmlCharacters(coordinate.getId()));

    // version
    final Element versionElement = parentElement.getOwnerDocument().createElement("version");
    versionElement.setTextContent(CharacterFilterUtils.filterInvalidXmlCharacters(coordinate.getVersion()));

    // bundle
    final Element bundleElement = parentElement.getOwnerDocument().createElement("bundle");
    bundleElement.appendChild(groupElement);
    bundleElement.appendChild(artifactElement);
    bundleElement.appendChild(versionElement);

    parentElement.appendChild(bundleElement);
}
 
Example 5
Source File: FolderEncryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Element createBase64EncryptedData(Document doc, String encryptedMessageString) {
   Element base64EncryptedData = doc.createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   Element cd = doc.createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "cd");
   cd.setAttribute("SV", "1.0");
   cd.setAttribute("S", "CD-ENCRYPTION-METHOD");
   cd.setTextContent("CMS");
   base64EncryptedData.appendChild(cd);
   Element base64EncryptedValue = doc.createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
   base64EncryptedValue.setTextContent(encryptedMessageString);
   base64EncryptedData.appendChild(base64EncryptedValue);
   return base64EncryptedData;
}
 
Example 6
Source File: TagXMLArrayMemberHandler.java    From hkxpack with MIT License 5 votes vote down vote up
private void handlePtrOutType(final Element memberNode, final HKXArrayMember member) {
	StringBuffer accu = new StringBuffer();
	accu.append('\n');
	for(HKXData data : member.getContentsList()) {
		HKXPointerMember subMember = (HKXPointerMember) data;
		String subMemberString = subMember.get();
		accu.append(subMemberString).append('\n');
	}
	memberNode.setTextContent(accu.toString());
}
 
Example 7
Source File: OrderParameter.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void saveValueToXML(Element xmlElement) {
  if (value == null)
    return;
  Document parentDocument = xmlElement.getOwnerDocument();
  for (ValueType item : value) {
    Element newElement = parentDocument.createElement("item");
    newElement.setTextContent(item.toString());
    xmlElement.appendChild(newElement);
  }
}
 
Example 8
Source File: PaymentServiceProviderBean.java    From development with Apache License 2.0 5 votes vote down vote up
private void appendAddressCriterion(Document doc,
        ChargingData chargingData, Element analysisNode) {
    Element addressCriterion = doc
            .createElement(HeidelpayXMLTags.XML_ANALYSIS_CRITERION);
    addressCriterion.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_NAME,
            HeidelpayXMLTags.XML_ANALYSIS_ADDRESS_COMPLETE);
    if (chargingData.getAddress() != null) {
        addressCriterion.setTextContent(chargingData.getAddress());
    }
    analysisNode.appendChild(addressCriterion);
}
 
Example 9
Source File: DirectoryParameter.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void saveValueToXML(final Element xmlElement) {

  if (value != null) {

    xmlElement.setTextContent(value.getPath());
  }
}
 
Example 10
Source File: ComboParameter.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void saveValueToXML(@Nonnull Element xmlElement) {
  Object value = getValue();
  if (value == null)
    return;
  xmlElement.setTextContent(value.toString());
}
 
Example 11
Source File: JunitReportGenerator.java    From lightning with MIT License 5 votes vote down vote up
private static void setCommonFailureData(Element element, LightningTest test) {
    String testType = test.type();
    String actualResultDescription = test.actualResultDescription();
    String testExecutionReport = test.getTestExecutionReport();

    element.setAttribute("type", testType);
    element.setAttribute("message", actualResultDescription);
    element.setTextContent(testExecutionReport);
}
 
Example 12
Source File: FragmentPutAddTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void addAttributeTest() throws XMLStreamException {
    String content = "<a/>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    Put request = new Put();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    Fragment fragment = new Fragment();
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
    expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_ADD);
    expression.getContent().add("/a");

    Document doc = DOMUtils.getEmptyDocument();
    Element addedAttr = doc.createElementNS(
            FragmentDialectConstants.FRAGMENT_2011_03_IRI,
            FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME
    );
    addedAttr.setAttributeNS(
            FragmentDialectConstants.FRAGMENT_2011_03_IRI,
            FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR,
            "foo"
    );
    addedAttr.setTextContent("1");
    ValueType value = new ValueType();
    value.getContent().add(addedAttr);
    fragment.setExpression(expression);
    fragment.setValue(value);
    request.getAny().add(fragment);

    PutResponse response = client.put(request);
    Element aEl = (Element) response.getRepresentation().getAny();
    String attribute = aEl.getAttribute("foo");
    Assert.assertEquals("1", attribute);

    resource.destroy();
}
 
Example 13
Source File: FolderEncryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Element createBase64EncryptedData(Document doc, String encryptedMessageString) {
   Element base64EncryptedData = doc.createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   Element cd = doc.createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "cd");
   cd.setAttribute("SV", "1.0");
   cd.setAttribute("S", "CD-ENCRYPTION-METHOD");
   cd.setTextContent("CMS");
   base64EncryptedData.appendChild(cd);
   Element base64EncryptedValue = doc.createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
   base64EncryptedValue.setTextContent(encryptedMessageString);
   base64EncryptedData.appendChild(base64EncryptedValue);
   return base64EncryptedData;
}
 
Example 14
Source File: SimpleCaptureDemo.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void addEventFieldExtension(ObjectEventType objEvent) {
	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
		Element elem = builder.newDocument().createElementNS("http://www.example.com/epcis/extensions/", "temperature");
		elem.setPrefix("xyz");
		elem.setTextContent("30");
		objEvent.getAny().add(elem);
	} catch (ParserConfigurationException e) {
		System.err.println("unable to construct the event field extension");
		e.printStackTrace();
	}
}
 
Example 15
Source File: DitaDocumentationGenerator.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
private void addDita(final ComponentDescription componentDescription, final DocumentBuilderFactory factory,
        final TransformerFactory transformerFactory, final ZipOutputStream zip,
        final Collection<String> directories) throws ParserConfigurationException {

    final String family = componentDescription.getFamily();
    final String name = componentDescription.getName();
    final String componentId = family + '-' + name;

    final DocumentBuilder builder = factory.newDocumentBuilder();
    final Document xml = builder.newDocument();

    final Element reference = xml.createElement("reference");
    reference.setAttribute("id", "connector_" + componentId);
    reference.setAttribute("id", "connector-" + family + '-' + name);
    reference
            .setAttribute("xml:lang",
                    ofNullable(getLocale().getLanguage()).filter(it -> !it.isEmpty()).orElse("en-us"));
    xml.appendChild(reference);

    final Element title = xml.createElement("title");
    title.setAttribute("id", "component_title_" + componentId);
    title.setTextContent(name + " parameters");
    reference.appendChild(title);

    final Element shortdesc = xml.createElement("shortdesc");
    shortdesc.setTextContent(componentDescription.getDocumentation().trim());
    reference.appendChild(shortdesc);

    final Element prolog = xml.createElement("prolog");
    final Element metadata = xml.createElement("metadata");

    final Element othermeta = xml.createElement("othermeta");
    othermeta.setAttribute("content", family);
    othermeta.setAttribute("name", "pageid");
    metadata.appendChild(othermeta);
    prolog.appendChild(metadata);
    reference.appendChild(prolog);

    final Element body = xml.createElement("refbody");
    body.setAttribute("outputclass", "subscription");

    Map<String, Map<String, List<Param>>> parametersWithUInfo2 = componentDescription.getParametersWithUInfo();

    generateConfigurationSection(xml, body, family, name, reference.getAttribute("id"),
            parametersWithUInfo2.get("datastore"), "connection");
    generateConfigurationSection(xml, body, family, name, reference.getAttribute("id"),
            parametersWithUInfo2.get("dataset"), "dataset");
    generateConfigurationSection(xml, body, family, name, reference.getAttribute("id"),
            parametersWithUInfo2.get(""), "other");

    reference.appendChild(body);

    final StringWriter writer = new StringWriter();
    final StreamResult result = new StreamResult(writer);
    try {
        final Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
        transformer.transform(new DOMSource(xml), result);

        final String rootDir = output.getName().replace(".zip", "");
        if (directories.add(rootDir)) {
            zip.putNextEntry(new ZipEntry(rootDir + '/'));
            zip.closeEntry();
        }
        final String ditaFolder = rootDir + '/' + family;
        if (directories.add(ditaFolder)) {
            zip.putNextEntry(new ZipEntry(ditaFolder + '/'));
            zip.closeEntry();
        }

        final String path = ditaFolder + '/' + name + ".dita";
        zip.putNextEntry(new ZipEntry(path));
        final String content = writer.toString();
        final int refIdx = content.indexOf("<reference");
        zip
                .write((content.substring(0, refIdx)
                        + "<!DOCTYPE reference PUBLIC \"-//Talend//DTD DITA Composite//EN\" \"TalendDitabase.dtd\">\n"
                        + content.substring(refIdx)).getBytes(StandardCharsets.UTF_8));
        zip.closeEntry();
    } catch (final IOException | TransformerException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 16
Source File: MCRTypeOfResource.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setInElement(Element element) {
    element.setTextContent(code);
}
 
Example 17
Source File: Config.java    From edslite with GNU General Public License v2.0 4 votes vote down vote up
private Element makeCfgElement(Document doc)
{
    Element cfgEl = doc.createElement("cfg");
    cfgEl.setAttribute("class_id", "0");
    cfgEl.setAttribute("tracking_level", "0");
    cfgEl.setAttribute("version", "20");

    Element el = doc.createElement("version");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_subVersion));

    el = doc.createElement("creator");
    cfgEl.appendChild(el);
    el.setTextContent(_creator);

    el = makeAlgInfoElement(doc, "cipherAlg", _dataCipher);
    cfgEl.appendChild(el);
    el.setAttribute("class_id", "1");
    el.setAttribute("tracking_level", "0");
    el.setAttribute("version", "0");

    el = makeAlgInfoElement(doc, "nameAlg", _nameCipher);
    cfgEl.appendChild(el);

    el = doc.createElement("keySize");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_keySizeBits));

    el = doc.createElement("blockSize");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_blockSize));

    el = doc.createElement("uniqueIV");
    cfgEl.appendChild(el);
    el.setTextContent(_uniqueIV ? "1" : "0");

    el = doc.createElement("chainedNameIV");
    cfgEl.appendChild(el);
    el.setTextContent(_chainedNameIV ? "1" : "0");

    el = doc.createElement("externalIVChaining");
    cfgEl.appendChild(el);
    el.setTextContent(_externalIVChaining ? "1" : "0");

    el = doc.createElement("blockMACBytes");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_blockMACBytes));

    el = doc.createElement("blockMACRandBytes");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_blockMACRandBytes));

    el = doc.createElement("allowHoles");
    cfgEl.appendChild(el);
    el.setTextContent(_allowHoles ? "1" : "0");

    el = doc.createElement("encodedKeySize");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_keyData.length));

    el = doc.createElement("encodedKeyData");
    cfgEl.appendChild(el);
    el.setTextContent(Base64.encodeToString(_keyData, Base64.DEFAULT));

    el = doc.createElement("saltLen");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_salt.length));

    el = doc.createElement("saltData");
    cfgEl.appendChild(el);
    el.setTextContent(Base64.encodeToString(_salt, Base64.DEFAULT));

    el = doc.createElement("kdfIterations");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_kdfIterations));

    el = doc.createElement("desiredKDFDuration");
    cfgEl.appendChild(el);
    el.setTextContent(String.valueOf(_desiredKDFDuration));

    return cfgEl;
}
 
Example 18
Source File: ConfigTests.java    From utah-parser with Apache License 2.0 4 votes vote down vote up
/**
 * Add a delimiter to the config node
 * @param delim the regex for the delim
 */
private Element addDelimiter(String delim) {
  Element newChild = addDelimiterElement();
  newChild.setTextContent(delim);
  return newChild;
}
 
Example 19
Source File: TraceabilityQueryService.java    From epcis with Apache License 2.0 4 votes vote down vote up
public String getReadPoint(String traceEPC, String traceTarget, String startTime, String endTime, Long fromTimeMil,
		Long toTimeMil, String orderDirection) {
	Document doc = createBaseQueryResults(traceEPC, traceTarget, startTime, endTime, orderDirection);

	// Time processing
	long startTimeMil = 0;
	startTimeMil = TimeUtil.getTimeMil(startTime);

	ChronoGraph g = Configuration.persistentGraph;

	ChronoVertex v = g.getChronoVertex(traceEPC);
	TreeMap<Long, ChronoVertex> timestampNeighbors = v.getTimestampNeighborVertices(Direction.OUT, "isLocatedIn",
			startTimeMil, AC.$gte);

	// outV : [ "t1", "t2", "t3", "t4" ];
	JSONObject retObj = new JSONObject();
	Iterator<Entry<Long, ChronoVertex>> iterator = timestampNeighbors.entrySet().iterator();
	Element readPointTrace = doc.createElement("readPointTrace");
	while (iterator.hasNext()) {
		Entry<Long, ChronoVertex> elem = iterator.next();
		Long time = elem.getKey();
		ChronoVertex neighbor = elem.getValue();

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		Element eventTime = doc.createElement("eventTime");
		Date date = new Date(time);
		String dateString = sdf.format(date);
		eventTime.setTextContent(dateString);
		Element readPoint = doc.createElement("readPoint");
		readPoint.setTextContent(neighbor.toString());
		Element readPointElement = doc.createElement("readPointElement");
		readPointElement.appendChild(eventTime);
		readPointElement.appendChild(readPoint);
		readPointTrace.appendChild(readPointElement);
		retObj.put(time.toString(), neighbor.toString());
	}

	Element resultsBody = doc.createElement("resultsBody");
	resultsBody.appendChild(readPointTrace);
	doc.getFirstChild().appendChild(resultsBody);

	return toString(doc);
}
 
Example 20
Source File: MassListParameter.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void saveValueToXML(Element xmlElement) {
  if (value == null)
    return;
  xmlElement.setTextContent(value);
}