Example usage for org.dom4j.io OutputFormat setNewlines

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

Introduction

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

Prototype

public void setNewlines(boolean newlines) 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.mule.devkit.model.studio.StudioModel.java

License:Open Source License

private void serializeXml() throws JAXBException, IOException {
    JAXBContext jaxbContext = JAXBContext.newInstance(NamespaceType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    NamespaceFilter outFilter = new NamespaceFilter("mule", "http://www.mulesoft.org/schema/mule/core", true);
    OutputFormat format = new OutputFormat();
    format.setIndent(true);/*from w  ww.  j a va  2  s  . c o m*/
    format.setNewlines(true);
    OutputStream schemaStream = codeWriter.openBinary(null, outputFileName);
    XMLWriter writer = new XMLWriter(schemaStream, format);
    outFilter.setContentHandler(writer);
    marshaller.marshal(namespaceType, outFilter);
}

From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaGenerator.java

License:Open Source License

private String renderSchema(Schema schema) {
    try {/*from   w  w  w  . j av  a2 s.  c o  m*/
        JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        NamespaceFilter outFilter = new NamespaceFilter("mule", SchemaConstants.MULE_NAMESPACE, true);
        OutputFormat format = new OutputFormat();
        format.setIndent(true);
        format.setNewlines(true);

        StringWriter sw = new StringWriter();
        XMLWriter writer = new XMLWriter(sw, format);
        outFilter.setContentHandler(writer);
        marshaller.marshal(schema, outFilter);
        return sw.toString();
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }

}

From source file:org.nuxeo.ecm.jsf2.migration.impl.MigrationServiceImpl.java

License:Open Source License

/**
 * Create a file containing the migration done in the Document.
 *
 * @param input/*w  ww.j  a v a 2s  . co  m*/
 * @param filePath
 * @throws Exception
 */
protected void createFile(Document input, String filePath, boolean createNewFile) throws Exception {

    // Create file
    File fileMigrated = new File(filePath);
    if (createNewFile) {
        fileMigrated.createNewFile();
    }
    PrintWriter printWriter = new PrintWriter(fileMigrated);
    OutputFormat format = new OutputFormat();
    format.setIndentSize(2);
    format.setNewlines(true);
    format.setTrimText(true);
    XMLWriter writer = new XMLWriter(printWriter, format);
    writer.write(input);

    printWriter.close();
}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

/**
 * Convert a dom4j document to a pretty string, for formatting/debugging purposes only.
 *
 * @param document  document to convert/* w  w  w  . j  ava 2 s.co  m*/
 * @return          resulting string
 */
public static String domToPrettyString(final Document document) {
    final OutputFormat format = new OutputFormat();
    format.setIndentSize(4);
    format.setNewlines(true);
    format.setTrimText(true);
    return domToString(document.getRootElement(), format);
}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

/**
 * Convert a dom4j document to a compact string, with all text being trimmed.
 *
 * @param document  document to convert//  www  . j a v  a2 s.  co m
 * @return          resulting string
 */
public static String domToCompactString(final Document document) {
    final OutputFormat format = new OutputFormat();
    format.setIndent(false);
    format.setNewlines(false);
    format.setTrimText(true);
    return domToString(document.getRootElement(), format);
}

From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java

License:Open Source License

private static String domToString(final Branch branch) {
    final OutputFormat format = new OutputFormat();
    format.setIndent(false);/*  w  w w.j  a  v a 2  s  .  com*/
    format.setNewlines(false);
    return domToString(branch, format);
}

From source file:org.projectforge.framework.xstream.XmlHelper.java

License:Open Source License

public static String toString(final Element el, final boolean prettyFormat) {
    if (el == null) {
        return "";
    }/*from ww  w . j a  va  2s .  co m*/
    final StringWriter out = new StringWriter();
    final OutputFormat format = new OutputFormat();
    if (prettyFormat == true) {
        format.setNewlines(true);
        format.setIndentSize(2);
    }
    final XMLWriter writer = new XMLWriter(out, format);
    String result = null;
    try {
        writer.write(el);
        result = out.toString();
        writer.close();
    } catch (final IOException ex) {
        log.error(ex.getMessage(), ex);
    }
    return result;
}

From source file:org.sipfoundry.sipxconfig.admin.dialplan.config.XmlFile.java

License:Contributor Agreement License

/**
 * Overwrite to prepare XML format for this file.
 *//* w w w . jav a2  s  . c om*/
public OutputFormat createFormat() {
    OutputFormat format = new OutputFormat();
    format.setNewlines(true);
    format.setIndent(true);
    return format;
}

From source file:org.sipfoundry.sipxconfig.dialplan.config.AuthRules.java

License:Contributor Agreement License

@Override
public Document getDocument() {
    Location location = getLocation();
    if (location == null) {
        return null;
    }//from www .j  a  v  a  2  s.com

    try {
        StringWriter stringWriter = new StringWriter();
        OutputFormat format = new OutputFormat();
        format.setNewlines(true);
        format.setIndent(true);
        XMLWriter xmlWriter = new XMLWriter(stringWriter, format);
        xmlWriter.write(m_doc);

        String rulesString = stringWriter.toString();
        rulesString = rulesString.replace("${SIPXCHANGE_DOMAIN_NAME}", getDomainName());
        rulesString = rulesString.replace("${MY_IP_ADDR}", location.getAddress());
        rulesString = rulesString.replace("${MY_FULL_HOSTNAME}", location.getFqdn());
        rulesString = rulesString.replace("${MY_HOSTNAME}", location.getHostname());

        StringReader stringReader = new StringReader(rulesString);
        SAXReader saxReader = new SAXReader();
        return saxReader.read(stringReader);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    } catch (DocumentException de) {
        throw new RuntimeException(de);
    }
}

From source file:org.sipfoundry.sipxconfig.dialplan.config.XmlFile.java

License:Contributor Agreement License

/**
 * Overwrite to prepare XML format for this file.
 *//*from  ww  w . j av  a2 s  .c  o m*/
public OutputFormat getFormat() {
    if (m_format != null) {
        return m_format;
    }
    OutputFormat format = new OutputFormat();
    format.setNewlines(true);
    format.setIndent(true);
    return format;
}