Example usage for javax.xml.stream XMLOutputFactory newInstance

List of usage examples for javax.xml.stream XMLOutputFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.stream XMLOutputFactory newInstance.

Prototype

public static XMLOutputFactory newInstance() throws FactoryConfigurationError 

Source Link

Document

Creates a new instance of the factory in exactly the same manner as the #newFactory() method.

Usage

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

/**
 * //ww  w  . j  a  v  a 2 s  .co  m
 * @throws IOException
 */
private void flushPartialTemplateFiles() throws IOException {
    XMLOutputFactory xmlOutFactory = XMLOutputFactory.newInstance();
    flushAppXmlFile(xmlOutFactory);
    flushWorkbookRelsXmlFile(xmlOutFactory);
    flushWorkbookXmlFile(xmlOutFactory);
}

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

/**
 * Write all shared strings to ./xl/SharedStrings.xml file
 * /*from w  ww  . j  a  v a  2s .c  o  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.tldgen.writers.TldLibraryWriter.java

/**
 * Write the TLD file/*  w w w .j a v a 2  s. c o m*/
 * 
 * @param library the library to create the TLD documentation
 * @param folder the folder where the TLD file should be created 
 * @throws XMLStreamException if there is any problem writing the TLD 
 */
public void writeTLD(Library library, String folder) throws XMLStreamException, IOException {

    String filename = folder + "/" + library.getLibrarySignature().getShortName() + ".tld";
    if (warnIfExists(filename) && doNotOverwrite) {
        return;
    }
    log.info("Creating TLD file: " + filename);

    // write the TLD to memory
    StringWriter buffer = new StringWriter();
    try {
        writer = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer);
        startTaglibElement(library);
        if (library.getTags() != null) {
            writeTags(library.getTags());
        }

        if (library.getFunctions() != null) {
            writeFunctions(library.getFunctions());
        }

        if (library.getListeners() != null) {
            writeListeners(library.getListeners());
        }

        endTaglibElement();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }

    DirectoryUtils.createParentFolder(filename);
    // format the generated XML and write to disk
    formatAndWriteXml(buffer.toString(), filename);
}

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

public void streamResultsXML(Writer out, DataQueryResults dq) {
    Long totalCount = null;/*from www  . j a  v a2  s. c om*/
    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  w ww .j a v a 2  s  .com
        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  va2  s .  c  om*/
        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 {//from   ww w .j av  a  2 s  .co m
        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 ww . ja  va 2s  . co  m*/
        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);
    }
}

From source file:org.tolven.assembler.facesconfig.FacesConfigAssembler.java

protected String getXSLT(PluginDescriptor pluginDescriptor) throws XMLStreamException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    boolean added = false;
    try {/*from  w  w  w . j a v  a2 s . c  om*/
        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);
        added = added | addApplicationChildren(pluginDescriptor, xmlStreamWriter);
        added = added | addGlobalValidatorTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addGlobalConverterTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addLifeCycleTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addNavigationRuleTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addManagedBeanTemplates(pluginDescriptor, xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    if (added) {
        return xslt.toString();
    } else {
        return null;
    }
}

From source file:org.tolven.assembler.tomcatserver.TomcatServerXMLAssembler.java

protected String getXSLT(ExtensionPoint connectorExtensionPoint) throws XMLStreamException, IOException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    try {//from w  w w .  j  a va2 s  .c o  m
        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.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);
        addServiceTemplate(connectorExtensionPoint, xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    return xslt.toString();
}