Example usage for org.dom4j.io OutputFormat setEncoding

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

Introduction

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

Prototype

public void setEncoding(String encoding) 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.alfresco.module.org_alfresco_module_wcmquickstart.util.AssetSerializerXmlImpl.java

License:Open Source License

public void start(Writer underlyingWriter) throws AssetSerializationException {
    try {//from   w  w  w.  ja  v  a 2s  .c  o m
        OutputFormat format = OutputFormat.createCompactFormat();
        format.setEncoding("UTF-8");

        writer = new XMLWriter(underlyingWriter, format);
        writer.startDocument();
        startElement("assets", EMPTY_ATTRIBUTES);
    } catch (Exception ex) {
        throw new AssetSerializationException(ex);
    }
}

From source file:org.alfresco.repo.admin.patch.util.ImportFileUpdater.java

License:Open Source License

/**
 * Get the writer for the import file/*from  w w w .  j a v  a  2  s .  com*/
 * 
 * @param destination   the destination XML import file
 * @return            the XML writer
 */
private XMLWriter getWriter(String destination) {
    try {
        // Define output format
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setNewLineAfterDeclaration(false);
        format.setIndentSize(INDENT_SIZE);
        format.setEncoding(this.fileEncoding);

        return new XMLWriter(new FileOutputStream(destination), format);
    } catch (Exception exception) {
        throw new AlfrescoRuntimeException("Unable to create XML writer.", exception);
    }
}

From source file:org.alfresco.repo.exporter.ExporterComponent.java

License:Open Source License

/**
 * Create an XML Exporter that exports repository information to the specified
 * output stream in xml format.//from ww w  . j  a v  a  2  s  . c o m
 * 
 * @param viewWriter  the output stream to write to
 * @param referenceType  the format of references to export
 * @return  the xml exporter
 */
private Exporter createXMLExporter(OutputStream viewWriter, ReferenceType referenceType) {
    // Define output format
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(indentSize);
    format.setEncoding("UTF-8");

    // Construct an XML Exporter
    try {
        XMLWriter writer = new XMLWriter(viewWriter, format);
        ViewXMLExporter exporter = new ViewXMLExporter(namespaceService, nodeService, searchService,
                dictionaryService, permissionService, writer);
        exporter.setReferenceType(referenceType);
        return exporter;
    } catch (UnsupportedEncodingException e) {
        throw new ExporterException("Failed to create XML Writer for export", e);
    } catch (Exception e) {
        throw new ExporterException("Failed to create XML Writer for export", e);
    }
}

From source file:org.alfresco.repo.importer.ExportSourceImporter.java

License:Open Source License

private XMLWriter createXMLExporter(Writer writer) {
    // Define output format
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);//from w w w . j a v a2  s . c o m
    format.setEncoding("UTF-8");

    // Construct an XML Exporter

    XMLWriter xmlWriter = new XMLWriter(writer, format);
    return xmlWriter;
}

From source file:org.alfresco.repo.transfer.report.XMLTransferReportWriter.java

License:Open Source License

/**
 * Start the transfer report/*from  w w  w  .j av  a 2  s. c  o  m*/
 */
public void startTransferReport(String encoding, Writer writer) throws SAXException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);

    this.writer = new XMLWriter(writer, format);
    this.writer.startDocument();

    this.writer.startPrefixMapping(PREFIX, TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI);

    // Start Transfer Manifest  // uri, name, prefix
    this.writer.startElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI,
            TransferReportModel.LOCALNAME_TRANSFER_REPORT,
            PREFIX + ":" + TransferReportModel.LOCALNAME_TRANSFER_REPORT, EMPTY_ATTRIBUTES);
}

From source file:org.alfresco.repo.transfer.reportd.XMLTransferDestinationReportWriter.java

License:Open Source License

/**
 * Start the transfer report//from  w  w  w.j  a  va 2  s .c o m
 */
public void startTransferReport(String encoding, Writer writer) {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);

    try {

        this.writer = new XMLWriter(writer, format);
        this.writer.startDocument();

        this.writer.startPrefixMapping(PREFIX, TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI);

        // Start Transfer Manifest  // uri, name, prefix
        this.writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI,
                TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT,
                PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT, EMPTY_ATTRIBUTES);

    } catch (SAXException se) {
        se.printStackTrace();
    }
}

From source file:org.alfresco.repo.transfer.requisite.XMLTransferRequsiteWriter.java

License:Open Source License

public XMLTransferRequsiteWriter(Writer out) {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);/*  ww w.  j a va  2 s .c o  m*/
    format.setEncoding("UTF-8");

    this.writer = new XMLWriter(out, format);
}

From source file:org.alfresco.repo.transfer.XMLWriter.java

License:Open Source License

public XMLWriter(OutputStream outputStream, boolean prettyPrint, String encoding)
        throws UnsupportedEncodingException {
    OutputFormat format = prettyPrint ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);//from  ww  w  . j a  v  a 2s .c o  m
    format.setEncoding(encoding);
    output = outputStream;
    this.dom4jWriter = new org.dom4j.io.XMLWriter(outputStream, format);
}

From source file:org.apache.commons.jelly.tags.core.FileTag.java

License:Apache License

/**
 * A Factory method to create a new XMLOutput from the given Writer.
 *//* www . ja v a  2  s .c o m*/
protected XMLOutput createXMLOutput(Writer writer) {

    OutputFormat format = null;
    if (prettyPrint) {
        format = OutputFormat.createPrettyPrint();
    } else {
        format = new OutputFormat();
    }
    if (encoding != null) {
        format.setEncoding(encoding);
    }
    if (omitXmlDeclaration) {
        format.setSuppressDeclaration(true);
    }

    boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase("html");
    final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(writer, format) : new XMLWriter(writer, format);

    xmlWriter.setEscapeText(isEscapeText());

    XMLOutput answer = new XMLOutput() {
        public void close() throws IOException {
            xmlWriter.close();
        }
    };
    answer.setContentHandler(xmlWriter);
    answer.setLexicalHandler(xmlWriter);
    return answer;
}

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

License:Apache License

/**
 * {@inheritDoc}//from w  w w  .  j  a  va  2  s  .  c  om
 */
public void execute() throws BuildException {
    if (_dataSource == null) {
        log("No data source specified, so there is nothing to do.", Project.MSG_INFO);
        return;
    }

    Connection connection = null;
    try {
        Document document = DocumentFactory.getInstance().createDocument();
        Element root = document.addElement("metadata");

        root.addAttribute("driverClassName", _dataSource.getDriverClassName());

        connection = _dataSource.getConnection();

        dumpMetaData(root, connection.getMetaData());

        OutputFormat outputFormat = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = null;

        outputFormat.setEncoding(_outputEncoding);
        if (_outputFile == null) {
            xmlWriter = new XMLWriter(System.out, outputFormat);
        } else {
            xmlWriter = new XMLWriter(new FileOutputStream(_outputFile), outputFormat);
        }
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (Exception ex) {
        throw new BuildException(ex);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException ex) {
            }
        }
    }
}