Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

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

Prototype

public Document() 

Source Link

Document

Creates a new empty document.

Usage

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.SingleNucleotideVariantExperiment.java

License:Open Source License

public void generateXMLConfigurationFile(File output) throws IOException {
    Document configurationFile = new Document();
    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);
    configData.setAttribute(ExperimentUtils.BRANCH, ExperimentUtils.BRANCH_SNV);

    Element genRef = new Element(GENREF);
    genRef.addContent(this.getGenRefPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(genRef);

    Element dbSnpAnnot = new Element(DBSNPANNOT);
    dbSnpAnnot.addContent(this.getDbSnpAnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dbSnpAnnot);

    Element genomes1000Annot = new Element(GENOMES1000ANNOT);
    genomes1000Annot.addContent(this.getGenomes1000AnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(genomes1000Annot);

    Element indelAnnot = new Element(INDELANNOT);
    indelAnnot.addContent(this.getIndelAnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(indelAnnot);

    if (this.getIntervalsPath() != getIntervalsPath_DV()) {
        Element intervals = new Element(INTERVALS);
        intervals.addContent(this.getIntervalsPath().getFile().getAbsolutePath());
        configurationFile.getRootElement().addContent(intervals);
    }/*from ww w .j  a v  a  2  s.  co m*/

    if (this.getKnownIndels().size() > 0) {
        for (KnownIndels kI : this.getKnownIndels()) {
            Element knownIndels = new Element(KNOWNINDELS);
            knownIndels.addContent(kI.getFile().getFile().getAbsolutePath());
            configurationFile.getRootElement().addContent(knownIndels);
        }
    }

    Element plattform = new Element(PLATTFORM);
    plattform.addContent(this.getPlattform().getDisplayName());
    configurationFile.getRootElement().addContent(plattform);

    if (!this.getCheckCasava().equals(checkCasava_DV)) {
        Element checkCasava = new Element(CHECKCASAVA);
        checkCasava.addContent(this.getCheckCasava().toString());
        configurationFile.getRootElement().addContent(checkCasava);
    }

    Element dirOutBase = new Element(DIROUTBASE);
    dirOutBase.addContent(this.getDirOutBase().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dirOutBase);

    Element projectId = new Element(PROJECTID);
    projectId.addContent(this.getProjectId());
    configurationFile.getRootElement().addContent(projectId);

    if (!this.getUserName().equals(userName_DV)) {
        Element userName = new Element(USERNAME);
        userName.addContent(this.getUserName());
        configurationFile.getRootElement().addContent(userName);
    }

    Element dataInDirpreProcess = new Element(INDIRPREPROCESS);
    dataInDirpreProcess.addContent(this.getDataInDirpreProcess().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dataInDirpreProcess);

    for (Sample s : this.getSamples()) {
        Element sample = new Element(SAMPLE);

        Element sampleName = new Element(SAMPLE_NAME);
        sampleName.addContent(s.getSampleName());
        sample.addContent(sampleName);

        Element sampleFiles = new Element(SAMPLE_FILES);
        sampleFiles.addContent(s.getSampleFiles());
        sample.addContent(sampleFiles);

        Element sampleSuffix = new Element(SAMPLE_SUFFIX);
        sampleSuffix.addContent(s.getSampleSuffix());
        sample.addContent(sampleSuffix);

        Element sampleType = new Element(SAMPLE_TYPE);
        sampleType.addContent(s.getSampleType().getDisplayName());
        sample.addContent(sampleType);

        configurationFile.getRootElement().addContent(sample);
    }

    if (!this.getCallingType().equals(callingType_DV)) {
        Element callingType = new Element(CALLYING_TYPE);
        callingType.addContent(this.getCallingType().toString());
        configurationFile.getRootElement().addContent(callingType);
    }

    if (!this.getgATKoutputMode().equals(gATKoutputMode_DV)) {
        Element gATKoutputModeoutputMode = new Element(GATKOUTPUTMODE);
        gATKoutputModeoutputMode.addContent(this.getgATKoutputMode().toString());
        configurationFile.getRootElement().addContent(gATKoutputModeoutputMode);
    }

    if (!this.getRsFilter().equals(rsFilter_DV)) {
        Element rsFilter = new Element(RSFILTER);
        rsFilter.addContent(this.getRsFilter().toString());
        configurationFile.getRootElement().addContent(rsFilter);
    }

    if (!this.getrUbioSeqMode().equals(rUbioSeqMode_DV)) {
        Element rUbioSeq_Mode = new Element(RUBIOSEQMODE);
        rUbioSeq_Mode.addContent(this.getrUbioSeqMode().toString());
        configurationFile.getRootElement().addContent(rUbioSeq_Mode);
    }

    if (!this.getFastqc().equals(fastqc_DV)) {
        Element fastqc = new Element(FASTQC);
        fastqc.addContent(this.getFastqc().toString());
        configurationFile.getRootElement().addContent(fastqc);
    }

    if (!this.getvEPFlag().equals(vEPFlag_DV)) {
        Element vEPFlag = new Element(VEPFLAG);
        vEPFlag.addContent(this.getvEPFlag().toString());
        configurationFile.getRootElement().addContent(vEPFlag);
    }

    if (!this.gettCFlag().equals(tCFlag_DV)) {
        Element tCFlag = new Element(TCFLAG);
        tCFlag.addContent(this.gettCFlag().toString());
        configurationFile.getRootElement().addContent(tCFlag);
    }

    if (!this.getmDFlag().equals(mDFlag_DV)) {
        Element mDFlag = new Element(MDFLAG);
        mDFlag.addContent(this.getmDFlag().toString());
        configurationFile.getRootElement().addContent(mDFlag);
    }

    if (!this.getStandCallConf().equals(standCallConf_DV)) {
        Element standCallConf = new Element(STANDCALLCONF);
        standCallConf.addContent(this.getStandCallConf().toString());
        configurationFile.getRootElement().addContent(standCallConf);
    }

    if (!this.getStandEmitConf().equals(standEmitConf_DV)) {
        Element standEmitConf = new Element(STANDEMITCONF);
        standEmitConf.addContent(this.getStandEmitConf().toString());
        configurationFile.getRootElement().addContent(standEmitConf);
    }

    if (!this.getQueueSGEProject().equals(queueSGEProject_DV)) {
        Element queueSGEProject = new Element(QUEUESGEPROJECT);
        queueSGEProject.addContent(this.getQueueSGEProject().toString());
        configurationFile.getRootElement().addContent(queueSGEProject);
    }

    if (this.getChoiceVqrsHardFilters().equals(VQRSHardFiltersChoice.VQRS)
            && this.getvQSRblockMills() != VQSRblockMills_DV && this.getvQSRblockHapMAp() != VQSRblockHapMAp_DV
            && this.getvQSRblockThousandG() != VQSRblockThousandG_DV) {

        Element vQSR_block = new Element(VQSRBLOCK);

        Element mills = new Element(MILLS);
        mills.addContent(this.getvQSRblockMills().getFile().getAbsolutePath());
        vQSR_block.addContent(mills);

        Element hapmap = new Element(HAPMAP);
        hapmap.addContent(this.getvQSRblockHapMAp().getFile().getAbsolutePath());
        vQSR_block.addContent(hapmap);

        Element thousandg = new Element(THOUSANDG);
        thousandg.addContent(this.getvQSRblockThousandG().getFile().getAbsolutePath());
        vQSR_block.addContent(thousandg);

        configurationFile.getRootElement().addContent(vQSR_block);
    }

    if (this.getChoiceVqrsHardFilters().equals(VQRSHardFiltersChoice.HARDFILTERS)
            && (!this.getminQual().equals(minQual_DV) || !this.getdPmin().equals(DPmin_DV)
                    || this.getHardFilters().size() > 0)) {

        Element hardFiltersBlock = new Element(HFILTERS);

        if (!this.getdPmin().equals(DPmin_DV)) {
            Element dpMin = new Element(DPMIN);
            dpMin.addContent(this.getdPmin().toString());
            hardFiltersBlock.addContent(dpMin);
        }

        if (!this.getminQual().equals(minQual_DV)) {
            Element minQual = new Element(MINQUAL);
            minQual.addContent(this.getminQual().toString());
            hardFiltersBlock.addContent(minQual);
        }

        for (HardFilter hF : this.getHardFilters()) {
            Element name = hF.getType().equals(HardFilter.HFilterType.SNP) ? new Element(HFILTER_NAME_SNP)
                    : new Element(HFILTER_NAME_INDEL);
            name.addContent(hF.getName());
            Element rule = hF.getType().equals(HardFilter.HFilterType.SNP) ? new Element(HFILTER_RULE_SNP)
                    : new Element(HFILTER_RULE_INDEL);
            rule.addContent(hF.getRule());
            hardFiltersBlock.addContent(name);
            hardFiltersBlock.addContent(rule);
        }

        configurationFile.getRootElement().addContent(hardFiltersBlock);
    }

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

From source file:facturacion.xml.FacturaXml.java

public void crearFacturaAutorizadaXml(facturacion.model.beans.RespuestaComprobante autorizaciones) {
    Element root = new Element("autorizacion");
    //root.setAttribute("id", "comprobante");
    //root.setAttribute("version","1.0.0");
    doc = new Document();

    this.doc.setRootElement(root);

    for (facturacion.model.beans.Comprobante autorizacion : autorizaciones.getComprobantes()) {
        root.addContent(new Element("estado").setText(autorizacion.getEstado()));
        root.addContent(new Element("numeroAutorizacion").setText(autorizacion.getNumeroAutorizacion()));
        root.addContent(new Element("fechaAutorizacion").setText("" + autorizacion.getFechaAutorizacion()));
        String cad = "<![CDATA[" + autorizacion.getComprobante() + "]]>";
        byte ptext[] = cad.getBytes();
        //System.out.println("--------------------------------------------===");
        //System.out.println(cad);
        //System.out.println("--------------------------------------------===");

        try {//from  w ww.  j  a va2 s  . com
            cad = (new String(ptext, "UTF-8"));
            //System.out.println(cad);
            //System.out.println("--------------------------------------------===");
            root.addContent(new Element("comprobante").setText(cad));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Element mensajes = new Element("mensajes");
        Element mensaje1 = new Element("mensaje");
        for (facturacion.model.beans.Mensaje mensaje : autorizacion.getMensajes()) {
            Element mensaje2 = new Element("mensaje");
            mensaje2.addContent(new Element("identificador").setText(mensaje.getIdentificador()));
            mensaje2.addContent(new Element("informacionAdicional").setText(mensaje.getInformacionAdicional()));
            mensaje2.addContent(new Element("mensaje").setText(mensaje.getMensaje()));
            mensaje2.addContent(new Element("tipo").setText(mensaje.getTipo()));

            mensaje1.addContent(mensaje2);
            break;
        }

        mensajes.addContent(mensaje1);

        root.addContent(mensajes);
        break;
    }
}

From source file:facturacion.xml.FacturaXml.java

private void initXml() throws ParserConfigurationException {
    /*// w  ww  . ja  va 2  s  .c o  m
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setCoalescing(true);
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setIgnoringComments(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    */
    Element root = new Element("factura");
    root.setAttribute("id", "comprobante");
    root.setAttribute("version", "1.0.0");
    doc = new Document();
    this.doc.setRootElement(root);
}

From source file:ilarkesto.feeds.Feed.java

License:Open Source License

public Document createRssJDom() {
    Document document = new Document();
    Element eRoot = new Element("rss");
    eRoot.setAttribute("version", "2.0");
    document.setRootElement(eRoot);//  w w w.j a v  a2  s . c  o  m

    Element eChannel = JDom.addElement(eRoot, "channel");
    JDom.addTextElement(eChannel, "title", title);
    JDom.addTextElement(eChannel, "link", link);
    JDom.addTextElement(eChannel, "description", description);
    if (language != null)
        JDom.addTextElement(eChannel, "language", language);
    if (pubDate != null)
        JDom.addTextElement(eChannel, "pubDate", pubDate);
    if (lastBuildDate != null)
        JDom.addTextElement(eChannel, "lastBuildDate", lastBuildDate);

    for (FeedItem item : items) {
        item.appendTo(eChannel);
    }

    return document;
}

From source file:ilarkesto.rss.Rss20Builder.java

License:Open Source License

public Document createXmlDocument() {
    Document doc = new Document();

    Element eRss = new Element("rss");
    doc.setRootElement(eRss);//from   ww  w  .j a va 2 s. c o  m
    eRss.setAttribute("version", "2.0");

    Element eChannel = JDom.addElement(eRss, "channel");
    if (title != null)
        JDom.addTextElement(eChannel, "title", title);
    if (link != null)
        JDom.addTextElement(eChannel, "link", link);
    if (description != null)
        JDom.addTextElement(eChannel, "description", description);
    if (language != null)
        JDom.addTextElement(eChannel, "language", language);
    if (pubDate != null)
        JDom.addTextElement(eChannel, "pubDate", Tm.FORMAT_RFC822.format(pubDate));
    if (image != null) {
        Element eImage = JDom.addElement(eChannel, "image");
        JDom.addTextElement(eImage, "url", image);
        JDom.addTextElement(eImage, "title", "Logo");
    }

    for (Item item : items) {
        Element eItem = JDom.addElement(eChannel, "item");
        item.appendTo(eItem);
    }

    return doc;
}

From source file:interfacermi.Traza.java

public void insertarTraza(String hora, String actor, String accion) {

    Document document = null;//from w w w.  ja  va  2s .c om
    Element root = null;
    File xmlFile = new File("Traza.xml");
    //Se comprueba si el archivo XML ya existe o no.
    if (xmlFile.exists()) {
        FileInputStream fis;
        try {
            fis = new FileInputStream(xmlFile);
            SAXBuilder sb = new SAXBuilder();
            document = sb.build(fis);
            //Si existe se obtiene su nodo raiz.
            root = document.getRootElement();
            fis.close();
        } catch (JDOMException | IOException e) {
            e.printStackTrace();
        }
    } else {
        //Si no existe se crea su nodo raz.
        document = new Document();
        root = new Element("Traza");
    }

    //Se crea un nodo Hecho para insertar la informacin.
    Element nodohecho = new Element("Hecho");
    //Se crea un nodo hora para insertar la informacin correspondiente a la hora.
    Element nodohora = new Element("Hora");
    //Se crea un nodo actor para insertar la informacin correspondiente al actor.
    Element nodoactor = new Element("Actor");
    //Se crea un nodo accion para insertar la informacin correspondiente a la accin.
    Element nodoaccion = new Element("Accion");

    //Se asignan los valores enviados para cada nodo.
    nodohora.setText(hora);
    nodoactor.setText(actor);
    nodoaccion.setText(accion);
    //Se aade el contenido al nodo Hecho.  
    nodohecho.addContent(nodohora);
    nodohecho.addContent(nodoactor);
    nodohecho.addContent(nodoaccion);
    //Se aade el nodo Hecho al nodo raz.
    root.addContent(nodohecho);
    document.setContent(root);

    //Se procede a exportar el nuevo o actualizado archivo de traza XML   
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());

    try {
        xmlOutput.output(document, new FileWriter("Traza.xml"));
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:io.LoadSave.java

License:Open Source License

/**
 * loads a .oger file/*from  www  .  j a  v  a  2s.c o m*/
 */
public static void load() {

    ParticipantTableModel tableModel = ParticipantTableModel.getInstance();
    RoomTreeModel slotModel = RoomTreeModel.getInstance();

    if (!Main.isSaved()) {

        // current game must be saved
        int saveResult = JOptionPane.showOptionDialog(null, "Mchten Sie vorher speichern?", "Speichern?",
                JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
        if (saveResult == JOptionPane.YES_OPTION) {
            save();
        }
    }

    Document document = new Document();
    Element root = new Element("root");

    SAXBuilder saxBuilder = new SAXBuilder();

    // Dialog to choose the oger file to parse
    JFileChooser fileChoser = new JFileChooser(".xml");
    fileChoser.setFileFilter(new OgerDialogFilter());

    int result = fileChoser.showOpenDialog(null);
    switch (result) {

    case JFileChooser.APPROVE_OPTION:
        try {
            // clear models
            tableModel.clear();
            slotModel.clear();

            // Create a new JDOM document from a oger file
            File file = fileChoser.getSelectedFile();
            document = saxBuilder.build(file);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Fehler beim Parsen der Datei!");
        }

        // Initialize the root Element with the document root Element
        try {
            root = document.getRootElement();
        } catch (NullPointerException e) {
            JOptionPane.showMessageDialog(null, "Fehler beim Parsen der Datei!");
        }

        // participants
        Element participantsElement = root.getChild("allParticipants");

        for (Element participant : participantsElement.getChildren("participant")) {
            String firstName = participant.getAttributeValue("firstName");
            String lastName = participant.getAttributeValue("lastName");
            String mail = participant.getAttributeValue("mail");
            int group = Integer.parseInt(participant.getAttributeValue("group"));

            Participant newParticipant = new Participant(firstName, lastName, mail, group);
            tableModel.addParticipant(newParticipant);
        }

        // slots
        final DateFormat dateFormat = new SimpleDateFormat("dd.MM.yy");
        final DateFormat timeFormat = new SimpleDateFormat("HH:mm");
        boolean parseFailed = false;

        Element slotsElement = root.getChild("Slots");
        for (Element slotElement : slotsElement.getChildren("Slot")) {
            Date date = null;
            Date beginTime = null;
            Date endTime = null;

            try {
                date = dateFormat.parse(slotElement.getAttributeValue("Date"));
            } catch (ParseException e) {
                JOptionPane.showMessageDialog(null, "Konnte Slot-Datum nicht parsen", "Datum nicht erkannt",
                        JOptionPane.ERROR_MESSAGE);
                parseFailed = true;
            }

            try {
                beginTime = timeFormat.parse(slotElement.getAttributeValue("Begin"));
            } catch (ParseException e) {
                JOptionPane.showMessageDialog(null, "Konnte Slot-Angfangszeit nicht parsen",
                        "Anfangszeit nicht erkannt", JOptionPane.ERROR_MESSAGE);
                parseFailed = true;
            }

            try {
                endTime = timeFormat.parse(slotElement.getAttributeValue("End"));
            } catch (ParseException e) {
                JOptionPane.showMessageDialog(null, "Konnte Slot-Endzeit nicht parsen", "Endzeit nicht erkannt",
                        JOptionPane.ERROR_MESSAGE);
                parseFailed = true;
            }

            if (!parseFailed) {
                Slot slot = new Slot(date, beginTime, endTime);
                SlotNode newSlotNode = new SlotNode();
                newSlotNode.setUserObject(slot);
                ((DefaultMutableTreeNode) RoomTreeModel.getInstance().getRoot()).add(newSlotNode);

                // Rooms
                Element roomsElement = slotElement.getChild("AllRooms");
                for (Element roomElement : roomsElement.getChildren("Room")) {
                    parseFailed = false;

                    String roomString = roomElement.getAttributeValue("ID");
                    Date roomBeginTime = null;
                    Date roomEndTime = null;

                    Boolean hasBeamer = false;
                    String hasBeamerString = roomElement.getAttributeValue("Beamer");
                    if (hasBeamerString.equals("false")) {
                        hasBeamer = false;
                    } else if (hasBeamerString.equals("true")) {
                        hasBeamer = true;
                    } else {
                        JOptionPane.showMessageDialog(null, "Beamer nicht erkannt", "Beamer nicht erkannt",
                                JOptionPane.ERROR_MESSAGE);
                        parseFailed = true;
                    }

                    try {
                        roomBeginTime = timeFormat.parse(roomElement.getAttributeValue("Begin"));
                    } catch (ParseException e) {
                        JOptionPane.showMessageDialog(null, "Konnte Slot-Angfangszeit nicht parsen",
                                "Anfangszeit nicht erkannt", JOptionPane.ERROR_MESSAGE);
                        parseFailed = true;
                    }

                    try {
                        roomEndTime = timeFormat.parse(roomElement.getAttributeValue("End"));
                    } catch (ParseException e) {
                        JOptionPane.showMessageDialog(null, "Konnte Slot-Endzeit nicht parsen",
                                "Endzeit nicht erkannt", JOptionPane.ERROR_MESSAGE);
                        parseFailed = true;
                    }

                    if (!parseFailed) {
                        Room room = new Room(roomString, hasBeamer, roomBeginTime, roomEndTime);

                        RoomNode newRoomNode = new RoomNode();
                        newRoomNode.setUserObject(room);

                        newSlotNode.add(newRoomNode);
                        Gui.getRoomTree().updateUI();
                    }
                }

                Gui.getRoomTree().updateUI();
            }
        }

    }

}

From source file:io.wcm.maven.plugins.i18n.SlingI18nMap.java

License:Apache License

private Document getMixLanguageXmlDocument() {
    Document doc = new Document();
    Element root = new Element("root", NAMESPACE_JCR);
    root.addNamespaceDeclaration(NAMESPACE_JCR);
    root.addNamespaceDeclaration(NAMESPACE_MIX);
    root.addNamespaceDeclaration(NAMESPACE_NT);
    root.addNamespaceDeclaration(NAMESPACE_SLING);
    doc.setRootElement(root);/*from  w w w .  j a  v a  2s . co  m*/

    // add boiler plate
    root.setAttribute(JCR_PRIMARY_TYPE, JCR_NODETYPE_FOLDER, NAMESPACE_JCR);
    root.setAttribute(JCR_MIXIN_TYPES, "[" + StringUtils.join(JCR_MIX_LANGUAGE, ",") + "]", NAMESPACE_JCR);

    // add language
    root.setAttribute(JCR_LANGUAGE, languageKey, NAMESPACE_JCR);

    return doc;
}

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);/*from   w  w w . ja v  a 2 s. c  o m*/

    template.addContent(metaData());
    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());/*  ww  w .j a v  a2  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.");
}