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:ca.uhn.fhir.parser.XmlParser.java

private void encodeBundleToWriterDstu1(Bundle theBundle, XMLStreamWriter eventWriter)
        throws XMLStreamException {
    eventWriter.writeStartElement("feed");
    eventWriter.writeDefaultNamespace(ATOM_NS);

    writeTagWithTextNode(eventWriter, "title", theBundle.getTitle());
    writeTagWithTextNode(eventWriter, "id", theBundle.getBundleId());

    writeAtomLink(eventWriter, Constants.LINK_SELF, theBundle.getLinkSelf());
    writeAtomLink(eventWriter, Constants.LINK_FIRST, theBundle.getLinkFirst());
    writeAtomLink(eventWriter, Constants.LINK_PREVIOUS, theBundle.getLinkPrevious());
    writeAtomLink(eventWriter, Constants.LINK_NEXT, theBundle.getLinkNext());
    writeAtomLink(eventWriter, Constants.LINK_LAST, theBundle.getLinkLast());
    writeAtomLink(eventWriter, Constants.LINK_FHIR_BASE, theBundle.getLinkBase());

    if (theBundle.getTotalResults().getValue() != null) {
        eventWriter.writeStartElement("os", "totalResults", OPENSEARCH_NS);
        eventWriter.writeNamespace("os", OPENSEARCH_NS);
        eventWriter.writeCharacters(theBundle.getTotalResults().getValue().toString());
        eventWriter.writeEndElement();//from w  ww  . j  a v  a  2s .  c om
    }

    writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated());

    writeAuthor(eventWriter, theBundle);

    writeCategories(eventWriter, theBundle.getCategories());

    for (BundleEntry nextEntry : theBundle.getEntries()) {
        boolean deleted = false;
        if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) {
            deleted = true;
            eventWriter.writeStartElement("at", "deleted-entry", TOMBSTONES_NS);
            eventWriter.writeNamespace("at", TOMBSTONES_NS);

            if (nextEntry.getDeletedResourceId().isEmpty()) {
                writeOptionalAttribute(eventWriter, "ref", nextEntry.getId().getValueAsString());
            } else {
                writeOptionalAttribute(eventWriter, "ref", nextEntry.getDeletedResourceId().getValueAsString());
            }

            writeOptionalAttribute(eventWriter, "when", nextEntry.getDeletedAt().getValueAsString());
            if (nextEntry.getDeletedByEmail().isEmpty() == false
                    || nextEntry.getDeletedByName().isEmpty() == false) {
                eventWriter.writeStartElement(TOMBSTONES_NS, "by");
                if (nextEntry.getDeletedByName().isEmpty() == false) {
                    eventWriter.writeStartElement(TOMBSTONES_NS, "name");
                    eventWriter.writeCharacters(nextEntry.getDeletedByName().getValue());
                    eventWriter.writeEndElement();
                }
                if (nextEntry.getDeletedByEmail().isEmpty() == false) {
                    eventWriter.writeStartElement(TOMBSTONES_NS, "email");
                    eventWriter.writeCharacters(nextEntry.getDeletedByEmail().getValue());
                    eventWriter.writeEndElement();
                }
                eventWriter.writeEndElement();
            }
            if (nextEntry.getDeletedComment().isEmpty() == false) {
                eventWriter.writeStartElement(TOMBSTONES_NS, "comment");
                eventWriter.writeCharacters(nextEntry.getDeletedComment().getValue());
                eventWriter.writeEndElement();
            }
        } else {
            eventWriter.writeStartElement("entry");
        }

        writeOptionalTagWithTextNode(eventWriter, "title", nextEntry.getTitle());
        if (!deleted) {
            if (nextEntry.getId().isEmpty() == false) {
                writeTagWithTextNode(eventWriter, "id", nextEntry.getId());
            } else {
                writeTagWithTextNode(eventWriter, "id", nextEntry.getResource().getId());
            }
        }
        writeOptionalTagWithTextNode(eventWriter, "updated", nextEntry.getUpdated());
        writeOptionalTagWithTextNode(eventWriter, "published", nextEntry.getPublished());

        writeAuthor(eventWriter, nextEntry);

        writeCategories(eventWriter, nextEntry.getCategories());

        if (!nextEntry.getLinkSelf().isEmpty()) {
            writeAtomLink(eventWriter, "self", nextEntry.getLinkSelf());
        }

        if (!nextEntry.getLinkAlternate().isEmpty()) {
            writeAtomLink(eventWriter, "alternate", nextEntry.getLinkAlternate());
        }

        if (!nextEntry.getLinkSearch().isEmpty()) {
            writeAtomLink(eventWriter, "search", nextEntry.getLinkSearch());
        }

        IResource resource = nextEntry.getResource();
        if (resource != null && !resource.isEmpty() && !deleted) {
            eventWriter.writeStartElement("content");
            eventWriter.writeAttribute("type", "text/xml");
            encodeResourceToXmlStreamWriter(resource, eventWriter, false, true);
            eventWriter.writeEndElement(); // content
        } else {
            ourLog.debug("Bundle entry contains null resource");
        }

        if (!nextEntry.getSummary().isEmpty()) {
            eventWriter.writeStartElement("summary");
            eventWriter.writeAttribute("type", "xhtml");
            encodeXhtml(nextEntry.getSummary(), eventWriter);
            eventWriter.writeEndElement();
        }

        eventWriter.writeEndElement(); // entry
    }

    eventWriter.writeEndElement();
    eventWriter.close();
}

From source file:com.fiorano.openesb.application.aps.ApplicationHeader.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {
    //Start Application Header
    writer.writeStartElement("ApplicationHeader");
    writer.writeAttribute("isSubgraphable", "" + m_canBeSubGraphed);
    writer.writeAttribute("Scope", m_scope);

    //Write Name/*  w w w  .j  a  v a 2  s .  c o  m*/
    FioranoStackSerializer.writeElement("Name", m_appName, writer);

    //Write ApplicationGUID
    FioranoStackSerializer.writeElement("ApplicationGUID", m_appGUID, writer);

    //Write Auther Vector
    FioranoStackSerializer.writeVector("Author", m_authorNames, writer);

    //Write Creation Date
    FioranoStackSerializer.writeElement("CreationDate", m_creationDate, writer);

    //Write Icon
    if (!StringUtils.isEmpty(m_iconName)) {
        FioranoStackSerializer.writeElement("Icon", m_iconName, writer);
    }

    //Write Version
    if (m_version != null) {
        writer.writeStartElement("Version");
        writer.writeAttribute("isLocked", "" + m_isVersionLocked);
        writer.writeCharacters(m_version);
        writer.writeEndElement();
    }

    //Write Label
    FioranoStackSerializer.writeElement("Label", m_strProfile, writer);

    //Write CompatibleWith
    FioranoStackSerializer.writeVector("CompatibleWith", m_compatibleWith, writer);

    //Write Category
    FioranoStackSerializer.writeElement("Category", m_category, writer);

    //Write Maximum Instances
    if (m_maxInstLimit == -1 || m_maxInstLimit > 0) {
        writer.writeStartElement("MaximumInstances");
        writer.writeCharacters("" + m_maxInstLimit);
        writer.writeEndElement();
    }

    //Write Long Description
    if (!StringUtils.isEmpty(m_longDescription)) {
        FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer);
    }

    //Write Short Description
    if (!StringUtils.isEmpty(m_shortDescription)) {
        FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer);
    }

    //Write mParams
    if (m_params != null && m_params.size() > 0) {
        Enumeration enums = m_params.elements();

        while (enums.hasMoreElements()) {
            Param param = (Param) enums.nextElement();
            if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue()))
                param.toJXMLString(writer);
        }

    }

    // Write AppContext
    if (m_appContext != null) {
        m_appContext.toJXMLString(writer);
    }

    //End Application Header
    writer.writeEndElement();

}

From source file:ca.uhn.fhir.parser.XmlParser.java

private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws XMLStreamException {
    if (theDt == null || theDt.getValue() == null) {
        return;//from   w  w w.  j a  v  a2s.  c o  m
    }

    boolean firstElement = true;
    for (XMLEvent event : theDt.getValue()) {
        switch (event.getEventType()) {
        case XMLStreamConstants.ATTRIBUTE:
            Attribute attr = (Attribute) event;
            if (isBlank(attr.getName().getPrefix())) {
                if (isBlank(attr.getName().getNamespaceURI())) {
                    theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue());
                } else {
                    theEventWriter.writeAttribute(attr.getName().getNamespaceURI(),
                            attr.getName().getLocalPart(), attr.getValue());
                }
            } else {
                theEventWriter.writeAttribute(attr.getName().getPrefix(), attr.getName().getNamespaceURI(),
                        attr.getName().getLocalPart(), attr.getValue());
            }

            break;
        case XMLStreamConstants.CDATA:
            theEventWriter.writeCData(((Characters) event).getData());
            break;
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.SPACE:
            String data = ((Characters) event).getData();
            theEventWriter.writeCharacters(data);
            break;
        case XMLStreamConstants.COMMENT:
            theEventWriter.writeComment(((Comment) event).getText());
            break;
        case XMLStreamConstants.END_ELEMENT:
            theEventWriter.writeEndElement();
            break;
        case XMLStreamConstants.ENTITY_REFERENCE:
            EntityReference er = (EntityReference) event;
            theEventWriter.writeEntityRef(er.getName());
            break;
        case XMLStreamConstants.NAMESPACE:
            Namespace ns = (Namespace) event;
            theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());
            break;
        case XMLStreamConstants.START_ELEMENT:
            StartElement se = event.asStartElement();
            if (firstElement) {
                if (StringUtils.isBlank(se.getName().getPrefix())) {
                    String namespaceURI = se.getName().getNamespaceURI();
                    if (StringUtils.isBlank(namespaceURI)) {
                        namespaceURI = "http://www.w3.org/1999/xhtml";
                    }
                    theEventWriter.writeStartElement(se.getName().getLocalPart());
                    theEventWriter.writeDefaultNamespace(namespaceURI);
                } else {
                    String prefix = se.getName().getPrefix();
                    String namespaceURI = se.getName().getNamespaceURI();
                    theEventWriter.writeStartElement(prefix, se.getName().getLocalPart(), namespaceURI);
                    theEventWriter.writeNamespace(prefix, namespaceURI);
                }
                firstElement = false;
            } else {
                if (isBlank(se.getName().getPrefix())) {
                    if (isBlank(se.getName().getNamespaceURI())) {
                        theEventWriter.writeStartElement(se.getName().getLocalPart());
                    } else {
                        if (StringUtils.isBlank(se.getName().getPrefix())) {
                            theEventWriter.writeStartElement(se.getName().getLocalPart());
                            // theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI());
                        } else {
                            theEventWriter.writeStartElement(se.getName().getNamespaceURI(),
                                    se.getName().getLocalPart());
                        }
                    }
                } else {
                    theEventWriter.writeStartElement(se.getName().getPrefix(), se.getName().getLocalPart(),
                            se.getName().getNamespaceURI());
                }
                for (Iterator<?> attrIter = se.getAttributes(); attrIter.hasNext();) {
                    Attribute next = (Attribute) attrIter.next();
                    theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue());
                }
            }
            break;
        case XMLStreamConstants.DTD:
        case XMLStreamConstants.END_DOCUMENT:
        case XMLStreamConstants.ENTITY_DECLARATION:
        case XMLStreamConstants.NOTATION_DECLARATION:
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
        case XMLStreamConstants.START_DOCUMENT:
            break;
        }

    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates an constraint with the content <code>constraintContent</code>.
 * /*from  ww  w .jav  a2 s  . c  o m*/
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param constraintContent
 *            {@link String} the content of the constraint which will be
 *            created
 * @param id
 *            {@link String} the id of the created <code>ownedRule</code>
 *            tag, which represents <code>constraint</code>
 * @param constrainedElement
 *            {@link String} qualified name of the
 *            {@link AttributedElementClass} which is constrained
 * @throws XMLStreamException
 */
private void createConstraint(XMLStreamWriter writer, String constraintContent, String id,
        String constrainedElement) throws XMLStreamException {
    // start ownedRule
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDRULE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.OWNEDRULE_TYPE_VALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDRULE_ATTRIBUTE_CONSTRAINEDELEMENT,
            constrainedElement);

    // start specification
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_SPECIFICATION);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.TYPE_VALUE_OPAQUEEXPRESSION);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
            id + "_" + XMIConstants4SchemaGraph2XMI.TAG_SPECIFICATION);

    // start and end language
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_LANGUAGE);
    writer.writeEndElement();

    // start body
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_BODY);
    writer.writeCharacters(constraintContent);

    // end body
    writer.writeEndElement();

    // end specification
    writer.writeEndElement();

    // end ownedRule
    writer.writeEndElement();
}

From source file:com.liferay.portal.util.LocalizationImpl.java

public String updateLocalization(String xml, String key, String value, String requestedLanguageId,
        String defaultLanguageId, boolean cdata, boolean localized) {

    xml = _sanitizeXML(xml);//www.  ja va2  s  . co m

    XMLStreamReader xmlStreamReader = null;
    XMLStreamWriter xmlStreamWriter = null;

    ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    try {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(portalClassLoader);
        }

        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();

        xmlStreamReader = xmlInputFactory.createXMLStreamReader(new UnsyncStringReader(xml));

        String availableLocales = StringPool.BLANK;

        // Read root node

        if (xmlStreamReader.hasNext()) {
            xmlStreamReader.nextTag();

            availableLocales = xmlStreamReader.getAttributeValue(null, _AVAILABLE_LOCALES);

            if (Validator.isNull(availableLocales)) {
                availableLocales = defaultLanguageId;
            }

            if (availableLocales.indexOf(requestedLanguageId) == -1) {
                availableLocales = StringUtil.add(availableLocales, requestedLanguageId, StringPool.COMMA);
            }
        }

        UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();

        xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(unsyncStringWriter);

        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(_ROOT);

        if (localized) {
            xmlStreamWriter.writeAttribute(_AVAILABLE_LOCALES, availableLocales);
            xmlStreamWriter.writeAttribute(_DEFAULT_LOCALE, defaultLanguageId);
        }

        _copyNonExempt(xmlStreamReader, xmlStreamWriter, requestedLanguageId, defaultLanguageId, cdata);

        xmlStreamWriter.writeStartElement(key);

        if (localized) {
            xmlStreamWriter.writeAttribute(_LANGUAGE_ID, requestedLanguageId);
        }

        if (cdata) {
            xmlStreamWriter.writeCData(value);
        } else {
            xmlStreamWriter.writeCharacters(value);
        }

        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeEndDocument();

        xmlStreamWriter.close();
        xmlStreamWriter = null;

        xml = unsyncStringWriter.toString();
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }
    } finally {
        if (contextClassLoader != portalClassLoader) {
            currentThread.setContextClassLoader(contextClassLoader);
        }

        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.close();
            } catch (Exception e) {
            }
        }

        if (xmlStreamWriter != null) {
            try {
                xmlStreamWriter.close();
            } catch (Exception e) {
            }
        }
    }

    return xml;
}

From source file:com.predic8.membrane.annot.bean.MCUtil.java

private static void addXML(Object object, String id, XMLStreamWriter xew, SerializationContext sc)
        throws XMLStreamException {
    if (object == null)
        throw new InvalidParameterException("'object' must not be null.");

    Class<? extends Object> clazz = object.getClass();

    MCElement e = clazz.getAnnotation(MCElement.class);
    if (e == null)
        throw new IllegalArgumentException("'object' must be @MCElement-annotated.");

    BeanWrapperImpl src = new BeanWrapperImpl(object);

    xew.writeStartElement(e.name());/*  w  ww.  jav  a2 s  .c o  m*/

    if (id != null)
        xew.writeAttribute("id", id);

    HashSet<String> attributes = new HashSet<String>();
    for (Method m : clazz.getMethods()) {
        if (!m.getName().startsWith("set"))
            continue;
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));
        MCAttribute a = m.getAnnotation(MCAttribute.class);
        if (a != null) {
            Object value = src.getPropertyValue(propertyName);
            String str;
            if (value == null)
                continue;
            else if (value instanceof String)
                str = (String) value;
            else if (value instanceof Boolean)
                str = ((Boolean) value).toString();
            else if (value instanceof Integer)
                str = ((Integer) value).toString();
            else if (value instanceof Long)
                str = ((Long) value).toString();
            else if (value instanceof Enum<?>)
                str = value.toString();
            else {
                MCElement el = value.getClass().getAnnotation(MCElement.class);
                if (el != null) {
                    str = defineBean(sc, value, null, true);
                } else {
                    str = "?";
                    sc.incomplete = true;
                }
            }

            if (a.attributeName().length() > 0)
                propertyName = a.attributeName();

            attributes.add(propertyName);
            xew.writeAttribute(propertyName, str);
        }
    }
    for (Method m : clazz.getMethods()) {
        if (!m.getName().startsWith("set"))
            continue;
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));
        MCOtherAttributes o = m.getAnnotation(MCOtherAttributes.class);
        if (o != null) {
            Object value = src.getPropertyValue(propertyName);
            if (value instanceof Map<?, ?>) {
                Map<?, ?> map = (Map<?, ?>) value;
                for (Map.Entry<?, ?> entry : map.entrySet()) {
                    Object key = entry.getKey();
                    Object val = entry.getValue();
                    if (!(key instanceof String) || !(val instanceof String)) {
                        sc.incomplete = true;
                        key = "incompleteAttributes";
                        val = "?";
                    }
                    if (attributes.contains(key))
                        continue;
                    attributes.add((String) key);
                    xew.writeAttribute((String) key, (String) val);
                }
            } else {
                xew.writeAttribute("incompleteAttributes", "?");
                sc.incomplete = true;
            }
        }
    }

    List<Method> childElements = new ArrayList<Method>();
    for (Method m : clazz.getMethods()) {
        if (!m.getName().startsWith("set"))
            continue;
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));

        MCChildElement c = m.getAnnotation(MCChildElement.class);
        if (c != null) {
            childElements.add(m);
        }
        MCTextContent t = m.getAnnotation(MCTextContent.class);
        if (t != null) {
            Object value = src.getPropertyValue(propertyName);
            if (value == null) {
                continue;
            } else if (value instanceof String) {
                xew.writeCharacters((String) value);
            } else {
                xew.writeCharacters("?");
                sc.incomplete = true;
            }
        }
    }

    Collections.sort(childElements, new Comparator<Method>() {

        @Override
        public int compare(Method o1, Method o2) {
            MCChildElement c1 = o1.getAnnotation(MCChildElement.class);
            MCChildElement c2 = o2.getAnnotation(MCChildElement.class);
            return c1.order() - c2.order();
        }
    });

    for (Method m : childElements) {
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));

        Object value = src.getPropertyValue(propertyName);
        if (value != null) {
            if (value instanceof Collection<?>) {
                for (Object item : (Collection<?>) value)
                    addXML(item, null, xew, sc);
            } else {
                addXML(value, null, xew, sc);
            }
        }
    }

    xew.writeEndElement();
}

From source file:com.fiorano.openesb.application.aps.Route.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {

    //Start Route
    writer.writeStartElement("Route");

    //Add Route Attributes
    writer.writeAttribute("isP2PRoute", "" + m_isP2PRoute);
    writer.writeAttribute("isPersistant", "" + m_isPersitant);
    writer.writeAttribute("isDurable", "" + m_isDurable);
    writer.writeAttribute("applyTransformationAtSrc", "" + m_applyTransformationAtSrc);

    //Name//ww  w.  j a v a  2 s .  com
    FioranoStackSerializer.writeElement("Name", m_routeName, writer);

    //RouteGuid
    FioranoStackSerializer.writeElement("RouteGUID", m_routeGUID, writer);

    //TimeToLive
    FioranoStackSerializer.writeElement("TimeToLive", "" + m_iTimeToLive, writer);

    //SrcServiceInstance
    FioranoStackSerializer.writeElement("SrcServiceInstance", m_srcServInst, writer);

    //SrcPort
    FioranoStackSerializer.writeElement("SrcPort", m_srcPortName, writer);

    //TransformationXSL
    if (m_transformationXSL != null) {
        writer.writeStartElement("TransformationXSL");
        writer.writeCData(m_transformationXSL);
        writer.writeEndElement();

    }
    //Selectors
    if (m_selectors != null) {
        Iterator itr = m_selectors.keySet().iterator();

        while (itr.hasNext()) {
            writer.writeStartElement("Selector");
            String type = (String) itr.next();
            writer.writeAttribute("type", type);
            Object val = m_selectors.get(type);
            String value = null;
            if (val instanceof String) {
                value = (String) m_selectors.get(type);
            } else if (val instanceof XPathDmi) {
                value = ((XPathDmi) val).getXPath();

                HashMap map = ((XPathDmi) val).getNameSpace();

                if (map != null) {
                    Set keys = map.keySet();
                    Iterator iter = keys.iterator();

                    while (iter.hasNext()) {
                        String key = (String) iter.next();
                        String keyval = (String) map.get(key);
                        writer.writeAttribute("esb_" + key, keyval);
                    }
                }
            }
            writer.writeCharacters(value);

            //End Selector
            writer.writeEndElement();
        }
    }

    //TgtServiceInstance
    FioranoStackSerializer.writeElement("TgtServiceInstance", m_trgtServInst, writer);

    //TgtPort
    FioranoStackSerializer.writeElement("TgtPort", m_trgtPortName, writer);

    //LongDescription
    if (!StringUtils.isEmpty(m_longDescription)) {
        FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer);
    }

    //ShortDescription
    if (!StringUtils.isEmpty(m_shortDescription)) {
        FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer);
    }

    if (m_altDestination != null) {
        m_altDestination.toJXMLString(writer);
    }

    if (m_params != null && m_params.size() > 0) {
        Enumeration enums = m_params.elements();

        while (enums.hasMoreElements()) {
            Param param = (Param) enums.nextElement();
            if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue()))
                param.toJXMLString(writer);
        }
    }
    //End Route
    writer.writeEndElement();
}

From source file:com.fiorano.openesb.application.application.Route.java

protected void toJXMLString(XMLStreamWriter writer, boolean writeCDataSections)
        throws XMLStreamException, FioranoException {
    writer.writeStartElement(ELEM_ROUTE);
    {/*  w w  w .j  av  a 2 s.  c om*/
        writer.writeAttribute(ATTR_NAME, name);
        if (ignoreAbsenceOfTransformation) {//write only if true
            writer.writeAttribute(ATTR_IGNORE_ABSENCE_TRANSFORMATION,
                    String.valueOf(ignoreAbsenceOfTransformation));
        }
        writer.writeStartElement(ELEM_SOURCE);
        {
            writer.writeAttribute(ATTR_SOURCE_SERVICE_INSTANCE, sourceServiceInstance);
            writer.writeAttribute(ATTR_SOURCE_PORT_INSTANCE, sourcePortInstance);
        }
        writer.writeEndElement();

        writer.writeStartElement(ELEM_TARGET);
        {
            writer.writeAttribute(ATTR_TARGET_SERVICE_INSTANCE, targetServiceInstance);
            writer.writeAttribute(ATTR_TARGET_PORT_INSTANCE, targetPortInstance);
        }
        writer.writeEndElement();

        writeElement(writer, ELEM_SHORT_DESCRIPTION, shortDescription);
        writeElement(writer, ELEM_LONG_DESCRIPTION, longDescription);

        if (messagingConfigName != null) {
            writer.writeStartElement(ELEM_MESSAGING_CONFIG_NAME);
            {
                writer.writeAttribute(ATTR_NAME, messagingConfigName);
            }
            writer.writeEndElement();
        } else {
            writer.writeStartElement(ELEM_MESSAGES);
            {
                if (compressed)
                    writer.writeAttribute(ATTR_COMPRESS, String.valueOf(true));
                if (durable)
                    writer.writeAttribute(ATTR_DURABLE, String.valueOf(true));
                if (encrypted)
                    writer.writeAttribute(ATTR_ENCRYPT, String.valueOf(true));
                writer.writeAttribute(ATTR_ROUTE_DURABLE_PRIORITY, String.valueOf(durabilitySource));
            }
            writer.writeEndElement();
        }

        if (messageTransformation != null)
            messageTransformation.toJXMLString(writer, writeCDataSections);

        if (selectorConfigName != null) {
            writer.writeStartElement(ELEM_SELECTOR_CONFIG_NAME);
            {
                writer.writeAttribute(ATTR_NAME, selectorConfigName);
            }
            writer.writeEndElement();
        } else if (selectors.size() > 0) {
            writer.writeStartElement(ELEM_SELECTORS);
            {
                Iterator iter = selectors.entrySet().iterator();
                while (iter.hasNext()) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    writer.writeStartElement(ELEM_SELECTOR);
                    {
                        writer.writeAttribute(ATTR_TYPE, (String) entry.getKey());
                        if (entry.getValue() instanceof XPathSelector)
                            ((XPathSelector) entry.getValue()).toJXMLString(writer);
                        else
                            writer.writeCharacters((String) entry.getValue());
                    }
                    writer.writeEndElement();
                }
            }
            writer.writeEndElement();
        }

        if (logManager != null)
            logManager.toJXMLString(writer);
        writeCollection(writer, logModules, ELEM_LOGMODULES);
    }
    writer.writeEndElement();
}

From source file:com.fiorano.openesb.application.aps.ServiceInstance.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException, FioranoException {

    //Start ServiceInstance
    writer.writeStartElement("ServiceInstance");

    //Write Attributes
    writer.writeAttribute("isManualLaunch", "" + m_isManualLaunch);
    writer.writeAttribute("isStateful", "" + m_isStateful);
    writer.writeAttribute("isDelayedLaunch", "" + m_isDelayedLaunch);
    writer.writeAttribute("delayedPort", "" + m_delayedPortName);
    writer.writeAttribute("maxRetries", "" + m_maxRetries);
    writer.writeAttribute("isTransacted", "" + m_isTransacted);
    writer.writeAttribute("isErrorHandlingEnabled", "" + m_isErrorHandlingEnabled);
    writer.writeAttribute("isInMemoryLaunch", "" + m_isInMemoryLaunch);
    writer.writeAttribute("isEndOfWorkflow", "" + m_isEndOfWorkflow);
    writer.writeAttribute("preferLaunchOnHigherLevelNode", "" + m_bPreferLaunchOnHigherLevelNode);
    writer.writeAttribute("killPrimaryOnSecondaryLaunch", "" + m_bKillPrimaryOnSecondaryLaunch);
    writer.writeAttribute("isDebugMode", "" + m_bIsDebugMode);
    writer.writeAttribute("debugPort", "" + m_iDebugPort);
    writer.writeAttribute("isTransportLPC", "" + m_isTransportLPC);
    writer.writeAttribute("profile", "" + m_profile);

    FioranoStackSerializer.writeElement("ServiceInstanceName", m_servInstName, writer);
    FioranoStackSerializer.writeElement("ServiceGUID", m_servGUID, writer);
    FioranoStackSerializer.writeElement("BufferSizePerPort", m_dBufferSizePerPort + "", writer);

    if (m_version != null) {
        writer.writeStartElement("Version");
        writer.writeAttribute("isLocked", "" + m_isVersionLocked);
        writer.writeCharacters(m_version);
        writer.writeEndElement();/*w ww  . jav  a  2s.  c  om*/
    }
    if (m_nodes != null && m_nodes.size() > 0) {
        Enumeration nodeNameEnum = m_nodes.keys();
        Enumeration nodeLevelEnum = m_nodes.elements();

        while (nodeNameEnum.hasMoreElements()) {
            String nodeName = (String) nodeNameEnum.nextElement();
            String nodeLevel = (String) nodeLevelEnum.nextElement();
            writer.writeStartElement("Node");
            writer.writeAttribute("level", nodeLevel);
            writer.writeCharacters(nodeName);
            writer.writeEndElement();
        }
    }
    if (m_eventHandler > 0) {
        writer.writeStartElement("EventHandler");
        writer.writeAttribute("deliveryMode", "" + m_eventDeliveryMode);
        writer.writeAttribute("expiryTime", "" + m_eventExpiryTime);
        writer.writeCharacters("" + m_eventHandler);
        writer.writeEndElement();
    }
    if (m_runtimeDependencies != null && m_runtimeDependencies.size() > 0) {
        Enumeration enums = m_runtimeDependencies.elements();

        while (enums.hasMoreElements()) {
            RuntimeDependency runtimeDependency = (RuntimeDependency) enums.nextElement();
            runtimeDependency.toJXMLString(writer);
        }
    }
    if (m_runtimeArgs != null) {
        m_runtimeArgs.toJXMLString(writer);
    }
    if (m_portInstDescriptor != null) {
        m_portInstDescriptor.toJXMLString(writer);
    }

    if (!StringUtils.isEmpty(m_longDescription)) {
        FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer);

    }
    if (!StringUtils.isEmpty(m_shortDescription)) {
        FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer);

    }
    //LogManager
    if (m_logManager != null) {
        //Start LogMangaer
        writer.writeStartElement("LogManager");

        FioranoStackSerializer.writeElement("Name", m_logManager, writer);

        if (m_logParams != null && m_logParams.size() > 0) {
            Enumeration enums = m_logParams.elements();
            while (enums.hasMoreElements()) {
                Param param = (Param) enums.nextElement();
                if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) {
                    param.toJXMLString(writer);
                }
            }
        }
        //End LogManager
        writer.writeEndElement();
    }
    if (m_params != null && m_params.size() > 0) {
        Enumeration enums = m_params.elements();

        while (enums.hasMoreElements()) {
            Param param = (Param) enums.nextElement();
            if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue()))
                param.toJXMLString(writer);
        }
    }
    if (m_statusTracking != null) {
        m_statusTracking.toJXMLString(writer);
    }
    if (m_vecEndStates != null) {
        for (int i = 0; i < m_vecEndStates.size(); i++) {
            EndState endState = (EndState) m_vecEndStates.get(i);
            endState.toJXMLString(writer);

        }
    }
    if (m_monitor != null) {
        m_monitor.toJXMLString(writer);
    }
    if (m_logModules != null) {
        m_logModules.toJXMLString(writer);

    }

    //End ServiceInstance
    writer.writeEndElement();

}

From source file:com.amalto.core.load.io.XMLStreamUnwrapper.java

/**
 * Moves to next record in stream and stores it in {@link #stringWriter}.
 *//*from   w w w  .  j  a  v  a2s .c om*/
private void moveToNext() {
    try {
        XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(stringWriter);
        boolean hasMadeChanges;
        do {
            if (!reader.hasNext()) {
                break;
            }
            hasMadeChanges = false; // Keep a state to skip line feeds
            final XMLEvent event = reader.nextEvent();
            if (event.isEndElement()) {
                level--;
            } else if (event.isStartElement()) {
                level++;
            } else if (event.isEndDocument()) {
                level--;
            }
            if (level >= RECORD_LEVEL) {
                if (event.isEndElement()) {
                    writer.writeEndElement();
                    hasMadeChanges = true;
                } else if (event.isStartElement()) {
                    final StartElement startElement = event.asStartElement();
                    final QName name = startElement.getName();
                    writer.writeStartElement(name.getNamespaceURI(), name.getLocalPart());
                    boolean isRecordRootElement = (RECORD_LEVEL == level - 1);
                    if (isRecordRootElement) {
                        for (int i = 0; i < rootNamespaceList.size(); i++) {
                            Namespace namespace = rootNamespaceList.get(i);
                            writer.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
                        }
                    }
                    // Declare namespaces (if any)
                    final Iterator elementNamespaces = startElement.getNamespaces();
                    while (elementNamespaces.hasNext()) {
                        Namespace elementNamespace = (Namespace) elementNamespaces.next();
                        if (isRecordRootElement) {
                            if (rootNamespaceList.size() > 0) {
                                for (int i = 0; i < rootNamespaceList.size(); i++) {
                                    Namespace namespace = rootNamespaceList.get(i);
                                    if (!namespace.getPrefix().equals(elementNamespace.getPrefix())
                                            || !namespace.getNamespaceURI()
                                                    .equals(elementNamespace.getNamespaceURI())) {
                                        writer.writeNamespace(elementNamespace.getPrefix(),
                                                elementNamespace.getNamespaceURI());
                                    }
                                }
                            } else {
                                writer.writeNamespace(elementNamespace.getPrefix(),
                                        elementNamespace.getNamespaceURI());
                            }
                        } else {
                            writer.writeNamespace(elementNamespace.getPrefix(),
                                    elementNamespace.getNamespaceURI());
                        }
                    }
                    // Write attributes
                    final Iterator attributes = startElement.getAttributes();
                    while (attributes.hasNext()) {
                        Attribute attribute = (Attribute) attributes.next();
                        QName attributeName = attribute.getName();
                        String value = attribute.getValue();
                        if (StringUtils.isEmpty(attributeName.getNamespaceURI())) {
                            writer.writeAttribute(attributeName.getLocalPart(), value);
                        } else {
                            writer.writeAttribute(attributeName.getNamespaceURI(), attributeName.getLocalPart(),
                                    value);
                        }
                    }
                    hasMadeChanges = true;
                } else if (event.isCharacters()) {
                    final String text = event.asCharacters().getData().trim();
                    if (!text.isEmpty()) {
                        writer.writeCharacters(text);
                        hasMadeChanges = true;
                    }
                }
            }
        } while (level > RECORD_LEVEL || !hasMadeChanges);
        writer.flush();
    } catch (XMLStreamException e) {
        throw new RuntimeException("Unexpected parsing exception.", e);
    }
}