Example usage for javax.xml.stream XMLStreamWriter writeStartElement

List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeStartElement.

Prototype

public void writeStartElement(String localName) throws XMLStreamException;

Source Link

Document

Writes a start tag to the output.

Usage

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

private void writeOptionalTagWithValue(XMLStreamWriter theEventWriter, String theName, String theValue)
        throws XMLStreamException {
    if (StringUtils.isNotBlank(theValue)) {
        theEventWriter.writeStartElement(theName);
        theEventWriter.writeAttribute("value", theValue);
        theEventWriter.writeEndElement();
    }// w w w.j a v a  2  s .c o m
}

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

private void writeAuthor(XMLStreamWriter theEventWriter, BaseBundle theBundle) throws XMLStreamException {
    if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) {
        theEventWriter.writeStartElement("author");
        writeTagWithTextNode(theEventWriter, "name", theBundle.getAuthorName());
        writeOptionalTagWithTextNode(theEventWriter, "uri", theBundle.getAuthorUri());
        theEventWriter.writeEndElement();
    }/*ww  w . ja  v a2s.  com*/
}

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

private void writeCategories(XMLStreamWriter eventWriter, TagList categories) throws XMLStreamException {
    if (categories != null) {
        for (Tag next : categories) {
            eventWriter.writeStartElement("category");
            eventWriter.writeAttribute("term", defaultString(next.getTerm()));
            eventWriter.writeAttribute("label", defaultString(next.getLabel()));
            eventWriter.writeAttribute("scheme", defaultString(next.getScheme()));
            eventWriter.writeEndElement();
        }//www.  j a v a2s  . c om
    }
}

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

private void writeOptionalTagWithTextNode(XMLStreamWriter theEventWriter, String theTagName,
        InstantDt theInstantDt) throws XMLStreamException {
    if (theInstantDt.getValue() != null) {
        theEventWriter.writeStartElement(theTagName);
        theEventWriter.writeCharacters(theInstantDt.getValueAsString());
        theEventWriter.writeEndElement();
    }/*  w  w  w .ja  v  a2  s.  c o  m*/
}

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

private void writeAtomLink(XMLStreamWriter theEventWriter, String theRel, StringDt theStringDt)
        throws XMLStreamException {
    if (StringUtils.isNotBlank(theStringDt.getValue())) {
        theEventWriter.writeStartElement("link");
        theEventWriter.writeAttribute("rel", theRel);
        theEventWriter.writeAttribute("href", theStringDt.getValue());
        theEventWriter.writeEndElement();
    }//from   ww  w.j  a v  a2s  . c  o m
}

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  ww  w  .  j a  va2  s.c  o m*/
    }

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

private void writeOptionalTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName,
        StringDt theTextValue) throws XMLStreamException {
    if (StringUtils.isNotBlank(theTextValue.getValue())) {
        theEventWriter.writeStartElement(theElementName);
        theEventWriter.writeCharacters(theTextValue.getValue());
        theEventWriter.writeEndElement();
    }/*w w  w. ja v  a 2 s .  c  o m*/
}

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//from w  ww  .  j a v  a2  s  . co 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:org.gaul.s3proxy.S3ProxyHandler.java

private static void writeInitiatorStanza(XMLStreamWriter xml) throws XMLStreamException {
    xml.writeStartElement("Initiator");

    writeSimpleElement(xml, "ID", FAKE_INITIATOR_ID);
    writeSimpleElement(xml, "DisplayName", FAKE_INITIATOR_DISPLAY_NAME);

    xml.writeEndElement();//  ww w.j a va 2s  .  c o m
}

From source file:org.gaul.s3proxy.S3ProxyHandler.java

private static void writeOwnerStanza(XMLStreamWriter xml) throws XMLStreamException {
    xml.writeStartElement("Owner");

    writeSimpleElement(xml, "ID", FAKE_OWNER_ID);
    writeSimpleElement(xml, "DisplayName", FAKE_OWNER_DISPLAY_NAME);

    xml.writeEndElement();/*from   www. ja  v a 2 s  . c  o  m*/
}