Example usage for org.jdom2.output Format setLineSeparator

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

Introduction

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

Prototype

public Format setLineSeparator(LineSeparator separator) 

Source Link

Document

This will set the newline separator sequence.

Usage

From source file:jodtemplate.util.JDOMHelper.java

License:Apache License

public void write(final Document dom, final OutputStream stream) throws IOException {
    final Format format = Format.getRawFormat();
    format.setLineSeparator(LineSeparator.UNIX);
    final XMLOutputter outputter = new XMLOutputter(format, new StandaloneOutputProcessor());
    outputter.output(dom, stream);/*from   w  ww  .j  av  a  2s  .  c o m*/
}

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  ww  w .jav a  2 s  .  c  o m

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

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;/*from  w ww .j  av a2 s.c  om*/

        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();
}

From source file:org.mycore.frontend.editor.MCREditorServlet.java

License:Open Source License

private void sendToDebug(HttpServletResponse res, Document unprocessed, MCREditorSubmission sub)
        throws IOException, UnsupportedEncodingException {
    res.setContentType("text/html; charset=UTF-8");

    PrintWriter pw = res.getWriter();

    pw.println("<html><body><p><pre>");

    for (int i = 0; i < sub.getVariables().size(); i++) {
        MCREditorVariable var = (MCREditorVariable) sub.getVariables().get(i);
        pw.println(var.getPath() + " = " + var.getValue());

        FileItem file = var.getFile();

        if (file != null) {
            pw.println("      is uploaded file " + file.getContentType() + ", " + file.getSize() + " bytes");
        }/*from  w  w  w  . ja  v  a2 s.  co m*/
    }

    pw.println("</pre></p><p>");

    XMLOutputter outputter = new XMLOutputter();
    Format fmt = Format.getPrettyFormat();
    fmt.setLineSeparator("\n");
    fmt.setOmitDeclaration(true);
    outputter.setFormat(fmt);

    Element pre = new Element("pre");
    pre.addContent(outputter.outputString(unprocessed));
    outputter.output(pre, pw);

    pre = new Element("pre");
    pre.addContent(outputter.outputString(sub.getXML()));
    outputter.output(pre, pw);

    pw.println("</p></body></html>");
    pw.close();
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

public static void convertViewPoint(ViewPointResource viewPointResource) {

    File viewPointDirectory = ResourceLocator.retrieveResourceAsFile(viewPointResource.getDirectory());
    File xmlFile = (File) viewPointResource.getFlexoIODelegate().getSerializationArtefact();// getFile();

    logger.info("Converting " + viewPointDirectory.getAbsolutePath());

    File diagramSpecificationDir = new File(viewPointDirectory, "DiagramSpecification");
    diagramSpecificationDir.mkdir();//  www .j av a  2s  .co  m

    logger.fine("Creating directory " + diagramSpecificationDir.getAbsolutePath());

    try {
        Document viewPointDocument = XMLUtils.readXMLFile(xmlFile);
        Document diagramSpecificationDocument = XMLUtils.readXMLFile(xmlFile);

        for (File f : viewPointDirectory.listFiles()) {
            if (!f.equals(xmlFile) && !f.equals(diagramSpecificationDir) && !f.getName().endsWith("~")) {
                if (f.getName().endsWith(".shema")) {
                    try {
                        File renamedExampleDiagramFile = new File(f.getParentFile(),
                                f.getName().substring(0, f.getName().length() - 6) + ".diagram");
                        FileUtils.rename(f, renamedExampleDiagramFile);
                        f = renamedExampleDiagramFile;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                File destFile = new File(diagramSpecificationDir, f.getName());
                FileUtils.rename(f, destFile);
                logger.fine("Moving file " + f.getAbsolutePath() + " to " + destFile.getAbsolutePath());
            }
            if (f.getName().endsWith("~")) {
                f.delete();
            }
        }

        Element diagramSpecification = XMLUtils.getElement(diagramSpecificationDocument, "ViewPoint");
        diagramSpecification.setName("DiagramSpecification");
        FileOutputStream fos = new FileOutputStream(
                new File(diagramSpecificationDir, "DiagramSpecification.xml"));
        Format prettyFormat = Format.getPrettyFormat();
        prettyFormat.setLineSeparator(LineSeparator.SYSTEM);
        XMLOutputter outputter = new XMLOutputter(prettyFormat);
        try {
            outputter.output(diagramSpecificationDocument, fos);
        } catch (IOException e) {
            e.printStackTrace();
        }
        fos.flush();
        fos.close();
    } catch (JDOMException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    ((ViewPointResourceImpl) viewPointResource).exploreVirtualModels(viewPointResource.getDirectory());

}

From source file:org.openflexo.foundation.utils.XMLUtils.java

License:Open Source License

public static boolean saveXMLFile(org.jdom2.Document document, OutputStream os) {
    try {/* w w  w.j  a  v a2s  . co  m*/
        Format prettyFormat = Format.getPrettyFormat();
        prettyFormat.setLineSeparator(LineSeparator.SYSTEM);
        XMLOutputter outputter = new XMLOutputter(prettyFormat);
        outputter.output(document, os);
        return true;
    } catch (Exception e) {
        // Warns about the exception
        if (logger.isLoggable(Level.WARNING)) {
            logger.warning("Exception raised: " + e.getClass().getName() + ". See console for details.");
        }
        e.printStackTrace();
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}

From source file:org.openflexo.foundation.viewpoint.rm.ViewPointResourceImpl.java

License:Open Source License

public static void convertViewPoint(ViewPointResource viewPointResource) {

    File viewPointDirectory = ResourceLocator.retrieveResourceAsFile(viewPointResource.getDirectory());
    File xmlFile = (File) viewPointResource.getFlexoIODelegate().getSerializationArtefact();//getFile();

    logger.info("Converting " + viewPointDirectory.getAbsolutePath());

    File diagramSpecificationDir = new File(viewPointDirectory, "DiagramSpecification");
    diagramSpecificationDir.mkdir();//  w w  w. j a  va  2s .  c  om

    logger.fine("Creating directory " + diagramSpecificationDir.getAbsolutePath());

    try {
        Document viewPointDocument = XMLUtils.readXMLFile(xmlFile);
        Document diagramSpecificationDocument = XMLUtils.readXMLFile(xmlFile);

        for (File f : viewPointDirectory.listFiles()) {
            if (!f.equals(xmlFile) && !f.equals(diagramSpecificationDir) && !f.getName().endsWith("~")) {
                if (f.getName().endsWith(".shema")) {
                    try {
                        File renamedExampleDiagramFile = new File(f.getParentFile(),
                                f.getName().substring(0, f.getName().length() - 6) + ".diagram");
                        FileUtils.rename(f, renamedExampleDiagramFile);
                        f = renamedExampleDiagramFile;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                File destFile = new File(diagramSpecificationDir, f.getName());
                FileUtils.rename(f, destFile);
                logger.fine("Moving file " + f.getAbsolutePath() + " to " + destFile.getAbsolutePath());
            }
            if (f.getName().endsWith("~")) {
                f.delete();
            }
        }

        Element diagramSpecification = XMLUtils.getElement(diagramSpecificationDocument, "ViewPoint");
        diagramSpecification.setName("DiagramSpecification");
        FileOutputStream fos = new FileOutputStream(
                new File(diagramSpecificationDir, "DiagramSpecification.xml"));
        Format prettyFormat = Format.getPrettyFormat();
        prettyFormat.setLineSeparator(LineSeparator.SYSTEM);
        XMLOutputter outputter = new XMLOutputter(prettyFormat);
        try {
            outputter.output(diagramSpecificationDocument, fos);
        } catch (IOException e) {
            e.printStackTrace();
        }
        fos.flush();
        fos.close();
    } catch (JDOMException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    ((ViewPointResourceImpl) viewPointResource).exploreVirtualModels(viewPointResource.getDirectory());

}

From source file:org.polago.deployconf.DeploymentWriter.java

License:Open Source License

/**
 * Write the given DeploymentConfig to persistent storage.
 *
 * @param deploymentConfig the DeploymentConfig to persist
 * @throws IOException indicating IO problems
 *//*w  w w.j a v  a 2  s.  c  om*/
public void persist(DeploymentConfig deploymentConfig) throws IOException {
    Format format = Format.getPrettyFormat();
    format.setLineSeparator(LineSeparator.UNIX);
    format.setExpandEmptyElements(true);
    XMLOutputter outputter = new XMLOutputter(format);

    Element root = new Element(DOM_ROOT);
    String name = deploymentConfig.getName();
    if (name != null) {
        root.setAttribute(ATTR_NAME, name);
    }
    Document document = new Document();
    document.setRootElement(root);

    for (Task task : deploymentConfig.getTasks()) {
        Element node = new Element(task.getSerializedName());
        root.addContent(node);
        task.serialize(node, groupManager);
    }

    outputter.output(document, outputStream);
}