Example usage for org.jdom2.output LineSeparator SYSTEM

List of usage examples for org.jdom2.output LineSeparator SYSTEM

Introduction

In this page you can find the example usage for org.jdom2.output LineSeparator SYSTEM.

Prototype

LineSeparator SYSTEM

To view the source code for org.jdom2.output LineSeparator SYSTEM.

Click Source Link

Document

The system-dependent Separator sequence NL which is obtained from System.getProperty("line.separator").

Usage

From source file:com.c4om.utils.xmlutils.JDOMUtils.java

License:Apache License

/**
 * Method that converts a JDOM2 {@link Document} to String
 * @param document the document/*from w  w  w  .j a  v  a  2 s  .  com*/
 * @return the string
 */
public static String convertJDOMDocumentToString(Document document) {
    Format xmlFormat = Format.getPrettyFormat();
    xmlFormat.setLineSeparator(LineSeparator.SYSTEM);
    XMLOutputter outputter = new XMLOutputter(xmlFormat);
    String result = outputter.outputString(document);
    return result;
}

From source file:es.upm.dit.xsdinferencer.Results.java

License:Apache License

/**
 * Converts a Map<String,Document> to a Map<String,String> with the same keys and String representations 
 * of the documents as values.<br/>
 * The XMLs are generated using the format returned by {@link Format#getPrettyFormat()} and the system line separator. 
 * For more information about this, see {@link Format}.
 * @param inputMap a map between Strings and Documents
 * @return a map between the Strings and the String representation of the documents (null if inputMap is null).
 *///from   w w  w  .  j ava2  s  . c  om
private Map<String, String> getStringMapFromXMLMap(Map<String, Document> inputMap, TextMode textMode) {
    if (inputMap == null) {
        return null;
    }
    Map<String, String> results = new HashMap<>(inputMap.size());
    Format xmlFormat = Format.getPrettyFormat();
    xmlFormat.setLineSeparator(LineSeparator.SYSTEM);
    //xmlFormat.setTextMode(textMode);
    XMLOutputter outputter = new XMLOutputter(xmlFormat);
    for (String fileName : inputMap.keySet()) {
        Document currentDocument = inputMap.get(fileName);
        String xsdString = outputter.outputString(currentDocument);
        results.put(fileName, xsdString);
    }
    return ImmutableMap.copyOf(results);
}

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();/*from w  ww.  ja v  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 {// ww w  .j a v a 2s .com
        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();/*from  ww w.ja v a2 s  . c  o  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());

}