Example usage for org.dom4j.io OutputFormat createPrettyPrint

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

Introduction

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

Prototype

public static OutputFormat createPrettyPrint() 

Source Link

Document

A static helper method to create the default pretty printing format.

Usage

From source file:org.intalio.tempo.workflow.fds.dispatches.LoggerDispatcher.java

License:Open Source License

private void logMessage(String message, org.dom4j.Document doc) {
    if (logger.isDebugEnabled()) {
        try {// ww w  .  jav a 2  s . c om
            logger.debug("Dispatcher " + targetDispatcherClass.getCanonicalName() + ": " + message);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            OutputFormat of = OutputFormat.createPrettyPrint();
            of.setEncoding("UTF-8");

            XMLWriter writer = new XMLWriter(bos, of);
            writer.write(doc);

            String serializedDoc = bos.toString();

            logger.debug(serializedDoc);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.jahia.utils.maven.plugin.osgi.ConvertToOSGiMojo.java

License:Open Source License

private void parsePom() throws DocumentException, IOException {
    SAXReader reader = new SAXReader();
    File pom = new File(baseDir, "pom.xml");
    Document pomDocument = reader.read(pom);

    Document bundleModuleDocument = reader
            .read(getClass().getClassLoader().getResourceAsStream("bundleModule.xml"));

    Element root = pomDocument.getRootElement();

    // Set packaging
    Element packaging = root.element("packaging");
    if (packaging == null) {
        root.addElement("packaging");
    } else {//w  w w. j  ava2 s  . c  om
        if (packaging.getTextTrim().toLowerCase().equals("war")) {
            packaging.setText("bundle");
        } else {
            getLog().info("Non WAR packaging found : " + packaging.getTextTrim()
                    + ", not modifying it to bundle, but you might want to double-check this.");
        }
    }

    // Copy template dependencies
    Element dependencies = root.element("dependencies");
    if (dependencies == null) {
        dependencies = root.addElement("dependencies");
    }
    List dependenciesTemplate = bundleModuleDocument.selectNodes("/project/*[local-name()='dependencies']/*");
    for (Element dep : (Iterable<? extends Element>) dependenciesTemplate) {
        dependencies.add(dep.detach());
    }

    // Generate plugin instructions
    Element plugins = (Element) pomDocument
            .selectSingleNode("/project/*[local-name()='build']/*[local-name()='plugins']");
    if (plugins != null) {
        Element mavenWarPluginArtifactId = (Element) plugins
                .selectSingleNode("//*[local-name()='artifactId'][text()='maven-war-plugin']");
        if (mavenWarPluginArtifactId != null) {
            Element previousPluginConfig = (Element) mavenWarPluginArtifactId.getParent().detach();
            Element manifestEntries = previousPluginConfig.element("configuration").element("archive")
                    .element("manifestEntries");

            Element pluginTemplate = (Element) bundleModuleDocument.selectSingleNode(
                    "/project/*[local-name()='build']/*[local-name()='plugins']/*[local-name()='plugin']");
            if (pluginTemplate != null) {
                Element instructionsTemplate = (Element) pluginTemplate.element("configuration")
                        .element("instructions").detach();
                Element instructions = pluginTemplate.element("configuration").addElement("instructions");

                generateBundlePlugin(manifestEntries, instructions, instructionsTemplate);
                if (!instructions.elements().isEmpty()) {
                    plugins.add(pluginTemplate.detach());
                }
            }
        }
    }

    // Export pom
    XMLWriter writer = new XMLWriter(new FileOutputStream(pom), OutputFormat.createPrettyPrint());
    writer.write(pomDocument);
    writer.close();
}

From source file:org.jboss.as.ee.deployment.spi.DeploymentMetaData.java

License:Open Source License

public String toXMLString() {
    try {//  ww w  .  j a va2s . c om
        OutputFormat format = OutputFormat.createPrettyPrint();
        StringWriter strWriter = new StringWriter(1024);
        XMLWriter metaWriter = new XMLWriter(strWriter, format);
        metaWriter.write(getDocument());
        metaWriter.close();
        return strWriter.toString();
    } catch (IOException ex) {
        ROOT_LOGGER.cannotTransformDeploymentPlanToXML(ex);
        return null;
    }
}

From source file:org.jboss.deployment.spi.DeploymentMetaData.java

License:Open Source License

public String toXMLString() {
    try {//from  w w  w  .  j a v a  2  s  . c  o m
        OutputFormat format = OutputFormat.createPrettyPrint();
        StringWriter strWriter = new StringWriter(1024);
        XMLWriter metaWriter = new XMLWriter(strWriter, format);
        metaWriter.write(getDocument());
        metaWriter.close();
        return strWriter.toString();
    } catch (IOException e) {
        log.error("Cannot get XML string", e);
        return null;
    }
}

From source file:org.jboss.ide.eclipse.as.core.extensions.descriptors.XMLDocumentRepository.java

License:Open Source License

public static void saveDocument(Document doc, String fullPath) {
    Exception ex = null;/*from ww w.  j a va 2s . c o m*/
    try {
        File outFile = new File(fullPath);
        FileOutputStream os = new FileOutputStream(outFile);
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(os, outformat);
        writer.write(doc);
        writer.flush();
    } catch (MalformedURLException e) {
        ex = e;
    } catch (FileNotFoundException e) {
        ex = e;
    } catch (UnsupportedEncodingException e) {
        ex = e;
    } catch (IOException e) {
        ex = e;
    }
    if (ex != null) {
        JBossServerCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                JBossServerCorePlugin.PLUGIN_ID, NLS.bind(Messages.saveXMLDocumentFailed, fullPath), ex));
    }
}

From source file:org.jboss.rusheye.CommandCrawl.java

License:Open Source License

private void writeDocument() {
    OutputFormat format = OutputFormat.createPrettyPrint();
    OutputStream out = openOutputStream();

    try {//from  w  ww .  j ava 2s. c o m
        XMLWriter writer = new XMLWriter(out, format);
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        printErrorMessage(e);
        System.exit(7);
    }
}

From source file:org.jbpm.gd.common.editor.AbstractContentProvider.java

License:Open Source License

protected void write(RootContainer rootContainer, Writer writer) {
    try {//from w  w w .  ja v  a 2 s.  c o  m
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("root-container");
        write(rootContainer, root);
        XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
        xmlWriter.write(document);
    } catch (IOException e) {
        e.printStackTrace(new PrintWriter(writer));
    }
}

From source file:org.jbpm.gd.jpdl.properties.TaskFormGenerationDialog.java

License:Open Source License

private void saveDocument(IFile formFile, Document document) {
    try {/*from w  w w.  jav a 2s .  c  o  m*/
        StringWriter stringWriter = new StringWriter();
        XMLWriter xmlWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
        xmlWriter.write(document);
        formFile.setContents(new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes()), true,
                true, null);
    } catch (IOException e) {
        Logger.logError("Problem writing xml document to file", e);
    } catch (CoreException e) {
        Logger.logError("Problem writing xml document to file", e);
    }
}

From source file:org.jbpm.jpdl.convert.Converter.java

License:Open Source License

public void serializetoXML(OutputStream out, Document document) throws Exception {

    OutputFormat outformat = OutputFormat.createPrettyPrint();
    //outformat.setEncoding(aEncodingScheme);
    XMLWriter writer = new XMLWriter(out, outformat);
    writer.write(document);/*  www.  j  ava2  s  .  co  m*/
    writer.flush();
}

From source file:org.jbpm.jpdl.internal.convert.JpdlConverterTool.java

License:Open Source License

public static void main(String[] args) {
    JpdlConverterTool jpdlConverterTool = new JpdlConverterTool();

    // Parse and validate the command line arguments
    ConverterContext context = null;/* w w w.j  a  v  a 2 s. c o m*/
    try {
        context = jpdlConverterTool.parseParam(args);
        jpdlConverterTool.validate(context);
    } catch (IllegalCommandException e) {
        System.err.println(e.getMessage());
        System.err.println(jpdlConverterTool.getUsage());
        return;
    } catch (Exception e) {
        System.err.println(e.getMessage());
        return;
    }

    boolean verbose = false;
    if (context.get(ConverterContext.VERBOSE) != null) {
        verbose = true;
    }
    Jpdl3Converter jpdlConverter = new Jpdl3Converter((URL) context.get(context.PROCESS_FILE_URL));

    try {
        if (verbose) {
            System.out.println(
                    "Loading process file from URL [" + context.get(context.PROCESS_FILE_URL) + "]...");
        }
        Document jpdl4Doc = jpdlConverter.readAndConvert();

        if (verbose) {
            System.out.println("Converting the process file to jPDL4 version....");
        }

        String outputFilePath = (String) context.get(context.OUPUTFILE);
        File outputFile = new File(outputFilePath);

        //well print xml to file
        Writer fileWriter = new FileWriter(outputFile);
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(fileWriter, format);
        writer.write(jpdl4Doc);
        writer.close();

        if (verbose) {
            System.out.println("Generating converted file to:"
                    + (outputFile.isAbsolute() ? outputFile.getAbsolutePath() : outputFile.getName()));
        }

    } catch (Exception e) {

        for (Problem problem : jpdlConverter.problems) {
            if (problem.getLevel() == problem.LEVEL_WARNING) {
                System.err.println(problem);
            }
            if (problem.getLevel() < problem.LEVEL_WARNING) {
                System.err.println(problem);
                if (problem.getException() != null && context.get(ConverterContext.VERBOSE) != null) {
                    problem.getException().printStackTrace(System.err);
                    System.err.println();
                }
            }
        }

    }
}