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.mule.modules.jive.api.xml.XmlMapper.java

/**Writes the xml of the internal data.
 * @param w The writer in which it'll write the xml
 * @param model The entity//ww  w.ja v a2 s.  c  o  m
 * @throws XMLStreamException When fails
 * */
@SuppressWarnings("unchecked")
private void writeXML(final XMLStreamWriter w, final Map<String, Object> model) throws XMLStreamException {
    final Set<Entry<String, Object>> entries = model.entrySet();
    for (final Entry<String, Object> entry : entries) {
        if (List.class.isInstance(entry.getValue())) {
            for (final String elem : (List<String>) entry.getValue()) {
                w.writeStartElement(entry.getKey());
                w.writeCharacters(elem);
                w.writeEndElement();
            }
        } else {
            String key = entry.getKey();
            if (StringUtils.startsWith(key, "return")) {
                key = "return";
            }
            w.writeStartElement(key);
            if (!HashMap.class.isInstance(entry.getValue())) {
                w.writeCharacters(entry.getValue().toString());
            } else {
                writeXML(w, (HashMap<String, Object>) entry.getValue());
            }
            w.writeEndElement();
        }
    }
}

From source file:org.opentox.toxotis.ontology.impl.MetaInfoImpl.java

private void writeMetaDatumToStAX(String metaDatumNS, String metaDatumName, LiteralValue<?> value,
        javax.xml.stream.XMLStreamWriter writer) throws XMLStreamException {
    if (value != null) {
        String propertyTag = metaDatumNS + ":" + metaDatumName;
        if (value.getValue().toString().isEmpty()) {
            writer.writeEmptyElement(propertyTag);
        }/*from w w  w .ja v  a2 s .  c om*/
        writer.writeStartElement(propertyTag);
        writer.writeCharacters(value.getValue().toString());
        writer.writeEndElement();
    }
}

From source file:org.ops4j.pax.exam.karaf.container.internal.DependenciesDeployer.java

/**
 * Write a feature xml structure for test dependencies specified as ProvisionOption
 * in system to the given writer/*from w  w w  .  j av a2 s  . c  om*/
 * 
 * @param writer where to write the feature xml
 * @param provisionOptions dependencies
 */
static void writeDependenciesFeature(Writer writer, ProvisionOption<?>... provisionOptions) {
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    xof.setProperty("javax.xml.stream.isRepairingNamespaces", true);
    XMLStreamWriter sw = null;
    try {
        sw = xof.createXMLStreamWriter(writer);
        sw.writeStartDocument("UTF-8", "1.0");
        sw.setDefaultNamespace(KARAF_FEATURE_NS);
        sw.writeCharacters("\n");
        sw.writeStartElement("features");
        sw.writeAttribute("name", "test-dependencies");
        sw.writeCharacters("\n");
        sw.writeStartElement("feature");
        sw.writeAttribute("name", "test-dependencies");
        sw.writeCharacters("\n");
        for (ProvisionOption<?> provisionOption : provisionOptions) {
            if (provisionOption.getURL().startsWith("link")
                    || provisionOption.getURL().startsWith("scan-features")) {
                // well those we've already handled at another location...
                continue;
            }
            sw.writeStartElement("bundle");
            if (provisionOption.getStartLevel() != null) {
                sw.writeAttribute("start-level", provisionOption.getStartLevel().toString());
            }
            sw.writeCharacters(provisionOption.getURL());
            endElement(sw);
        }
        endElement(sw);
        endElement(sw);
        sw.writeEndDocument();
    } catch (XMLStreamException e) {
        throw new RuntimeException("Error writing feature " + e.getMessage(), e);
    } finally {
        close(sw);
    }
}

From source file:org.ops4j.pax.exam.karaf.container.internal.DependenciesDeployer.java

private static void endElement(XMLStreamWriter sw) throws XMLStreamException {
    sw.writeEndElement();//from  www .jav  a2  s  .c  o m
    sw.writeCharacters("\n");
}

From source file:org.osaf.cosmo.dav.caldav.SupportedCalendarComponentException.java

protected void writeContent(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement(NS_CALDAV, "supported-calendar-component");
    writer.writeCharacters(getMessage());
    writer.writeEndElement();//from  www  . j  a v  a 2s. c o  m
}

From source file:org.osaf.cosmo.dav.caldav.SupportedCollationException.java

protected void writeContent(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement(NS_CALDAV, "supported-collation");
    writer.writeCharacters(getMessage());
    writer.writeEndElement();/*  w  ww  .  j av a  2  s  .c o m*/
}

From source file:org.osaf.cosmo.mc.CollectionService.java

public void writeTo(OutputStream out) throws IOException, XMLStreamException {
    XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
    writer.setPrefix(PRE_XML, NS_XML);//from w  ww.  ja  va 2  s.c o m
    writer.setDefaultNamespace(NS_MC);

    try {
        writer.writeStartDocument();
        writer.writeStartElement(EL_MC_SERVICE);
        writer.writeDefaultNamespace(NS_MC);
        writer.writeAttribute(NS_XML, EL_XML_BASE, locator.getMorseCodeBase());

        for (CollectionItem collection : collections) {
            writer.writeStartElement(EL_MC_COLLECTION);
            writer.writeAttribute(ATTR_MC_UUID, collection.getUid());
            writer.writeAttribute(ATTR_MC_HREF, href(collection));

            writer.writeStartElement(EL_MC_NAME);
            writer.writeCharacters(collection.getDisplayName());
            writer.writeEndElement();

            for (Ticket ticket : visibleTickets(collection)) {
                writer.writeStartElement(EL_MC_TICKET);
                writer.writeAttribute(ATTR_MC_TYPE, ticket.getType().toString());
                writer.writeCharacters(ticket.getKey());
                writer.writeEndElement();
            }

            writer.writeEndElement();
        }

        writer.writeEndElement();
        writer.writeEndDocument();
    } finally {
        writer.close();
    }
}

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

public String format(CollectionItem collection) {
    try {//from   w  w w  .j  ava  2  s . 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 RuntimeException("Error formatting XML", e);
    }
}

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

public String format(Preference pref) {
    try {//from  w ww.j av  a2s  .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 RuntimeException("Error formatting XML", e);
    }
}

From source file:org.osaf.cosmo.model.text.XhtmlSubscriptionFormat.java

private String format(CollectionSubscription sub, boolean isCollectionProvided, CollectionItem collection,
        boolean isTicketProvided, Ticket ticket) {
    try {//from   ww w .ja v a2  s .c  o m
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = createXmlWriter(sw);

        writer.writeStartElement("div");
        writer.writeAttribute("class", "local-subscription");

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

        if (sub.getCollectionUid() != null) {
            writer.writeStartElement("div");
            writer.writeAttribute("class", "collection");
            writer.writeCharacters("Collection: ");
            writer.writeStartElement("span");
            writer.writeAttribute("class", "uuid");
            writer.writeCharacters(sub.getCollectionUid());
            writer.writeEndElement();
            if (isCollectionProvided) {
                writer.writeCharacters(" Exists? ");
                writer.writeStartElement("span");
                writer.writeAttribute("class", "exists");
                writer.writeCharacters(Boolean.valueOf(collection != null).toString());
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }

        if (sub.getTicketKey() != null) {
            writer.writeStartElement("div");
            writer.writeAttribute("class", "ticket");
            writer.writeCharacters("Ticket: ");
            writer.writeStartElement("span");
            writer.writeAttribute("class", "key");
            writer.writeCharacters(sub.getTicketKey());
            writer.writeEndElement();
            if (isTicketProvided) {
                writer.writeCharacters(" Exists? ");
                writer.writeStartElement("span");
                writer.writeAttribute("class", "exists");
                writer.writeCharacters(Boolean.valueOf(ticket != null).toString());
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }

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

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