Example usage for org.w3c.dom Element setTextContent

List of usage examples for org.w3c.dom Element setTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element setTextContent.

Prototype

public void setTextContent(String textContent) throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:Main.java

public static Element generateMvnFailsafePlugin(Document document) {
    //generate plugin element
    Element plugin = document.createElement(PLUGIN_NAME);

    //generate groupId tag, add to plugin
    Element groupId = document.createElement(GROUPID_NAME);
    groupId.setTextContent("org.apache.maven.plugins");
    plugin.appendChild(groupId);/*from w w w .j ava 2  s .  c om*/

    //artifactId
    Element artifactId = document.createElement(ARTIFACTID_NAME);
    artifactId.setTextContent("maven-failsafe-plugin");
    plugin.appendChild(artifactId);

    //version
    Element version = document.createElement(VERSION_NAME);
    version.setTextContent("2.13");
    plugin.appendChild(version);

    //Executions
    Element executions = document.createElement(EXECUTIONS_NAME);
    plugin.appendChild(executions);

    //There are two Execute elements

    //Execute1
    Element execution1 = document.createElement(EXECUTION_NAME);
    executions.appendChild(execution1);
    //Its id
    Element id1 = document.createElement(ID_NAME);
    id1.setTextContent("integration-test");
    execution1.appendChild(id1);
    //Its goals
    Element goals1 = document.createElement(GOALS_NAME);
    execution1.appendChild(goals1);
    //The goals' goal
    Element goal1 = document.createElement(GOAL_NAME);
    goal1.setTextContent("integration-test");
    goals1.appendChild(goal1);

    //Execute2
    Element execution2 = document.createElement(EXECUTION_NAME);
    executions.appendChild(execution2);
    //Its id
    Element id2 = document.createElement(ID_NAME);
    id2.setTextContent("verify");
    execution2.appendChild(id2);
    //Its goals
    Element goals2 = document.createElement(GOALS_NAME);
    execution2.appendChild(goals2);
    //The goals' goal
    Element goal2 = document.createElement(GOAL_NAME);
    goal2.setTextContent("verify");
    goals2.appendChild(goal2);

    return plugin;
}

From source file:Main.java

static void initializeXMLReport(int numThreads, int experiment, int sampleInterval, String managerClassName,
        String benchmarkClassName, String adapterClassName) {
    try {//  w w w.j a v a2  s .  com
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        doc = builder.newDocument();

        Element root = doc.createElement("Statistics");
        doc.appendChild(root);

        Element element = doc.createElement("Benchmark");
        element.setTextContent(benchmarkClassName);
        root.appendChild(element);

        element = doc.createElement("Adapter");
        element.setTextContent(adapterClassName);
        root.appendChild(element);

        element = doc.createElement("ContentionManager");
        element.setTextContent(managerClassName);
        root.appendChild(element);

        element = doc.createElement("Threads");
        element.setTextContent(Integer.toString(numThreads));
        root.appendChild(element);

        element = doc.createElement("Mix");
        element.setTextContent(Integer.toString(experiment));
        root.appendChild(element);

        element = doc.createElement("SampleInterval");
        element.setTextContent(Long.toString(sampleInterval));
        root.appendChild(element);

        String name = System.getProperty("user.name");
        if (name == null)
            name = "";
        element = doc.createElement("Owner");
        element.setTextContent(name);
        root.appendChild(element);

        java.util.Calendar cal = java.util.Calendar.getInstance(java.util.TimeZone.getDefault());
        String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
        sdf.setTimeZone(java.util.TimeZone.getDefault());
        element = doc.createElement("Date");
        element.setTextContent(sdf.format(cal.getTime()));
        root.appendChild(element);

    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:com.sonar.maven.it.ItUtils.java

/**
 * Creates a settings xml with a sonar profile, containing all the given properties
 * Also adds repox to continue to use QAed artifacts 
 *///w  ww .  j  ava  2 s  . co  m
public static String createSettingsXml(Map<String, String> props) throws Exception {
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = docBuilder.newDocument();

    Element settings = doc.createElement("settings");
    Element profiles = doc.createElement("profiles");
    Element profile = doc.createElement("profile");

    Element id = doc.createElement("id");
    id.setTextContent("sonar");

    Element properties = doc.createElement("properties");

    for (Map.Entry<String, String> e : props.entrySet()) {
        Element el = doc.createElement(e.getKey());
        el.setTextContent(e.getValue());
        properties.appendChild(el);
    }

    profile.appendChild(id);
    profile.appendChild(properties);
    profile.appendChild(createRepositories(doc));
    profile.appendChild(createPluginRepositories(doc));

    profiles.appendChild(profile);
    settings.appendChild(profiles);
    doc.appendChild(settings);

    Writer writer = new StringWriter();
    Transformer tf = TransformerFactory.newInstance().newTransformer();
    tf.transform(new DOMSource(doc), new StreamResult(writer));
    return writer.toString();
}

From source file:com.thinkbiganalytics.feedmgr.nifi.NifiTemplateParser.java

public static String updateTemplateName(String nifiTemplate, String newName) throws Exception {

    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    Document doc = stringToDocument(nifiTemplate);

    InputSource source = new InputSource(new StringReader(nifiTemplate));

    Element element = (Element) xpath.compile("//template/name").evaluate(doc, XPathConstants.NODE);

    element.setTextContent(newName);
    return documentToString(doc);
}

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlBuilder.java

private static Element buildAttribute(Document doc, String attributeName, String attributeValue) {
    Element attribute = doc.createElement(ENTRY_ATTRIBUTE_NODE);
    attribute.setAttribute(ENTRY_QUALIFIEDNAME, attributeName);
    Element value = doc.createElement(ENTRY_ATTRIBUTE_VALUE);
    value.setTextContent(attributeValue);
    attribute.appendChild(value);//  w w  w  .  jav  a2  s .c  o  m
    return attribute;
}

From source file:com.sonar.maven.it.ItUtils.java

private static Element createRepositories(Document doc) {
    Element repositories = doc.createElement("repositories");
    Element repository = doc.createElement("repository");
    Element id = doc.createElement("id");
    Element url = doc.createElement("url");

    id.setTextContent("sonarsource");
    url.setTextContent("https://repox.sonarsource.com/sonarsource");

    repositories.appendChild(repository);
    repository.appendChild(id);/*from  www.  j  a v a 2 s  .  co  m*/
    repository.appendChild(url);

    return repositories;
}

From source file:com.sonar.maven.it.ItUtils.java

private static Element createPluginRepositories(Document doc) {
    Element repositories = doc.createElement("pluginRepositories");
    Element repository = doc.createElement("pluginRepository");
    Element id = doc.createElement("id");
    Element url = doc.createElement("url");

    id.setTextContent("sonarsource");
    url.setTextContent("https://repox.sonarsource.com/sonarsource");

    repositories.appendChild(repository);
    repository.appendChild(id);/*from   ww w .j  a va  2s  . c  om*/
    repository.appendChild(url);

    return repositories;
}

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlBuilder.java

private static Element buildAttributeCollection(Document doc, String localName, Collection<?> values) {
    Element attribute = doc.createElement(ENTRY_ATTRIBUTE_NODE);
    attribute.setAttribute(ENTRY_QUALIFIEDNAME, localName);
    for (Object value : values) {
        Element valueElement = doc.createElement(ENTRY_ATTRIBUTE_VALUE);
        valueElement.setTextContent(value.toString());
        attribute.appendChild(valueElement);
    }/*from w w  w .  j a  va2s .c om*/
    return attribute;
}

From source file:Main.java

public static Element clear(Element node, String subElement) {
    Element child = findFirst(node, subElement);
    if (child == null) {
        child = node.getOwnerDocument().createElement(subElement);
        node.appendChild(child);/*w  w w.j av  a2s.  com*/
    }
    child.setTextContent(null); // remove all descendants
    return child;
}

From source file:Main.java

public static void appendStringElement(Element parentElement, String nodeName, String nodeValue) {
    // check for exists
    Element elem = selectSingleElement(parentElement, nodeName);

    if (elem == null) {
        elem = parentElement.getOwnerDocument().createElement(nodeName);
        parentElement.appendChild(elem);
    }/* ww  w. j ava  2  s  . co m*/

    elem.setTextContent(nodeValue);
}