Example usage for javax.xml.stream XMLStreamWriter writeEndDocument

List of usage examples for javax.xml.stream XMLStreamWriter writeEndDocument

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeEndDocument.

Prototype

public void writeEndDocument() throws XMLStreamException;

Source Link

Document

Closes any start tags and writes corresponding end tags.

Usage

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

private void writeExportAnchors() throws DITAOTException {
    if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) {
        // Output plugin id
        final File pluginIdFile = new File(job.tempDir, FILE_NAME_PLUGIN_XML);
        final DelayConrefUtils delayConrefUtils = new DelayConrefUtils();
        delayConrefUtils.writeMapToXML(exportAnchorsFilter.getPluginMap(), pluginIdFile);

        XMLStreamWriter export = null;
        try (OutputStream exportStream = new FileOutputStream(new File(job.tempDir, FILE_NAME_EXPORT_XML))) {
            export = XMLOutputFactory.newInstance().createXMLStreamWriter(exportStream, "UTF-8");
            export.writeStartDocument();
            export.writeStartElement("stub");
            for (final ExportAnchor e : exportAnchorsFilter.getExportAnchors()) {
                export.writeStartElement("file");
                export.writeAttribute("name",
                        tempFileNameScheme.generateTempFileName(toFile(e.file).toURI()).toString());
                for (final String t : sort(e.topicids)) {
                    export.writeStartElement("topicid");
                    export.writeAttribute("name", t);
                    export.writeEndElement();
                }//from www  .  j a v  a  2s. c  o  m
                for (final String i : sort(e.ids)) {
                    export.writeStartElement("id");
                    export.writeAttribute("name", i);
                    export.writeEndElement();
                }
                for (final String k : sort(e.keys)) {
                    export.writeStartElement("keyref");
                    export.writeAttribute("name", k);
                    export.writeEndElement();
                }
                export.writeEndElement();
            }
            export.writeEndElement();
            export.writeEndDocument();
        } catch (final IOException e) {
            throw new DITAOTException("Failed to write export anchor file: " + e.getMessage(), e);
        } catch (final XMLStreamException e) {
            throw new DITAOTException("Failed to serialize export anchor file: " + e.getMessage(), e);
        } finally {
            if (export != null) {
                try {
                    export.close();
                } catch (final XMLStreamException e) {
                    logger.error("Failed to close export anchor file: " + e.getMessage(), e);
                }
            }
        }
    }
}

From source file:org.dita.dost.reader.ChunkMapReader.java

/**
 * Create the new topic stump.//from ww w. j  a v  a2 s .  c o m
 */
private void createTopicStump(final File newFile) {
    OutputStream newFileWriter = null;
    try {
        newFileWriter = new FileOutputStream(newFile);
        final XMLStreamWriter o = XMLOutputFactory.newInstance().createXMLStreamWriter(newFileWriter, UTF8);
        o.writeStartDocument();
        o.writeProcessingInstruction(PI_WORKDIR_TARGET,
                UNIX_SEPARATOR + newFile.getParentFile().getAbsolutePath());
        o.writeProcessingInstruction(PI_WORKDIR_TARGET_URI, newFile.getParentFile().toURI().toString());
        o.writeStartElement(ELEMENT_NAME_DITA);
        o.writeEndElement();
        o.writeEndDocument();
        o.close();
        newFileWriter.flush();
    } catch (final RuntimeException e) {
        throw e;
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        try {
            if (newFileWriter != null) {
                newFileWriter.close();
            }
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:org.eclipse.gyrex.logback.config.model.LogbackConfig.java

/**
 * Serializes the Logback configuration to the specified XML writer.
 * <p>/*from w ww . j a  v  a  2s . com*/
 * The XML is expected to be readable by Logback. As such, it depends
 * heavily on Logback and may be bound to different evolution/compatibility
 * rules.
 * </p>
 * 
 * @param writer
 *            the stream writer
 * @throws XMLStreamException
 */
@Override
public void toXml(final XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();

    writer.writeStartElement("configuration");
    writer.writeAttribute("scan", "true");
    writer.writeAttribute("scanPeriod", "2 minutes");

    writeCommonProperties(writer);
    writeJulLevelChangePropagator(writer);

    for (final Appender appender : getAppenders().values()) {
        appender.toXml(writer);
    }
    for (final Logger logger : getLoggers().values()) {
        logger.toXml(writer);
    }

    writeRootLogger(writer);

    writer.writeEndElement();

    writer.writeEndDocument();
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void writeMessage(final OutputStream out) throws XMLStreamException {
    final XMLStreamWriter writer = this.dmClient.createXMLStreamWriter(out, ENCODING);
    writer.writeStartDocument(ENCODING, "1.0"); //$NON-NLS-1$
    // CHECKSTYLE:OFF (imbricated blocks)
    {//from w w  w.ja va  2 s  .  co m
        writer.writeStartElement("SyncML"); //$NON-NLS-1$
        writer.writeAttribute("xmlns", "SYNCML:SYNCML1.2"); //$NON-NLS-1$//$NON-NLS-2$
        {
            writer.writeStartElement("SyncHdr"); //$NON-NLS-1$
            {
                writer.writeStartElement("VerDTD"); //$NON-NLS-1$
                writer.writeCharacters("1.2"); //$NON-NLS-1$
                writer.writeEndElement();
                writer.writeStartElement("VerProto"); //$NON-NLS-1$
                writer.writeCharacters("DM/1.2"); //$NON-NLS-1$
                writer.writeEndElement();
                writer.writeStartElement("SessionID"); //$NON-NLS-1$
                writer.writeCharacters(this.sessionId);
                writer.writeEndElement();
                writer.writeStartElement("MsgID"); //$NON-NLS-1$
                writer.writeCharacters(String.valueOf(this.idGenerator.nextMsgID()));
                writer.writeEndElement();
                writer.writeStartElement("Target"); //$NON-NLS-1$
                {
                    writer.writeStartElement("LocURI"); //$NON-NLS-1$
                    writer.writeCharacters(this.server.toString());
                    writer.writeEndElement();
                }
                writer.writeEndElement();
                writer.writeStartElement("Source"); //$NON-NLS-1$
                {
                    writer.writeStartElement("LocURI"); //$NON-NLS-1$
                    writer.writeCharacters(this.client.toString());
                    writer.writeEndElement();
                }
                writer.writeEndElement();

                /*
                 * Add basic authentication
                 */
                writer.writeStartElement("Cred"); //$NON-NLS-1$
                {
                    writer.writeStartElement("Meta"); //$NON-NLS-1$
                    {
                        writer.writeStartElement("Format"); //$NON-NLS-1$
                        writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$
                        writer.writeCharacters("b64"); //$NON-NLS-1$
                        writer.writeEndElement();

                        writer.writeStartElement("Type"); //$NON-NLS-1$
                        writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$
                        writer.writeCharacters("syncml:auth-basic"); //$NON-NLS-1$
                        writer.writeEndElement();
                    }
                    writer.writeEndElement();

                    writer.writeStartElement("Data"); //$NON-NLS-1$
                    writer.writeCharacters(userAuth);
                    writer.writeEndElement();

                }
                writer.writeEndElement();
                /*
                 * End authentication
                 */
            }
            writer.writeEndElement();
            writer.writeStartElement("SyncBody"); //$NON-NLS-1$
            {
                writeStatus(writer);
                if (!this.isClientAuthenticated) {
                    writeAlert(writer, "1201"); //$NON-NLS-1$
                    writeGenericAlert(writer, this.genericAlerts);
                    writeReplace(writer, this.devInfoNodes);
                }

                writer.writeStartElement("Final"); //$NON-NLS-1$
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    // CHECKSTYLE:ON
    writer.writeEndDocument();
    writer.flush();
    writer.close();
}

From source file:org.eclipse.smila.datamodel.tools.DatamodelSerializationUtils.java

/**
 * Serialize2string.//from w w  w  .ja v  a2  s.c  o  m
 * 
 * @param id
 *          the id
 * 
 * @return the string
 */
public static String serialize2string(final Id id) {
    if (id == null) {
        return null;
    }
    try {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLStreamWriter writer = null;
        try {
            writer = getStaxWriterFactory().createXMLStreamWriter(out, "utf-8");
            writer.writeStartDocument("utf-8", "1.1");
            getIdWriter().writeId(writer, id);
            writer.writeEndDocument();
            return out.toString("utf-8");
        } catch (final Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (final XMLStreamException e) {
                    ; // nothing to do
                }
            } // if
            if (out != null) {
                IOUtils.closeQuietly(out);
            }
        } // finally
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.smila.datamodel.tools.DatamodelSerializationUtils.java

/**
 * Serializes a Record into a ByteArrayOutputStream. It does NOT serialize Attachment values, only their names !
 * /* w w  w  .  j ava2s.com*/
 * @param record
 *          the record
 * @return the ByteArrayOutputStream
 */
public static ByteArrayOutputStream serialize2stream(final Record record) {
    if (record == null) {
        return null;
    }

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLStreamWriter writer = null;
    try {
        writer = getStaxWriterFactory().createXMLStreamWriter(out, "utf-8");
        writer.writeStartDocument("utf-8", "1.1");
        getRecordWriter().writeRecord(writer, record);
        writer.writeEndDocument();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final XMLStreamException e) {
                ; // nothing to do
            }
        } // if
        if (out != null) {
            IOUtils.closeQuietly(out);
        }
    } // finally
    return out;
}

From source file:org.exist.webstart.JnlpWriter.java

/**
 * Write JNLP xml file to browser./*from ww w.  j a v a2 s. co m*/
 *
 * @param response Object for writing to end user.
 * @throws java.io.IOException
 */
void writeJnlpXML(JnlpJarFiles jnlpFiles, HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    logger.debug("Writing JNLP file");

    // Format URL: "http://host:8080/CONTEXT/webstart/exist.jnlp"
    final String currentUrl = request.getRequestURL().toString();

    // Find BaseUrl http://host:8080/CONTEXT
    final int webstartPos = currentUrl.indexOf("/webstart");
    final String existBaseUrl = currentUrl.substring(0, webstartPos);

    // Find codeBase for jarfiles http://host:8080/CONTEXT/webstart/
    final String codeBase = existBaseUrl + "/webstart/";

    // Perfom sanity checks
    int counter = 0;
    for (final File jar : jnlpFiles.getAllWebstartJars()) {
        counter++; // debugging
        if (jar == null || !jar.exists()) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Missing Jar file! (" + counter + ")");
            return;
        }
    }

    // Find URL to connect to with client
    final String startUrl = existBaseUrl.replaceFirst("http:", "xmldb:exist:")
            .replaceFirst("https:", "xmldb:exist:").replaceAll("-", "%2D") + "/xmlrpc";

    //        response.setDateHeader("Last-Modified", mainJar.lastModified());
    response.setContentType("application/x-java-jnlp-file");
    try {
        final XMLStreamWriter writer = XMLOutputFactory.newInstance()
                .createXMLStreamWriter(response.getOutputStream());

        writer.writeStartDocument();
        writer.writeStartElement("jnlp");
        writer.writeAttribute("spec", "1.0+");
        writer.writeAttribute("codebase", codeBase);
        writer.writeAttribute("href", "exist.jnlp");

        writer.writeStartElement("information");

        writer.writeStartElement("title");
        writer.writeCharacters("eXist XML-DB client");
        writer.writeEndElement();

        writer.writeStartElement("vendor");
        writer.writeCharacters("exist-db.org");
        writer.writeEndElement();

        writer.writeStartElement("homepage");
        writer.writeAttribute("href", "http://exist-db.org");
        writer.writeEndElement();

        writer.writeStartElement("description");
        writer.writeCharacters("Integrated command-line and gui client, "
                + "entirely based on the XML:DB API and provides commands "
                + "for most database related tasks, like creating and "
                + "removing collections, user management, batch-loading " + "XML data or querying.");
        writer.writeEndElement();

        writer.writeStartElement("description");
        writer.writeAttribute("kind", "short");
        writer.writeCharacters("eXist XML-DB client");
        writer.writeEndElement();

        writer.writeStartElement("description");
        writer.writeAttribute("kind", "tooltip");
        writer.writeCharacters("eXist XML-DB client");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_logo.jpg");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_icon_128x128.gif");
        writer.writeAttribute("width", "128");
        writer.writeAttribute("height", "128");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_icon_64x64.gif");
        writer.writeAttribute("width", "64");
        writer.writeAttribute("height", "64");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_icon_32x32.gif");
        writer.writeAttribute("width", "32");
        writer.writeAttribute("height", "32");
        writer.writeEndElement();

        writer.writeEndElement(); // information

        writer.writeStartElement("security");
        writer.writeEmptyElement("all-permissions");
        writer.writeEndElement();

        // ----------

        writer.writeStartElement("resources");

        writer.writeStartElement("property");
        writer.writeAttribute("name", "jnlp.packEnabled");
        writer.writeAttribute("value", "true");
        writer.writeEndElement();

        writer.writeStartElement("j2se");
        writer.writeAttribute("version", "1.6+");
        writer.writeEndElement();

        for (final File jar : jnlpFiles.getAllWebstartJars()) {
            writer.writeStartElement("jar");
            writer.writeAttribute("href", jar.getName());
            writer.writeAttribute("size", "" + jar.length());
            writer.writeEndElement();
        }

        writer.writeEndElement(); // resources

        writer.writeStartElement("application-desc");
        writer.writeAttribute("main-class", "org.exist.client.InteractiveClient");

        writer.writeStartElement("argument");
        writer.writeCharacters("-ouri=" + startUrl);
        writer.writeEndElement();

        writer.writeStartElement("argument");
        writer.writeCharacters("--no-embedded-mode");
        writer.writeEndElement();

        if (request.isSecure()) {
            writer.writeStartElement("argument");
            writer.writeCharacters("--use-ssl");
            writer.writeEndElement();
        }

        writer.writeEndElement(); // application-desc

        writer.writeEndElement(); // jnlp

        writer.writeEndDocument();

        writer.flush();
        writer.close();

    } catch (final Throwable ex) {
        logger.error(ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }

}

From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java

protected File createSingleMetadata(String groupId, String artifactId, String version)
        throws FileNotFoundException {
    File temp = null;//from   w ww. j av a  2  s .  c  om
    try {
        String filename = getUniqueFilename("maven-metadata.xml");
        temp = File.createTempFile(filename, null);

        OutputStream os = new FileOutputStream(temp);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(os);
        try {
            writer.writeStartDocument("UTF-8", "1.0");
            writer.writeStartElement("metadata");

            writer.writeStartElement("groupId");
            writer.writeCharacters(groupId);
            writer.writeEndElement();

            writer.writeStartElement("artifactId");
            writer.writeCharacters(artifactId);
            writer.writeEndElement();

            writer.writeStartElement("version");
            writer.writeCharacters(version);
            writer.writeEndElement();

            writer.writeEndElement();
            writer.writeEndDocument();
        } finally {
            writer.flush();
            writer.close();
            os.close();
        }
    } catch (XMLStreamException e) {
        LOG.error("Error on creating metadata - XML", e);
    } catch (IOException e) {
        LOG.error("Error on creating metadata - FILE", e);
    }
    return (temp != null && temp.exists()) ? temp : null;
}

From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java

protected File createMultiMetadata(String groupId, String artifactId, String current_version,
        List<String> v_list) throws FileNotFoundException {
    File temp = null;/*w w w  .  j  av a 2 s .c om*/
    try {
        String filename = getUniqueFilename("maven-metadata.xml");
        temp = File.createTempFile(filename, null);

        OutputStream os = new FileOutputStream(temp);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(os);
        try {
            writer.writeStartDocument("UTF-8", "1.0");
            writer.writeStartElement("metadata");

            writer.writeStartElement("groupId");
            writer.writeCharacters(groupId);
            writer.writeEndElement();

            writer.writeStartElement("artifactId");
            writer.writeCharacters(artifactId);
            writer.writeEndElement();

            String elderVersion;
            if (v_list.size() > 0) {
                Collections.sort(v_list); // sort list
                elderVersion = v_list.get(0); // get first element
            } else
                elderVersion = current_version;
            v_list.add(current_version);

            writer.writeStartElement("version");
            writer.writeCharacters(elderVersion);
            writer.writeEndElement();

            writer.writeStartElement("versions");
            writer.writeStartElement("versioning");

            for (Iterator<String> iterator = v_list.iterator(); iterator.hasNext();) {
                writer.writeStartElement("version");
                writer.writeCharacters(iterator.next());
                writer.writeEndElement();
            }

            writer.writeEndElement();
            writer.writeEndElement();

            writer.writeEndElement();
            writer.writeEndDocument();
        } finally {
            writer.flush();
            writer.close();
            os.close();
        }
    } catch (XMLStreamException e) {
        LOG.error("Error on creating metadata - XML", e);
    } catch (IOException e) {
        LOG.error("Error on creating metadata - FILE", e);
    }
    return (temp != null && temp.exists()) ? temp : null;
}

From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java

public byte[] convertToXML(BpmnModel model, String encoding) {
    try {/*from www  .j av a2  s .  c om*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        DefinitionsRootExport.writeRootElement(model, xtw, encoding);
        CollaborationExport.writePools(model, xtw);
        DataStoreExport.writeDataStores(model, xtw);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);

        for (Process process : model.getProcesses()) {

            if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
                // empty process, ignore it
                continue;
            }

            ProcessExport.writeProcess(process, xtw);

            for (FlowElement flowElement : process.getFlowElements()) {
                createXML(flowElement, model, xtw);
            }

            for (Artifact artifact : process.getArtifacts()) {
                createXML(artifact, model, xtw);
            }

            // end process element
            xtw.writeEndElement();
        }

        BPMNDIExport.writeBPMNDI(model, xtw);

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new XMLException("Error writing BPMN XML", e);
    }
}