Example usage for org.dom4j.io XMLWriter close

List of usage examples for org.dom4j.io XMLWriter close

Introduction

In this page you can find the example usage for org.dom4j.io XMLWriter close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the underlying Writer

Usage

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

License:Apache License

@TaskAction
protected void generateClasspath() {
    File eclipseClasspathFile = getProject().file(CLASSPATH_FILE_NAME);

    backupOldClasspathFile(eclipseClasspathFile);

    try {//www  . ja  va2 s. c o m
        XMLWriter writer = new XMLWriter(new FileWriter(eclipseClasspathFile),
                OutputFormat.createPrettyPrint());
        writer.write(createXmlDocument());
        writer.close();
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }

}

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

License:Apache License

@TaskAction
protected void generateProject() {
    File projectFile = getProject().file(PROJECT_FILE_NAME);
    try {/*  w w  w. j  a v a 2 s.  c o m*/
        XMLWriter writer = new XMLWriter(new FileWriter(projectFile), OutputFormat.createPrettyPrint());
        writer.write(createXmlDocument());
        writer.close();

    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

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

License:Apache License

@TaskAction
protected void generateWtp() {
    File wtpFile = getProject().file(WTP_FILE_DIR + "/" + WTP_FILE_NAME);
    if (wtpFile.exists()) {
        wtpFile.delete();//  w  w  w .  j  a  v a  2 s.com
    }
    if (!wtpFile.getParentFile().exists()) {
        wtpFile.getParentFile().mkdirs();
    }
    try {
        XMLWriter writer = new XMLWriter(new FileWriter(wtpFile), OutputFormat.createPrettyPrint());
        writer.write(createXmlDocument());
        writer.close();

        createFacets(getProject());
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

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

License:Apache License

private void createFacets(Project project) {
    Document document = DocumentFactory.getInstance().createDocument();

    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.java"));
    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.web"));

    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.java"),
            new DefaultAttribute("version", "5.0"));
    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.web"),
            new DefaultAttribute("version", "2.4"));

    try {//from   w  ww  . ja  v  a 2 s  .  c  om
        File facetFile = project.file(".settings/org.eclipse.wst.common.project.facet.core.xml");
        if (facetFile.exists()) {
            facetFile.delete();
        }
        if (!facetFile.getParentFile().exists()) {
            facetFile.getParentFile().mkdirs();
        }
        XMLWriter writer = new XMLWriter(new FileWriter(facetFile), OutputFormat.createPrettyPrint());
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

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

License:Apache License

@TaskAction
protected void generateWtpModule() {
    File wtpFile = getProject().file(EclipseWtp.WTP_FILE_DIR + "/" + EclipseWtp.WTP_FILE_NAME);
    if (wtpFile.exists()) {
        wtpFile.delete();//from www.  j  a va 2 s  . c o m
    }
    if (!wtpFile.getParentFile().exists()) {
        wtpFile.getParentFile().mkdirs();
    }
    try {
        XMLWriter writer = new XMLWriter(new FileWriter(wtpFile), OutputFormat.createPrettyPrint());
        writer.write(createXmlDocument());
        writer.close();

        createFacets(getProject());
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

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

License:Apache License

private void createFacets(Project project) {
    Document document = DocumentFactory.getInstance().createDocument();

    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.java"));
    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.utility"));

    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.java"),
            new DefaultAttribute("version", "5.0"));
    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.utility"),
            new DefaultAttribute("version", "1.0"));

    try {/*from   w w w .  java 2 s  .c  o  m*/
        File facetFile = project.file(".settings/org.eclipse.wst.common.project.facet.core.xml");
        if (facetFile.exists()) {
            facetFile.delete();
        }
        if (!facetFile.getParentFile().exists()) {
            facetFile.getParentFile().mkdirs();
        }
        XMLWriter writer = new XMLWriter(new FileWriter(facetFile), OutputFormat.createPrettyPrint());
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

From source file:org.hibernatespatial.pojo.MappingsGenerator.java

License:Open Source License

public void write(Writer writer) throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter xmlWriter = new XMLWriter(writer, format);
    xmlWriter.write(this.mappingDoc);
    xmlWriter.close();
}

From source file:org.hightides.annotations.util.SpringXMLUtil.java

License:Apache License

/**
 * Private helper to save XML document.//ww w  .  j  a  v  a  2 s  .  co  m
 * @param filename
 * @param doc
 * @param backup
 * @return
 */
private static boolean saveXMLDocument(String filename, Document doc, boolean backup) {
    // copy the target to backup folder
    if (backup)
        FileUtil.backupFile(filename);

    // overwrite the target
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setExpandEmptyElements(false);
    format.setIndentSize(4);
    format.setNewLineAfterDeclaration(true);
    XMLWriter out;
    try {
        out = new XMLWriter(new FileWriter(filename), format);
        out.write(doc);
        out.flush();
        out.close();
        return true;
    } catch (IOException e) {
        _log.info("Failed to write to output filename [" + filename + "]", e);
        return false;
    }
}

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);
    }/*from  w  ww .j av a 2s . co 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.util.dom.DOMBuilder.java

License:Open Source License

/**
 * This method writes a document to file.
 *//*w  w w . ja  v a  2 s.  c  o  m*/

public void write(Document document, String fileName) throws Exception {
    OutputFormat format = OutputFormat.createCompactFormat();
    format.setEncoding("UTF-8");
    XMLWriter writer = new XMLWriter(new FileWriter(fileName), format);
    writer.write(document);
    writer.close();
}