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

Source Link

Document

Creates an OutputFormat with no additional whitespace (indent or new lines) added.

Usage

From source file:com.globalsight.everest.tm.exporter.TmxWriter.java

License:Apache License

public TmxWriter(ExportOptions p_options, Tm p_database) {
    m_database = p_database;
    setExportOptions(p_options);

    m_outputFormat = new OutputFormat();
    m_outputFormat.setExpandEmptyElements(true);
}

From source file:com.globalsight.everest.tm.exporter.TmxWriter.java

License:Apache License

public TmxWriter(ExportOptions p_options, Tm p_database, Tmx tmx) {
    m_tmx = tmx;/*ww  w . j av  a 2 s  .  c  om*/
    m_database = p_database;
    setExportOptions(p_options);

    m_outputFormat = new OutputFormat();
    m_outputFormat.setExpandEmptyElements(true);
}

From source file:com.jaspersoft.jasperserver.export.ExporterImpl.java

License:Open Source License

protected void writeIndexDocument(Document indexDocument) {
    OutputStream indexOut = getIndexOutput();
    boolean closeIndexOut = true;
    try {//from w  w w. j av  a 2s .c  om
        OutputFormat format = new OutputFormat();
        format.setEncoding(getCharacterEncoding());
        XMLWriter writer = new XMLWriter(indexOut, format);
        writer.write(indexDocument);

        closeIndexOut = false;
        indexOut.close();
    } catch (IOException e) {
        log.error(e);
        throw new JSExceptionWrapper(e);
    } finally {
        if (closeIndexOut) {
            try {
                indexOut.close();
            } catch (IOException e) {
                log.error("Error while closing index output", e);
            }
        }
    }
}

From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java

License:Apache License

/**
 * //from  ww w.  j a  v  a 2  s  .  com
 * @param document
 * @throws IOException
 */
private void write(Document document) throws IOException {
    XMLWriter xmlWriter = null;
    try {
        FileWriter writer = new FileWriter(new File(this.exportFileName));
        OutputFormat format = new OutputFormat();
        format.setEncoding("UTF-8");
        //? 
        format.setIndent(true);
        format.setIndent("    ");
        //? 
        format.setNewlines(true);
        xmlWriter = new XMLWriter(writer, format);
        xmlWriter.write(document);
    } finally {
        if (null != xmlWriter) {
            xmlWriter.close();
        }
    }
}

From source file:com.mor.blogengine.xml.io.XmlDataSourceProvider.java

License:Open Source License

/**
 * writes in a file/*  w  w w .j a v a  2 s . co m*/
 *
 * @param document DOM model to write in
 * @param pOutputFile output file
 * @throws java.io.IOException
 * @param pDocument
 */
boolean write(Document pDocument) throws MissingPropertyException, IncorrectPropertyValueException {
    boolean ret = false;
    try {
        OutputFormat format = new OutputFormat();
        format.setEncoding(getFileEncoding());
        XMLWriter writer;
        writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(xml.getFile()),
                Charset.forName(getFileEncoding())));

        writer.write(pDocument);
        writer.close();
        ret = true;

    } catch (IOException ex) {
        trace("Error saving file..." + ex);

    }
    return ret;

}

From source file:com.test.android.push.xmpp.net.Connection.java

License:Open Source License

/**
 * Delivers the packet to this connection (without checking the recipient).
 * //from   ww  w .  j a  v  a  2 s.  c o  m
 * @param packet the packet to deliver
 */
public void deliver(Packet packet) {
    log.debug("SENT: " + packet.toXML());
    if (!isClosed()) {
        IoBuffer buffer = IoBuffer.allocate(4096);
        buffer.setAutoExpand(true);

        boolean errorDelivering = false;
        try {
            XMLWriter xmlSerializer = new XMLWriter(new IoBufferWriter(buffer, (CharsetEncoder) encoder.get()),
                    new OutputFormat());
            xmlSerializer.write(packet.getElement());
            xmlSerializer.flush();
            buffer.flip();
            ioSession.write(buffer);
        } catch (Exception e) {
            log.debug("Connection: Error delivering packet" + "\n" + this.toString(), e);
            errorDelivering = true;
        }
        if (errorDelivering) {
            close();
        } else {
            session.incrementServerPacketCount();
        }
    }
    log.debug("deliver() end...");
}

From source file:com.zrsf.push.xmpp.net.Connection.java

License:Open Source License

/**
 * Delivers the packet to this connection (without checking the recipient).
 * /* w  w  w  .j ava 2  s.c om*/
 * @param packet the packet to deliver
 */
public void deliver(Packet packet) {
    log.debug("SENT: " + packet.toXML());
    if (!isClosed()) {
        IoBuffer buffer = IoBuffer.allocate(4096);
        buffer.setAutoExpand(true);
        boolean errorDelivering = false;
        try {
            XMLWriter xmlSerializer = new XMLWriter(new IoBufferWriter(buffer, (CharsetEncoder) encoder.get()),
                    new OutputFormat());
            xmlSerializer.write(packet.getElement());
            xmlSerializer.flush();
            buffer.flip();
            ioSession.write(buffer);
        } catch (Exception e) {
            log.debug("Connection: Error delivering packet" + "\n" + this.toString(), e);
            errorDelivering = true;
        }
        if (errorDelivering) {
            close();
        }
    }
}

From source file:nl.tue.gale.common.GaleUtil.java

License:Open Source License

public static String serializeXML(Element element) {
    StringWriter out = new StringWriter();
    OutputFormat of = new OutputFormat();
    of.setExpandEmptyElements(true);//from  www  .j  av  a2s. c  o m
    XMLWriter writer = new XMLWriter(out, of) {
        @Override
        protected void writeEmptyElementClose(String qualifiedName) throws IOException {
            if (omitCloseSet.contains(qualifiedName.toUpperCase())) {
                writer.write(" />");
            } else {
                super.writeEmptyElementClose(qualifiedName);
            }
        }
    };
    try {
        writer.write(element);
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("unable to serialize XML: " + e.getMessage());
    }
    return out.toString();
}

From source file:org.alfresco.module.vti.web.fp.DeleteMethod.java

License:Open Source License

@Override
protected OutputFormat getXMLOutputFormat() {
    OutputFormat outputFormat = new OutputFormat();
    outputFormat.setNewLineAfterDeclaration(false);
    outputFormat.setNewlines(false);//from  w  w  w  .  jav  a 2  s. c o m
    outputFormat.setIndent(false);
    return outputFormat;
}

From source file:org.alfresco.module.vti.web.fp.LockMethod.java

License:Open Source License

/**
 * @see org.alfresco.repo.webdav.WebDAVMethod#createXMLWriter()
 *//*w  ww .j a  va2  s  . com*/
@Override
protected OutputFormat getXMLOutputFormat() {
    OutputFormat outputFormat = new OutputFormat();
    outputFormat.setNewLineAfterDeclaration(false);
    outputFormat.setNewlines(false);
    outputFormat.setIndent(false);
    return outputFormat;
}