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.war.WARAssembler.java

protected void addTagSource(File dir, XMLStreamWriter writer) throws XMLStreamException {
    for (File file : dir.listFiles()) {
        String src = dir.getName() + "/" + file.getName();
        writer.writeStartElement("tag");
        writer.writeCharacters("\n");
        writer.writeStartElement("tag-name");
        int index = file.getName().lastIndexOf(".");
        if (index == -1) {
            writer.writeCharacters(file.getName());
        } else {/*from w w  w .  j  ava  2  s.  co  m*/
            writer.writeCharacters(file.getName().substring(0, index));
        }
        writer.writeEndElement();
        writer.writeCharacters("\n");
        writer.writeStartElement("source");
        writer.writeCharacters(src);
        writer.writeEndElement();
        writer.writeCharacters("\n");
        writer.writeEndElement();
        writer.writeCharacters("\n");
    }
}

From source file:org.tolven.assembler.war.WARAssembler.java

protected void addTagValidator(PluginDescriptor pd, XMLStreamWriter writer) throws XMLStreamException {
    ExtensionPoint validatorExnPt = pd.getExtensionPoint("tagValidator");
    if (validatorExnPt != null) {
        for (Extension exn : validatorExnPt.getConnectedExtensions()) {
            writer.writeStartElement("tag");
            writer.writeCharacters("\n");
            writer.writeStartElement("tag-name");
            writer.writeCharacters(exn.getParameter("tag-name").valueAsString());
            writer.writeEndElement();/*from   w  w  w.java 2  s. c  om*/
            writer.writeCharacters("\n");
            writer.writeStartElement("validator");
            writer.writeCharacters("\n");
            writer.writeStartElement("validator-id");
            writer.writeCharacters(exn.getParameter("validator-id").valueAsString());
            writer.writeEndElement();
            writer.writeCharacters("\n");
            Parameter handlerClass = exn.getParameter("handler-class");
            if (handlerClass != null) {
                writer.writeStartElement("handler-class");
                writer.writeCharacters(handlerClass.valueAsString());
                writer.writeEndElement();
                writer.writeCharacters("\n");
            }
            writer.writeEndElement();
            writer.writeCharacters("\n");
            writer.writeEndElement();
            writer.writeCharacters("\n");
        }
    }
}

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

protected void addContextParameterCallTemplate(String paramName, String paramValue,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test", "count(tp:context-param[tp:param-name = '" + paramName + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:call-template");
    xmlStreamWriter.writeAttribute("name", "context-param");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:with-param");
    xmlStreamWriter.writeAttribute("name", "param-name");
    xmlStreamWriter.writeCharacters(paramName);
    xmlStreamWriter.writeEndElement();// ww w  .  j  a v  a 2  s .  c  om
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:with-param");
    xmlStreamWriter.writeAttribute("name", "param-value");
    xmlStreamWriter.writeCharacters(paramValue);
    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 addContextParameterCallTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addContextParameters");
    xmlStreamWriter.writeCharacters("\n");
    List<Extension> contextParams = new ArrayList<Extension>();
    contextParams.addAll(getExtensions(pd, "context-param"));
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_CTX_PARAM_ADPTR);
    if (exnPt != null) {
        contextParams.addAll(exnPt.getConnectedExtensions());
    }//from   w w w . j  a va 2  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("param-name").valueAsString()
                    .compareTo(e2.getParameter("param-name").valueAsString());
        };
    };
    Collections.sort(contextParams, comparator);
    for (Extension exn : contextParams) {
        String paramValue = evaluate(exn.getParameter("param-value").valueAsString(), pd);
        addContextParameterCallTemplate(exn.getParameter("param-name").valueAsString(), paramValue,
                xmlStreamWriter);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    List<Extension> relevantExns = new ArrayList<Extension>();
    for (Extension exn : getExtensions(pd, "taglib")) {
        if (pd.getId().equals(exn.getParameter("target-plugin-id").valueAsString())) {
            relevantExns.add(exn);
        }
    }
    boolean semicolonSeparator = false;
    if (relevantExns.isEmpty()) {
        addInitTagLibContextParameterCallTemplate(null, xmlStreamWriter);
    } else {
        for (int i = 0; i < relevantExns.size(); i++) {
            Extension exn = relevantExns.get(i);
            String tagLib = "/META-INF/tags/" + exn.getParameter("tag-filename").valueAsString();
            String templateName = tagLib.replace("/", "");
            if (i == 0) {
                addInitTagLibContextParameterCallTemplate(templateName, xmlStreamWriter);
            }
            if (i > 0) {
                semicolonSeparator = true;
            }
            if (i == relevantExns.size() - 1) {
                addTagLibContextParameterCallTemplate(tagLib, semicolonSeparator, templateName, "context-param",
                        xmlStreamWriter);
            } else {
                String tagLib2 = "/META-INF/tags/"
                        + relevantExns.get(i + 1).getParameter("tag-filename").valueAsString();
                String templateName2 = tagLib2.replace("/", "");
                addTagLibContextParameterCallTemplate(tagLib, semicolonSeparator, templateName, templateName2,
                        xmlStreamWriter);
            }
        }
    }
}

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

protected void addContextParameterTemplate(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "context-param");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:param");
    xmlStreamWriter.writeAttribute("name", "param-name");
    xmlStreamWriter.writeEndElement();/*www.jav  a  2s  .  c o m*/
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:param");
    xmlStreamWriter.writeAttribute("name", "param-value");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("context-param");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("param-name");
    xmlStreamWriter.writeStartElement("xsl:value-of");
    xmlStreamWriter.writeAttribute("select", "$param-name");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("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");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addEJBLocalRef(String ejbRefName, String ejbRefType, String localHome, String local,
        String ejbLink, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test",
            "count(tp:ejb-local-ref[tp:ejb-ref-name = '" + ejbRefName + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("ejb-local-ref");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("ejb-ref-name");
    xmlStreamWriter.writeCharacters(ejbRefName);
    xmlStreamWriter.writeEndElement();//from w  w w. j  a  v a  2 s .com
    xmlStreamWriter.writeCharacters("\n");
    if (ejbRefType != null) {
        xmlStreamWriter.writeStartElement("ejb-ref-type");
        xmlStreamWriter.writeCharacters(ejbRefType);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    if (localHome != null) {
        xmlStreamWriter.writeStartElement("local-home");
        xmlStreamWriter.writeCharacters(localHome);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    if (local != null) {
        xmlStreamWriter.writeStartElement("local");
        xmlStreamWriter.writeCharacters(local);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    if (ejbLink != null) {
        xmlStreamWriter.writeStartElement("ejb-link");
        xmlStreamWriter.writeCharacters(ejbLink);
        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 addEJBLocalRefTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addEJBLocalRefs");
    xmlStreamWriter.writeCharacters("\n");
    List<Extension> ejbLocalRefExns = getEJBLocalRefExtensions(pd);
    for (Extension exn : ejbLocalRefExns) {
        String ejbRefName = null;
        if (exn.getParameter("ejb-ref-name") != null) {
            ejbRefName = exn.getParameter("ejb-ref-name").valueAsString();
        }//w  ww .  j ava 2s. c om
        String ejbRefType = null;
        if (exn.getParameter("ejb-ref-type") != null) {
            ejbRefType = exn.getParameter("ejb-ref-type").valueAsString();
        }
        String localHome = null;
        if (exn.getParameter("local-home") != null) {
            localHome = exn.getParameter("local-home").valueAsString();
        }
        String local = null;
        if (exn.getParameter("local") != null) {
            local = exn.getParameter("local").valueAsString();
        }
        String ejbLink = null;
        if (exn.getParameter("ejb-link") != null) {
            ejbLink = exn.getParameter("ejb-link").valueAsString();
        }
        addEJBLocalRef(ejbRefName, ejbRefType, localHome, local, ejbLink, xmlStreamWriter);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addEnvEntry(String envEntryName, String envEntryType, String envEntryValue,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test",
            "count(tp:env-entry[tp:env-entry-name = '" + envEntryName + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("env-entry");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("env-entry-name");
    xmlStreamWriter.writeCharacters(envEntryName);
    xmlStreamWriter.writeEndElement();// w  w  w .j a  v  a2 s.c o  m
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("env-entry-type");
    xmlStreamWriter.writeCharacters(envEntryType);
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("env-entry-value");
    xmlStreamWriter.writeCharacters(envEntryValue);
    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 addEnvEntryTemplates(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addEnvEntrys");
    xmlStreamWriter.writeCharacters("\n");
    for (Extension exn : getExtensions(pd, "env-entry")) {
        String envEntryName = exn.getParameter("env-entry-name").valueAsString();
        String envEntryType = exn.getParameter("env-entry-type").valueAsString();
        String envEntryValue = exn.getParameter("env-entry-value").valueAsString();
        addEnvEntry(envEntryName, envEntryType, envEntryValue, xmlStreamWriter);
    }/*w w w  .  j a v a 2  s .  c  om*/
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

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

protected void addErrorPage(String errorCode, String exceptionType, String location,
        XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:if");
    xmlStreamWriter.writeAttribute("test", "count(tp:error-page[tp:error-code = '" + errorCode + "']) = 0");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("error-page");
    xmlStreamWriter.writeCharacters("\n");
    if (errorCode.length() > 0) {
        xmlStreamWriter.writeStartElement("error-code");
        xmlStreamWriter.writeCharacters(errorCode);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }//from  w  w  w . j  a  v a 2  s.  c o m
    if (exceptionType.length() > 0) {
        xmlStreamWriter.writeStartElement("exception-type");
        xmlStreamWriter.writeCharacters(exceptionType);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    if (location.length() > 0) {
        xmlStreamWriter.writeStartElement("location");
        xmlStreamWriter.writeCharacters(location);
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}