Example usage for javax.xml.stream XMLStreamWriter writeCharacters

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

Introduction

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

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

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

protected void addRootAssemblyDescriptorSelects(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:for-each");
    xmlStreamWriter.writeAttribute("select", "tp:assembly-descriptor");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:copy-of");
    xmlStreamWriter.writeAttribute("select", ".");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:apply-templates");
    xmlStreamWriter.writeAttribute("select", "* | @* | text() | comment()");
    xmlStreamWriter.writeEndElement();//from w ww.  j  a  v a 2s .  c o m
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "addAssemblyDescriptorChildren");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "createAssemblyDescriptor");
    xmlStreamWriter.writeEndElement();
}

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

protected void addRootEnterpriseBeansSelects(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:for-each");
    xmlStreamWriter.writeAttribute("select", "tp:enterprise-beans");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:copy-of");
    xmlStreamWriter.writeAttribute("select", ".");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:apply-templates");
    xmlStreamWriter.writeAttribute("select", "* | @* | text() | comment()");
    xmlStreamWriter.writeEndElement();/*from ww w  .  ja va 2  s .c om*/
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "addEnterpriseBeansChildren");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "createEnterpriseBeans");
    xmlStreamWriter.writeEndElement();
}

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

protected void addRootTemplate(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("match", "tp:ejb-jar");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("ejb-jar");
    xmlStreamWriter.writeAttribute("version", "{@version}");
    xmlStreamWriter.writeAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
    xmlStreamWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    xmlStreamWriter.writeAttribute("xsi:schemaLocation",
            "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd");
    xmlStreamWriter.writeCharacters("\n");
    addRootEnterpriseBeansSelects(xmlStreamWriter);
    addRootAssemblyDescriptorSelects(xmlStreamWriter);
    xmlStreamWriter.writeEndElement();/*from  www  .j a  v a2s. c om*/
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addTableGenerators(PluginDescriptor pd, String ormId, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_TABLE_GENERATOR);
    if (exnPt != null && getDescriptor().getId().equals(exnPt.getParentPluginId())) {
        ParameterDefinition targetPluginIdParamDef = exnPt.getParameterDefinition("target-plugin-id");
        if (targetPluginIdParamDef == null || targetPluginIdParamDef.getDefaultValue() == null
                || targetPluginIdParamDef.getDefaultValue().trim().length() == 0) {
            throw new RuntimeException(exnPt.getUniqueId()
                    + " must defined a parameter-def called target-plugin-id with a default value");
        }/*  w  ww  . ja  v  a 2  s.  co m*/
        if (pd.getId().equals(targetPluginIdParamDef.getDefaultValue())) {
            for (Extension exn : exnPt.getConnectedExtensions()) {
                if (containsORMId(ormId, exn.getParameters("ormId"))) {
                    xmlStreamWriter.writeStartElement("table-generator");
                    String name = exn.getParameter("name").valueAsString();
                    if (name == null || name.trim().length() == 0) {
                        throw new RuntimeException(exn.getUniqueId() + " requires a name parameter value");
                    }
                    xmlStreamWriter.writeAttribute("name", name);
                    if (exn.getParameter("table") != null) {
                        String table = exn.getParameter("table").valueAsString();
                        if (table.trim().length() == 0) {
                            throw new RuntimeException(exn.getUniqueId() + " requires a table parameter value");
                        }
                        xmlStreamWriter.writeAttribute("table", table);
                    }
                    if (exn.getParameter("schema") != null) {
                        String schema = exn.getParameter("schema").valueAsString();
                        if (schema.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a schema parameter value");
                        }
                        xmlStreamWriter.writeAttribute("schema", schema);
                    }
                    if (exn.getParameter("pk-column-name") != null) {
                        String pkColumnName = exn.getParameter("pk-column-name").valueAsString();
                        if (pkColumnName.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a pkColumnName parameter value");
                        }
                        xmlStreamWriter.writeAttribute("pk-column-name", pkColumnName);
                    }
                    if (exn.getParameter("value-column-name") != null) {
                        String valueColumnName = exn.getParameter("value-column-name").valueAsString();
                        if (valueColumnName.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a valueColumnName parameter value");
                        }
                        xmlStreamWriter.writeAttribute("value-column-name", valueColumnName);
                    }
                    if (exn.getParameter("pk-column-value") != null) {
                        String pkColumnValue = exn.getParameter("pk-column-value").valueAsString();
                        if (pkColumnValue.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a pkColumnValue parameter value");
                        }
                        xmlStreamWriter.writeAttribute("pk-column-value", pkColumnValue);
                    }
                    if (exn.getParameter("initial-value") != null) {
                        String initialValue = exn.getParameter("initial-value").valueAsString();
                        if (initialValue.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a initialValue parameter value");
                        }
                        xmlStreamWriter.writeAttribute("initial-value", initialValue);
                    }
                    if (exn.getParameter("allocation-size") != null) {
                        String allocationSize = exn.getParameter("allocation-size").valueAsString();
                        if (allocationSize.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a allocationSize parameter value");
                        }
                        xmlStreamWriter.writeAttribute("allocation-size", allocationSize);
                    }
                    xmlStreamWriter.writeCharacters("\n");
                    addUniqueConstraints(exn.getParameters("unique-constraint"), xmlStreamWriter);
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                }
            }
        }
    }
}

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

protected void addUniqueConstraints(Collection<Parameter> params, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    for (Parameter uniqueConstraintParameter : params) {
        xmlStreamWriter.writeStartElement("unique-constraint");
        xmlStreamWriter.writeCharacters("\n");
        for (Parameter columnNameParam : uniqueConstraintParameter.getSubParameters("column-name")) {
            xmlStreamWriter.writeStartElement("column-name");
            xmlStreamWriter.writeCharacters(columnNameParam.valueAsString());
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }//from  w ww  .ja va 2 s .  c om
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
}

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 {//from  w w  w .j  a va 2  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.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 w ww  .j a  v  a  2s.  c  o  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 {/*from  w  w w  .  ja va  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("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 va 2 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.facesconfig.FacesConfigAssembler.java

protected void addRootTemplate(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("match", "tp:faces-config");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("faces-config");
    xmlStreamWriter.writeAttribute("version", "{@version}");
    xmlStreamWriter.writeAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
    xmlStreamWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    xmlStreamWriter.writeAttribute("xsi:schemaLocation",
            "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd");
    xmlStreamWriter.writeCharacters("\n");
    addRootApplicationSelects(xmlStreamWriter);
    addRootValidatorSelects(xmlStreamWriter);
    addRootConverterSelects(xmlStreamWriter);
    addRootLifeCycleSelects(xmlStreamWriter);
    addRootNavigationRuleSelects(xmlStreamWriter);
    addRootManagedBeanSelects(xmlStreamWriter);
    xmlStreamWriter.writeEndElement();//from  ww  w .  j a  va2  s  .com
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}