Example usage for javax.xml.stream XMLStreamWriter writeStartDocument

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

Introduction

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

Prototype

public void writeStartDocument(String encoding, String version) throws XMLStreamException;

Source Link

Document

Write the XML Declaration.

Usage

From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java

public static final void writeSchema(final List<PsmDocument<Type>> documents, final ModelIndex model,
        final Uml2XsdPlugin plugin, final OutputStream outstream) {
    final XMLOutputFactory xof = XMLOutputFactory.newInstance();
    try {/*ww w.j av a 2 s .c  om*/
        final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8"));
        xsw.writeStartDocument("UTF-8", "1.0");
        try {
            writeSchema(documents, model, plugin, xsw);
        } finally {
            xsw.writeEndDocument();
        }
        xsw.flush();
        // We close the stream writer knowing (from the documentation) that it will not close
        // the underlying output stream.
        xsw.close();
    } catch (final XMLStreamException e) {
        throw new XsdGenRuntimeException(e);
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

public static final void writeDocument(final Application app, final Map<String, String> prefixMappings,
        final OutputStream outstream) {
    final XMLOutputFactory xof = XMLOutputFactory.newInstance();
    try {/*from  w w w  .  j  a  v a 2 s .  c  o m*/
        final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8"));
        xsw.writeStartDocument("UTF-8", "1.0");
        try {
            writeApplication(app, prefixMappings, xsw);
        } finally {
            xsw.writeEndDocument();
        }
        xsw.flush();
    } catch (final XMLStreamException e) {
        throw new WadlRuntimeException(e);
    }
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

public static final void writeMappingDocument(final XmiComparison document, final OutputStream outstream) {
    final XMLOutputFactory xof = XMLOutputFactory.newInstance();
    try {//  w ww .  j  ava  2s.  c om
        final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8"));
        xsw.writeStartDocument("UTF-8", "1.0");
        try {
            writeMappingDocument(document, xsw);
        } finally {
            xsw.writeEndDocument();
        }
        xsw.flush();
        xsw.close();
    } catch (final XMLStreamException e) {
        throw new XmiCompRuntimeException(e);
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

public static final void writeDocument(final Model model, final ModelIndex mapper,
        final OutputStream outstream) {
    final XMLOutputFactory xof = XMLOutputFactory.newInstance();
    try {//  w w w  .  j a  v a2  s. co m
        final XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(outstream, "UTF-8"));
        xsw.writeStartDocument("UTF-8", "1.0");
        try {
            XmiWriter.writeXMI(model, mapper, xsw);
        } finally {
            xsw.writeEndDocument();
        }
        xsw.flush();
    } catch (final XMLStreamException e) {
        throw new XmiRuntimeException(e);
    }
}

From source file:org.staxcel.internal.SpreadSheetImpl.java

/**
 * Write all shared strings to ./xl/SharedStrings.xml file
 * /*from   ww  w. j a  va 2  s.co m*/
 * @throws IOException
 */
protected void addSharedStringsFile() throws IOException {
    try {
        BufferedWriter writer = createWriter(OpenXMLFormatConstants.SHARED_STRING_FILE_NAME);
        XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
        xmlWriter.writeStartDocument("UTF-8", "1.0");
        xmlWriter.writeStartElement("sst");
        xmlWriter.writeAttribute("xmlns", OpenXMLNamespace.NS_OPENXML_SPREADSHEETML_2006_MAIN);
        xmlWriter.writeAttribute("count", String.valueOf(this.sharedStrings.size()));
        xmlWriter.writeAttribute("uniqueCount", String.valueOf(this.sharedStrings.size()));

        for (Entry<String, Integer> entry : this.sharedStrings.entrySet()) {
            xmlWriter.writeStartElement("si");
            xmlWriter.writeStartElement("t");
            xmlWriter.writeCharacters(entry.getKey());
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndElement();
        xmlWriter.writeEndDocument();
        xmlWriter.close();
        writer.flush();
        writer.close();
    } catch (XMLStreamException ex) {
        logger.error("XML error when creating SharedStrings.xml file", ex);
        throw new StaxcelException("XML error when creating SharedStrings.xml file", ex);
    }
}

From source file:org.tolven.app.bean.DataExtractBean.java

public void streamResultsXML(Writer out, DataQueryResults dq) {
    Long totalCount = null;//  w  w w  .j  a va2 s  .  com
    if (dq.isReturnTotalCount()) {
        getMDQueryResults(dq, true);
        totalCount = (Long) dq.getIterator().next();
    }

    if (dq.getLimit() != 0) {
        getMDQueryResults(dq, false);
    }
    try {
        XMLStreamWriter xmlStreamWriter = null;
        try {
            XMLOutputFactory factory = XMLOutputFactory.newInstance();
            xmlStreamWriter = factory.createXMLStreamWriter(out);
            xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
            xmlStreamWriter.writeStartElement("results");
            xmlStreamWriter.writeAttribute("path", dq.getPath());
            xmlStreamWriter.writeAttribute("account", String.valueOf(dq.getAccount().getId()));
            xmlStreamWriter.writeAttribute("database",
                    getTolvenPropertiesBean().getProperty("tolven.repository.oid"));
            GregorianCalendar nowCal = new GregorianCalendar();
            nowCal.setTime(dq.getNow());
            DatatypeFactory xmlFactory = DatatypeFactory.newInstance();
            XMLGregorianCalendar ts = xmlFactory.newXMLGregorianCalendar(nowCal);
            xmlStreamWriter.writeAttribute("timestamp", ts.toXMLFormat());
            if (!dq.isItemQuery()) {
                xmlStreamWriter.writeAttribute("offset", Long.toString(dq.getOffset()));
                xmlStreamWriter.writeAttribute("limit", Long.toString(dq.getLimit()));
                xmlStreamWriter.writeAttribute("count", Long.toString(dq.getCount()));
            }
            if (!dq.isItemQuery() && totalCount != null) {
                xmlStreamWriter.writeAttribute("totalCount", totalCount.toString());
            }
            addExtendedFields(dq);
            //addPlaceholderIds(dq);
            if (MenuStructure.PLACEHOLDER.equals(dq.getMenuStructure().getRole())) {
                addParentFields(dq);
            }
            addSimpleXMLColumnHeadings(dq, xmlStreamWriter);
            if (dq.getLimit() != 0) {
                addXMLRows(dq, xmlStreamWriter);
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeEndDocument();
        } finally {
            if (xmlStreamWriter != null) {
                xmlStreamWriter.close();
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException("Could not obtain XML results for menupath: " + dq.getPath()
                + " in account: " + dq.getAccount().getId(), ex);
    }
}

From source file:org.tolven.assembler.ear.EARAssembler.java

protected String getXSLT(PluginDescriptor pd, File localDestDir) throws XMLStreamException, IOException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = null;
    try {//from   ww w.  j av a  2 s  .  c o m
        writer = factory.createXMLStreamWriter(xslt);
        writer.writeStartDocument("UTF-8", "1.0");
        writer.writeCharacters("\n");
        writer.writeStartElement("xsl:stylesheet");
        writer.writeAttribute("version", "2.0");
        writer.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        writer.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters("\n");
        writer.writeStartElement("xsl:output");
        writer.writeAttribute("method", "xml");
        writer.writeAttribute("indent", "yes");
        writer.writeAttribute("encoding", "UTF-8");
        writer.writeAttribute("omit-xml-declaration", "no");
        writer.writeEndElement();
        writer.writeCharacters("\n");
        addMainTemplate(writer);
        addRootTemplate(writer);
        addJavaLibraryTemplates(pd, localDestDir);
        addConnectorModuleTemplates(pd, localDestDir, writer);
        addEJBModuleTemplates(pd, localDestDir, writer);
        addWARModuleTemplates(pd, localDestDir, writer);
        addSecurityRoleTemplates(pd, writer);
        writer.writeEndDocument();
        writer.writeEndDocument();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    return xslt.toString();
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected String getEJBJARXSLT() throws XMLStreamException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    try {/*  ww  w  .  j  a  va  2  s .com*/
        xmlStreamWriter = factory.createXMLStreamWriter(xslt);
        xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:stylesheet");
        xmlStreamWriter.writeAttribute("version", "2.0");
        xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        xmlStreamWriter.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee");
        xmlStreamWriter.writeAttribute("exclude-result-prefixes", "tp");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:output");
        xmlStreamWriter.writeAttribute("method", "xml");
        xmlStreamWriter.writeAttribute("indent", "yes");
        xmlStreamWriter.writeAttribute("encoding", "UTF-8");
        xmlStreamWriter.writeAttribute("omit-xml-declaration", "no");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        addMainTemplate(xmlStreamWriter);
        addRootTemplate(xmlStreamWriter);
        addEnterpriseBeansChildren(xmlStreamWriter);
        addAssemblyDescriptorChildren(xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    return xslt.toString();
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected String getORM(PluginDescriptor pd) {
    try {// w  w w . j  ava2 s . c om
        StringWriter writer = new StringWriter();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter xmlStreamWriter = null;
        try {
            xmlStreamWriter = factory.createXMLStreamWriter(writer);
            xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
            xmlStreamWriter.writeCharacters("\n");
            xmlStreamWriter.writeStartElement("entity-mappings");
            xmlStreamWriter.writeAttribute("xmlns", "http://java.sun.com/xml/ns/persistence/orm");
            xmlStreamWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmlStreamWriter.writeAttribute("xsi:schemaLocation",
                    "http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm/orm_2_0.xsd");
            xmlStreamWriter.writeAttribute("version", "2.0");
            xmlStreamWriter.writeCharacters("\n");
            ExtensionPoint exnPt = getMyExtensionPoint(EXNPT_ORM);
            Extension exn = exnPt.getConnectedExtensions().iterator().next();
            String ormId = exn.getParameter("ormId").valueAsString();
            if (ormId == null || ormId.length() == 0) {
                throw new RuntimeException(exnPt.getUniqueId() + "@ormId must have a value");
            }
            addPersistenceUnitMetadata(pd, ormId, xmlStreamWriter);
            addTableGenerators(pd, ormId, xmlStreamWriter);
            addMappedSuperclasses(pd, ormId, xmlStreamWriter);
            addEntities(pd, ormId, xmlStreamWriter);
            addEmbeddables(pd, ormId, xmlStreamWriter);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeEndDocument();
        } finally {
            if (xmlStreamWriter != null) {
                xmlStreamWriter.close();
            }
        }
        return writer.toString();
    } catch (XMLStreamException ex) {
        throw new RuntimeException("Could not create orm.xml", ex);
    }
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected String getPersistenceXML(PluginDescriptor pd) {
    try {//  w  w  w.j a v a2  s . c om
        StringWriter writer = new StringWriter();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter xmlStreamWriter = null;
        try {
            xmlStreamWriter = factory.createXMLStreamWriter(writer);
            xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
            xmlStreamWriter.writeCharacters("\n");
            xmlStreamWriter.writeStartElement("persistence");
            xmlStreamWriter.writeAttribute("xmlns", "http://java.sun.com/xml/ns/persistence");
            xmlStreamWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmlStreamWriter.writeAttribute("xsi:schemaLocation",
                    "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
            xmlStreamWriter.writeAttribute("version", "2.0");
            xmlStreamWriter.writeCharacters("\n");
            addPersistenceUnit(pd, xmlStreamWriter);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
            xmlStreamWriter.writeEndDocument();
        } finally {
            if (xmlStreamWriter != null) {
                xmlStreamWriter.close();
            }
        }
        return writer.toString();
    } catch (XMLStreamException ex) {
        throw new RuntimeException("Could not create orm.xml", ex);
    }
}