Example usage for org.dom4j.io XMLWriter XMLWriter

List of usage examples for org.dom4j.io XMLWriter XMLWriter

Introduction

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

Prototype

public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException 

Source Link

Usage

From source file:org.alfresco.repo.transfer.manifest.XMLTransferManifestWriter.java

License:Open Source License

/**
 * Start the transfer manifest//from w w  w . j a v a 2  s.  c  o  m
 */
public void startTransferManifest(Writer writer) throws SAXException {
    format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding("UTF-8");

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

    this.writer.startPrefixMapping(PREFIX, TransferModel.TRANSFER_MODEL_1_0_URI);
    this.writer.startPrefixMapping("cm", NamespaceService.CONTENT_MODEL_1_0_URI);

    // Start Transfer Manifest // uri, name, prefix
    this.writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_TRANSFER_MAINIFEST,
            PREFIX + ":" + ManifestModel.LOCALNAME_TRANSFER_MAINIFEST, EMPTY_ATTRIBUTES);
}

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

License:Open Source License

/**
 * Start the transfer report/*from   w  ww .  j a v  a 2 s .  com*/
 */
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.  ja v  a 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);//from www  .j a  v  a2  s  .  co  m
    format.setEncoding("UTF-8");

    this.writer = new XMLWriter(out, 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.
 *//*  ww w.j  av a2  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}//ww w  .j  av  a  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) {
            }
        }
    }
}

From source file:org.apache.directory.studio.connection.core.io.ConnectionIO.java

License:Apache License

/**
 * Saves the connections using the writer.
 *
 * @param connections the connections/*w  ww.ja v a 2  s  .  co  m*/
 * @param stream the OutputStream
 * @throws IOException if an I/O error occurs
 */
public static void save(Set<ConnectionParameter> connections, OutputStream stream) throws IOException {
    // Creating the Document
    Document document = DocumentHelper.createDocument();

    // Creating the root element
    Element root = document.addElement(CONNECTIONS_TAG);

    if (connections != null) {
        for (ConnectionParameter connection : connections) {
            addConnection(root, connection);
        }
    }

    // Writing the file to disk
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding("UTF-8"); //$NON-NLS-1$
    XMLWriter writer = new XMLWriter(stream, outformat);
    writer.write(document);
    writer.flush();
}

From source file:org.apache.directory.studio.connection.core.io.ConnectionIO.java

License:Apache License

/**
 * Saves the connection folders using the writer.
 *
 * @param connectionFolders the connection folders
 * @param stream the OutputStream/*from  w w w.ja v a  2s .  c  o m*/
 * @throws IOException if an I/O error occurs
 */
public static void saveConnectionFolders(Set<ConnectionFolder> connectionFolders, OutputStream stream)
        throws IOException {
    // Creating the Document
    Document document = DocumentHelper.createDocument();

    // Creating the root element
    Element root = document.addElement(CONNECTION_FOLDERS_TAG);

    if (connectionFolders != null) {
        for (ConnectionFolder connectionFolder : connectionFolders) {
            addFolderConnection(root, connectionFolder);
        }
    }

    // Writing the file to disk
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding("UTF-8"); //$NON-NLS-1$
    XMLWriter writer = new XMLWriter(stream, outformat);
    writer.write(document);
    writer.flush();
}

From source file:org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO.java

License:Apache License

/**
 * Saves the browser connections using the output stream.
 *
 * @param stream/*from  w w  w  . j a v a2 s .  co m*/
 *      the OutputStream
 * @param browserConnectionMap
 *      the map of browser connections
 * @throws IOException
 *      if an I/O error occurs
 */
public static void save(OutputStream stream, Map<String, IBrowserConnection> browserConnectionMap)
        throws IOException {
    // Creating the Document
    Document document = DocumentHelper.createDocument();

    // Creating the root element
    Element root = document.addElement(BROWSER_CONNECTIONS_TAG);

    if (browserConnectionMap != null) {
        for (IBrowserConnection browserConnection : browserConnectionMap.values()) {
            writeBrowserConnection(root, browserConnection);
        }
    }

    // Writing the file to disk
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding("UTF-8"); //$NON-NLS-1$
    XMLWriter writer = new XMLWriter(stream, outformat);
    writer.write(document);
    writer.flush();
}

From source file:org.apache.directory.studio.ldapservers.LdapServersManagerIO.java

License:Apache License

/**
 * Writes the list of servers to the given stream.
 *
 * @param servers/*www. j a  v a 2 s.com*/
 *      the servers
 * @param outputStream
 *      the output stream
 * @throws IOException
 *      if an error occurs when writing to the stream
 */
public static void write(List<LdapServer> servers, OutputStream outputStream) throws IOException {
    // Creating the Document
    Document document = DocumentHelper.createDocument();

    // Creating the root element
    Element root = document.addElement(LDAP_SERVERS_TAG);

    if (servers != null) {
        for (LdapServer server : servers) {
            addLdapServer(server, root);
        }
    }

    // Writing the file to the stream
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding("UTF-8"); //$NON-NLS-1$
    XMLWriter writer = new XMLWriter(outputStream, outformat);
    writer.write(document);
    writer.flush();
}