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:pl.edu.pwr.iiar.zak.thermalKit.util.ReadDesign.java

License:Open Source License

public void showDesign(String filename) throws JDOMException, IOException {
    try {/*from w w w . j a  va2  s.c  om*/
        System.out.println("Converting NCD file to XDL...");
        FileConverter.convertNCD2XDL(filename);
    } catch (NullPointerException e) {
        System.out.println("Please indicate correct ncd file!");
        System.exit(0);
    }
    Design design = new Design();
    design.loadXDLFile(filename.substring(0, filename.length() - 3) + "xdl");
    Device device = design.getDevice();

    Document writer = new Document();
    Element rootElement = new Element("device");
    writer.addContent(rootElement);
    rootElement.setAttribute(new Attribute("version", "0.2"));
    rootElement.setAttribute(new Attribute("name", device.getPartName()));

    Element size = new Element("size");
    rootElement.addContent(size);
    size.setAttribute(new Attribute("cols", String.format("%d", device.getColumns())));
    size.setAttribute(new Attribute("rows", String.format("%d", device.getRows())));

    Element clbsize = new Element("clbsize");
    rootElement.addContent(clbsize);
    clbsize.setAttribute(new Attribute("width", "0.00025"));
    clbsize.setAttribute(new Attribute("height", "0.0002"));

    int old_z = -1;
    int k = 0;
    String progress_bar = "|/-\\";
    for (int row = 0; row < device.getColumns(); row++) {
        if (print) {
            System.out.format("%d\t", row + 1);
        }
        for (int col = 0; col < device.getRows(); col++) {
            System.out.println(String.format("Col: %d, Row: %d", col, row));
            System.out.println(design.getDevice().getTile(col, row).getName());
            if (design.getDevice().getTile(col, row).getName().contains("CLB")) {
                try {
                    boolean used = false;
                    for (PrimitiveSite ps : design.getDevice().getTile(col, row).getPrimitiveSites()) {
                        if (design.isPrimitiveSiteUsed(ps)) {
                            used = true;
                        }
                    }
                    if (used) {
                        if (print) {
                            System.out.print("@");
                        }
                        rootElement.addContent(addElement(row, col, "unit"));
                    } else {
                        if (print) {
                            System.out.print("*");
                        }
                    }
                    k++;
                } catch (Exception e) {
                    if (print) {
                        System.out.print("#");
                    }
                    rootElement.addContent(addElement(row, col, "obstacle"));
                }
            } else {
                rootElement.addContent(addElement(row, col, "obstacle"));
                if (print) {
                    System.out.print("#");
                }
            }
        }
        if (print) {
            System.out.println();
        } else {
            int z = (int) ((row / 177.0) * 100);
            if (old_z != z) {
                System.out.write(progressBar(z, 50).getBytes());
                old_z = z;
            }
        }
    }
    System.out.format("\nNumber of CLB tiles %d\n", k);
    System.out.format("Number of columns %d; Number of rows %d\n", design.getDevice().getColumns(),
            design.getDevice().getRows());
    System.out.println("Creating XML file with device floorplan...");
    XMLOutputter xml = new XMLOutputter();
    xml.setFormat(Format.getPrettyFormat());

    String path = "floorplan.xml";

    if (!print) {
        PrintWriter xmlWriter = new PrintWriter(path, "UTF-8");
        xmlWriter.print(xml.outputString(writer));
        xmlWriter.close();
        System.out.println("FPGA description saved in floorplan.xml!");
    }
}

From source file:princetonPlainsboro.EcritureXML.java

public void saveDossier(DossierMedical dossier) {

    FileOutputStream out = null;/*from   w  w w. j  a va2s.  co  m*/
    // cr le document jDOM contnenant le dossier mdical
    Document jdomDoc = createJDOM(dossier);

    // de jDOM vers xml
    XMLOutputter xml = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setEncoding("UTF-8"); // pour gerer les accents
    xml.setFormat(format);

    try {
        xml.output(jdomDoc, new FileOutputStream(classeur));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(EcritureXML.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(EcritureXML.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:projetxml.model.XMLManagement.java

private void sauverFichier(String nomFichier) {
    try {/*from   w ww . j  a va2 s. c o m*/
        XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
        String rep = nomFichier.replaceAll(".xml", "");
        sortie.output(documentOutput,
                new FileOutputStream(this.pathOutput + "\\" + nomFichier + "\\" + nomFichier + ".xml"));
    } catch (java.io.IOException e) {
    }
}

From source file:pt.ist.socialsoftware.edition.export.ExpertEditionTEIExport.java

License:Creative Commons License

public String getXMLResult() {
    XMLOutputter xml = new XMLOutputter();
    // we want to format the xml. This is used only for demonstration.
    // pretty formatting adds extra spaces and is generally not required.
    xml.setFormat(Format.getPrettyFormat());
    return updateTeiHeader(xml.outputString(this.jdomDoc));
}

From source file:pt.ist.socialsoftware.edition.visitors.TEIGenerator.java

License:Creative Commons License

public String getXMLResult() {
    XMLOutputter xml = new XMLOutputter();
    // we want to format the xml. This is used only for demonstration.
    // pretty formatting adds extra spaces and is generally not required.
    xml.setFormat(Format.getPrettyFormat());
    return updateTeiHeader(xml.outputString(jdomDoc));

}

From source file:qtiscoringengine.QTIUtility.java

License:Open Source License

static String nodeToString(Element node) {
    if (node == null)
        return "";
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    return out.outputString(node);
}

From source file:Report.Report.java

License:Open Source License

public void printOut(PrintStream pw) {
    unlazy();//from w  w  w  . ja  v  a 2s  . c  o m
    XMLOutputter xml = new XMLOutputter();
    xml.setFormat(Format.getPrettyFormat());
    pw.println(xml.outputString(jdomDoc));

}

From source file:rezeptsuperpos.GenericArchive.java

License:Open Source License

@Override
public String toString() {
    Format format = Format.getPrettyFormat();
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(format);/*from  w ww  . j  a  v  a 2s.  c  o  m*/
    return xmlOutputter.outputString(document);
}

From source file:rezeptsuperpos.Ingredient.java

License:Open Source License

@Override
public String toString() {
    Format format = Format.getPrettyFormat();
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(format);/*from w  w  w .  j a  v a 2s.c  o m*/
    return xmlOutputter.outputString(toElement());
}

From source file:rezeptsuperpos.IngredientArchive.java

License:Open Source License

public void saveIngredients() throws FileNotFoundException, UnsupportedEncodingException {
    File ingredientFile = new File(documentPathFile);
    PrintWriter ingredientPrintWriter = new PrintWriter(ingredientFile, "UTF-8");
    Format format = Format.getPrettyFormat();
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(format);//from www  . ja v a2s . co  m
    ingredientPrintWriter.println(xmlOutputter.outputString(document));
    ingredientPrintWriter.close();
}