Example usage for org.dom4j.io OutputFormat isNewLineAfterDeclaration

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

Introduction

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

Prototype

public boolean isNewLineAfterDeclaration() 

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.u2apple.rt.util.StandaloneWriter.java

@Override
protected void writeDeclaration() throws IOException {
    OutputFormat format = getOutputFormat();

    String encoding = format.getEncoding();

    if (!format.isSuppressDeclaration()) {
        if (encoding.equals("UTF8")) {
            writer.write("<?xml version=\"1.0\"");

            if (!format.isOmitEncoding()) {
                writer.write(" encoding=\"UTF-8\"");
            }/*www.jav  a 2  s.  co  m*/

            writer.write(" standalone=\"yes\"");
            writer.write("?>");
        } else {
            writer.write("<?xml version=\"1.0\"");

            if (!format.isOmitEncoding()) {
                writer.write(" encoding=\"" + encoding + "\"");
            }

            writer.write(" standalone=\"yes\"");
            writer.write("?>");
        }

        if (format.isNewLineAfterDeclaration()) {
            println();
        }
    }
}

From source file:org.talend.core.model.genhtml.XMLHandler.java

License:Open Source License

/**
 * Generates xml file base on inputted path, file path and an instance of <code>Document</code>
 * /* w  w w  . j a  v  a 2 s . co  m*/
 * @param tempFolderPath
 * @param filePath
 * @param document
 */
public static void generateXMLFile(String tempFolderPath, String filePath, Document document) {
    XMLWriter output = null;
    FileOutputStream out = null;
    Writer writer = null;

    try {
        // OutputFormat format = OutputFormat.createPrettyPrint();
        out = new java.io.FileOutputStream(filePath);
        writer = new OutputStreamWriter(out, "UTF-8"); //$NON-NLS-1$

        OutputFormat format = OutputFormat.createPrettyPrint();
        output = new XMLWriter(writer, format) {

            /*
             * (non-Javadoc)
             * 
             * @see org.dom4j.io.XMLWriter#writeDeclaration()
             */
            @Override
            protected void writeDeclaration() throws IOException {
                OutputFormat formatTmp = this.getOutputFormat();
                String encoding = formatTmp.getEncoding();

                // Only print of declaration is not suppressed
                if (!formatTmp.isSuppressDeclaration()) {
                    // Assume 1.0 version
                    if (encoding.equals("UTF8")) { //$NON-NLS-1$
                        writer.write("<?xml version=\"1.1\""); //$NON-NLS-1$

                        if (!formatTmp.isOmitEncoding()) {
                            writer.write(" encoding=\"UTF-8\""); //$NON-NLS-1$
                        }

                        writer.write("?>"); //$NON-NLS-1$
                    } else {
                        writer.write("<?xml version=\"1.1\""); //$NON-NLS-1$

                        if (!formatTmp.isOmitEncoding()) {
                            writer.write(" encoding=\"" + encoding + "\""); //$NON-NLS-1$ //$NON-NLS-2$
                        }

                        writer.write("?>"); //$NON-NLS-1$
                    }

                    if (formatTmp.isNewLineAfterDeclaration()) {
                        println();
                    }
                }
            }
        };
        output.setMaximumAllowedCharacter(127);
        output.write(document);
        output.flush();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }

    }
}