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:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter;
    try {//from  w  w w .ja v  a2 s  .co  m
        xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement("root");
        xmlStreamWriter.writeAttribute("url", getUrl());
        // xmlStreamWriter.writeAttribute("level",
        // String.valueOf(getLevel()));
        process(xmlStreamWriter, getUrl(), getLevel());
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.flush();
        xmlStreamWriter.close();
    } catch (XMLStreamException e) {
        throw new PipeRunException(this, "XMLStreamException", e);
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, "DomBuilderException", e);
    } catch (XPathExpressionException e) {
        throw new PipeRunException(this, "XPathExpressionException", e);
    }

    return new PipeRunResult(getForward(), stringWriter.getBuffer().toString());
}

From source file:nl.nn.adapterframework.soap.Wsdl.java

/**
 * Writes the WSDL to an output stream/* ww w  . j  av  a  2  s. c o  m*/
 * @param out
 * @param servlet  The servlet what is used as the web service (because this needs to be present in the WSDL)
 * @throws XMLStreamException
 * @throws IOException
 */
public void wsdl(OutputStream out, String servlet)
        throws XMLStreamException, IOException, ConfigurationException, NamingException {
    XMLStreamWriter w = WsdlUtils.getWriter(out, isIndent());

    w.writeStartDocument(XmlUtils.STREAM_FACTORY_ENCODING, "1.0");
    w.setPrefix(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE);
    w.setPrefix(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE);
    w.setPrefix(soapPrefix, soapNamespace);
    if (jmsActive) {
        if (esbSoap) {
            w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, ESB_SOAP_JMS_NAMESPACE);
            w.setPrefix(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE);
        } else {
            w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, SOAP_JMS_NAMESPACE);
        }
    }
    w.setPrefix(getTargetNamespacePrefix(), getTargetNamespace());
    for (String prefix : namespaceByPrefix.keySet()) {
        w.setPrefix(prefix, namespaceByPrefix.get(prefix));
    }
    w.writeStartElement(WSDL_NAMESPACE, "definitions");
    {
        w.writeNamespace(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE);
        w.writeNamespace(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE);
        w.writeNamespace(soapPrefix, soapNamespace);
        if (esbSoap) {
            w.writeNamespace(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE);
        }
        w.writeNamespace(getTargetNamespacePrefix(), getTargetNamespace());
        for (String prefix : namespaceByPrefix.keySet()) {
            w.writeNamespace(prefix, namespaceByPrefix.get(prefix));
        }
        w.writeAttribute("targetNamespace", getTargetNamespace());

        documentation(w);
        types(w);
        messages(w);
        portType(w);
        binding(w);
        service(w, servlet);
    }
    w.writeEndDocument();
    warnings(w);
    w.close();
}

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

public static void main(String[] args) {

    logger.info("Starting application [ rtd ] ...");

    try {/*from w  ww  .j  a v  a  2s .  co m*/

        config.addConfiguration(
                new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME)));

        HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT);

        EodDataProvider eodDataProvider = null;

        OutputStream out = new FileOutputStream(OUTPUT_FILENAME);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);

        eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME);

        writer.writeStartDocument("utf-8", "1.0");
        writer.writeCharacters(NEWLINE);
        writer.writeComment("Test data for running DataScraper unit tests against");
        writer.writeCharacters(NEWLINE);

        writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI);

        writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME);
        writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI);
        writer.writeCharacters(NEWLINE);

        serializeExchanges(eodDataProvider, writer);
        serializeSymbols(eodDataProvider, writer);
        serializeQuotes(eodDataProvider, writer);

        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
        writer.writeEndDocument();
        writer.flush();
        writer.close();

    } catch (ConfigurationException ce) {

        logger.error(ce.toString());
        ce.printStackTrace();

    } catch (Exception e) {

        logger.error(e.toString());
        logger.error(e);

    }

    logger.info("Exiting application [ rtd ] ...");

}

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

public byte[] convertToXML(BpmnModel model, String encoding) {
    try {/*from w ww  .  java  2  s . co  m*/

        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);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
        PoolExport.writePools(model, xtw);

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

            if (process.getFlowElements().size() == 0 && process.getLanes().size() == 0) {
                // 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);
    }
}

From source file:org.activiti.dmn.xml.converter.DmnXMLConverter.java

public byte[] convertToXML(DmnDefinition model, String encoding) {
    try {/*from   w  w w . ja v a2 s.  co m*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

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

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

        xtw.writeStartElement(ELEMENT_DEFINITIONS);
        xtw.writeDefaultNamespace(DMN_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_ID, model.getId());
        if (StringUtils.isNotEmpty(model.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, model.getName());
        }
        xtw.writeAttribute(ATTRIBUTE_NAMESPACE, MODEL_NAMESPACE);

        DmnXMLUtil.writeElementDescription(model, xtw);
        DmnXMLUtil.writeExtensionElements(model, xtw);

        for (ItemDefinition itemDefinition : model.getItemDefinitions()) {
            xtw.writeStartElement(ELEMENT_ITEM_DEFINITION);
            xtw.writeAttribute(ATTRIBUTE_ID, itemDefinition.getId());
            if (StringUtils.isNotEmpty(itemDefinition.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, itemDefinition.getName());
            }

            DmnXMLUtil.writeElementDescription(itemDefinition, xtw);
            DmnXMLUtil.writeExtensionElements(itemDefinition, xtw);

            xtw.writeStartElement(ELEMENT_TYPE_DEFINITION);
            xtw.writeCharacters(itemDefinition.getTypeDefinition());
            xtw.writeEndElement();

            xtw.writeEndElement();
        }

        for (Decision decision : model.getDrgElements()) {
            xtw.writeStartElement(ELEMENT_DECISION);
            xtw.writeAttribute(ATTRIBUTE_ID, decision.getId());
            if (StringUtils.isNotEmpty(decision.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, decision.getName());
            }

            DmnXMLUtil.writeElementDescription(decision, xtw);
            DmnXMLUtil.writeExtensionElements(decision, xtw);

            DecisionTable decisionTable = decision.getDecisionTable();
            xtw.writeStartElement(ELEMENT_DECISION_TABLE);
            xtw.writeAttribute(ATTRIBUTE_ID, decisionTable.getId());

            if (decisionTable.getHitPolicy() != null) {
                xtw.writeAttribute(ATTRIBUTE_HIT_POLICY, decisionTable.getHitPolicy().toString());
            }

            DmnXMLUtil.writeElementDescription(decisionTable, xtw);
            DmnXMLUtil.writeExtensionElements(decisionTable, xtw);

            for (InputClause clause : decisionTable.getInputs()) {
                xtw.writeStartElement(ELEMENT_INPUT_CLAUSE);
                if (StringUtils.isNotEmpty(clause.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getId());
                }
                if (StringUtils.isNotEmpty(clause.getLabel())) {
                    xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel());
                }

                DmnXMLUtil.writeElementDescription(clause, xtw);
                DmnXMLUtil.writeExtensionElements(clause, xtw);

                if (clause.getInputExpression() != null) {
                    xtw.writeStartElement(ELEMENT_INPUT_EXPRESSION);
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getInputExpression().getId());

                    if (StringUtils.isNotEmpty(clause.getInputExpression().getTypeRef())) {
                        xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getInputExpression().getTypeRef());
                    }

                    if (StringUtils.isNotEmpty(clause.getInputExpression().getText())) {
                        xtw.writeStartElement(ELEMENT_TEXT);
                        xtw.writeCharacters(clause.getInputExpression().getText());
                        xtw.writeEndElement();
                    }

                    xtw.writeEndElement();
                }

                xtw.writeEndElement();
            }

            for (OutputClause clause : decisionTable.getOutputs()) {
                xtw.writeStartElement(ELEMENT_OUTPUT_CLAUSE);
                if (StringUtils.isNotEmpty(clause.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getId());
                }
                if (StringUtils.isNotEmpty(clause.getLabel())) {
                    xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel());
                }
                if (StringUtils.isNotEmpty(clause.getName())) {
                    xtw.writeAttribute(ATTRIBUTE_NAME, clause.getName());
                }
                if (StringUtils.isNotEmpty(clause.getTypeRef())) {
                    xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getTypeRef());
                }

                DmnXMLUtil.writeElementDescription(clause, xtw);
                DmnXMLUtil.writeExtensionElements(clause, xtw);

                xtw.writeEndElement();
            }

            for (DecisionRule rule : decisionTable.getRules()) {
                xtw.writeStartElement(ELEMENT_RULE);
                if (StringUtils.isNotEmpty(rule.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, rule.getId());
                }

                DmnXMLUtil.writeElementDescription(rule, xtw);
                DmnXMLUtil.writeExtensionElements(rule, xtw);

                for (RuleInputClauseContainer container : rule.getInputEntries()) {
                    xtw.writeStartElement(ELEMENT_INPUT_ENTRY);
                    xtw.writeAttribute(ATTRIBUTE_ID, container.getInputEntry().getId());

                    xtw.writeStartElement(ELEMENT_TEXT);
                    xtw.writeCharacters(container.getInputEntry().getText());
                    xtw.writeEndElement();

                    xtw.writeEndElement();
                }

                for (RuleOutputClauseContainer container : rule.getOutputEntries()) {
                    xtw.writeStartElement(ELEMENT_OUTPUT_ENTRY);
                    xtw.writeAttribute(ATTRIBUTE_ID, container.getOutputEntry().getId());

                    xtw.writeStartElement(ELEMENT_TEXT);
                    xtw.writeCharacters(container.getOutputEntry().getText());
                    xtw.writeEndElement();

                    xtw.writeEndElement();
                }

                xtw.writeEndElement();
            }

            xtw.writeEndElement();

            xtw.writeEndElement();
        }

        // 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 DmnXMLException("Error writing BPMN XML", e);
    }
}

From source file:org.apache.axis2.fastinfoset.FastInfosetMessageFormatter.java

/**
 * Retrieves the raw bytes from the SOAP envelop.
 * /* w ww .j  a  v  a  2 s  .co m*/
 * @see org.apache.axis2.transport.MessageFormatter#getBytes(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat)
 */
public byte[] getBytes(MessageContext messageContext, OMOutputFormat format) throws AxisFault {
    OMElement element = messageContext.getEnvelope();
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    try {
        //Creates StAX document serializer which actually implements the XMLStreamWriter
        XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream);
        element.serializeAndConsume(streamWriter);
        //TODO Looks like the SOAP envelop doesn't have an end document tag. Find out why?
        streamWriter.writeEndDocument();

        return outStream.toByteArray();

    } catch (XMLStreamException xmlse) {
        logger.error(xmlse.getMessage());
        throw new AxisFault(xmlse.getMessage(), xmlse);
    }
}

From source file:org.apache.axis2.fastinfoset.FastInfosetMessageFormatter.java

/**
 * Write the SOAP envelop to the given OutputStream.
 * /*from   www  .ja v a 2 s . c  o  m*/
 * @see org.apache.axis2.transport.MessageFormatter#writeTo(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat, java.io.OutputStream, boolean)
 */
public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream,
        boolean preserve) throws AxisFault {
    OMElement element = messageContext.getEnvelope();

    try {
        //Create the StAX document serializer
        XMLStreamWriter streamWriter = new StAXDocumentSerializer(outputStream);
        if (preserve) {
            element.serialize(streamWriter);
        } else {
            element.serializeAndConsume(streamWriter);
        }
        //         TODO Looks like the SOAP envelop doesn't have a end document tag. Find out why?
        streamWriter.writeEndDocument();
    } catch (XMLStreamException xmlse) {
        logger.error(xmlse.getMessage());
        throw new AxisFault(xmlse.getMessage(), xmlse);
    }
}

From source file:org.apache.axis2.fastinfoset.FastInfosetPOXMessageFormatter.java

/**
 * Retrieves the raw bytes from the SOAP envelop.
 * /*w  w  w.  j a  v a2 s. c om*/
 * @see org.apache.axis2.transport.MessageFormatter#getBytes(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat)
 */
public byte[] getBytes(MessageContext messageContext, OMOutputFormat format) throws AxisFault {
    //For POX drop the SOAP envelope and use the message body
    OMElement element = messageContext.getEnvelope().getBody().getFirstElement();
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    try {
        //Creates StAX document serializer which actually implements the XMLStreamWriter
        XMLStreamWriter streamWriter = new StAXDocumentSerializer(outStream);
        //Since we drop the SOAP envelop we have to manually write the start document and the end document events
        streamWriter.writeStartDocument();
        element.serializeAndConsume(streamWriter);
        streamWriter.writeEndDocument();

        return outStream.toByteArray();

    } catch (XMLStreamException xmlse) {
        logger.error(xmlse.getMessage());
        throw new AxisFault(xmlse.getMessage(), xmlse);
    }
}

From source file:org.apache.axis2.fastinfoset.FastInfosetPOXMessageFormatter.java

/**
 * Write the SOAP envelop to the given OutputStream.
 * /*from ww w.  j a v  a2s  . co m*/
 * @see org.apache.axis2.transport.MessageFormatter#writeTo(org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat, java.io.OutputStream, boolean)
 */
public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream,
        boolean preserve) throws AxisFault {
    //For POX drop the SOAP envelope and use the message body
    OMElement element = messageContext.getEnvelope().getBody().getFirstElement();

    try {
        //Create the StAX document serializer
        XMLStreamWriter streamWriter = new StAXDocumentSerializer(outputStream);
        //Since we drop the SOAP envelop we have to manually write the start document and the end document events         
        streamWriter.writeStartDocument();
        if (preserve) {
            element.serialize(streamWriter);
        } else {
            element.serializeAndConsume(streamWriter);
        }
        streamWriter.writeEndDocument();
    } catch (XMLStreamException xmlse) {
        logger.error(xmlse.getMessage());
        throw new AxisFault(xmlse.getMessage(), xmlse);
    }
}

From source file:org.apache.flex.compiler.config.Configuration.java

/**
 * @return Metadata XML string./*from ww  w . j a  va 2s.c  om*/
 */
private final String generateMetadata() {
    final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    assert xmlOutputFactory != null : "Expect XMLOutputFactory implementation.";
    final StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = null;

    try {
        xmlWriter = new XMLFormatter(xmlOutputFactory.createXMLStreamWriter(stringWriter));
        xmlWriter.writeStartDocument();

        xmlWriter.writeStartElement("rdf", "RDF", RDF_URI);
        xmlWriter.setPrefix("rdf", RDF_URI);
        xmlWriter.writeNamespace("rdf", RDF_URI);

        // write rdf:Description
        xmlWriter.writeStartElement(RDF_URI, "Description");
        xmlWriter.setPrefix("dc", DC_URI);
        xmlWriter.setPrefix(VersionInfo.COMPILER_NAMESPACE_PREFIX, VersionInfo.COMPILER_NAMESPACE_URI);
        xmlWriter.writeNamespace("dc", DC_URI);
        xmlWriter.writeNamespace(VersionInfo.COMPILER_NAMESPACE_PREFIX, VersionInfo.COMPILER_NAMESPACE_URI);

        // write dc:format
        xmlWriter.writeStartElement(DC_URI, "format");
        xmlWriter.writeCharacters("application/x-shockwave-flash");
        xmlWriter.writeEndElement();

        if (isFlex()) {
            // write localizedTitles
            writeMap(xmlWriter, DC_URI, "description", localizedDescriptions);

            // write localizedDescription
            writeMap(xmlWriter, DC_URI, "title", localizedTitles);

            // write publisher
            writeCollection(xmlWriter, DC_URI, "publisher", publishers);

            // write creators
            writeCollection(xmlWriter, DC_URI, "creator", creators);

            // write contributor
            writeCollection(xmlWriter, DC_URI, "contributor", contributors);

            // write language
            writeCollection(xmlWriter, DC_URI, "language", langs);

            // write date
            writeDate(xmlWriter);
        }

        // write compiledBy
        writeCompiledBy(xmlWriter);

        // write
        xmlWriter.writeEndElement(); // Description
        xmlWriter.writeEndDocument();
    } catch (XMLStreamException e) {
        return "";
    }

    return stringWriter.toString();
}