Example usage for org.dom4j DocumentHelper createComment

List of usage examples for org.dom4j DocumentHelper createComment

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createComment.

Prototype

public static Comment createComment(String text) 

Source Link

Usage

From source file:io.mashin.oep.model.Workflow.java

License:Open Source License

@Override
public void write(org.dom4j.Element parent) {
    Document document = parent.getDocument();
    parent.detach();/* w  ww .  j  a v a2 s.c o m*/

    Element rootElement = document.addElement("workflow-app");
    Element graphicalInfoElement = DocumentHelper.createElement("workflow");

    XMLWriteUtils.writeWorkflowSchemaVersion(getSchemaVersion(), rootElement);
    XMLWriteUtils.writeSLAVersion(this, rootElement);
    XMLWriteUtils.writeTextPropertyAsAttribute(name, rootElement, "name");
    XMLWriteUtils.writePropertiesCollection(parameters, rootElement, "parameters", "property");
    XMLWriteUtils.writeGlobalProperty(global, rootElement);
    XMLWriteUtils.writeCredentialsCollection(credentials, rootElement);

    startNode.write(rootElement);
    for (Node node : nodes) {
        if (!(node.equals(startNode) || node.equals(endNode))) {
            node.write(rootElement);
        }
        graphicalInfoElement.addElement("node").addAttribute("name", node.getName())
                .addAttribute("x", node.getPosition().x + "").addAttribute("y", node.getPosition().y + "");
    }
    endNode.write(rootElement);

    XMLWriteUtils.writeSLAProperty(this, sla, rootElement);

    Comment graphicalInfoNode = null;
    try {
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
        writer.write(graphicalInfoElement);
        writer.flush();
        graphicalInfoNode = DocumentHelper.createComment(stringWriter.toString());
    } catch (Exception e) {
        graphicalInfoNode = DocumentHelper.createComment(graphicalInfoElement.asXML());
    }
    document.add(graphicalInfoNode);
}

From source file:net.unicon.toro.installer.tools.MergeConfiguration.java

License:Open Source License

private void addNode(Element source, Element replace, String xpath) {
    List list = replace.selectNodes("value");
    if (list == null)
        return;/* ww w  .  j  a  va2 s.com*/

    Element newContent = DocumentHelper.createElement("newContent");
    Comment prefixComment = DocumentHelper.createComment(CHANGE_START_COMMENT);
    Comment suffixComment = DocumentHelper.createComment(CHANGE_END_COMMENT);
    newContent.add(prefixComment);
    Iterator itr = list.iterator();
    while (itr.hasNext()) {
        Element value = (Element) itr.next();
        newContent.appendContent(value);
    }
    newContent.add(suffixComment);

    List sourceList = source.selectNodes(xpath);
    if (sourceList == null || sourceList.size() == 0) {
        throw new RuntimeException("xpath expression doesn't resolve to a node: " + xpath);
    }

    System.out.println("Xpath: " + xpath + " resolves to " + sourceList.size() + " nodes.");

    itr = sourceList.iterator();
    while (itr.hasNext()) {
        Element sourceEl = (Element) itr.next();
        System.out.println("Appending to xpath: " + sourceEl.getPath()); // + "newContent:\n" + newContent.asXML());
        sourceEl.appendContent(newContent);
    }
}