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 addErrorPageTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addErrorPages");
    xmlStreamWriter.writeCharacters("\n");
    Map<String, Extension> errorPageMap = new HashMap<String, Extension>();
    for (Extension defaultExn : getErrorPageExtensions(pd, true)) {
        String errorCode = defaultExn.getParameter("error-code").valueAsString();
        errorPageMap.put(errorCode, defaultExn);
    }//w w w . ja  v a  2 s  .co  m
    for (Extension nonDefaultExn : getErrorPageExtensions(pd, false)) {
        String errorCode = nonDefaultExn.getParameter("error-code").valueAsString();
        Extension errorPageExtension = errorPageMap.get(errorCode);
        if (errorPageExtension != null) {
            if (nonDefaultExn.getParameter("override") == null) {
                throw new RuntimeException(nonDefaultExn.getUniqueId()
                        + " requires an override parameter to override " + errorPageExtension.getUniqueId());
            }
            logger.debug(nonDefaultExn.getUniqueId() + " overrides " + errorPageExtension.getUniqueId());
        }
        errorPageMap.put(errorCode, nonDefaultExn);
    }
    for (Extension exn : errorPageMap.values()) {
        Parameter errorCode = exn.getParameter("error-code");
        String errorCodeString = "";
        if (errorCode != null) {
            errorCodeString = errorCode.valueAsString();
        }
        String exceptionTypeString = "";
        Parameter exceptionType = exn.getParameter("exception-type");
        if (exceptionType != null) {
            exceptionTypeString = exceptionType.valueAsString();
        }
        Parameter location = exn.getParameter("location");
        String locationString = "";
        if (location != null) {
            locationString = location.valueAsString();
        }
        addErrorPage(errorCodeString, exceptionTypeString, locationString, xmlStreamWriter);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addFilter(Extension filterExtension, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    String filterName = filterExtension.getParameter("filter-name").valueAsString();
    String filterClass = filterExtension.getParameter("filter-class").valueAsString();
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test", "count(tp:filter[tp:filter-name = '" + filterName + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("filter");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("filter-name");
    xmlStreamWriter.writeCharacters(filterName);
    xmlStreamWriter.writeEndElement();/*w  w  w.j ava 2  s  .  c  o m*/
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("filter-class");
    xmlStreamWriter.writeCharacters(filterClass);
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    for (Parameter param : filterExtension.getParameters("init-param")) {
        xmlStreamWriter.writeStartElement("init-param");
        String paramName = param.getSubParameter("param-name").valueAsString();
        xmlStreamWriter.writeStartElement("param-name");
        xmlStreamWriter.writeCharacters(paramName);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        String paramValue = param.getSubParameter("param-value").valueAsString();
        xmlStreamWriter.writeStartElement("param-value");
        xmlStreamWriter.writeCharacters(paramValue);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        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 addFilterMapping(String filterName, String urlPattern, String[] dispatchers,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test", "count(tp:filter-mapping[tp:filter-name = '" + filterName
            + "' and tp:url-pattern = '" + urlPattern + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("filter-mapping");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("filter-name");
    xmlStreamWriter.writeCharacters(filterName);
    xmlStreamWriter.writeEndElement();//  w w  w  . java 2 s .  com
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("url-pattern");
    xmlStreamWriter.writeCharacters(urlPattern);
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    if (dispatchers != null) {
        for (String dispatcher : dispatchers) {
            xmlStreamWriter.writeStartElement("dispatcher");
            xmlStreamWriter.writeCharacters(dispatcher);
            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 addFilterTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addFilters");
    xmlStreamWriter.writeCharacters("\n");
    List<Extension> filterExns = getFilterExtensions(pd);
    Extension transactionFilterExn = getTransactionFilter(pd);
    Extension securityFilterExn = getSecurityFilter(pd);
    Map<String, Map<String, Object>> filterMappings = getFilterMappings(pd, filterExns);
    for (Extension exn : filterExns) {
        String filterName = exn.getParameter("filter-name").valueAsString();
        addFilter(exn, xmlStreamWriter);
        if (exn.equals(transactionFilterExn)) {
            addTransactionFilterMapping(exn, filterMappings, xmlStreamWriter);
        } else if (securityFilterExn != null && securityFilterExn.equals(exn)) {
            addSecurityFilterMapping(exn, filterMappings, pd, xmlStreamWriter);
        } else {//from  w  w  w.j a  v  a 2  s  .c  o m
            Set<String> urlPatterns = new HashSet<String>();
            String[] dispatchers = null;
            Map<String, Object> map = filterMappings.get(filterName);
            List<Extension> mappingExns = (List<Extension>) map.get("mappings");
            for (Extension mappingExn : mappingExns) {
                for (Parameter param : mappingExn.getParameters("url-pattern")) {
                    urlPatterns.add(param.valueAsString());
                }
                Parameter dispatcherParam = mappingExn.getParameter("dispatchers");
                if (dispatcherParam != null && dispatcherParam.valueAsString().length() > 0) {
                    dispatchers = dispatcherParam.valueAsString().split(",");
                }
            }
            List<String> sortedURLPatterns = new ArrayList<String>(urlPatterns);
            Collections.sort(sortedURLPatterns);
            for (String urlPattern : sortedURLPatterns) {
                addFilterMapping(filterName, urlPattern, dispatchers, xmlStreamWriter);
            }
        }
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addInitTagLibContextParameterCallTemplate(String initialTagTemplate,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "initTagContextParameter");
    xmlStreamWriter.writeCharacters("\n");
    if (initialTagTemplate != null) {
        xmlStreamWriter.writeStartElement("xsl:call-template");
        xmlStreamWriter.writeAttribute("name", initialTagTemplate);
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:with-param");
        xmlStreamWriter.writeAttribute("name", "param-name");
        xmlStreamWriter.writeCharacters("javax.faces.FACELETS_LIBRARIES");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:with-param");
        xmlStreamWriter.writeAttribute("name", "param-value");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }/*from   w  ww .  j a  v a  2  s  .  com*/
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addListener(String listenerClass, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test",
            "count(tp:listener[tp:listener-class = '" + listenerClass + "']) = 0");
    xmlStreamWriter.writeStartElement("listener");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("listener-class");
    xmlStreamWriter.writeCharacters(listenerClass);
    xmlStreamWriter.writeEndElement();//w ww .  j a v  a  2s  .co m
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addListenerTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addListeners");
    xmlStreamWriter.writeCharacters("\n");
    List<Extension> listeners = new ArrayList<Extension>();
    listeners.addAll(getExtensions(pd, "listener"));
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_CTX_LISTENER_ADPTR);
    if (exnPt != null) {
        listeners.addAll(exnPt.getConnectedExtensions());
    }//from   w  w w. j  a v a2  s  . c o  m
    Comparator<Object> comparator = new Comparator<Object>() {
        public int compare(Object obj1, Object obj2) {
            Extension e1 = (Extension) obj1;
            Extension e2 = (Extension) obj2;
            return e1.getParameter("listener-class").valueAsString()
                    .compareTo(e2.getParameter("listener-class").valueAsString());
        };
    };
    Collections.sort(listeners, comparator);
    for (Extension exn : listeners) {
        addListener(exn.getParameter("listener-class").valueAsString(), xmlStreamWriter);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addLoginConfig(String authMethod, String formLoginPage, String formErrorPage,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test",
            "count(tp:login-config[tp:form-login-config/tp:form-login-page = '" + formLoginPage + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("login-config");
    xmlStreamWriter.writeCharacters("\n");
    if (authMethod.length() > 0) {
        xmlStreamWriter.writeStartElement("auth-method");
        xmlStreamWriter.writeCharacters(authMethod);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }//from   w w  w  . jav a  2  s .co m
    xmlStreamWriter.writeStartElement("form-login-config");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("form-login-page");
    xmlStreamWriter.writeCharacters(formLoginPage);
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("form-error-page");
    xmlStreamWriter.writeCharacters(formErrorPage);
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    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 addLoginConfigTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addLoginConfigs");
    xmlStreamWriter.writeCharacters("\n");
    for (Extension exn : getExtensions(pd, "login-config")) {
        Parameter authMethod = exn.getParameter("auth-method");
        String authMethodString = "";
        if (authMethod != null) {
            authMethodString = authMethod.valueAsString();
        }//from w ww  .  j  a v a  2  s.c om
        addLoginConfig(authMethodString, exn.getParameter("form-login-page").valueAsString(),
                exn.getParameter("form-error-page").valueAsString(), xmlStreamWriter);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addRootContextParameterSelects(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "initTagContextParameter");
    xmlStreamWriter.writeEndElement();//from ww w .j  a  v a2s  .  c  om
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:for-each");
    xmlStreamWriter.writeAttribute("select", "tp:context-param");
    xmlStreamWriter.writeStartElement("xsl:copy-of");
    xmlStreamWriter.writeAttribute("select", ".");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:apply-templates");
    xmlStreamWriter.writeAttribute("select", "* | @* | text() | comment()");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "addContextParameters");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}