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:org.goobi.production.export.ExportXmlLog.java

License:Open Source License

/**
 * This method exports the production metadata for al list of processes as a single file to a given stream.
 * /*from w  w  w  .  j av a 2 s .  co  m*/
 * @param processList
 * @param outputStream
 * @param xslt
 */

public void startExport(List<Process> processList, OutputStream outputStream, String xslt) {
    Document answer = new Document();
    Element root = new Element("processes");
    answer.setRootElement(root);
    Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile");

    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.addNamespaceDeclaration(xsi);
    root.setNamespace(xmlns);
    Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd",
            xsi);
    root.setAttribute(attSchema);
    for (Process p : processList) {
        Document doc = createDocument(p, false);
        Element processRoot = doc.getRootElement();
        processRoot.detach();
        root.addContent(processRoot);
    }

    XMLOutputter outp = new XMLOutputter();
    outp.setFormat(Format.getPrettyFormat());

    try {

        outp.output(answer, outputStream);
    } catch (IOException e) {

    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                outputStream = null;
            }
        }
    }

}

From source file:org.helm.notation2.MonomerFactory.java

License:Open Source License

private static String buildMonomerDbXMLFromCache(MonomerCache cache) throws MonomerException {
    XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat());

    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.getProperty("line.separator")
            + "<MonomerDB xmlns=\"lmr\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
            + System.getProperty("line.separator"));

    Map<String, Map<String, Monomer>> mDB = cache.getMonomerDB();
    Element polymerListElement = new Element(POLYMER_LIST_ELEMENT);
    Set<String> polymerTypeSet = mDB.keySet();
    for (Iterator i = polymerTypeSet.iterator(); i.hasNext();) {
        String polymerType = (String) i.next();
        Element polymerElement = new Element(POLYMER_ELEMENT);
        Attribute att = new Attribute(POLYMER_TYPE_ATTRIBUTE, polymerType);
        polymerElement.setAttribute(att);
        polymerListElement.getChildren().add(polymerElement);

        Map<String, Monomer> monomerMap = mDB.get(polymerType);
        Set<String> monomerSet = monomerMap.keySet();

        for (Iterator it = monomerSet.iterator(); it.hasNext();) {
            String monomerID = (String) it.next();
            Monomer m = monomerMap.get(monomerID);
            Element monomerElement = MonomerParser.getMonomerElement(m);
            polymerElement.getChildren().add(monomerElement);
        }/*  w ww. j  a  v a 2 s.c o  m*/
    }
    String polymerListString = outputer.outputString(polymerListElement);
    sb.append(polymerListString + System.getProperty("line.separator"));

    Map<String, Attachment> aDB = cache.getAttachmentDB();
    Element attachmentListElement = new Element(ATTACHMENT_LIST_ELEMENT);
    Set<String> attachmentSet = aDB.keySet();
    for (Iterator itr = attachmentSet.iterator(); itr.hasNext();) {
        String attachmentID = (String) itr.next();
        Attachment attachment = aDB.get(attachmentID);
        Element attachmentElement = MonomerParser.getAttachementElement(attachment);
        attachmentListElement.getChildren().add(attachmentElement);
    }
    String attachmentListString = outputer.outputString(attachmentListElement);
    sb.append(attachmentListString);

    sb.append(System.getProperty("line.separator") + "</MonomerDB>" + System.getProperty("line.separator"));

    return sb.toString();
}

From source file:org.helm.notation2.tools.NucleotideParser.java

License:Open Source License

public static String getNucleotideTemplatesXML(Map<String, Map<String, String>> templates) {
    XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat());

    StringBuilder sb = new StringBuilder();
    sb.append(/*ww  w . ja  va 2s  .  c o m*/
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<NUCLEOTIDE_TEMPLATES xsi:schemaLocation=\"lmr NucleotideTemplateSchema.xsd\" xmlns=\"lmr\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");

    Set<String> templateSet = templates.keySet();
    for (Iterator i = templateSet.iterator(); i.hasNext();) {
        String template = (String) i.next();
        Element templateElement = new Element(TEMPLATE_ELEMENT);
        Attribute att = new Attribute(TEMPLATE_NOTATION_SOURCE_ATTRIBUTE, template);
        templateElement.setAttribute(att);

        Map<String, String> nucMap = templates.get(template);
        Set<String> nucleotideSet = nucMap.keySet();

        for (Iterator it = nucleotideSet.iterator(); it.hasNext();) {
            Element nucleotideElement = new Element(NUCLEOTIDE_ELEMENT);
            templateElement.getChildren().add(nucleotideElement);

            String symbol = (String) it.next();
            Element symbolElement = new Element(NUCLEOTIDE_SYMBOL_ELEMENT);
            symbolElement.setText(symbol);
            nucleotideElement.getChildren().add(symbolElement);

            String notation = nucMap.get(symbol);
            Element notationElement = new Element(NUCLEOTIDE_MONOMER_NOTATION_ELEMENT);
            notationElement.setText(notation);
            nucleotideElement.getChildren().add(notationElement);
        }

        String templateString = outputer.outputString(templateElement);
        sb.append(templateString);
    }

    sb.append("\n</NUCLEOTIDE_TEMPLATES>");

    return sb.toString();
}

From source file:org.helm.notation2.tools.xHelmNotationExporter.java

License:Open Source License

/**
 * method to get xhelm for the helm2 notation with the new functionality
 *
 * @param helm2notation, HELM2Notation object
 * @return xhelm/*ww w  . ja  va  2 s  .co  m*/
 * @throws MonomerException
 * @throws JDOMException
 * @throws IOException
 * @throws ChemistryException
 */
public static String getXHELM2(HELM2Notation helm2notation)
        throws MonomerException, IOException, JDOMException, ChemistryException {
    set = new HashSet<Monomer>();
    Element root = new Element(xHelmNotationExporter.XHELM_ELEMENT);

    Document doc = new Document(root);

    Element helmElement = new Element(xHelmNotationExporter.HELM_NOTATION_ELEMENT);
    helmElement.setText(helm2notation.toHELM2());

    root.addContent(helmElement);

    Element monomerListElement = new Element(xHelmNotationExporter.MONOMER_LIST_ELEMENT);

    /* save all adhocMonomers */
    for (MonomerNotation monomernotation : MethodsMonomerUtils
            .getListOfMonomerNotation(helm2notation.getListOfPolymers())) {
        /* get all elements of an rna */
        if (monomernotation instanceof MonomerNotationUnitRNA) {
            for (MonomerNotationUnit unit : ((MonomerNotationUnitRNA) monomernotation).getContents()) {
                addAdHocMonomer(unit);
            }
        } else {
            addAdHocMonomer(monomernotation);

        }

    }
    /* give the adhocMonomer's information */
    for (Monomer distinctmonomer : set) {
        Element monomerElement = MonomerParser.getMonomerElement(distinctmonomer);
        monomerListElement.getChildren().add(monomerElement);
    }

    root.addContent(monomerListElement);
    XMLOutputter xmlOutput = new XMLOutputter();
    // display nice
    xmlOutput.setFormat(Format.getPrettyFormat());
    return xmlOutput.outputString(doc);
}

From source file:org.helm.notation2.tools.xHelmNotationExporter.java

License:Open Source License

/**
 * method to get xhelm for the helm notation, only if it was possible to
 * convert the helm in the old format//w  w  w.j a v  a 2 s .  co m
 *
 * @param helm2notation, HELM2Notation object
 * @return xhelm
 * @throws MonomerException
 * @throws HELM1FormatException
 * @throws JDOMException
 * @throws IOException
 * @throws NotationException
 * @throws CTKException
 * @throws ValidationException
 * @throws ChemistryException if the Chemistry Engine can not be initialized
 */
public static String getXHELM(HELM2Notation helm2notation) throws MonomerException, HELM1FormatException,
        IOException, JDOMException, NotationException, CTKException, ValidationException, ChemistryException {
    set = new HashSet<Monomer>();
    Element root = new Element(xHelmNotationExporter.XHELM_ELEMENT);

    Document doc = new Document(root);

    Element helmElement = new Element(xHelmNotationExporter.HELM_NOTATION_ELEMENT);
    helmElement.setText(HELM1Utils.getStandard(helm2notation));

    root.addContent(helmElement);

    Element monomerListElement = new Element(xHelmNotationExporter.MONOMER_LIST_ELEMENT);

    /* save all adhocMonomers in the set */
    for (MonomerNotation monomernotation : MethodsMonomerUtils
            .getListOfMonomerNotation(helm2notation.getListOfPolymers())) {
        /* get all elements of an rna */
        if (monomernotation instanceof MonomerNotationUnitRNA) {
            for (MonomerNotationUnit unit : ((MonomerNotationUnitRNA) monomernotation).getContents()) {
                addAdHocMonomer(unit);
            }
        } else {
            addAdHocMonomer(monomernotation);
        }
    }

    /* give adhoc monomer's information */
    for (Monomer distinctmonomer : set) {
        Element monomerElement = MonomerParser.getMonomerElement(distinctmonomer);
        monomerListElement.getChildren().add(monomerElement);
    }

    root.addContent(monomerListElement);

    XMLOutputter xmlOutput = new XMLOutputter();
    // display nice
    xmlOutput.setFormat(Format.getPrettyFormat());

    return xmlOutput.outputString(doc);

}

From source file:org.humsat.demo.gssw.sensorlocator.kml.SimpleKMLWriter.java

License:Open Source License

/**
 * Writes the current KML tree to the given output stream.
 * //w w w  . ja v  a 2s. c  o m
 * @param os The output stream where the KML tree is to be written.
 * @throws IOException In case an IO error occurs.
 */
public void writeXML(OutputStream os) throws IOException {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    outputter.output(this.kmlDocument, os);
}

From source file:org.isima.carsharing.launcher.Launcher.java

public static void addConfigComment(SettingsDelegate settingsDelegate, File out) {
    try {/*from   w  ww  .  ja  v a2 s. c o m*/
        SAXBuilder builder = new SAXBuilder();

        Document doc = (Document) builder.build(out);
        Element rootNode = doc.getRootElement();
        Element rootNodeCopy = rootNode.clone();

        doc.removeContent(rootNode);
        rootNodeCopy.detach();

        Comment comment = new Comment(settingsDelegate.usedConfigsToXMLComment());
        doc.addContent(comment);
        doc.addContent(rootNodeCopy);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(out));
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.isisaddons.module.docx.fixture.dom.templates.CustomerConfirmation.java

License:Apache License

@Action(semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING)
@ActionLayout(contributed = Contributed.AS_ACTION)
@MemberOrder(sequence = "11")
public Clob downloadCustomerConfirmationInputHtml(final Order order)
        throws IOException, JDOMException, MergeException {

    final Document orderAsHtmlJdomDoc = asInputDocument(order);

    final XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());

    final String html = xmlOutput.outputString(orderAsHtmlJdomDoc);

    final String clobName = "customerConfirmation-" + order.getNumber() + ".html";
    final String clobMimeType = "text/html";
    final String clobBytes = html;

    return new Clob(clobName, clobMimeType, clobBytes);
}

From source file:org.jls.toolbox.util.xml.XMLParser.java

License:Open Source License

/**
 * Permet  partir d'un document XML gnr par JDom de rcuprer la chane
 * formate en XML./*from ww  w .j av a2s  .co m*/
 * 
 * @param xmlDocument
 *            Fichier XML gnr avec JDom.
 * @return Chane formate en XML.
 */
public static String getStream(Document xmlDocument) {
    Format format = Format.getPrettyFormat();
    format.setIndent("\t");
    XMLOutputter output = new XMLOutputter(format);
    return output.outputString(xmlDocument);
}

From source file:org.jls.toolbox.util.xml.XMLParser.java

License:Open Source License

/**
 * Permet d'exporter un {@link Document} vers un fichier XML.
 * /*from w ww . j a  va2s  .  c  om*/
 * @param doc
 *            Document  exporter dans un fichier.
 * @param file
 *            Fichier vers lequel exporter le fichier.
 * @throws FileNotFoundException
 *             Le fichier est cr donc on s'en fout.
 * @throws IOException
 *             Si une erreur survient pendant l'criture, une exception est
 *             leve.
 */
public static void exportToFile(final Document doc, final File file) throws FileNotFoundException, IOException {
    if (doc != null && file != null) {
        try (FileOutputStream os = new FileOutputStream(file)) {
            XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
            out.output(doc, os);
        }
    } else {
        throw new NullPointerException();
    }
}