Example usage for org.jdom2.output Format getPrettyFormat

List of usage examples for org.jdom2.output Format getPrettyFormat

Introduction

In this page you can find the example usage for org.jdom2.output Format getPrettyFormat.

Prototype

public static Format getPrettyFormat() 

Source Link

Document

Returns a new Format object that performs whitespace beautification with 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy.

Usage

From source file:ca.nrc.cadc.vosi.TableWriter.java

License:Open Source License

public void write(TableDesc table, Writer writer) throws IOException {
    TableSet tset = new TableSet(null);
    Document doc = tset.getTableDocument(table);
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(doc, writer);/*from  w ww. j  a  v a 2 s  .co  m*/
}

From source file:cager.parser.test.SimpleTest2.java

License:Open Source License

private String elementoToString(Element segmento) {

    Document documentJDOM = new Document();
    documentJDOM.addContent(segmento);/*  www  . j av  a2  s.  co m*/
    // Vamos a serializar el XML  
    // Lo primero es obtener el formato de salida  
    // Partimos del "Formato bonito", aunque tambin existe el plano y el compacto  
    Format format = Format.getPrettyFormat();
    // Creamos el serializador con el formato deseado  
    XMLOutputter xmloutputter = new XMLOutputter(format);
    // Serializamos el document parseado  
    String docStr = xmloutputter.outputString(documentJDOM);

    FileOutputStream fout;
    try {
        fout = new FileOutputStream(ruta + "VBParser\\ejemplosKDM\\archivo.kdm");
        //fout = new FileOutputStream("E:\\WorkspaceParser\\VBParser\\ejemplosKDM\\archivo.kdm");
        xmloutputter.output(documentJDOM, fout);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return docStr;
}

From source file:cager.parser.test.SimpleTest3.java

License:Open Source License

private String elementoToString(Element segmento) {

    Document documentJDOM = new Document();
    documentJDOM.addContent(segmento);//from   w  w w . ja  va 2  s.c  om
    // Vamos a serializar el XML  
    // Lo primero es obtener el formato de salida  
    // Partimos del "Formato bonito", aunque tambin existe el plano y el compacto  
    Format format = Format.getPrettyFormat();
    // Creamos el serializador con el formato deseado  
    XMLOutputter xmloutputter = new XMLOutputter(format);
    // Serializamos el document parseado  
    String docStr = xmloutputter.outputString(documentJDOM);

    FileOutputStream fout;
    try {
        fout = new FileOutputStream(ruta + "VBParser\\ejemplosKDM\\archivo.kdm");
        //fout = new FileOutputStream("E:\\WorkspaceParser\\VBParser\\ejemplosKDM\\archivo.kdm");
        xmloutputter.output(documentJDOM, fout);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return docStr;
}

From source file:carb.view.ParsingEverything.java

static void affiche() {
    try {//  ww w. ja  va  2s  .c  o m
        //On utilise ici un affichage classique avec getPrettyFormat()
        XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
        sortie.output(document, System.out);
    } catch (java.io.IOException e) {
    }
}

From source file:carb.view.ParsingEverything.java

static void enregistre(String fichier) {
    try {/*from  www  .  j av a  2 s .co m*/
        //On utilise ici un affichage classique avec getPrettyFormat()
        XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
        //Remarquez qu'il suffit simplement de crer une instance de FileOutputStream
        //avec en argument le nom du fichier pour effectuer la srialisation.
        sortie.output(document, new FileOutputStream(fichier));
    } catch (java.io.IOException e) {
    }
}

From source file:catalogo.XMLOut.java

public static void criaXML(Document doc) {

    /**//  w  ww .ja va  2 s. com
     * Esta funo recebe como parmetro um objeto Document corretamente estruturado
     * e cria um arquivo .XML com nome fornecido pelo usurio.
     */

    Scanner in = new Scanner(System.in);

    //Mgica que cria o arquivo
    XMLOutputter xmlOutput = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setEncoding("ISO-8859-1");
    xmlOutput.setFormat(format);

    System.out.printf("Informe o nome do arquivo .xml a ser criado: \n" + "(exemplo: listagem.xml)\n>>> ");
    String name = in.nextLine();

    try {
        xmlOutput.output(doc, new FileWriter("outputs/".concat(name)));
        System.out.println("Arquivo de listagem criado.");
    } catch (Exception e) {
        System.out.println("Falha ao criar arquivo.");
    }
}

From source file:ch.ledcom.maven.sitespeed.utils.XmlPrettyPrinter.java

License:Apache License

public static void prettyPrint(Document doc, OutputStream out) throws IOException {
    new XMLOutputter(Format.getPrettyFormat()).output(doc, out);
}

From source file:ch.rotscher.maven.plugins.InstallWithVersionOverrideMojo.java

License:Apache License

private void replaceVersion(File originalPomFile, File newPomFile, String newVersion)
        throws IOException, JDOMException {

    //we assume that the version of "internal" dependencies are declared with ${project.version}
    FileWriter writer = new FileWriter(newPomFile);
    SAXBuilder parser = new SAXBuilder();
    XMLOutputter xmlOutput = new XMLOutputter();
    // display nice nice
    xmlOutput.setFormat(Format.getPrettyFormat());

    //parse the document
    Document doc = parser.build(originalPomFile);
    Element versionElem = findVersionElement(doc);
    versionElem.setText(newVersion);//from w  ww  .  jav  a 2 s.c o  m
    xmlOutput.output(doc, writer);
    writer.flush();
    writer.close();
}

From source file:com.archimatetool.jdom.JDOMUtils.java

License:Open Source License

/**
 * Writes a JDOM Document to file/*from ww  w . j  av  a  2s. co m*/
 * @param doc The JDOM Document to write
 * @param file The file to write to
 * @throws IOException
 */
public static void write2XMLFile(Document doc, File file) throws IOException {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());

    // Create parent folder if it doesn't exist
    File parent = file.getParentFile();
    if (parent != null) {
        parent.mkdirs();
    }

    FileOutputStream out = new FileOutputStream(file);
    outputter.output(doc, out);
    out.close();
}

From source file:com.archimatetool.jdom.JDOMUtils.java

License:Open Source License

/**
 * Convert a JDOM Document to a String format
 * @param doc The JDOM Document/*from ww w.  ja  v a 2  s . co  m*/
 * @return The resulting String
 * @throws IOException
 */
public static String write2XMLString(Document doc) throws IOException {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());

    StringWriter out = new StringWriter();
    outputter.output(doc, out);
    out.close();

    return out.toString();
}