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(List<? extends Content> content) 

Source Link

Document

This will create a new Document, with the supplied list of content, and a DocType declaration only if the content contains a DocType instance.

Usage

From source file:strategies.StatusDataForNinety.java

public void SaveTradingStatus() {
    try {/*w  ww.  j  a v a 2  s. c  om*/
        Element rootElement = new Element("status");
        Document doc = new Document(rootElement);

        Element moneyElement = new Element("money");
        moneyElement.setAttribute("currentCash", TradeFormatter.toString(currentCash));
        moneyElement.setAttribute("currentFees", TradeFormatter.toString(currentFees));
        rootElement.addContent(moneyElement);

        Element heldPosElement = new Element("heldPositions");
        heldPosElement.setAttribute("heldStocks", Integer.toString(heldStocks.size()));
        rootElement.addContent(heldPosElement);

        for (HeldStock held : heldStocks.values()) {
            held.AddToXml(heldPosElement);
        }

        XMLOutputter xmlOutput = new XMLOutputter();

        File statusFile = new File(FilePaths.tradingStatusPathFileOutput);
        statusFile.createNewFile();
        FileOutputStream oFile = new FileOutputStream(statusFile, false);

        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, oFile);

    } catch (IOException e) {
        logger.severe("Failed to save held positions to XML file - " + e.toString());
    }
}

From source file:strategy.log.LogXML.java

public LogXML() {
    this.arq = new File(diretorio);
    if (!arq.exists()) {
        try {//from   w w  w  .j av  a 2  s . c  o  m
            arq.createNewFile();
        } catch (IOException ex) {
            Logger.getLogger(LogXML.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    this.formata = new FormatLog();
    this.root = new Element("log");
    this.doclog = new Document(root);

}

From source file:studentformapp.StudentMainForm.java

private void saveToXML() {
    try {/*  w w  w  .  j a va2  s.  c  o m*/
        Element root = new Element("students");
        Document doc = new Document(root);

        for (int i = 0; i < model.getSize(); i++) {
            String[] elements = ((String) model.get(i)).split("   ");
            Element node = new Element("student-data");
            root.addContent(node);
            Element fNom = new Element("Faculty-Number");
            fNom.setText(elements[0]);
            node.addContent(fNom);
            Element name = new Element("Name");
            name.setText(elements[1]);
            node.addContent(name);
            Element mark = new Element("Mark");
            mark.setText(elements[2]);
            node.addContent(mark);
        }

        XMLOutputter out = new XMLOutputter();
        out.output(doc, new FileWriter(new File(fname + ".xml")));
    } catch (IOException ex) {
        Logger.getLogger(StudentMainForm.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:swing.xml.Form.java

@Override
public void actionPerformed(ActionEvent e) {
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    if (e.getSource() == Enter) {
        String String1 = Text1.getText();
        String String2 = Text2.getText();
        String String3 = Text3.getText();

        try {/*from   www.j a  v a 2s .  c om*/

            Element Lala = new Element("Texts");
            Lala.detach();
            Document doc = new Document(Lala);

            Element Element_Text1 = new Element("Text");
            Element_Text1.addContent(new Element("text_id").setText("1"));
            Element_Text1.addContent(new Element("text_content").setText(String1));

            doc.getRootElement().addContent(Element_Text1);

            Element Element_Text2 = new Element("Text");
            Element_Text2.addContent(new Element("text_id").setText("2"));
            Element_Text2.addContent(new Element("text_content").setText(String2));

            doc.getRootElement().addContent(Element_Text2);

            Element Element_Text3 = new Element("Text");
            Element_Text3.addContent(new Element("text_id").setText("3"));
            Element_Text3.addContent(new Element("text_content").setText(String3));

            doc.getRootElement().addContent(Element_Text3);

            // new XMLOutputter().output(doc, System.out);
            XMLOutputter xmlOutput = new XMLOutputter();

            // display nice nice
            xmlOutput.setFormat(Format.getPrettyFormat());
            xmlOutput.output(doc, new FileWriter("C:\\Users\\Alumno\\Desktop\\Text.xml"));

            System.out.println("File Saved!");
        } catch (IOException io) {
            System.out.println(io.getMessage());
        }

        System.out.println("Texto 1: " + String1);
        System.out.println("Texto 2: " + String2);
        System.out.println("Texto 3: " + String3);
        JOptionPane.showMessageDialog(null,
                "Texto 1: " + String1 + "\nTexto 2: " + String2 + "\nTexto 3: " + String3);
    }
}

From source file:tds.itemscoringengine.web.server.AdminHandler.java

License:Open Source License

@RequestMapping(value = "/Admin", method = RequestMethod.GET)
public void ProcessRequest(ServletResponse response) {
    try {/*from ww  w  .  ja  v a 2s.  c o  m*/
        response.setContentType("text/xml");
        OutputStream output = response.getOutputStream();

        Element docElement = new Element("status");
        docElement.addContent("Item scoring server is running");
        Document doc = new Document(docElement);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.output(doc, output);
    } catch (IOException e) {
        _logger.error("Exception writing output from AdminHandler", e);
    }
}

From source file:TFG.Lector_XML.java

public void write_xml(String path, String cad_string, String id_iniciativa) {

    //Creamos un elemento root 
    Element iniciativa = new Element("iniciativa");
    iniciativa.setAttribute("id", id_iniciativa);
    //Creamos un hijo para el root  
    Element discurso = new Element("discurso").setText(cad_string);
    iniciativa.addContent(discurso);/*  ww w. j  av a  2  s.  c om*/
    Document doc = new Document(iniciativa);
    //Creamos el documento   
    try {
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        FileOutputStream file = new FileOutputStream("discursos/" + path + ".xml", true);
        out.output(doc, file);
        file.flush();
        file.close();
        out.output(doc, System.out);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:todoapp.app.services.export.ExportToWordService.java

License:Apache License

private Document asInputDocument(final List<ToDoItem> items) {

    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);/*  w w w .j  a  v  a  2  s  .c  om*/

    addPara(body, "ExportedOn", "date", clockService.nowAsLocalDateTime().toString("dd-MMM-yyyy"));

    final Element table = addTable(body, "ToDoItems");
    for (final ToDoItem item : items) {
        addTableRow(table,
                new String[] { item.getDescription(), item.getCost() != null ? item.getCost().toString() : "",
                        item.getDueBy() != null ? item.getDueBy().toString("dd-MMM") : "" });
    }
    return document;
}

From source file:tuupertunut.hintahaku.asetukset.Asetukset.java

License:Open Source License

public Document kirjoitaXML() {
    Element juuri = new Element("asetukset");
    juuri.setAttribute("info", "Hintahaku-asetukset");

    juuri.addContent(new Element("suodatintiedosto").setText(suodatintiedosto.toString()));
    juuri.addContent(new Element("viimeisinSuodatinKansio").setText(viimeisinSuodatinKansio.toString()));
    juuri.addContent(new Element("viimeisinOstoskoriKansio").setText(viimeisinOstoskoriKansio.toString()));

    return new Document(juuri);
}

From source file:tuupertunut.hintahaku.korjaukset.Korjaukset.java

License:Open Source License

public Document kirjoitaXML() {
    Element juuri = new Element("korjaukset");
    juuri.setAttribute("info", "Hintahaku-korjaukset");

    for (Korjaus korjaus : korjaukset.values()) {
        Element korjausElem = new Element("korjaus");
        korjausElem.addContent(new Element("tuoteUrl").setText(korjaus.getTuoteUrl().toString()));
        korjausElem.addContent(new Element("tuoteNimi").setText(korjaus.getTuoteNimi()));
        korjausElem.addContent(new Element("kaupanNimi").setText(korjaus.getKaupanNimi()));
        korjausElem.addContent(new Element("kohde").setText(korjaus.getKohde().toString()));
        korjausElem.addContent(new Element("korjattuHinta").setText(korjaus.getKorjattuHinta().toString()));

        juuri.addContent(korjausElem);/*from   w w w  .  ja  va2 s .  co m*/
    }

    return new Document(juuri);
}

From source file:tuupertunut.hintahaku.ostoskori.Ostoskori.java

License:Open Source License

public Document kirjoitaXML() {
    Element juuri = new Element("ostoskori");
    juuri.setAttribute("info", "Tallennettu Hintahaku-ostoskori").setAttribute("versio", "2");

    for (Ostos ostos : ostokset) {
        Element ktElem = new Element("ostos");

        Element vaihtoehdotElem = new Element("vaihtoehdot");
        for (Tuote vaihtoehto : ostos.getVaihtoehdot()) {
            vaihtoehdotElem.addContent(new Element("url").setText(vaihtoehto.getUrl().toString()));
        }//from w w w  .ja va 2 s . c o  m

        ktElem.addContent(vaihtoehdotElem);

        ktElem.addContent(new Element("mr").setText(Integer.toString(ostos.getMaara())));

        juuri.addContent(ktElem);
    }

    return new Document(juuri);
}