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:persistence.xml.ExportarContatosXML.java

public ExportarContatosXML(Component Paiview) throws SQLException, ClassNotFoundException, IOException {
    this.view = Paiview;
    this.lista = new PessoaDAO().getCompletos();
    this.root = new Element("contatos");
    this.agendaContatos = new Document(this.root);
    fc = new JFileChooser();
    int rjanela = fc.showSaveDialog(view);
    if (rjanela == JFileChooser.APPROVE_OPTION) {
        this.diretorioArquivo = fc.getSelectedFile().getAbsolutePath()
                .replace(fc.getSelectedFile().getAbsoluteFile().getName(), "");
        this.nomeArquivo = fc.getSelectedFile().getAbsoluteFile().getName();
        this.arquivo = new FileWriter(new File(diretorioArquivo + nomeArquivo));
        exportar();//from   w  w w .j a  va  2 s . c o m
    }
}

From source file:projetxml.model.XMLManagement.java

/**
 * Create file that we'll put datas about the serie
 * This method creates also the xsd and the xsl equivalent
 * @param fichier//  w w  w  .  j  ava 2 s.c  o  m
 * @throws FileNotFoundException
 * @throws IOException
 */
public void creerFichier(String fichier) throws FileNotFoundException, IOException {

    Element racine = new Element("episodes");
    documentOutput = new Document(racine);
    //Creation du repertoire de la serie                
    new File(this.pathOutput + "\\" + fichier).mkdir();
    //Ajout des fichier xsl et xsd
    copier(this.pathOutput + "\\output.xsd", this.pathOutput + "\\" + fichier + "\\output.xsd");
    copier(this.pathOutput + "\\output.xsl", this.pathOutput + "\\" + fichier + "\\output.xsl");
    //Ajout de la balise de lien pour le xsl
    Map instructions = new HashMap();
    instructions.put("href", "output.xsl");
    instructions.put("type", "text/xsl");
    ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet", instructions);
    documentOutput.getContent().add(0, pi);

    sauverFichier(fichier);
}

From source file:pt.ua.dicoogle.server.web.dicom.Information.java

License:Open Source License

/**
 * Based on a SOP Instance UID returns a String containing a XML document filled with all name and value tag pairs for the respective .dcm file.
 *
 * @param sopInstanceUID a String containing a valid/indexed SOP Instance UID.
 * @return a String containing a XML document filled with all name and value tag pairs for the respective .dcm file if the SOP Instance UID is valid and indexed, null otherwise.
 *//*from  ww w. j a  va2 s. com*/
public static String getXMLTagListFromFile(String sopInstanceUID) {
    // get all the tags and their values present on the file
    HashMap<String, Object> tags = searchForFileIndexedMetaData(sopInstanceUID);
    if (tags == null) {
        return null;
    }

    // create the XML string builder and open the xml document
    StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
    xml.append("<tags>");

    Element rootElem = new Element("tags");

    // loop through all the tags set and add them and their values to the XML tree
    Iterator<String> it = tags.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        String value = (String) tags.get(key);
        value = value.trim();

        value = CharMatcher.inRange(start, end).and(CharMatcher.noneOf("\t\r\n")).collapseFrom(value, ' ');

        Element tagElem = new Element("tag");
        tagElem.setAttribute("name", key);
        tagElem.setText(value);

        rootElem.addContent(tagElem);
    }

    XMLOutputter outStream = new XMLOutputter(Format.getCompactFormat());
    StringWriter wr = new StringWriter();
    try {
        outStream.output(new Document(rootElem), wr);
    } catch (IOException e) {
        return null;
    }

    return wr.toString();
}

From source file:pt.ua.dicoogle.webservices.RestTagsResource.java

License:Open Source License

@Get
public Representation representXML() {
    StringRepresentation sr;//  w w  w.j av a2  s  .  com

    HashMap<String, Integer> tagList = DictionaryAccess.getInstance().getTagList();

    ArrayList<String> list = new ArrayList<String>();
    Element tags = new Element("tags");
    for (String tag : tagList.keySet()) {
        int value = tagList.get(tag);

        Element e = new Element("tag");
        e.setAttribute("id", Integer.toString(value));
        e.setAttribute("name", tag);
        tags.addContent(e);
    }

    tags.setAttribute("count", Integer.toString(tags.getChildren().size()));
    Document xmlDoc = new Document(tags);

    XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
    String str = out.outputString(xmlDoc);

    StringRepresentation rep = new StringRepresentation(str, MediaType.APPLICATION_XML);

    return rep;
}

From source file:rodrigorar.data.IOManager.java

License:Open Source License

public void writeBookDatabaseDocument() throws InexistentBookException {
    Document document = new Document(new Element("Books"));
    Element rootElement = document.getRootElement();
    Map<String, Element> bookXMLMap = this.buildBookXMLObjects();
    Set<String> keySet = bookXMLMap.keySet();

    for (String key : keySet) {
        Element bookElement = bookXMLMap.get(key);
        bookElement.detach();//from   w w w . j  a  v a2 s  .  c o m
        rootElement.addContent(bookElement);
    }

    this.printDocument(this.buildFilePath(IOManager.BOOK_DB), document);
}

From source file:rodrigorar.data.IOManager.java

License:Open Source License

public void writeReadingFileDatabaseDocument() throws InexistentReadingFileException {
    Document document = new Document(new Element("ReadingFiles"));
    Element rootElement = document.getRootElement();
    Map<String, Element> readingFileXMLMap = this.buildReadingFileXMLObjects();
    Set<String> keySet = readingFileXMLMap.keySet();

    for (String key : keySet) {
        Element readingFileElement = readingFileXMLMap.get(key);
        readingFileElement.detach();// w ww. java  2s  .  c  o m
        rootElement.addContent(readingFileElement);
    }
    this.printDocument(this.buildFilePath(IOManager.READINGFILE_DB), document);
}

From source file:segunda.progra.Servidor.java

/**
 * Este mtodo se usa para guardar los productos del servidor en un archivo .xml a salvo
 * @param XML El nombre del XML donde se desea guardar los productos
 *//*from   ww w. ja va2s  . c o m*/
private void guardarProductosXML(String XML) {
    //Defino una nueva etiqueta con cabecera para guardar los productos
    Element root = new Element("Productos");

    //recorro toda la lista de productos para guardar los productos
    for (int i = 0; i < productos.size(); i++) {
        Producto get = productos.get(i);
        //El elemento que va a contener todos los datos del producto
        Element producto = new Element(colocaUnderScores(get.getNombre()));

        //Ahora llenar los datos del producto dentro de su elemento
        Element codigo = new Element("Codigo");
        codigo.addContent(get.getCodigo());
        producto.addContent(codigo);

        Element descripcion = new Element("Descripcion");
        descripcion.addContent(get.getDescripcion());
        producto.addContent(descripcion);

        Element tamanhoPorcion = new Element("TamanhoPorcion");
        tamanhoPorcion.addContent(String.valueOf(get.getTamanhoPorcion()));
        producto.addContent(tamanhoPorcion);

        Element piezaPorPorcion = new Element("PiezasPorPorcion");
        piezaPorPorcion.addContent(String.valueOf(get.getPiezasPorcion()));
        producto.addContent(piezaPorPorcion);

        Element caloriasEnUnaPorcion = new Element("CaloriasEnUnaPorcion");
        caloriasEnUnaPorcion.addContent(String.valueOf(get.getCaloriasPorcion()));
        producto.addContent(caloriasEnUnaPorcion);

        Element caloriasPorPieza = new Element("CaloriasPorPieza");
        caloriasPorPieza.addContent(String.valueOf(get.getCaloriasPieza()));
        producto.addContent(caloriasPorPieza);

        Element precio = new Element("Precio");
        precio.addContent(String.valueOf(get.getPrecio()));
        producto.addContent(precio);

        //agrego el producto a la raz del XML
        root.addContent(producto);
    }
    //ahora slo falta guardarlo
    XMLOutputter outputterXML = new XMLOutputter(Format.getPrettyFormat());
    try {
        outputterXML.output(new Document(root), new FileOutputStream(XML));
    } catch (IOException e) {
        System.out.println("Ocurri un error a la hora de guardar el XML");
    }
}

From source file:services.docx.DisposicionServiceDocx.java

License:Apache License

private static Document asInputDocument(Disposicion disposicion) {
    Element html = new Element("html");
    Document document = new Document(html);

    Element body = new Element("body");
    html.addContent(body);/*from ww w.j a  v  a  2  s  .  co  m*/
    addPara(body, "titulo", "plain", " DISPOSICION ");

    addPara(body, "nro", "plain", disposicion.getNro_Disposicion() + "");
    DateTimeFormatter fmt = DateTimeFormat.forPattern("d MMMM, yyyy");
    addPara(body, "fecha", "plain", disposicion.getFecha().toString(fmt));
    addPara(body, "origen", "plain", disposicion.getSector().getNombre_sector());
    addPara(body, "descripcion", "plain", disposicion.getDescripcion());

    return document;
}

From source file:services.docx.ExpedienteServiceDocx.java

License:Apache License

private static Document asInputDocument(Expediente expediente) {
    Element html = new Element("html");
    Document document = new Document(html);

    Element body = new Element("body");
    html.addContent(body);//from w  w w.j ava 2s  .c om

    addPara(body, "titulo", "plain", " EXPEDIENTE ");

    addPara(body, "nro", "plain", expediente.getNro_expediente() + "");
    DateTimeFormatter fmt = DateTimeFormat.forPattern("d MMMM, yyyy");

    addPara(body, "fecha", "plain", expediente.getFecha().toString(fmt));
    addPara(body, "origen", "plain", expediente.getSector().getNombre_sector());
    addPara(body, "descripcion", "plain", expediente.getDescripcion());

    addPara(body, "empresa", "plain", expediente.getExpte_cod_empresa());
    addPara(body, "codigo", "plain", expediente.getExpte_cod_letra());
    addPara(body, "anio", "plain", expediente.getExpte_cod_anio() + "");
    addPara(body, "numero", "plain", expediente.getExpte_cod_numero() + "");

    return document;
}

From source file:services.docx.MemoServiceDocx.java

License:Apache License

private static Document asInputDocument(Memo memo) {
    Element html = new Element("html");
    Document document = new Document(html);

    Element body = new Element("body");
    html.addContent(body);//w w  w  .jav  a  2s. co  m
    addPara(body, "titulo", "plain", " MEMO ");
    addPara(body, "nro", "plain", memo.getNro_memo() + "");
    DateTimeFormatter fmt = DateTimeFormat.forPattern("d MMMM, yyyy");
    addPara(body, "fecha", "plain", memo.getFecha().toString(fmt));
    addPara(body, "origen", "plain", memo.getSector().getNombre_sector());
    if (memo.getDestinoSector() != null)
        addPara(body, "destino", "plain", memo.getDestinoSector().getNombre_sector());
    else if (memo.getOtroDestino() != null)
        addPara(body, "destino", "plain", memo.getOtroDestino());
    addPara(body, "descripcion", "plain", memo.getDescripcion());

    return document;
}