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.ear.EARAssembler.java

protected void addRootTemplate(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("xsl:template");
    writer.writeAttribute("match", "tp:application");
    writer.writeCharacters("\n");
    writer.writeStartElement("application");
    writer.writeAttribute("version", "{@version}");
    writer.writeAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
    writer.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    writer.writeAttribute("xsi:schemaLocation",
            "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd");
    writer.writeCharacters("\n");
    addRootDisplayName(writer);/*  www .  j  av  a  2 s  .  c om*/
    addRootConnectorModuleSelects(writer);
    addRootEJBModuleSelects(writer);
    addRootWEBModuleSelects(writer);
    addRootSecurityRoleSelects(writer);
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
}

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

protected void addRootWEBModuleSelects(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("xsl:for-each");
    writer.writeAttribute("select", "tp:module/tp:web");
    writer.writeCharacters("\n");
    writer.writeStartElement("xsl:copy-of");
    writer.writeAttribute("select", ".");
    writer.writeCharacters("\n");
    writer.writeStartElement("xsl:apply-templates");
    writer.writeAttribute("select", "* | @* | text() | comment()");
    writer.writeEndElement();/*from w  w w  . java 2  s.c om*/
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeStartElement("xsl:call-template");
    writer.writeAttribute("name", "addWEBModules");
    writer.writeEndElement();
    writer.writeCharacters("\n");
}

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

protected void addSecurityRoles(String description, String roleName, XMLStreamWriter writer)
        throws XMLStreamException {
    writer.writeStartElement("xsl:if");
    writer.writeAttribute("test", "count(security-role/role-name[text() = '" + roleName + "']) = 0");
    writer.writeCharacters("\n");
    writer.writeStartElement("security-role");
    writer.writeCharacters("\n");
    if (description != null) {
        writer.writeStartElement("description");
        writer.writeCharacters(description);
        writer.writeEndElement();//from  w  w w. j  a  v  a 2s.com
        writer.writeCharacters("\n");
    }
    writer.writeStartElement("role-name");
    writer.writeCharacters(roleName);
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
}

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

protected void addSecurityRoleTemplates(PluginDescriptor pd, XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("xsl:template");
    writer.writeAttribute("name", "addSecurityRoles");
    writer.writeCharacters("\n");
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_SECURITY_ROLE);
    if (exnPt != null) {
        for (Extension exn : exnPt.getConnectedExtensions()) {
            String description = null;
            if (exn.getParameter("description") != null) {
                description = exn.getParameter("description").valueAsString();
            }/*from w w  w . java2  s  .  co m*/
            String roleName = exn.getParameter("role-name").valueAsString();
            addSecurityRoles(description, roleName, writer);
        }
        writer.writeEndElement();
        writer.writeCharacters("\n");
    }
}

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

protected void addWARModuleTemplates(PluginDescriptor pd, File localDestDir, XMLStreamWriter writer)
        throws XMLStreamException, IOException {
    writer.writeStartElement("xsl:template");
    writer.writeAttribute("name", "addWEBModules");
    writer.writeCharacters("\n");
    assembleWARModules(pd, writer);/*from w w  w  .  j a  v a 2s  .  co  m*/
    assembleWARModuleProducts(pd, localDestDir, writer);
    assembleWARModuleProductsPlugins(pd, localDestDir, writer);
    assembleWARModuleAdaptors(pd, writer);
    writer.writeEndElement();
    writer.writeCharacters("\n");
}

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

protected void addWebModules(String webURI, String contextRoot, XMLStreamWriter writer)
        throws XMLStreamException {
    writer.writeStartElement("xsl:if");
    writer.writeAttribute("test", "count(module/web-uri[text() = '" + webURI + "']) = 0");
    writer.writeCharacters("\n");
    writer.writeStartElement("module");
    writer.writeCharacters("\n");
    writer.writeStartElement("web");
    writer.writeCharacters("\n");
    writer.writeStartElement("web-uri");
    writer.writeCharacters(webURI);/*  w w w .  j ava  2 s  .c o m*/
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeStartElement("context-root");
    writer.writeCharacters(contextRoot);
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
    writer.writeEndElement();
    writer.writeCharacters("\n");
}

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  a  va  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 void addAssemblyDescriptorChildren(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addAssemblyDescriptorChildren");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();//from ww  w  .j a  va2  s.  c  o m
    xmlStreamWriter.writeCharacters("\n");
    addAssemblyDescriptorCreate(false, xmlStreamWriter);
}

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

protected void addAssemblyDescriptorCreate(boolean hasAssemblyDescriptor, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "createAssemblyDescriptor");
    xmlStreamWriter.writeCharacters("\n");
    if (hasAssemblyDescriptor) {
        logger.debug("AssemblyDescriptor tag will be created");
        xmlStreamWriter.writeStartElement("assembly-descriptor");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:call-template");
        xmlStreamWriter.writeAttribute("name", "createAssemblyDescriptorChildren");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    } else {//  w  w  w .  jav a  2 s . co m
        logger.debug("No assembly-descriptor tag will be created");
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

private void addAttributes(Extension extension, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    Parameter attributesParam = extension.getParameter("attributes");
    if (attributesParam != null) {
        xmlStreamWriter.writeStartElement("attributes");
        xmlStreamWriter.writeCharacters("\n");
        for (Parameter idParam : attributesParam.getSubParameters("id")) {
            xmlStreamWriter.writeStartElement("id");
            String idName = idParam.getSubParameter("name").valueAsString();
            if (idName.trim().length() == 0) {
                throw new RuntimeException(extension.getUniqueId() + " requires a id name parameter value");
            }// w  ww .  jav  a2s .  c o m
            xmlStreamWriter.writeAttribute("name", idName);
            xmlStreamWriter.writeCharacters("\n");
            Parameter columnParam = idParam.getSubParameter("column");
            if (columnParam != null) {
                addColumn(columnParam, extension, xmlStreamWriter);
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }
        for (Parameter basicParam : attributesParam.getSubParameters("basic")) {
            xmlStreamWriter.writeStartElement("basic");
            String basicName = basicParam.getSubParameter("name").valueAsString();
            if (basicName == null || basicName.trim().length() == 0) {
                throw new RuntimeException(extension.getUniqueId() + " requires a name parameter value");
            }
            xmlStreamWriter.writeAttribute("name", basicName);
            xmlStreamWriter.writeCharacters("\n");
            Parameter columnParameter = basicParam.getSubParameter("column");
            if (columnParameter != null) {
                addColumn(columnParameter, extension, xmlStreamWriter);
            }
            Parameter lobParam = basicParam.getSubParameter("lob");
            if (lobParam != null) {
                xmlStreamWriter.writeStartElement("lob");
                xmlStreamWriter.writeEndElement();
                xmlStreamWriter.writeCharacters("\n");
            }
            Parameter temporalParam = basicParam.getSubParameter("temporal");
            if (temporalParam != null) {
                xmlStreamWriter.writeStartElement("temporal");
                String temporal = temporalParam.valueAsString();
                if (temporal.trim().length() == 0) {
                    throw new RuntimeException(
                            extension.getUniqueId() + " requires a temporal parameter value");
                }
                xmlStreamWriter.writeCharacters(temporal);
                xmlStreamWriter.writeEndElement();
                xmlStreamWriter.writeCharacters("\n");
            }
            Parameter enumeratedParam = basicParam.getSubParameter("enumerated");
            if (enumeratedParam != null) {
                xmlStreamWriter.writeStartElement("enumerated");
                String enumerated = enumeratedParam.valueAsString();
                if (enumerated.trim().length() == 0) {
                    throw new RuntimeException(
                            extension.getUniqueId() + " requires a enumerated parameter value");
                }
                xmlStreamWriter.writeCharacters(enumerated);
                xmlStreamWriter.writeEndElement();
                xmlStreamWriter.writeCharacters("\n");
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }
        for (Parameter idParam : attributesParam.getSubParameters("version")) {
            xmlStreamWriter.writeStartElement("version");
            String versionName = idParam.getSubParameter("name").valueAsString();
            if (versionName.trim().length() == 0) {
                throw new RuntimeException(
                        extension.getUniqueId() + " requires a version name parameter value");
            }
            xmlStreamWriter.writeAttribute("name", versionName);
            xmlStreamWriter.writeCharacters("\n");
            Parameter columnParamter = idParam.getSubParameter("column");
            if (columnParamter != null) {
                addColumn(columnParamter, extension, xmlStreamWriter);
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }
        for (Parameter idParam : attributesParam.getSubParameters("many-to-one")) {
            xmlStreamWriter.writeStartElement("many-to-one");
            String manyToOneName = idParam.getSubParameter("name").valueAsString();
            if (manyToOneName.trim().length() == 0) {
                throw new RuntimeException(
                        extension.getUniqueId() + " requires a many-to-one name parameter value");
            }
            xmlStreamWriter.writeAttribute("name", manyToOneName);
            xmlStreamWriter.writeCharacters("\n");
            Parameter joinColumnParamter = idParam.getSubParameter("join-column");
            if (joinColumnParamter != null) {
                addJoinColumn(joinColumnParamter, extension, xmlStreamWriter);
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }
        for (Parameter embeddedParam : attributesParam.getSubParameters("embedded")) {
            xmlStreamWriter.writeStartElement("embedded");
            String embeddedName = embeddedParam.getSubParameter("name").valueAsString();
            if (embeddedName.trim().length() == 0) {
                throw new RuntimeException(
                        extension.getUniqueId() + " requires a embedded name parameter value");
            }
            xmlStreamWriter.writeAttribute("name", embeddedName);
            xmlStreamWriter.writeCharacters("\n");
            for (Parameter attributeOverrideParam : embeddedParam.getSubParameters("attribute-override")) {
                xmlStreamWriter.writeStartElement("attribute-override");
                String attributeOverrideName = attributeOverrideParam.getSubParameter("name").valueAsString();
                if (attributeOverrideName == null || attributeOverrideName.trim().length() == 0) {
                    throw new RuntimeException(
                            extension.getUniqueId() + " requires an attribute-override name parameter value");
                }
                xmlStreamWriter.writeAttribute("name", attributeOverrideName);
                xmlStreamWriter.writeCharacters("\n");
                Parameter attributeOverrdieColumnParameter = attributeOverrideParam.getSubParameter("column");
                addColumn(attributeOverrdieColumnParameter, extension, xmlStreamWriter);
                xmlStreamWriter.writeEndElement();
                xmlStreamWriter.writeCharacters("\n");
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
}