Example usage for org.jdom2.output Format setIndent

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

Introduction

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

Prototype

public Format setIndent(String indent) 

Source Link

Document

This will set the indent String to use; this is usually a String of empty spaces.

Usage

From source file:ca.nrc.cadc.caom2.xml.JsonWriter.java

License:Open Source License

/**
 * Write the root Element to a writer./*from   ww w  . j a  va  2s.c  o  m*/
 *
 * @param root
 *            Root Element to write.
 * @param writer
 *            Writer to write to.
 * @throws IOException
 *             if the writer fails to write.
 */
@Override
protected void write(Element root, Writer writer) throws IOException {
    JsonOutputter outputter = new JsonOutputter();
    outputter.getListElementNames().add("planes");
    outputter.getListElementNames().add("artifacts");
    outputter.getListElementNames().add("parts");
    outputter.getListElementNames().add("vertices");
    outputter.getListElementNames().add("points");
    outputter.getListElementNames().add("inputs");
    outputter.getListElementNames().add("states");
    outputter.getListElementNames().add("samples");
    outputter.getListElementNames().add("members");
    if (docVersion >= 23) {
        outputter.getListElementNames().add("keywords");
    }

    outputter.getStringElementNames().add("observationID");
    outputter.getStringElementNames().add("productID");
    outputter.getStringElementNames().add("sequenceNumber");
    outputter.getStringElementNames().add("name"); // anything with a name

    Format fmt = null;
    if (prettyPrint) {
        fmt = Format.getPrettyFormat();
        fmt.setIndent("  "); // 2 spaces
    }
    outputter.setFormat(fmt);
    Document document = new Document(root);
    outputter.output(document, writer);
}

From source file:com.bc.ceres.nbmgen.NbmGenTool.java

License:Open Source License

private static void writeXml(File file, Document document) throws IOException {
    XMLOutputter xmlOutput = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent("    ");
    xmlOutput.setFormat(format);/* w  w w. jav a  2  s  .  c  o m*/
    xmlOutput.output(document, new FileWriter(file));
}

From source file:net.alegen.datpass.library.configure.XMLConfigurator.java

License:Open Source License

@Override
public boolean saveConfig() {
    XMLOutputter xmlOutput = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent("    ");
    xmlOutput.setFormat(format);//  www  .j av  a2 s .  c o  m
    try {
        xmlOutput.output(this.root.getDocument(), new FileOutputStream(configFileName));
        return true;
    } catch (IOException e) {
        log.error("An IO exception occured while saving data.");
        return false;
    }
}

From source file:nl.colorize.util.xml.XMLHelper.java

License:Apache License

private static XMLOutputter getOutputter() {
    Format formatter = Format.getPrettyFormat();
    formatter.setEncoding(Charsets.UTF_8.displayName());
    formatter.setIndent("    ");
    formatter.setLineSeparator(Platform.getLineSeparator());
    formatter.setExpandEmptyElements(false);
    formatter.setOmitDeclaration(false);
    formatter.setOmitEncoding(false);/*from w w w.ja  v a 2  s .  co  m*/

    XMLOutputter outputter = new XMLOutputter(formatter);
    outputter.setFormat(formatter);
    return outputter;
}

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.//www .j av a 2  s  .  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.mule.tools.apikit.output.MuleConfigGenerator.java

License:Open Source License

public void generate() {
    Map<API, Document> docs = new HashMap<API, Document>();

    for (GenerationModel flowEntry : flowEntries) {
        Document doc;/*ww w .  j ava 2  s.co m*/

        API api = flowEntry.getApi();
        try {
            doc = getOrCreateDocument(docs, api);
        } catch (Exception e) {
            log.error("Error generating xml for file: [" + api.getYamlFile() + "]", e);
            continue;
        }

        // Generate each of the APIKit flows
        doc.getRootElement().addContent(new APIKitFlowScope(flowEntry).generate());
    }

    // Write everything to files
    for (Map.Entry<API, Document> yamlFileDescriptorDocumentEntry : docs.entrySet()) {
        Format prettyFormat = Format.getPrettyFormat();
        prettyFormat.setIndent(INDENTATION);
        prettyFormat.setLineSeparator(System.getProperty("line.separator"));
        prettyFormat.setEncoding("UTF-8");
        XMLOutputter xout = new XMLOutputter(prettyFormat);
        Document doc = yamlFileDescriptorDocumentEntry.getValue();
        File xmlFile = yamlFileDescriptorDocumentEntry.getKey().getXmlFile(rootDirectory);
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(xmlFile);
            xout.output(doc, fileOutputStream);
            fileOutputStream.close();
            log.info("Updating file: [" + xmlFile + "]");
        } catch (IOException e) {
            log.error("Error writing to file: [" + xmlFile + "]", e);
        }
    }

    // Generate mule deploy properties file
    new MuleDeployWriter(rootDirectory).generate();
}