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.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeText(final DmText text, final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeCharacters(text.getStringValue());
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeStatus(final XmiMappingStatus status, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(XmiMappingConstants.STATUS.getNamespaceURI(),
            XmiMappingConstants.STATUS.getLocalPart());
    try {/*from w w w .  j a  va2  s.  c  om*/
        switch (status) {
        case MATCH: {
            xsw.writeCharacters(XmiMappingValues.STATUS_MATCH);
            break;
        }
        case IGNORABLE: {
            xsw.writeCharacters(XmiMappingValues.STATUS_IGNORABLE);
            break;
        }
        case UNKNOWN: {
            xsw.writeCharacters(XmiMappingValues.STATUS_UNKNOWN);
            break;
        }
        case TRANSIENT: {
            xsw.writeCharacters(XmiMappingValues.STATUS_TRANSIENT);
            break;
        }
        case ALIGN: {
            xsw.writeCharacters(XmiMappingValues.STATUS_ALIGN);
            break;
        }
        case BUG: {
            xsw.writeCharacters(XmiMappingValues.STATUS_BUG);
            break;
        }
        case FINANCIAL: {
            xsw.writeCharacters(XmiMappingValues.STATUS_FINANCIAL);
            break;
        }
        default: {
            // Handle non-schema status gracefully.
            LOG.warn("Unexpected status : " + status);
            xsw.writeCharacters(status.toString());
            break;
        }
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeComment(final String comment, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(XmiMappingConstants.COMMENT.getNamespaceURI(),
            XmiMappingConstants.COMMENT.getLocalPart());
    try {//w w w .j  a  v a2  s .  c o  m
        xsw.writeCharacters(comment);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeTracking(final String tracking, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(XmiMappingConstants.TRACKING.getNamespaceURI(),
            XmiMappingConstants.TRACKING.getLocalPart());
    try {/*  w  ww  . j a  v a2s .  c  o  m*/
        xsw.writeCharacters(tracking);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeReference(final XmiDefinition ref, final QName elementName,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(elementName.getNamespaceURI(), elementName.getLocalPart());
    try {//from  w  ww  .j a va 2 s  .  co  m
        xsw.writeStartElement(XmiMappingConstants.NAME.getNamespaceURI(),
                XmiMappingConstants.NAME.getLocalPart());
        try {
            xsw.writeCharacters(ref.getName());
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(XmiMappingConstants.VERSION.getNamespaceURI(),
                XmiMappingConstants.VERSION.getLocalPart());
        try {
            xsw.writeCharacters(ref.getVersion());
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(XmiMappingConstants.FILE.getNamespaceURI(),
                XmiMappingConstants.FILE.getLocalPart());
        try {
            xsw.writeCharacters(ref.getFile());
        } finally {
            xsw.writeEndElement();
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeFeature(final XmiFeature feature, final QName elementName,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(elementName.getNamespaceURI(), elementName.getLocalPart());
    try {/*from   ww w.  j  a  va 2  s. c o  m*/
        xsw.writeStartElement(XmiMappingConstants.NAME.getNamespaceURI(),
                XmiMappingConstants.NAME.getLocalPart());
        try {
            xsw.writeCharacters(feature.getName());
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(XmiMappingConstants.EXISTS.getNamespaceURI(),
                XmiMappingConstants.EXISTS.getLocalPart());
        try {
            xsw.writeCharacters(Boolean.toString(feature.exists()));
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(XmiMappingConstants.OWNER_NAME.getNamespaceURI(),
                XmiMappingConstants.OWNER_NAME.getLocalPart());
        try {
            xsw.writeCharacters(feature.getOwnerName());
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(XmiMappingConstants.OWNER_EXISTS.getNamespaceURI(),
                XmiMappingConstants.OWNER_EXISTS.getLocalPart());
        try {
            xsw.writeCharacters(Boolean.toString(feature.ownerExists()));
        } finally {
            xsw.writeEndElement();
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeTaggedValue(final TaggedValue taggedValue, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(PREFIX_UML, XmiElementName.TAGGED_VALUE.getLocalName(), NAMESPACE_UML);
    try {/*from  w w w  .j av a2  s  .  c o m*/
        writeId(taggedValue, xsw);
        xsw.writeStartElement(PREFIX_UML, XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE.getLocalName(),
                NAMESPACE_UML);
        try {
            xsw.writeCharacters(taggedValue.getValue());
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(PREFIX_UML, XmiElementName.TAGGED_VALUE_DOT_TYPE.getLocalName(), NAMESPACE_UML);
        try {
            writeReference(taggedValue.getTagDefinition(), mapper, xsw);
        } finally {
            xsw.writeEndElement();
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.staxcel.internal.SpreadSheetImpl.java

protected void flushDynamicTemplateWriter(TokenEnumerableTemplateWriter templateWriter,
        XMLOutputFactory xmlOutFactory) throws IOException {
    String token = templateWriter.getToken();
    while (token != null) {
        XMLStreamWriter xmlWriter = null;
        try {// w w  w.jav  a 2s.  c om
            if (token.equals("worksheets.count")) {
                templateWriter.getOutputWriter().write(String.valueOf(this.worksheetList.size()));
            } else if (token.equals("worksheets.vector")) {

                xmlWriter = xmlOutFactory.createXMLStreamWriter(appXmlTemplateWriter.getOutputWriter());
                xmlWriter.writeStartElement("vt:vector");
                xmlWriter.writeAttribute("size", String.valueOf(this.worksheetList.size()));
                xmlWriter.writeAttribute("baseType", "lpstr");

                for (int index = 0; index < this.worksheetList.size(); ++index) {
                    xmlWriter.writeStartElement("vt:lpstr");
                    xmlWriter.writeCharacters(this.worksheetList.get(index).getName());
                    xmlWriter.writeEndElement();
                }

                xmlWriter.writeEndElement();

            } else if (token.equals("worksheet.relationships")) {
                xmlWriter = xmlOutFactory.createXMLStreamWriter(templateWriter.getOutputWriter());
                for (int index = 0; index < worksheetList.size(); ++index) {
                    WorksheetImpl worksheet = worksheetList.get(index);
                    xmlWriter.writeStartElement("Relationship");
                    xmlWriter.writeAttribute("Id", "rId" + worksheet.getResourceId());
                    xmlWriter.writeAttribute("Type", OpenXMLNamespace.NS_OPENXML_OFFICE_DOC_2006_REL_WORKSHEET);
                    xmlWriter.writeAttribute("Target",
                            "worksheets/sheet" + worksheet.getWorksheetNumber() + ".xml");
                    xmlWriter.writeEndElement();
                }
            } else if (token.equals("workbook.sheets")) {
                xmlWriter = xmlOutFactory.createXMLStreamWriter(templateWriter.getOutputWriter());
                for (int index = 0; index < worksheetList.size(); ++index) {
                    WorksheetImpl worksheet = worksheetList.get(index);
                    xmlWriter.writeStartElement("sheet");
                    xmlWriter.writeAttribute("name", "Sheet" + worksheet.getWorksheetNumber());
                    xmlWriter.writeAttribute("sheetId", String.valueOf(worksheet.getWorksheetNumber()));
                    xmlWriter.writeAttribute("r:id", "rId" + worksheet.getResourceId());
                    xmlWriter.writeEndElement();
                }
            } else {
                // unknown. Invoke a protected method which can be
                // overridden by derived classes
                // to add new template variables and interpret them
                // accordingly.
                expandToken(token, templateWriter);
            }
        } catch (XMLStreamException ex) {
            throw new StaxcelException("Error when replacing " + token + " from template file", ex);
        } finally {
            if (xmlWriter != null) {
                try {
                    xmlWriter.flush();
                    xmlWriter.close();
                } catch (XMLStreamException ex2) {
                    logger.error("Error when closing xmlstream", ex2);
                }
            }
        }
        token = templateWriter.nextElement();
    }
    templateWriter.getOutputWriter().flush();
    templateWriter.getOutputWriter().close();
}

From source file:org.staxcel.internal.SpreadSheetImpl.java

/**
 * Write all shared strings to ./xl/SharedStrings.xml file
 * //from   ww  w. j  ava 2s.  co m
 * @throws IOException
 */
protected void addSharedStringsFile() throws IOException {
    try {
        BufferedWriter writer = createWriter(OpenXMLFormatConstants.SHARED_STRING_FILE_NAME);
        XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
        xmlWriter.writeStartDocument("UTF-8", "1.0");
        xmlWriter.writeStartElement("sst");
        xmlWriter.writeAttribute("xmlns", OpenXMLNamespace.NS_OPENXML_SPREADSHEETML_2006_MAIN);
        xmlWriter.writeAttribute("count", String.valueOf(this.sharedStrings.size()));
        xmlWriter.writeAttribute("uniqueCount", String.valueOf(this.sharedStrings.size()));

        for (Entry<String, Integer> entry : this.sharedStrings.entrySet()) {
            xmlWriter.writeStartElement("si");
            xmlWriter.writeStartElement("t");
            xmlWriter.writeCharacters(entry.getKey());
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndElement();
        xmlWriter.writeEndDocument();
        xmlWriter.close();
        writer.flush();
        writer.close();
    } catch (XMLStreamException ex) {
        logger.error("XML error when creating SharedStrings.xml file", ex);
        throw new StaxcelException("XML error when creating SharedStrings.xml file", ex);
    }
}

From source file:org.tolven.app.bean.DataExtractBean.java

protected void addSimpleXMLColumnHeadings(DataQueryResults dq, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("fields");
    boolean firstTime = true;
    for (DataField field : dq.getSelectedFields()) {
        if (firstTime) {
            firstTime = false;//from  w  w  w. jav a  2 s .  c  o  m
        } else {
            xmlStreamWriter.writeCharacters(",");
        }
        xmlStreamWriter.writeCharacters(xmlName(field));
    }
    xmlStreamWriter.writeEndElement();
}