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:org.gradle.api.tasks.ide.eclipse.EclipseWtp.java

License:Apache License

private Document createXmlDocument() {
    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement("project-modules").addAttribute("id", "moduleCoreId")
            .addAttribute("project-version", "1.5.0");
    Element wbModule = root.addElement("wb-module").addAttribute("deploy-name", getDeployName().toString());
    wbModule.addElement("property").addAttribute("name", "context-root").addAttribute("value",
            getDeployName().toString());
    addResourceMappings(wbModule);//from w w  w  .j  a  va 2  s .  co m
    wbModule.addElement("property").addAttribute("name", "java-output-path").addAttribute("value",
            relativePath(getOutputDirectory()));
    addLibs(wbModule);
    addDependsOnProjects(wbModule);
    return document;
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseWtpModule.java

License:Apache License

private Document createXmlDocument() {
    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement("project-modules").addAttribute("id", "moduleCoreId")
            .addAttribute("project-version", "1.5.0");
    Element wbModule = root.addElement("wb-module").addAttribute("deploy-name", getProject().getName());
    addResourceMappings(wbModule);//from  w  w  w  .j a  v a  2s  .  c o  m
    return document;
}

From source file:org.gradle.gradleplugin.foundation.DOM4JSerializer.java

License:Apache License

/**
 * Call this to save the JDOMSerializable to a file. This handles confirming overwriting an existing file as well as ensuring the extension is correct based on the passed in fileFilter.
 *///from   w w  w.  j ava  2 s .  c  o m
public static void exportToFile(String rootElementTag, ExportInteraction exportInteraction,
        ExtensionFileFilter fileFilter, SettingsSerializable... serializables) {
    File file = promptForFile(exportInteraction, fileFilter);
    if (file == null) {
        //the user canceled.
        return;
    }

    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        LOGGER.error("Could not write to file: " + file.getAbsolutePath(), e);
        exportInteraction.reportError("Could not write to file: " + file.getAbsolutePath());
        return;
    }

    try {
        XMLWriter xmlWriter = new XMLWriter(fileOutputStream, OutputFormat.createPrettyPrint());

        Document document = DocumentHelper.createDocument();
        Element rootElement = document.addElement(rootElementTag);
        DOM4JSettingsNode settingsNode = new DOM4JSettingsNode(rootElement);
        for (int index = 0; index < serializables.length; index++) {
            SettingsSerializable serializable = serializables[index];
            try { //don't let a single serializer stop the entire thing from being written in.
                serializable.serializeOut(settingsNode);
            } catch (Exception e) {
                LOGGER.error("serializing", e);
            }
        }
        xmlWriter.write(document);
    } catch (Throwable t) {
        LOGGER.error("Failed to save", t);
        exportInteraction.reportError("Internal error. Failed to save.");
    } finally {
        closeQuietly(fileOutputStream);
    }
}

From source file:org.gradle.gradleplugin.foundation.DOM4JSerializer.java

License:Apache License

public static DOM4JSettingsNode createBlankSettings() {
    Document document = DocumentHelper.createDocument();
    Element rootElement = document.addElement("root");
    DOM4JSettingsNode settings = new DOM4JSettingsNode(rootElement);
    return settings;
}

From source file:org.hibernate.envers.configuration.internal.metadata.MetadataTools.java

License:LGPL

private static Element createEntityCommon(Document document, String type, AuditTableData auditTableData,
        String discriminatorValue, Boolean isAbstract) {
    final Element hibernateMapping = document.addElement("hibernate-mapping");
    hibernateMapping.addAttribute("auto-import", "false");

    final Element classMapping = hibernateMapping.addElement(type);

    if (auditTableData.getAuditEntityName() != null) {
        classMapping.addAttribute("entity-name", auditTableData.getAuditEntityName());
    }/*from   www .j av a 2 s .c om*/

    if (discriminatorValue != null) {
        classMapping.addAttribute("discriminator-value", discriminatorValue);
    }

    if (!StringTools.isEmpty(auditTableData.getAuditTableName())) {
        classMapping.addAttribute("table", auditTableData.getAuditTableName());
    }

    if (!StringTools.isEmpty(auditTableData.getSchema())) {
        classMapping.addAttribute("schema", auditTableData.getSchema());
    }

    if (!StringTools.isEmpty(auditTableData.getCatalog())) {
        classMapping.addAttribute("catalog", auditTableData.getCatalog());
    }

    if (isAbstract != null) {
        classMapping.addAttribute("abstract", isAbstract.toString());
    }

    return classMapping;
}

From source file:org.hibernate.envers.configuration.internal.RevisionInfoConfiguration.java

License:LGPL

private Element generateRevisionInfoRelationMapping() {
    final Document document = XMLHelper.getDocumentFactory().createDocument();
    final Element revRelMapping = document.addElement("key-many-to-one");
    revRelMapping.addAttribute("type", revisionPropType);
    revRelMapping.addAttribute("class", revisionInfoEntityName);

    if (revisionPropSqlType != null) {
        // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
        MetadataTools.addColumn(revRelMapping, "*", null, null, null, revisionPropSqlType, null, null, false);
    }/* w w w.j  av a  2  s.com*/

    return revRelMapping;
}

From source file:org.hibernate.envers.configuration.metadata.MetadataTools.java

License:Open Source License

private static Element createEntityCommon(Document document, String type, AuditTableData auditTableData,
        String discriminatorValue) {
    Element hibernate_mapping = document.addElement("hibernate-mapping");
    hibernate_mapping.addAttribute("auto-import", "false");

    Element class_mapping = hibernate_mapping.addElement(type);

    if (auditTableData.getAuditEntityName() != null) {
        class_mapping.addAttribute("entity-name", auditTableData.getAuditEntityName());
    }// ww w.  ja  v a  2s.c o m

    if (discriminatorValue != null) {
        class_mapping.addAttribute("discriminator-value", discriminatorValue);
    }

    if (!StringTools.isEmpty(auditTableData.getAuditTableName())) {
        class_mapping.addAttribute("table", auditTableData.getAuditTableName());
    }

    if (!StringTools.isEmpty(auditTableData.getSchema())) {
        class_mapping.addAttribute("schema", auditTableData.getSchema());
    }

    if (!StringTools.isEmpty(auditTableData.getCatalog())) {
        class_mapping.addAttribute("catalog", auditTableData.getCatalog());
    }

    return class_mapping;
}

From source file:org.hibernate.envers.configuration.RevisionInfoConfiguration.java

License:Open Source License

private Element generateRevisionInfoRelationMapping() {
    Document document = DocumentHelper.createDocument();
    Element rev_rel_mapping = document.addElement("key-many-to-one");
    rev_rel_mapping.addAttribute("type", revisionPropType);
    rev_rel_mapping.addAttribute("class", revisionInfoEntityName);

    if (revisionPropSqlType != null) {
        // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
        MetadataTools.addColumn(rev_rel_mapping, "*", null, 0, 0, revisionPropSqlType);
    }//from   w  ww.j a  va 2s  . com

    return rev_rel_mapping;
}

From source file:org.hudsonci.utils.team.TeamManager.java

License:Open Source License

public void writeTeamsXml(File file) throws IOException {
    Document outDoc = DocumentHelper.createDocument();
    Element root = outDoc.addElement("teamManager");
    for (String admin : sysAdmins) {
        Team.addTextElement(root, "sysAdmin", admin);
    }/*ww w.  j a  va  2  s.c o m*/
    for (Team team : teamMap.values()) {
        Element teamElement = root.addElement("team");
        team.write(teamElement);
    }
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(file), format);
    try {
        writer.write(outDoc);
    } finally {
        writer.close();
    }
}

From source file:org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction.java

License:Open Source License

public String doApplicationSettings() throws Exception {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("applicationSettings");
    Properties props = CmsPropertyHandler.getProperties();
    for (Iterator i = props.keySet().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String elmKey = key;//from   w  w  w .  j  a  v  a2  s  .co m
        if (key.matches("^\\d.*"))
            elmKey = "_" + key;
        String value = (String) props.get(key);
        if (!isProtectedProperty(key))
            root.addElement(elmKey).setText(value);
    }

    root.addElement("serviceRevision").setText(SERVICEREVISION);
    return out(getFormattedDocument(doc));
}