Example usage for org.dom4j Document addElement

List of usage examples for org.dom4j Document addElement

Introduction

In this page you can find the example usage for org.dom4j Document addElement.

Prototype

Element addElement(String name);

Source Link

Document

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Usage

From source file:eu.planets_project.pp.plato.services.characterisation.xcl.Comparator.java

License:Open Source License

/**
 * Generates a PCR for all <param>mappedProperties</param> and their metrics.
 * Note: All possible metrics are included.
 * /*from  w w  w .  j a v  a2  s  .co m*/
 * @param mappedProperties
 * @return
 */
private String generateConfig(Set<XCLObjectProperty> mappedProperties) {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("pcRequest");

    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.add(xsi);
    root.addAttribute(xsi.getPrefix() + ":schemaLocation",
            "http://www.planets-project.eu/xcl/schemas/xcl data/pp5/schemas/pcr/pcr.xsd");
    Namespace xcl = new Namespace("", "http://www.planets-project.eu/xcl/schemas/xcl");
    root.add(xcl);
    Element compSet = root.addElement("compSet", xcl.getURI());
    compSet.addElement("source").addAttribute("name", "samplerecord");
    compSet.addElement("target").addAttribute("name", "experimentresult");
    /*
             Element root = doc.addElement("plans");
            Namespace xsi = new Namespace("xsi",  "http://www.w3.org/2001/XMLSchema-instance");
            
            root.add(xsi);
            root.addAttribute(xsi.getPrefix()+":noNamespaceSchemaLocation", "http://www.ifs.tuwien.ac.at/dp/plato/schemas/plato-1.9.xsd");
            
     */
    for (XCLObjectProperty objectProperty : mappedProperties) {
        Element prop = compSet.addElement("property").addAttribute("id", objectProperty.getPropertyId())
                .addAttribute("name", objectProperty.getName());
        for (Metric metric : objectProperty.getMetrics()) {
            prop.addElement("metric").addAttribute("id", metric.getMetricId()).addAttribute("name",
                    metric.getName());
        }
    }
    return doc.asXML();
}

From source file:eu.planets_project.pp.plato.xml.LibraryExport.java

License:Open Source License

public Document exportToDocument(LibraryTree lib) {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("library");

    root.add(xsi);/* ww w.jav a 2  s  .c  om*/
    root.add(platoLibNS);
    //        root.addAttribute(xsi.getPrefix()+":schemaLocation", "http://www.planets-project.eu/plato plato-2.1.xsd");
    //        root.addAttribute(xsi.getPrefix()+":noNamespaceSchemaLocation", "http://www.ifs.tuwien.ac.at/dp/plato/schemas/plato-2.1.xsd");
    root.addAttribute("name", lib.getName());

    Element rootReq = root.addElement(new QName("requirement", platoLibNS));
    addRequirementProperties(rootReq, lib.getRoot());

    return doc;

}

From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java

License:Open Source License

public Document createProjectDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("plans");

    root.add(xsi);/*from  w  w  w . ja  v  a  2s .c  o m*/
    root.add(platoNS);
    root.addAttribute(xsi.getPrefix() + ":schemaLocation", "http://www.planets-project.eu/plato plato-3.0.xsd");

    root.add(excutablePlanNS);
    root.add(new Namespace("fits", "http://hul.harvard.edu/ois/xml/ns/fits/fits_output"));

    // set version of corresponding schema
    root.addAttribute("version", "3.0.0");

    return doc;
}

From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java

License:Open Source License

public Document createTemplateDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("templates");

    root.add(xsi);/*from  w w w . ja  v a 2s .co m*/

    return doc;
}

From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java

License:Open Source License

public Document exportTemplates(List<TemplateTree> trees) {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("templates");

    for (TemplateTree template : trees) {
        addTemplateTree(template, root);
    }/*from ww w . jav  a 2  s . co m*/
    return doc;
}

From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java

License:Open Source License

public String exportTreeToFreemind(TreeNode treeRoot) {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("map");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    root.add(xsi);/*from   ww  w  .  java2  s  .  c  o m*/
    root.addAttribute("version", "0.8.1");

    root.addComment(
            "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");
    addSubTreeFreemind(root, treeRoot);

    String xml = doc.asXML();
    //PlatoLogger.getLogger(ProjectExporter.class).debug(arg0)
    return xml;
}

From source file:eu.scape_project.planning.criteria.bean.CriteriaHierarchyHelperBean.java

License:Apache License

/**
 * A function which exports all current criteria into a freemind xml string.
 * Used to ease creation of criteria-hierarchies (manual this is a hard
 * job)./*from  ww w .  ja va 2  s .  c  o m*/
 * 
 * @return the criteria as XML string
 */
private String exportAllCriteriaToFreeMindXml() {
    Document doc = DocumentHelper.createDocument();
    doc.setXMLEncoding("UTF-8");

    Element root = doc.addElement("map");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    root.add(xsi);
    root.addAttribute("version", "0.8.1");

    root.addComment(
            "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");

    Element baseNode = root.addElement("node");
    baseNode.addAttribute("TEXT", "allCriteria");

    Collection<Measure> allCriteria = criteriaManager.getAllMeasures();
    ArrayList<Measure> allCriteriaSortable = new ArrayList<Measure>(allCriteria);
    Collections.sort(allCriteriaSortable);
    allCriteria = allCriteriaSortable;

    // each criterion should be added as simple node
    for (Measure measure : allCriteria) {
        // construct node text
        String nodeText = measure.getAttribute().getName() + "#" + measure.getName() + "|" + measure.getUri();

        // add node
        Element node = baseNode.addElement("node");
        node.addAttribute("TEXT", nodeText);
    }

    String xml = doc.asXML();
    return xml;
}

From source file:eu.scape_project.planning.criteria.xml.CriteriaHierarchyExporter.java

License:Apache License

/**
 * Method responsible for exporting a CriteriaHierarchy-TreeNode to freemind-xml format.
 * // ww w. j a v  a  2 s . c om
 * @param criteriaTreeNode CriteriaHierarchy-Treenode to export
 * @return freemind-xml String.
 */
private String exportToFreemindXml(CriteriaTreeNode criteriaTreeNode) {
    Document doc = DocumentHelper.createDocument();
    doc.setXMLEncoding("UTF-8");

    Element root = doc.addElement("map");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    root.add(xsi);
    root.addAttribute("version", "0.8.1");

    root.addComment(
            "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");
    addSubTreeFreemind(root, criteriaTreeNode);

    String xml = doc.asXML();

    return xml;
}

From source file:eu.scape_project.planning.xml.PreservationActionPlanGenerator.java

License:Apache License

/**
 * Creates a document for the preservation action plan.
 * //w  ww  .  j  av  a2 s  .c  o m
 * @return the document
 */
private Document createPapDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement(new QName("preservationActionPlan", platoNS));

    root.add(xsi);
    root.add(platoNS);
    root.addAttribute(xsi.getPrefix() + ":schemaLocation",
            PlanXMLConstants.PLATO_NS + " " + PlanXMLConstants.PAP_SCHEMA);

    // Set version of corresponding schema
    root.addAttribute("version", "1.0");

    return doc;
}

From source file:eu.scape_project.planning.xml.ProjectExporter.java

License:Apache License

/**
 * Creates a dom4j document template to add plans.
 * //from   www . j  av a  2 s .  c o m
 * @return the dom4j document
 */
public Document createProjectDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("plans");

    root.add(XSI_NAMESPACE);
    root.add(PLATO_NAMESPACE);
    root.addAttribute(XSI_NAMESPACE.getPrefix() + ":schemaLocation",
            PlanXMLConstants.PLATO_NS + " " + PlanXMLConstants.PLATO_SCHEMA);
    root.add(new Namespace("fits", "http://hul.harvard.edu/ois/xml/ns/fits/fits_output"));

    // set version of corresponding schema
    root.addAttribute("version", PlanXMLConstants.PLATO_SCHEMA_VERSION);

    return doc;
}