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:de.knewcleus.openradar.gui.flightplan.FlightPlanExchangeManager.java

License:Open Source License

private String buildXml(FlightPlanData fpd) {
    Document doc = new Document();
    Element root = new Element("flightplanList");
    doc.addContent(root);// ww w.ja  va2  s .  co m

    try {
        root.setAttribute("version", "1.0");
        Element elementFp = FpXml_1_0.createXml(fpd);
        if (elementFp != null) {
            root.addContent(elementFp);
        }
    } catch (Exception ex) {
        log.error("Problem to create flightplan...", ex);
    }
    StringWriter sw = new StringWriter();
    try {
        // XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        sw = new StringWriter();
        outputter.output(doc, sw);
    } catch (Exception e) {
        log.error("Problem to create XML output...", e);
    }

    return sw.toString();
}

From source file:de.knowwe.visualization.dot.DOTRenderer.java

License:Open Source License

/**
 * Adds the target-tag to every URL in the svg-file
 *
 * @created 01.08.2012//from   w ww .  j a  v  a2 s.c  om
 */
private static void augmentSVG(File svg) throws IOException {
    Log.finest("Starting to augment SVG: " + svg.getAbsolutePath());
    try {
        // check if svg file is closed, otherwise wait timeout second
        long start = System.currentTimeMillis();
        while (!Utils.isFileClosed(svg)) {
            if ((System.currentTimeMillis() - start) > TIMEOUT) {
                Log.warning("Exceded timeout while waiting for SVG file to be closed.");
                return;
            }
        }

        Document doc = SAXBuilderSingleton.getInstance().build(svg);
        Element root = doc.getRootElement();
        if (root == null)
            return;

        findAndAugmentElements(root);

        XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
        xmlOutputter.output(doc, new FileWriter(svg));
        Log.finest("Finished augmenting SVG: " + svg.getAbsolutePath());
    } catch (JDOMException e) {
        Log.warning("Exception while augmenting SVG " + svg.getAbsolutePath(), e);
    }
}

From source file:de.nava.informa.exporters.RSS_0_91_Exporter.java

License:Open Source License

public void write(ChannelIF channel) throws IOException {
    if (writer == null) {
        throw new RuntimeException("No writer has been initialized.");
    }/*from  ww w .j  a  v a  2  s.c  om*/

    // create XML outputter with indent: 2 spaces, print new lines.
    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);
    XMLOutputter outputter = new XMLOutputter(format);

    // ----
    Element rootElem = new Element("rss");
    rootElem.setAttribute("version", RSS_VERSION);
    Element channelElem = new Element("channel");

    channelElem.addContent(new Element("title").setText(channel.getTitle()));

    channelElem.addContent(new Element("description").setText(channel.getDescription()));
    if (channel.getSite() != null) {
        channelElem.addContent(new Element("link").setText(channel.getSite().toString()));
    }
    if (channel.getLanguage() != null) {
        channelElem.addContent(new Element("language").setText(channel.getLanguage()));
    }

    Collection items = channel.getItems();
    Iterator it = items.iterator();
    while (it.hasNext()) {
        channelElem.addContent(getItemElement((ItemIF) it.next()));
    }

    // export channel image
    if (channel.getImage() != null) {
        Element imgElem = new Element("image");
        imgElem.addContent(new Element("title").setText(channel.getImage().getTitle()));
        imgElem.addContent(new Element("url").setText(channel.getImage().getLocation().toString()));
        imgElem.addContent(new Element("link").setText(channel.getImage().getLink().toString()));
        imgElem.addContent(new Element("height").setText("" + channel.getImage().getHeight()));
        imgElem.addContent(new Element("width").setText("" + channel.getImage().getWidth()));
        imgElem.addContent(new Element("description").setText(channel.getImage().getDescription()));
        channelElem.addContent(imgElem);
    }

    // TODO: add exporting textinput field
    //     if (channel.getTextInput() != null) {
    //       channelElem.addContent(channel.getTextInput().getElement());
    //     }

    if (channel.getCopyright() != null) {
        channelElem.addContent(new Element("copyright").setText(channel.getCopyright()));
    }

    // we have all together for the channel definition
    rootElem.addContent(channelElem);
    // ---
    DocType docType = new DocType("rss", PUBLIC_ID, SYSTEM_ID);
    Document doc = new Document(rootElem, docType);
    outputter.output(doc, writer);
}

From source file:de.nava.informa.exporters.RSS_1_0_Exporter.java

License:Open Source License

public void write(ChannelIF channel) throws IOException {
    if (writer == null) {
        throw new RuntimeException("No writer has been initialized.");
    }// w  ww  .  j a v a 2s  .  c o  m

    Element rootElem = new Element("RDF", NS_RDF);
    rootElem.addNamespaceDeclaration(NS_DEFAULT); // TODO
    rootElem.addNamespaceDeclaration(NS_DC);
    rootElem.addNamespaceDeclaration(NS_SY);
    // rootElem.setAttribute("version");
    Element channelElem = new Element("channel", NS_DEFAULT);
    if (channel.getLocation() != null) {
        channelElem.setAttribute("about", channel.getLocation().toString(), NS_RDF);
    }
    channelElem.addContent(new Element("title", NS_DEFAULT).setText(channel.getTitle()));
    if (channel.getSite() != null) {
        channelElem.addContent(new Element("link", NS_DEFAULT).setText(channel.getSite().toString()));
        channelElem.addContent(
                new Element("source", NS_DC).setAttribute("resource", channel.getSite().toString()));
    }

    channelElem.addContent(new Element("description", NS_DEFAULT).setText(channel.getDescription()));
    if (channel.getLanguage() != null) {
        channelElem.addContent(new Element("language", NS_DC).setText(channel.getLanguage()));
    }
    if (channel.getCopyright() != null) {
        channelElem.addContent(new Element("copyright", NS_DC).setText(channel.getCopyright()));
    }
    if (channel.getUpdateBase() != null) {
        channelElem.addContent(new Element("updateBase", NS_SY).setText(df.format(channel.getUpdateBase())));
    }
    if (channel.getUpdatePeriod() != null) {
        // don't put out frequency without specifying period
        channelElem.addContent(new Element("updateFrequency", NS_SY)
                .setText((new Integer(channel.getUpdateFrequency())).toString()));
        channelElem
                .addContent(new Element("updatePeriod", NS_SY).setText(channel.getUpdatePeriod().toString()));
    }
    // export channel image
    if (channel.getImage() != null) {
        Element imgElem = new Element("image", NS_DEFAULT);
        imgElem.addContent(new Element("title", NS_DEFAULT).setText(channel.getImage().getTitle()));
        imgElem.addContent(new Element("url", NS_DEFAULT).setText(channel.getImage().getLocation().toString()));
        imgElem.addContent(new Element("link", NS_DEFAULT).setText(channel.getImage().getLink().toString()));
        imgElem.addContent(new Element("height", NS_DEFAULT).setText("" + channel.getImage().getHeight()));
        imgElem.addContent(new Element("width", NS_DEFAULT).setText("" + channel.getImage().getWidth()));
        imgElem.addContent(new Element("description", NS_DEFAULT).setText(channel.getImage().getDescription()));
        channelElem.addContent(imgElem);
    }

    // TODO: add exporting textinput field
    //     if (channel.getTextInput() != null) {
    //       channelElem.addContent(channel.getTextInput().getElement());
    //     }

    // ===========================================
    Element itemsElem = new Element("items", NS_DEFAULT);
    Element seqElem = new Element("Seq", NS_RDF);
    Collection items = channel.getItems();
    Iterator it = items.iterator();
    while (it.hasNext()) {
        ItemIF item = (ItemIF) it.next();
        Element itemElem = new Element("li", NS_RDF);
        if (item.getLink() != null) {
            itemElem.setAttribute("resource", item.getLink().toString());
        }
        seqElem.addContent(itemElem);
    }
    itemsElem.addContent(seqElem);
    channelElem.addContent(itemsElem);
    rootElem.addContent(channelElem);

    // item-by-item en detail
    items = channel.getItems();
    it = items.iterator();
    while (it.hasNext()) {
        rootElem.addContent(getItemElement((ItemIF) it.next()));
    }

    // create XML outputter with indent: 2 spaces, print new lines.
    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);
    XMLOutputter outputter = new XMLOutputter(format);
    // write DOM to file
    Document doc = new Document(rootElem);
    outputter.output(doc, writer);
    writer.close();
}

From source file:de.nava.informa.exporters.RSS_2_0_Exporter.java

License:Open Source License

public void write(ChannelIF channel) throws IOException {
    if (writer == null) {
        throw new RuntimeException("No writer has been initialized.");
    }/*from  w  w  w.j a va2  s.c o  m*/

    // create XML outputter with indent: 2 spaces, print new lines.
    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);
    XMLOutputter outputter = new XMLOutputter(format);

    Namespace dcNs = Namespace.getNamespace("dc", NS_DC);
    Namespace syNs = Namespace.getNamespace("sy", NS_SY);
    Namespace adminNs = Namespace.getNamespace("admin", NS_ADMIN);
    //Namespace rdfNs = Namespace.getNamespace("rdf", NS_RDF);

    Element rootElem = new Element("rss");
    rootElem.addNamespaceDeclaration(dcNs);
    rootElem.addNamespaceDeclaration(syNs);
    rootElem.addNamespaceDeclaration(adminNs);
    rootElem.setAttribute("version", RSS_VERSION);

    Element channelElem = new Element("channel");
    // rootElem.setAttribute("version");
    channelElem.addContent(new Element("title").setText(channel.getTitle()));
    if (channel.getSite() != null) {
        channelElem.addContent(new Element("link").setText(channel.getSite().toString()));
    }

    channelElem.addContent(new Element("description").setText(channel.getDescription()));
    if (channel.getLanguage() != null) {
        channelElem.addContent(new Element("language", dcNs).setText(channel.getLanguage()));
    }
    if (channel.getCopyright() != null) {
        channelElem.addContent(new Element("copyright", dcNs).setText(channel.getCopyright()));
    }
    if (channel.getPubDate() != null) {
        channelElem.addContent(new Element("pubDate").setText(ParserUtils.formatDate(channel.getPubDate())));
    }
    if (channel.getCategories() != null) {
        Collection categories = channel.getCategories();
        for (Object category : categories) {
            CategoryIF cat = (CategoryIF) category;
            channelElem = getCategoryElements(channelElem, cat, null);
        }
    }

    if (channel.getUpdateBase() != null) {
        channelElem.addContent(new Element("updateBase", syNs).setText(df.format(channel.getUpdateBase())));
    }
    if (channel.getUpdatePeriod() != null) {
        // don't put out frequency without specifying period
        channelElem.addContent(new Element("updateFrequency", syNs)
                .setText((new Integer(channel.getUpdateFrequency())).toString()));
        channelElem.addContent(new Element("updatePeriod", syNs).setText(channel.getUpdatePeriod().toString()));
    }
    // export channel image            
    if (channel.getImage() != null) {
        Element imgElem = new Element("image");
        imgElem.addContent(new Element("title").setText(channel.getImage().getTitle()));
        imgElem.addContent(new Element("url").setText(channel.getImage().getLocation().toString()));
        imgElem.addContent(new Element("link").setText(channel.getImage().getLink().toString()));
        imgElem.addContent(new Element("height").setText("" + channel.getImage().getHeight()));
        imgElem.addContent(new Element("width").setText("" + channel.getImage().getWidth()));
        imgElem.addContent(new Element("description").setText(channel.getImage().getDescription()));
        channelElem.addContent(imgElem);
    }

    // TODO: add exporting textinput field
    //     if (channel.getTextInput() != null) {
    //       channelElem.addContent(channel.getTextInput().getElement());
    //     }

    Collection items = channel.getItems();
    for (Object item : items) {
        channelElem.addContent(getItemElement((ItemIF) item));
    }

    rootElem.addContent(channelElem);

    // ---
    Document doc = new Document(rootElem);
    outputter.output(doc, writer);
    // ---
    writer.close();
}

From source file:de.relaunch64.popelganda.database.CustomScripts.java

License:Open Source License

/**
 * Saves the scripts to xml-file/*  w  w w. ja  v a  2s.c o  m*/
 */
public void saveScripts() {
    // if file exists, go on...
    if (filepath != null) {
        OutputStream dest = null;
        try {
            XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
            dest = new FileOutputStream(filepath);
            out.output(scriptFile, dest);
        } catch (IOException ex) {
            ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage());
        } finally {
            if (dest != null) {
                try {
                    dest.close();
                } catch (IOException ex) {
                    ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage());
                }
            }
        }
    }
}

From source file:de.relaunch64.popelganda.database.Settings.java

License:Open Source License

/**
 * Loads the settings file/* w  ww  . j a  va2  s  .  c  o  m*/
 */
public void saveSettings() {
    // if file exists, go on...
    if (filepath != null) {
        OutputStream dest = null;
        try {
            XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
            dest = new FileOutputStream(filepath);
            out.output(settingsFile, dest);
        } catch (IOException ex) {
            ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage());
        } finally {
            if (dest != null) {
                try {
                    dest.close();
                } catch (IOException ex) {
                    ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage());
                }
            }
        }
    }
}

From source file:de.sixtyfourktec.mirrorhub.modules.NationalRailModule.java

License:Open Source License

private NationalRailModule() {
    /* Create the soap envelope document */
    Document doc = new Document();
    Namespace soap = Namespace.getNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
    Namespace ldb = Namespace.getNamespace("ldb", "http://thalesgroup.com/RTTI/2014-02-20/ldb/");
    Namespace typ = Namespace.getNamespace("typ", "http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes");
    Element env = new Element("Envelope", soap);
    /* Header *//*from   w  w w.  j  av a  2 s .  co m*/
    env.addContent(new Element("Header", soap).addContent(new Element("AccessToken", typ)
            .addContent(new Element("TokenValue", typ).addContent(BuildConfig.NATIONALRAIL_API_KEY))));
    /* Body */
    Element dep_request = new Element("GetDepartureBoardRequest", ldb)
            .addContent(new Element("crs", ldb).addContent(BuildConfig.NATIONALRAIL_CRS))
            .addContent(new Element("numRows", ldb).addContent("5"));
    if (!BuildConfig.NATIONALRAIL_FILTER_CRS.isEmpty()) {
        dep_request.addContent(new Element("filterCrs", ldb).addContent(BuildConfig.NATIONALRAIL_FILTER_CRS))
                .addContent(new Element("filterType", ldb).addContent(BuildConfig.NATIONALRAIL_FILTER_TYPE));
    }
    env.addContent(new Element("Body", soap).addContent(dep_request));
    doc.setContent(env);
    String xml = new XMLOutputter(Format.getPrettyFormat()).outputString(doc);
    if (showXml) {
        Log.i(TAG, xml);
    }

    /* Create a static request object we can reuse */
    RequestBody body = RequestBody.create(MediaType.parse("text/xml; charset=utf-8"), xml);
    request = new Request.Builder().url("https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb6.asmx")
            .post(body).build();
}

From source file:de.smartics.maven.plugin.jboss.modules.domain.ModuleBuilder.java

License:Apache License

private void createModuleXml(final File moduleFolder) throws IOException {
    final ModuleXmlBuilder xml = new ModuleXmlBuilder(context, module, dependencies);
    final XMLOutputter outputter = new XMLOutputter();
    outputter.setFormat(Format.getPrettyFormat());
    final File file = new File(moduleFolder, "module.xml");
    OutputStream out = null;/*w  w  w . j  a  va 2  s  . com*/
    try {
        out = new BufferedOutputStream(new FileOutputStream(file));
        final Document document = xml.build();
        outputter.output(document, out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:de.sub.goobi.helper.tasks.ProcessSwapOutTask.java

License:Open Source License

/**
 * Aufruf als Thread ================================================================
 *//* w  ww  .  j a va  2  s .  c  o  m*/
@SuppressWarnings("deprecation")
@Override
public void run() {
    setStatusProgress(5);
    Helper help = new Helper();
    String swapPath = null;
    //      ProzessDAO dao = new ProzessDAO();
    String processDirectory = "";

    if (ConfigurationHelper.getInstance().isUseSwapping()) {
        swapPath = ConfigurationHelper.getInstance().getSwapPath();
    } else {
        setStatusMessage("swapping not activated");
        setStatusProgress(-1);
        return;
    }
    if (swapPath == null || swapPath.length() == 0) {
        setStatusMessage("no swappingPath defined");
        setStatusProgress(-1);
        return;
    }
    Path swapFile = Paths.get(swapPath);
    if (!StorageProvider.getInstance().isFileExists(swapFile)) {
        setStatusMessage("Swap folder does not exist or is not mounted");
        setStatusProgress(-1);
        return;
    }
    try {
        processDirectory = getProzess().getProcessDataDirectoryIgnoreSwapping();
        //TODO: Don't catch Exception (the super class)
    } catch (Exception e) {
        logger.warn("Exception:", e);
        setStatusMessage(
                "Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage());
        setStatusProgress(-1);
        return;
    }

    Path fileIn = Paths.get(processDirectory);
    Path fileOut = Paths.get(swapPath + getProzess().getId() + FileSystems.getDefault().getSeparator());
    if (StorageProvider.getInstance().isFileExists(fileOut)) {
        setStatusMessage(getProzess().getTitel() + ": swappingOutTarget already exists");
        setStatusProgress(-1);
        return;
    }
    try {
        StorageProvider.getInstance().createDirectories(fileOut);
    } catch (IOException e1) {
        logger.error(e1);
    }

    /* ---------------------
     * Xml-Datei vorbereiten
    * -------------------*/
    Document doc = new Document();
    Element root = new Element("goobiArchive");
    doc.setRootElement(root);
    Element source = new Element("source").setText(fileIn.toString());
    Element target = new Element("target").setText(fileOut.toString());
    Element title = new Element("title").setText(getProzess().getTitel());
    Element mydate = new Element("date").setText(new Date().toString());
    root.addContent(source);
    root.addContent(target);
    root.addContent(title);
    root.addContent(mydate);

    /* ---------------------
     * Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren
    * -------------------*/
    setStatusProgress(50);
    try {
        setStatusMessage("copying process folder");
        Helper.copyDirectoryWithCrc32Check(fileIn, fileOut, help.getGoobiDataDirectory().length(), root);
    } catch (IOException e) {
        logger.warn("IOException:", e);
        setStatusMessage("IOException in copyDirectory: " + e.getMessage());
        setStatusProgress(-1);
        return;
    }
    setStatusProgress(80);
    StorageProvider.getInstance().deleteDataInDir(fileIn);

    /* ---------------------
     * xml-Datei schreiben
    * -------------------*/
    Format format = Format.getPrettyFormat();
    format.setEncoding("UTF-8");
    try {
        setStatusMessage("writing swapped.xml");
        XMLOutputter xmlOut = new XMLOutputter(format);
        FileOutputStream fos = new FileOutputStream(
                processDirectory + FileSystems.getDefault().getSeparator() + "swapped.xml");
        xmlOut.output(doc, fos);
        fos.close();
        //TODO: Don't catch Exception (the super class)
    } catch (Exception e) {
        logger.warn("Exception:", e);
        setStatusMessage(e.getClass().getName() + " in xmlOut.output: " + e.getMessage());
        setStatusProgress(-1);
        return;
    }
    setStatusProgress(90);

    /* in Prozess speichern */
    try {
        setStatusMessage("saving process");
        Process myProzess = ProcessManager.getProcessById(getProzess().getId());
        myProzess.setSwappedOutGui(true);
        ProcessManager.saveProcess(myProzess);
    } catch (DAOException e) {
        setStatusMessage("DAOException while saving process: " + e.getMessage());
        logger.warn("DAOException:", e);
        setStatusProgress(-1);
        return;
    }
    setStatusMessage("done");
    setStatusProgress(100);
}