Example usage for org.dom4j.io OutputFormat setPadText

List of usage examples for org.dom4j.io OutputFormat setPadText

Introduction

In this page you can find the example usage for org.dom4j.io OutputFormat setPadText.

Prototype

public void setPadText(boolean padText) 

Source Link

Document

Ensure that text immediately preceded by or followed by an element will be "padded" with a single space.

Usage

From source file:au.com.acegi.xmlformat.XmlFormatPlugin.java

License:Apache License

private OutputFormat buildFormatter() {
    final OutputFormat fmt = createPrettyPrint();
    fmt.setAttributeQuoteCharacter(attributeQuoteChar);
    fmt.setEncoding(encoding);/*from   w  w  w .  j  a  va  2 s  . c  o m*/
    fmt.setExpandEmptyElements(expandEmptyElements);
    fmt.setIndentSize(indentSize);
    fmt.setLineSeparator(determineLineSeparator());
    fmt.setNewLineAfterDeclaration(newLineAfterDeclaration);
    fmt.setNewLineAfterNTags(newLineAfterNTags);
    fmt.setNewlines(newlines);
    fmt.setOmitEncoding(omitEncoding);
    fmt.setPadText(padText);
    fmt.setSuppressDeclaration(suppressDeclaration);
    fmt.setTrimText(trimText);
    fmt.setXHTML(xhtml);
    return fmt;
}

From source file:delphsim.model.Epidemia.java

License:Open Source License

/**
 * Guarda la informacin de esta epidemia en el archivo pasado como
 * parmetro, siguiendo el esquema del .xsd de la aplicacin.
 * @param archivoDestino El archivo destino donde se guardar el modelo.
 * @throws java.io.IOException Si hay problemas al escribir en disco.
 * @throws org.dom4j.DocumentException Si hay problemas al crear el objeto de tipo rbol.
 * @throws java.lang.Exception Si se produce algn otro problema.
 *//*from  w  w  w  .jav  a  2s .  c  o  m*/
public void guardarXML(File archivoDestino) throws IOException, DocumentException, Exception {
    // Primero crear el documento dom4j con la informacin del modelo
    Document documento = DocumentHelper.createDocument();
    // Elemento raz epidemia
    Element elementoEpidemia = new DefaultElement("epidemia");
    documento.setRootElement(elementoEpidemia);
    elementoEpidemia.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    elementoEpidemia.addAttribute("xsi:noNamespaceSchemaLocation", "DelphSim1.18.xsd");
    elementoEpidemia.addAttribute("unidadTiempo", this.unidadTiempo);

    // Elementos parmetros
    if (this.parametros != null) {
        for (Parametro param : this.parametros) {
            Element elementoParametro = param.volcarAXML();
            elementoEpidemia.add(elementoParametro);
        }
    }

    // Elementos procesos
    if (this.procesos != null) {
        for (Proceso proc : this.procesos) {
            Element elementoProceso = proc.volcarAXML();
            elementoEpidemia.add(elementoProceso);
        }
    }

    // Elemento poblacin
    Element elementoPoblacion = this.poblacion.volcarAXML();
    elementoEpidemia.add(elementoPoblacion);

    // Elementos compartimentos
    for (Compartimento comp : this.compartimentos) {
        Element elementoCompartimento = comp.volcarAXML();
        elementoEpidemia.add(elementoCompartimento);
    }

    // Luego crear el formato, stream y escritor de la salida
    OutputFormat formato = OutputFormat.createPrettyPrint();
    formato.setEncoding("UTF-16");
    formato.setIndent("\t");
    formato.setNewLineAfterDeclaration(false);
    formato.setPadText(false);
    formato.setTrimText(true);
    formato.setXHTML(true);
    java.io.OutputStreamWriter salida = new java.io.OutputStreamWriter(
            new java.io.FileOutputStream(archivoDestino), "UTF-16");
    XMLWriter escritor = new XMLWriter(salida, formato);
    // Y escribir
    escritor.write(documento);
    escritor.close();
}

From source file:delphsim.model.Resultado.java

License:Open Source License

/**
 * Mtodo esttico que exporta los valores obtenidos tras la simulacin al
 * formato XML./*w w  w.  jav  a2s.  c om*/
 * @param destino El archivo de destino.
 * @param nombres Los nombres de las distintas columnas/funciones.
 * @param definiciones La definicin de cada columna/funcin.
 * @param temps Array con los archivos temporales de los cuales obtener los
 *              datos a exportar.
 * @param numPuntosTotal El nmero de puntos total que contienen los
 *                       archivos temporales.
 * @param numPuntosExportar El nmero de puntos que quiere obtener el usuario.
 * @throws java.io.IOException Si hubiera algn problema al crear el archivo en disco.
 */
public static void exportarComoXML(File destino, String[] nombres, String[] definiciones, File[] temps,
        long numPuntosTotal, long numPuntosExportar) throws IOException {
    // Crear el documento, el elemento 'raiz' y asignarlo
    org.dom4j.Document documento = DocumentHelper.createDocument();
    DefaultElement elementoResultado = new DefaultElement("resultado");
    documento.setRootElement(elementoResultado);

    // Creamos los bfers de lectura para leer los temporales
    BufferedReader[] buffers = new BufferedReader[temps.length];
    for (int i = 0; i < temps.length; i++) {
        buffers[i] = new BufferedReader(new FileReader(temps[i]));
    }
    // Calculamos cada cuanto tenemos que guardar un punto
    double cadaCuanto;
    if (numPuntosTotal == numPuntosExportar) {
        cadaCuanto = 1.0d;
    } else {
        cadaCuanto = new Double(numPuntosTotal) / new Double(numPuntosExportar - 1);
    }
    long siguientePuntoExportar = 0;
    long contadorNumPuntoLeido = 0;
    long contadorNumPuntosExportados = 0;
    // Comenzamos a leer los temporales aadiendo elementos al documento
    String[] valores = new String[buffers.length];
    for (int i = 0; i < buffers.length; i++) {
        valores[i] = buffers[i].readLine();
    }
    // En el momento en que se lee un null, se termina
    while (valores[0] != null) {
        // Para cada punto que haya que exportar
        if (siguientePuntoExportar == contadorNumPuntoLeido) {
            DefaultElement nuevaFila = new DefaultElement("fila");
            // Para el tiempo, nuevo elemento, su valor y aadirlo a la fila
            DefaultElement elementoTiempo = new DefaultElement("Tiempo");
            elementoTiempo.setText(valores[0]);
            nuevaFila.add(elementoTiempo);
            // Lo mismo para cada linea, pero ademas con nombre y definicin
            for (int i = 1; i < valores.length; i++) {
                DefaultElement elementoLinea = new DefaultElement("Lnea" + i);
                elementoLinea.add(new DefaultAttribute("nombre", nombres[i]));
                elementoLinea.add(new DefaultAttribute("definicion", definiciones[i]));
                elementoLinea.setText(valores[i]);
                nuevaFila.add(elementoLinea);
            }
            // Y aadimos la nueva fila
            elementoResultado.add(nuevaFila);
            // Calculamos el siguiente punto a exportar
            contadorNumPuntosExportados++;
            siguientePuntoExportar = Math.round(cadaCuanto * contadorNumPuntosExportados);
            if (siguientePuntoExportar >= numPuntosTotal) {
                siguientePuntoExportar = numPuntosTotal - 1;
            }
        }
        // Leemos la siguiente lnea de los ficheros
        for (int i = 0; i < buffers.length; i++) {
            valores[i] = buffers[i].readLine();
        }
        contadorNumPuntoLeido++;
    }
    // Cerramos los bfers y el archivo de salida
    for (int i = 0; i < buffers.length; i++) {
        buffers[i].close();
    }
    // Imprimimos el documento como XML
    OutputFormat formato = OutputFormat.createPrettyPrint();
    formato.setEncoding("UTF-16");
    formato.setIndent("\t");
    formato.setNewLineAfterDeclaration(false);
    formato.setPadText(false);
    formato.setTrimText(true);
    formato.setXHTML(true);
    OutputStreamWriter salida = new OutputStreamWriter(new FileOutputStream(destino), "UTF-16");
    XMLWriter escritor = new XMLWriter(salida, formato);
    escritor.write(documento);
    escritor.flush();
    escritor.close();
}

From source file:org.unitime.commons.ant.LowercaseTableNames.java

License:Open Source License

protected void write(String resource, Document document) throws IOException, DocumentException {
    File file = null;//w  w w . j  a  va  2 s  .c o m
    if (iSource == null) {
        file = new File(getClass().getClassLoader().getResource(resource).getFile());
    } else {
        file = new File(iSource + File.separator + resource);
    }
    info("  -- writing " + file + " ...");
    FileOutputStream fos = new FileOutputStream(file);
    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setIndentSize(4);
        format.setPadText(false);
        new MyXMLWriter(fos, format).write(document);
    } finally {
        fos.flush();
        fos.close();
    }
}