Example usage for org.jdom2 Document addContent

List of usage examples for org.jdom2 Document addContent

Introduction

In this page you can find the example usage for org.jdom2 Document addContent.

Prototype

@Override
public Document addContent(Collection<? extends Content> c) 

Source Link

Document

Appends all children in the given collection to the end of the content list.

Usage

From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java

License:Apache License

/**
 * XML ?//from w  w  w . j av a  2s  . c o m
 * 
 * @param doc - document ?
 * @param newNodeName - Root 
 * @param list - Element 
 * @param path - ? XML 
 * @throws TransformerException
 * @throws TransformerConfigurationException
 * @throws FileNotFoundException
 */
public void createNewXML(Document doc, String newNodeName, List<?> list, String path)
        throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException {

    StreamResult sTResult = null;
    FileOutputStream fos = null;
    Element root = new Element(newNodeName);
    doc.addContent(root);
    createXML(root, list);

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer serializer = transformerFactory.newTransformer();

    serializer.setOutputProperty(OutputKeys.ENCODING, "euc-kr");
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");

    if (path != null) {
        fos = new FileOutputStream(path);
        sTResult = new StreamResult(fos);
        serializer.transform(new JDOMSource(doc), sTResult);
        fos.close();
    } else {
        fos = new FileOutputStream(savedPath + "newXML.xml");
        sTResult = new StreamResult(fos);
        serializer.transform(new JDOMSource(doc), sTResult);
        fos.close();
    }
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsChipSeq.java

License:Open Source License

public void exportToXML(File output) throws IOException {
    Document configurationFile = new Document();
    Comment comment = new Comment(COMMENT_CHIPSEQ);
    configurationFile.addContent(comment);

    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);

    Element bwaPath = new Element(BWA_PATH);
    bwaPath.addContent(this.getBwaPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(bwaPath);

    Element samtoolsPath = new Element(SAMTOOLS_PATH);
    samtoolsPath.addContent(this.getSamtoolsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(samtoolsPath);

    Element picardPath = new Element(PICARD_PATH);
    picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(picardPath);

    Element MACSPath = new Element(MACS_PATH);
    MACSPath.addContent(this.getMacsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(MACSPath);

    Element PythonPath = new Element(PYTHON_PATH);
    PythonPath.addContent(this.getPythonPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(PythonPath);

    Element BEDToolsPath = new Element(BED_TOOLS_PATH);
    BEDToolsPath.addContent(this.getBedtoolsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(BEDToolsPath);

    Element CCATPath = new Element(CCAT_PATH);
    CCATPath.addContent(this.getCcatPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(CCATPath);

    Element BedgraphtoWigPath = new Element(BGTW_PATH);
    BedgraphtoWigPath.addContent(this.getBedgraphtobigwigPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(BedgraphtoWigPath);

    Element IDRPath = new Element(IDR_PATH);
    IDRPath.addContent(this.getIdrPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(IDRPath);

    Element PeakAnnotatorPath = new Element(PEAKANNOTATOR_PATH);
    PeakAnnotatorPath.addContent(this.getPeakannotatorPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(PeakAnnotatorPath);

    Element fastqcPath = new Element(FASTQC_PATH);
    fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(fastqcPath);

    if (!this.getNthr().equals(nthr_DV)) {
        Element nthr = new Element(NTHR);
        nthr.addContent(String.valueOf(this.getNthr()));
        configurationFile.getRootElement().addContent(nthr);
    }/*from w  ww.j  ava 2s .c o m*/

    if (!this.getJavaRam().equals(javaRam_DV)) {
        Element javaRam = new Element(JAVA_RAM);
        javaRam.addContent(this.getJavaRam());
        configurationFile.getRootElement().addContent(javaRam);
    }

    Element queueSystem = new Element(QUEUE_SYSTEM);
    queueSystem.addContent(this.getQueueSystem().getDisplayName());
    configurationFile.getRootElement().addContent(queueSystem);

    if (!this.getQueueName().equals(queueName_DV)) {
        Element queueName = new Element(QUEUE_NAME);
        queueName.addContent(this.getQueueName());
        configurationFile.getRootElement().addContent(queueName);
    }

    if (!this.getMulticoreName().equals(multicoreName_DV)) {
        Element multicoreName = new Element(MULTICORE_NAME);
        multicoreName.addContent(this.getMulticoreName());
        configurationFile.getRootElement().addContent(multicoreName);
    }

    if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) {
        Element multicoreNumber = new Element(MULTICORE_NUMBER);
        multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber()));
        configurationFile.getRootElement().addContent(multicoreNumber);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
    //      xmlOutput.output(configurationFile, new FileWriter(new File(output.getAbsolutePath()+".test")));
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsCNV.java

License:Open Source License

public void exportToXML(File output) throws IOException {
    Document configurationFile = new Document();
    Comment comment = new Comment(COMMENT_VARIANT_CALLER);
    configurationFile.addContent(comment);

    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);

    Element bwaPath = new Element(BWA_PATH);
    bwaPath.addContent(this.getBwaPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(bwaPath);

    Element samtoolsPath = new Element(SAMTOOLS_PATH);
    samtoolsPath.addContent(this.getSamtoolsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(samtoolsPath);

    Element gatkpath = new Element(GATK_PATH);
    gatkpath.addContent(this.getGatkpath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(gatkpath);

    Element picardPath = new Element(PICARD_PATH);
    picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(picardPath);

    Element BFASTPath = new Element(BFAST_PATH);
    BFASTPath.addContent(this.getBfastPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(BFASTPath);

    Element BEDToolsPath = new Element(BED_TOOLS_PATH);
    BEDToolsPath.addContent(this.getBedtoolsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(BEDToolsPath);

    Element CONTRAPath = new Element(CONTRA_PATH);
    CONTRAPath.addContent(this.getContraPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(CONTRAPath);

    Element fastqcPath = new Element(FASTQC_PATH);
    fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(fastqcPath);

    if (!this.getNthr().equals(nthr_DV)) {
        Element nthr = new Element(NTHR);
        nthr.addContent(String.valueOf(this.getNthr()));
        configurationFile.getRootElement().addContent(nthr);
    }//from   www.  j  av a  2  s .c o m

    if (!this.getJavaRam().equals(javaRam_DV)) {
        Element javaRam = new Element(JAVA_RAM);
        javaRam.addContent(this.getJavaRam());
        configurationFile.getRootElement().addContent(javaRam);
    }

    Element queueSystem = new Element(QUEUE_SYSTEM);
    queueSystem.addContent(this.getQueueSystem().getDisplayName());
    configurationFile.getRootElement().addContent(queueSystem);

    if (!this.getQueueName().equals(queueName_DV)) {
        Element queueName = new Element(QUEUE_NAME);
        queueName.addContent(this.getQueueName());
        configurationFile.getRootElement().addContent(queueName);
    }

    if (!this.getMulticoreName().equals(multicoreName_DV)) {
        Element multicoreName = new Element(MULTICORE_NAME);
        multicoreName.addContent(this.getMulticoreName());
        configurationFile.getRootElement().addContent(multicoreName);
    }

    if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) {
        Element multicoreNumber = new Element(MULTICORE_NUMBER);
        multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber()));
        configurationFile.getRootElement().addContent(multicoreNumber);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsMethylation.java

License:Open Source License

public void exportToXML(File output) throws IOException {
    Document configurationFile = new Document();
    Comment comment = new Comment(COMMENT_METHYLATION);
    configurationFile.addContent(comment);

    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);

    Element bismarkPath = new Element(BISMARK_PATH);
    bismarkPath.addContent(this.getBismarkPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(bismarkPath);

    Element bowtiePath = new Element(BOWTIE_PATH);
    bowtiePath.addContent(this.getBowtiePath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(bowtiePath);

    Element picardPath = new Element(PICARD_PATH);
    picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(picardPath);

    Element BEDToolsPath = new Element(BED_TOOLS_PATH);
    BEDToolsPath.addContent(this.getBedtoolsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(BEDToolsPath);

    Element fastxPath = new Element(FASTX_PATH);
    fastxPath.addContent(this.getFastxPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(fastxPath);

    Element filoPath = new Element(FILO_PATH);
    filoPath.addContent(this.getFiloPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(filoPath);

    Element fastqcPath = new Element(FASTQC_PATH);
    fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(fastqcPath);

    if (!this.getNthr().equals(nthr_DV)) {
        Element nthr = new Element(NTHR);
        nthr.addContent(String.valueOf(this.getNthr()));
        configurationFile.getRootElement().addContent(nthr);
    }//  www  . ja  v  a2s.  c o m

    if (!this.getJavaRam().equals(javaRam_DV)) {
        Element javaRam = new Element(JAVA_RAM);
        javaRam.addContent(this.getJavaRam());
        configurationFile.getRootElement().addContent(javaRam);
    }

    Element queueSystem = new Element(QUEUE_SYSTEM);
    queueSystem.addContent(this.getQueueSystem().getDisplayName());
    configurationFile.getRootElement().addContent(queueSystem);

    if (!this.getQueueName().equals(queueName_DV)) {
        Element queueName = new Element(QUEUE_NAME);
        queueName.addContent(this.getQueueName());
        configurationFile.getRootElement().addContent(queueName);
    }

    if (!this.getMulticoreName().equals(multicoreName_DV)) {
        Element multicoreName = new Element(MULTICORE_NAME);
        multicoreName.addContent(this.getMulticoreName());
        configurationFile.getRootElement().addContent(multicoreName);
    }

    if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) {
        Element multicoreNumber = new Element(MULTICORE_NUMBER);
        multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber()));
        configurationFile.getRootElement().addContent(multicoreNumber);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsSNV.java

License:Open Source License

public void exportToXML(File output) throws IOException {
    Document configurationFile = new Document();
    Comment comment = new Comment(COMMENT_VARIANT_CALLER);
    configurationFile.addContent(comment);

    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);

    Element bwaPath = new Element(BWA_PATH);
    bwaPath.addContent(this.getBwaPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(bwaPath);

    Element samtoolsPath = new Element(SAMTOOLS_PATH);
    samtoolsPath.addContent(this.getSamtoolsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(samtoolsPath);

    Element gatkpath = new Element(GATK_PATH);
    gatkpath.addContent(this.getGatkpath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(gatkpath);

    Element picardPath = new Element(PICARD_PATH);
    picardPath.addContent(this.getPicardPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(picardPath);

    Element BFASTPath = new Element(BFAST_PATH);
    BFASTPath.addContent(this.getBfastPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(BFASTPath);

    Element fastqcPath = new Element(FASTQC_PATH);
    fastqcPath.addContent(this.getFastqcPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(fastqcPath);

    if (!this.getNthr().equals(nthr_DV)) {
        Element nthr = new Element(NTHR);
        nthr.addContent(String.valueOf(this.getNthr()));
        configurationFile.getRootElement().addContent(nthr);
    }/* ww w.  j a  va  2s .c  om*/

    if (!this.getJavaRam().equals(javaRam_DV)) {
        Element javaRam = new Element(JAVA_RAM);
        javaRam.addContent(this.getJavaRam());
        configurationFile.getRootElement().addContent(javaRam);
    }

    Element queueSystem = new Element(QUEUE_SYSTEM);
    queueSystem.addContent(this.getQueueSystem().getDisplayName());
    configurationFile.getRootElement().addContent(queueSystem);

    if (!this.getQueueName().equals(queueName_DV)) {
        Element queueName = new Element(QUEUE_NAME);
        queueName.addContent(this.getQueueName());
        configurationFile.getRootElement().addContent(queueName);
    }

    if (!this.getMulticoreName().equals(multicoreName_DV)) {
        Element multicoreName = new Element(MULTICORE_NAME);
        multicoreName.addContent(this.getMulticoreName());
        configurationFile.getRootElement().addContent(multicoreName);
    }

    if (!this.getMulticoreNumber().equals(multicoreNumber_DV)) {
        Element multicoreNumber = new Element(MULTICORE_NUMBER);
        multicoreNumber.addContent(String.valueOf(this.getMulticoreNumber()));
        configurationFile.getRootElement().addContent(multicoreNumber);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
}

From source file:lu.list.itis.dkd.assess.cloze.template.Template.java

License:Apache License

public Document getTemplateDocument() {
    Document doc = new Document();
    Element template = new Element("template");
    doc.addContent(template);

    template.addContent(metaData());/*w  ww .  j  a va 2s .  com*/
    template.addContent(layer());

    return doc;
}

From source file:lu.list.itis.dkd.assess.cloze.template.Template.java

License:Apache License

public void save(String path, String name) {
    Document doc = new Document();
    Element template = new Element("template");
    template.addContent(metaData());/*from   w w w .j  a v a  2 s.c  o m*/
    template.addContent(layer());
    doc.addContent(template);

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    try {
        xmlOutput.output(doc, new FileWriter(path + name + ".xml"));
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Problem saving template", e);
        e.printStackTrace();
    }

    logger.log(Level.INFO, "File saved to " + path + name + ".xml.");
}

From source file:org.commonjava.maven.ext.io.PomIO.java

License:Apache License

private void write(final Project project, final File pom, final Model model) throws ManipulationException {
    try {/*  w ww  .  j ava2  s.  c om*/
        final String manifestInformation = project.isInheritanceRoot() ? ManifestUtils.getManifestInformation()
                : null;

        MavenJDOMWriter mjw = new MavenJDOMWriter(model);

        // We possibly could store the EOL type in the Project when we first read
        // the file but we would then have to do a dual read, then write as opposed
        // to a read, then read + write now.
        LineSeparator ls = determineEOL(pom);
        mjw.setLineSeparator(ls);

        mjw.write(model, pom, new DocumentModifier() {
            @Override
            public void postProcess(final Document doc) {
                // Only add the modified by to the top level pom.
                if (project.isExecutionRoot()) {
                    final Iterator<Content> it = doc.getContent(new ContentFilter(ContentFilter.COMMENT))
                            .iterator();
                    while (it.hasNext()) {
                        final Comment c = (Comment) it.next();

                        if (c.toString().contains(MODIFIED_BY)) {
                            it.remove();
                        }
                    }

                    doc.addContent(Collections.<Content>singletonList(
                            new Comment("\nModified by POM Manipulation Extension for Maven "
                                    + manifestInformation + "\n")));
                }
            }
        });
    } catch (final IOException e) {
        throw new ManipulationException("Failed to read POM for rewrite: %s. Reason: %s", e, pom,
                e.getMessage());
    } catch (final JDOMException e) {
        throw new ManipulationException("Failed to parse POM for rewrite: %s. Reason: %s", e, pom,
                e.getMessage());
    }
}

From source file:org.isima.carsharing.launcher.Launcher.java

public static void addConfigComment(SettingsDelegate settingsDelegate, File out) {
    try {/*  w ww .j a  va  2 s.  co  m*/
        SAXBuilder builder = new SAXBuilder();

        Document doc = (Document) builder.build(out);
        Element rootNode = doc.getRootElement();
        Element rootNodeCopy = rootNode.clone();

        doc.removeContent(rootNode);
        rootNodeCopy.detach();

        Comment comment = new Comment(settingsDelegate.usedConfigsToXMLComment());
        doc.addContent(comment);
        doc.addContent(rootNodeCopy);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(out));
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.mycore.restapi.v1.MCRRestAPIMessages.java

License:Open Source License

/**
 * returns a single messages entry./*from  w w  w .ja  va  2  s.  c o m*/
 * 
 * @param info - a Jersey Context Object for URI
 * @param format 
 *     Possible values are: props (default) | json | xml (required)
 */
@GET
@Path("/{value}")
@Produces({ MediaType.TEXT_XML + ";charset=UTF-8", MediaType.APPLICATION_JSON + ";charset=UTF-8",
        MediaType.TEXT_PLAIN + ";charset=UTF-8" })
public Response getMessage(@Context UriInfo info, @PathParam("value") String key,
        @QueryParam("lang") @DefaultValue("de") String lang,
        @QueryParam("format") @DefaultValue("text") String format) {

    Locale locale = Locale.forLanguageTag(lang);
    String result = MCRTranslation.translate(key, locale);
    try {
        if (FORMAT_PROPERTY.equals(format)) {
            return Response.ok(key + "=" + result).type("text/plain; charset=ISO-8859-1").build();
        }
        if (FORMAT_XML.equals(format)) {
            Document doc = new Document();
            Element root = new Element("entry");
            root.setAttribute("key", key);
            root.setText(result);
            doc.addContent(root);
            StringWriter sw = new StringWriter();
            XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
            outputter.output(doc, sw);
            return Response.ok(sw.toString()).type("application/xml; charset=UTF-8").build();
        }
        if (FORMAT_JSON.equals(format)) {
            StringWriter sw = new StringWriter();
            JsonWriter writer = new JsonWriter(sw);
            writer.setIndent("    ");
            writer.beginObject();
            writer.name(key);
            writer.value(result);
            writer.endObject();
            writer.close();
            return Response.ok(sw.toString()).type("application/json; charset=UTF-8").build();
        }
        //text only
        return Response.ok(result).type("text/plain; charset=UTF-8").build();
    } catch (IOException e) {
        //toDo
    }
    return Response.status(Status.BAD_REQUEST).build();
}