Example usage for org.dom4j.io OutputFormat OutputFormat

List of usage examples for org.dom4j.io OutputFormat OutputFormat

Introduction

In this page you can find the example usage for org.dom4j.io OutputFormat OutputFormat.

Prototype

public OutputFormat(String indent, boolean newlines) 

Source Link

Document

Creates an OutputFormat with the given indent added with optional newlines between the Elements.

Usage

From source file:org.olat.ims.qti.qpool.QTIImportProcessor.java

License:Apache License

protected void processAssessmentFiles(QuestionItemImpl item, ItemInfos itemInfos) {
    //a package with an item
    String dir = item.getDirectory();
    String rootFilename = item.getRootFilename();
    VFSContainer container = qpoolFileStorage.getContainer(dir);
    VFSLeaf endFile = container.createChildLeaf(rootFilename);

    //embed in <questestinterop>
    DocumentFactory df = DocumentFactory.getInstance();
    Document itemDoc = df.createDocument();
    Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
    itemDoc.setRootElement(questestinteropEl);
    Element deepClone = (Element) itemInfos.getItemEl().clone();
    questestinteropEl.add(deepClone);//from w ww  . j av a  2s .c o m

    //write
    try {
        OutputStream os = endFile.getOutputStream(false);
        ;
        XMLWriter xw = new XMLWriter(os, new OutputFormat("  ", true));
        xw.write(itemDoc.getRootElement());
        xw.close();
        os.close();
    } catch (IOException e) {
        log.error("", e);
    }

    //there perhaps some other materials
    if (importedFilename.toLowerCase().endsWith(".zip")) {
        processAssessmentMaterials(deepClone, container);
    }
}

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

public static void regionToKML(Region region, String filename, Color c) {
    String kmlFileName = filename + ".kml";
    Document doc = DocumentHelper.createDocument();
    Element root = new DefaultElement("kml", new Namespace("", "http://www.opengis.net/kml/2.2"));
    doc.add(root);/* ww w. ja va 2  s.c  o m*/

    Element e_doc = root.addElement("Document");
    Element e_doc_name = e_doc.addElement("name");
    e_doc_name.addText(kmlFileName);

    addBorderStyle(e_doc, c);
    addBorderVertexStyle(e_doc);
    addGridNodeStyle(e_doc, c);

    Element e_folder = e_doc.addElement("Folder");
    Element e_folder_name = e_folder.addElement("name");
    e_folder_name.addText("region");
    Element e_open = e_folder.addElement("open");
    e_open.addText("1");

    addBorder(e_folder, region);
    addPoints(e_folder, "Border Nodes", region.getBorder(), Style.BORDER_VERTEX);
    if (region.getInteriors() != null) {
        for (LocationList interior : region.getInteriors()) {
            addPoints(e_folder, "Interior Nodes", interior, Style.BORDER_VERTEX);
        }
    }

    if (region instanceof GriddedRegion) {
        addPoints(e_folder, "Grid Nodes", ((GriddedRegion) region).getNodeList(), Style.GRID_NODE);
    }

    // TODO absolutely need to create seom platform specific output directory
    // that is not in project space (e.g. desktop, Decs and Settings);

    String outDirName = "sha_kml/";
    File outDir = new File(outDirName);
    outDir.mkdirs();
    String tmpFile = outDirName + kmlFileName;

    try {
        //XMLUtils.writeDocumentToFile(tmpFile, doc);
        XMLWriter writer;
        OutputFormat format = new OutputFormat("\t", true);
        writer = new XMLWriter(new FileWriter(tmpFile), format);
        writer.write(doc);
        writer.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    //Element e = new Elem
}

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

public static void locListToKML(LocationList locs, String filename, Color c) {
    String kmlFileName = filename + ".kml";
    Document doc = DocumentHelper.createDocument();
    Element root = new DefaultElement("kml", new Namespace("", "http://www.opengis.net/kml/2.2"));
    doc.add(root);//from   w  w w.  jav a2s .c  o m

    Element e_doc = root.addElement("Document");
    Element e_doc_name = e_doc.addElement("name");
    e_doc_name.addText(kmlFileName);

    addBorderStyle(e_doc, c);
    addBorderVertexStyle(e_doc);
    addGridNodeStyle(e_doc, c);

    Element e_folder = e_doc.addElement("Folder");
    Element e_folder_name = e_folder.addElement("name");
    e_folder_name.addText("region");
    Element e_open = e_folder.addElement("open");
    e_open.addText("1");

    //      addLocationPoly(e_folder, locs);
    addLocationLine(e_folder, locs);
    addPoints(e_folder, "Border Nodes", locs, Style.BORDER_VERTEX);

    // TODO absolutely need to create seom platform specific output directory
    // that is not in project space (e.g. desktop, Decs and Settings);

    String outDirName = "sha_kml/";
    File outDir = new File(outDirName);
    outDir.mkdirs();
    String tmpFile = outDirName + kmlFileName;

    try {
        //XMLUtils.writeDocumentToFile(tmpFile, doc);
        XMLWriter writer;
        OutputFormat format = new OutputFormat("\t", true);
        writer = new XMLWriter(new FileWriter(tmpFile), format);
        writer.write(doc);
        writer.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    //Element e = new Elem
}

From source file:org.saiku.adhoc.utils.XmlUtils.java

License:Open Source License

public static String prettyPrint(final String xml) {
    StringWriter sw = null;/*from  w  ww .j a va  2  s .  c om*/

    try {
        final OutputFormat format = new OutputFormat("  ", true);
        //OutputFormat.createPrettyPrint();
        final org.dom4j.Document document = DocumentHelper.parseText(xml);
        sw = new StringWriter();
        final XMLWriter writer = new XMLWriter(sw, format);
        writer.write(document);
    } catch (Exception e) {
        System.out.println("creating beautified xml failed, refer to exc : " + e.getMessage());
    }
    return sw.toString();
}

From source file:org.xwiki.tool.xar.XARMojo.java

License:Open Source License

/**
 * Create and add package configuration file to the package.
 * //from  ww  w. ja  v a 2  s.  com
 * @param packageFile the package when to add configuration file.
 * @param files the files in the package.
 * @throws Exception error when writing the configuration file.
 */
private void generatePackageXml(File packageFile, Collection<ArchiveEntry> files) throws Exception {
    getLog().info(String.format("Generating package.xml descriptor at [%s]", packageFile.getPath()));

    OutputFormat outputFormat = new OutputFormat("", true);
    outputFormat.setEncoding(this.encoding);
    OutputStream out = new FileOutputStream(packageFile);
    XMLWriter writer = new XMLWriter(out, outputFormat);
    writer.write(toXML(files));
    writer.close();
    out.close();
}

From source file:RBNLearning.RelData.java

License:Open Source License

public void saveToRDEF(FileWriter fwriter) {
    try {//  w ww . j av a 2  s . c om
        XMLWriter writer = new XMLWriter(fwriter, new OutputFormat("   ", true));
        Document doc = this.toDocument();
        writer.write(doc);
        writer.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}