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.webxml.WebXMLAssembler.java

protected void addTagLibContextParameterOtherwiseCallTemplate(String templateName, String tabLib,
        boolean semicolonSeparator, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", templateName);
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:with-param");
    xmlStreamWriter.writeAttribute("name", "param-name");
    xmlStreamWriter.writeStartElement("xsl:value-of");
    xmlStreamWriter.writeAttribute("select", "$param-name");
    xmlStreamWriter.writeEndElement();//from  w  ww .  jav a 2  s  . c  om
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:with-param");
    xmlStreamWriter.writeAttribute("name", "param-value");
    xmlStreamWriter.writeStartElement("xsl:value-of");
    if (semicolonSeparator) {
        xmlStreamWriter.writeAttribute("select", "concat($param-value,'" + ";" + tabLib + "')");
    } else {
        xmlStreamWriter.writeAttribute("select", "concat($param-value,'" + tabLib + "')");
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected void addTagLibContextParameterWhenCallTemplate(String templateName, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", templateName);
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:with-param");
    xmlStreamWriter.writeAttribute("name", "param-name");
    xmlStreamWriter.writeStartElement("xsl:value-of");
    xmlStreamWriter.writeAttribute("select", "$param-name");
    xmlStreamWriter.writeEndElement();//from w  ww  . java2 s  .co  m
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:with-param");
    xmlStreamWriter.writeAttribute("name", "param-value");
    xmlStreamWriter.writeStartElement("xsl:value-of");
    xmlStreamWriter.writeAttribute("select", "$param-value");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected void addWebResourceCollection(String webResourceName, Set<String> urlPatterns,
        Set<String> httpMethods, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test",
            "count(tp:security-constraint[tp:web-resource-collection/tp:web-resource-name = '" + webResourceName
                    + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("web-resource-collection");
    xmlStreamWriter.writeStartElement("web-resource-name");
    xmlStreamWriter.writeCharacters(webResourceName);
    xmlStreamWriter.writeEndElement();//from   ww w  .ja  v a2s .  c o m
    xmlStreamWriter.writeCharacters("\n");
    List<String> sortedURLPatterns = new ArrayList<String>(urlPatterns);
    Collections.sort(sortedURLPatterns);
    for (String urlPattern : sortedURLPatterns) {
        xmlStreamWriter.writeStartElement("url-pattern");
        xmlStreamWriter.writeCharacters(urlPattern);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    List<String> sortedHttpMethods = new ArrayList<String>(httpMethods);
    Collections.sort(sortedHttpMethods);
    for (String httpMethod : sortedHttpMethods) {
        xmlStreamWriter.writeStartElement("http-method");
        xmlStreamWriter.writeCharacters(httpMethod);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected void addWebSecurityConstraint(PluginDescriptor pd, Extension securityConstraintExn,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("security-constraint");
    xmlStreamWriter.writeCharacters("\n");
    for (Parameter webResourceCollectionParam : securityConstraintExn
            .getParameters("web-resource-collection")) {
        Parameter webResourceNameParam = webResourceCollectionParam.getSubParameter("web-resource-name");
        if (webResourceNameParam == null || webResourceNameParam.valueAsString().trim().length() == 0) {
            throw new RuntimeException(
                    securityConstraintExn.getUniqueId() + " does not have a web-resource-name parameter value");
        }//from   w w w . j  a  v a2s  .c  o  m
        String webResourceName = webResourceNameParam.valueAsString();
        Set<String> urlPatterns = new HashSet<String>();
        urlPatterns.addAll(getFilterMappingURLPatterns(pd, webResourceName));
        urlPatterns.addAll(getServletMappingURLPatterns(pd, webResourceName));
        urlPatterns.addAll(getWebDirectoryURLPatterns(pd, webResourceName));
        for (Parameter urlPattern : webResourceCollectionParam.getSubParameters("url-pattern")) {
            urlPatterns.add(urlPattern.valueAsString());
        }
        Set<String> httpMethods = new HashSet<String>();
        for (Parameter httpMethod : webResourceCollectionParam.getSubParameters("http-method")) {
            httpMethods.add(httpMethod.valueAsString());
        }
        addWebResourceCollection(webResourceName, urlPatterns, httpMethods, xmlStreamWriter);
    }
    Set<String> roleNames = new HashSet<String>();
    for (Parameter param : securityConstraintExn.getParameters("role-name")) {
        if (param.valueAsString().trim().length() == 0) {
            throw new RuntimeException(
                    securityConstraintExn.getUniqueId() + " must have values for the role-name");
        }
        roleNames.add(param.valueAsString());
    }
    if (!roleNames.isEmpty()) {
        xmlStreamWriter.writeStartElement("auth-constraint");
        for (String roleName : roleNames) {
            xmlStreamWriter.writeStartElement("role-name");
            xmlStreamWriter.writeCharacters(roleName);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeCharacters("\n");
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    Parameter transportGuaranteeParam = securityConstraintExn.getParameter("transport-guarantee");
    if (transportGuaranteeParam != null) {
        xmlStreamWriter.writeStartElement("user-data-constraint");
        String transportGuarantee = transportGuaranteeParam.valueAsString();
        xmlStreamWriter.writeStartElement("transport-guarantee");
        xmlStreamWriter.writeCharacters(transportGuarantee);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected void addWebSecurityConstraintTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addWebSecurityConstraints");
    xmlStreamWriter.writeCharacters("\n");
    PluginDescriptor abstractPD = getAbstractWARPluginDescriptor();
    ExtensionPoint securityConstraintExnPt = abstractPD.getExtensionPoint("security-constraint");
    for (Extension exn : securityConstraintExnPt.getConnectedExtensions()) {
        Parameter targetPluginId = exn.getParameter("target-plugin-id");
        if (targetPluginId == null || targetPluginId.valueAsString().trim().length() == 0) {
            throw new RuntimeException(exn.getUniqueId() + " does not have a target-plugin-id parameter value");
        }//w w w.  ja v a 2s . c  o  m
        if (pd.getId().equals(targetPluginId.valueAsString())) {
            addWebSecurityConstraint(pd, exn, xmlStreamWriter);
        }
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected void addWelcomeFileList(String welcomeFile, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test",
            "count(tp:welcome-file-list[tp:welcome-file = '" + welcomeFile + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("welcome-file-list");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("welcome-file");
    xmlStreamWriter.writeCharacters(welcomeFile);
    xmlStreamWriter.writeEndElement();//from ww w .  ja va  2  s.co  m
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected void addWelcomeFileListTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addWelcomeFileLists");
    xmlStreamWriter.writeCharacters("\n");
    for (Extension exn : getExtensions(pd, "welcome-file-list")) {
        addWelcomeFileList(exn.getParameter("welcome-file").valueAsString(), xmlStreamWriter);
    }/*w  ww .  j  a  va 2  s.c  o  m*/
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected String getXSLT(PluginDescriptor pd) throws XMLStreamException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    try {//  w w w.  ja v  a  2s. 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);
        addContextParameterTemplate(xmlStreamWriter);
        addContextParameterCallTemplates(pd, xmlStreamWriter);
        addFilterTemplates(pd, xmlStreamWriter);
        addListenerTemplates(pd, xmlStreamWriter);
        addServletTemplates(pd, xmlStreamWriter);
        addEJBLocalRefTemplates(pd, xmlStreamWriter);
        addSessionConfigTemplates(pd, xmlStreamWriter);
        addWelcomeFileListTemplates(pd, xmlStreamWriter);
        addWebSecurityConstraintTemplates(pd, xmlStreamWriter);
        addLoginConfigTemplates(pd, xmlStreamWriter);
        addSecurityRoleTemplates(pd, xmlStreamWriter);
        addEnvEntryTemplates(pd, xmlStreamWriter);
        addErrorPageTemplates(pd, xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    return xslt.toString();
}

From source file:org.unitedinternet.cosmo.model.text.XhtmlCollectionFormat.java

public String format(CollectionItem collection) {
    try {//from  w  ww .ja  v  a2s. c o  m
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = createXmlWriter(sw);

        writer.writeStartElement("div");
        writer.writeAttribute("class", "collection");

        writer.writeCharacters("Collection: ");

        if (collection.getDisplayName() != null) {
            writer.writeStartElement("span");
            writer.writeAttribute("class", "name");
            writer.writeCharacters(collection.getDisplayName());
            writer.writeEndElement();
        }

        if (collection.getUid() != null) {
            writer.writeCharacters(" (uuid ");
            writer.writeStartElement("span");
            writer.writeAttribute("class", "uuid");
            writer.writeCharacters(collection.getUid());
            writer.writeEndElement();
            writer.writeCharacters(")");
        }

        writer.writeEndElement();
        writer.close();

        return sw.toString();
    } catch (XMLStreamException e) {
        throw new CosmoXMLStreamException("Error formatting XML", e);
    }
}

From source file:org.unitedinternet.cosmo.model.text.XhtmlPreferenceFormat.java

public String format(Preference pref) {
    try {/*from   w  w  w.  j  av a 2  s .c  o  m*/
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = createXmlWriter(sw);

        writer.writeStartElement("div");
        writer.writeAttribute("class", "preference");

        writer.writeCharacters("Preference: ");

        if (pref.getKey() != null) {
            writer.writeStartElement("span");
            writer.writeAttribute("class", "key");
            writer.writeCharacters(pref.getKey());
            writer.writeEndElement();
        }

        writer.writeCharacters(" = ");

        if (pref.getValue() != null) {
            writer.writeStartElement("span");
            writer.writeAttribute("class", "value");
            writer.writeCharacters(pref.getValue());
            writer.writeEndElement();
        }

        writer.writeEndElement();
        writer.close();

        return sw.toString();
    } catch (XMLStreamException e) {
        throw new CosmoXMLStreamException("Error formatting XML", e);
    }
}