Example usage for javax.xml.stream XMLStreamWriter writeEndElement

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

Introduction

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

Prototype

public void writeEndElement() throws XMLStreamException;

Source Link

Document

Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.

Usage

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

private void encodeExtension(IBaseResource theResource, XMLStreamWriter theEventWriter,
        boolean theContainedResource, CompositeChildElement nextChildElem, BaseRuntimeChildDefinition nextChild,
        IBase nextValue, String childName, String extensionUrl, BaseRuntimeElementDefinition<?> childDef)
        throws XMLStreamException {
    BaseRuntimeDeclaredChildDefinition extDef = (BaseRuntimeDeclaredChildDefinition) nextChild;
    if (extDef.isModifier()) {
        theEventWriter.writeStartElement("modifierExtension");
    } else {/*from   w  w  w . j a v a2 s.  com*/
        theEventWriter.writeStartElement("extension");
    }

    String elementId = getCompositeElementId(nextValue);
    if (isNotBlank(elementId)) {
        theEventWriter.writeAttribute("id", elementId);
    }

    theEventWriter.writeAttribute("url", extensionUrl);
    encodeChildElementToStreamWriter(theResource, theEventWriter, nextValue, childName, childDef, null,
            theContainedResource, nextChildElem);
    theEventWriter.writeEndElement();
}

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

protected void toJXMLString_1(XMLStreamWriter writer, boolean writeSchema)
        throws XMLStreamException, FioranoException {
    if (proxyUsed || !StringUtils.isEmpty(proxyURL) || !ANONYMOUS.equals(proxyUser)
            || !ANONYMOUS.equals(proxyPassword)) {
        writer.writeStartElement(ELEM_PROXY);
        {/*from w w  w  . ja v a2 s.  c o  m*/
            if (proxyUsed)
                writer.writeAttribute(ATTR_PROXY_USED, String.valueOf(proxyUsed));
            writeAttribute(writer, ATTR_PROXY_URL, proxyURL);

            if (!ANONYMOUS.equals(proxyUser) || !ANONYMOUS.equals(proxyPassword)) {
                writer.writeStartElement(ELEM_AUTHENTICATION);
                {
                    if (!ANONYMOUS.equals(proxyUser))
                        writer.writeAttribute(ATTR_PROXY_USER, proxyUser);
                    if (!ANONYMOUS.equals(proxyPassword))
                        writer.writeAttribute(ATTR_PROXY_PASSWORD, proxyPassword);
                }
                writer.writeEndElement();
            }
        }
        writer.writeEndElement();
    }

    writer.writeStartElement(ELEM_JMS);
    {
        writeAttribute(writer, ATTR_CLIENT_ID, clientID);
        if (!enabled)
            writer.writeAttribute(ATTR_ENABLED, String.valueOf(enabled));

        if (writeSchema || destinationConfigName == null) {
            writer.writeStartElement(ELEM_DESTINATION);
            {
                if (destinationType != getDefaultDestinationType())
                    writer.writeAttribute(ATTR_DESTINATION_TYPE, String.valueOf(destinationType));
                if (specifiedDestinationUsed)
                    writer.writeAttribute(ATTR_SPECIFIED_DESTINATION_USED,
                            String.valueOf(specifiedDestinationUsed));
                writeAttribute(writer, ATTR_DESTINATION, destination);
                if (isDestinationEncrypted) {
                    writer.writeAttribute(IS_DESTINATION_ENCRYPTED, String.valueOf(isDestinationEncrypted));
                    writer.writeAttribute(DESTINATION_ENCRYPT_ALGO, encryptionAlgorithm);
                    if (encryptionKey == null || encryptionKey.equals(""))
                        writer.writeAttribute(DESTINATION_ENCRYPT_KEY, "");
                    else
                        writer.writeAttribute(DESTINATION_ENCRYPT_KEY, encryptionKey);
                    writer.writeAttribute(DESTINATION_ALLOW_PADDING_TO_KEY, String.valueOf(allowPaddingToKey));
                    writer.writeAttribute(DESTINATION_INITIALIZATION_VECTOR, initializationVector);
                }
            }
            writer.writeEndElement();

        } else if (destinationConfigName != null) {
            writer.writeStartElement(ELEM_DESTINATION_CONFIG_NAME);
            writer.writeAttribute(ATTR_NAME, destinationConfigName);
            writer.writeEndElement();
        }

        if (!StringUtils.isEmpty(securityManager) || !ANONYMOUS.equals(user) || !ANONYMOUS.equals(password)) {
            writer.writeStartElement(ELEM_AUTHENTICATION);
            {
                writeAttribute(writer, ATTR_SECURITY_MANAGER, securityManager);
                if (!ANONYMOUS.equals(user))
                    writer.writeAttribute(ATTR_USER, user);
                if (!ANONYMOUS.equals(password))
                    writer.writeAttribute(ATTR_PASSWORD, password);
            }
            writer.writeEndElement();
        }

        toJXMLString_2(writer, writeSchema);
    }
    writer.writeEndElement();

    if ((writeSchema || workflowConfigName == null)) { // We need to write port properties to stream when passing application launch packet to peer
        writer.writeStartElement(ELEM_WORKFLOW);
        writer.writeAttribute(ATTR_WORKFLOW_TYPE, String.valueOf(workflow));
        writer.writeAttribute(ATTR_WORKFLOW_DATATYPE, String.valueOf(workflowDataType));
        writer.writeAttribute(ATTR_CALLOUT_ENABLED, String.valueOf(calloutEnabled));
        for (DBCallOutParameter dbCallOutParameter : dbCallOutParameterList) {
            dbCallOutParameter.toJXMLString(writer);
        }
        writer.writeEndElement();
    } else if (workflowConfigName != null) {
        writer.writeStartElement(ELEM_WORKFLOW_CONFIG_NAME);
        writer.writeAttribute(ATTR_NAME, workflowConfigName);
        writer.writeEndElement();
    }

    if ((writeSchema || messageFilterConfigName == null) && (isMessageFilterSet)) {
        writer.writeStartElement(ELEM_MESSAGE_FILTERS);
        for (Iterator itr = messageFilters.entrySet().iterator(); itr.hasNext();) {
            Map.Entry entry = (Map.Entry) itr.next();
            writer.writeStartElement(ELEM_MESSAGE_FILTER);
            writer.writeAttribute(ATTR_MESSAGE_FILTER_NAME, (String) entry.getKey());
            writer.writeAttribute(ATTR_MESSAGE_FILTER_VALUE, (String) entry.getValue());
            writer.writeEndElement();
        }
        writer.writeEndElement();
    } else if (messageFilterConfigName != null) {
        writer.writeStartElement(ELEM_MESSAGE_FILTER_CONFIG_NAME);
        writer.writeAttribute(ATTR_NAME, messageFilterConfigName);
        writer.writeEndElement();
    }

    if (!appContextAction.equalsIgnoreCase(NO_ACTION_APP_CONTEXT)) {
        writer.writeStartElement(ELEM_APP_CONTEXT_ACTION);
        writer.writeCharacters(appContextAction);
        writer.writeEndElement();
    }

    toJXMLString_3(writer, writeSchema);
}

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

private void _copyNonExempt(XMLStreamReader xmlStreamReader, XMLStreamWriter xmlStreamWriter,
        String exemptLanguageId, String defaultLanguageId, boolean cdata) throws XMLStreamException {

    while (xmlStreamReader.hasNext()) {
        int event = xmlStreamReader.next();

        if (event == XMLStreamConstants.START_ELEMENT) {
            String languageId = xmlStreamReader.getAttributeValue(null, _LANGUAGE_ID);

            if (Validator.isNull(languageId)) {
                languageId = defaultLanguageId;
            }/*from  w w  w.ja  va 2  s .  c  o m*/

            if (!languageId.equals(exemptLanguageId)) {
                xmlStreamWriter.writeStartElement(xmlStreamReader.getLocalName());
                xmlStreamWriter.writeAttribute(_LANGUAGE_ID, languageId);

                while (xmlStreamReader.hasNext()) {
                    event = xmlStreamReader.next();

                    if ((event == XMLStreamConstants.CHARACTERS) || (event == XMLStreamConstants.CDATA)) {

                        String text = xmlStreamReader.getText();

                        if (cdata) {
                            xmlStreamWriter.writeCData(text);
                        } else {
                            xmlStreamWriter.writeCharacters(xmlStreamReader.getText());
                        }

                        break;
                    } else if (event == XMLStreamConstants.END_ELEMENT) {
                        break;
                    }
                }

                xmlStreamWriter.writeEndElement();
            }
        } else if (event == XMLStreamConstants.END_DOCUMENT) {
            break;
        }
    }
}

From source file:com.smartbear.jenkins.plugins.testcomplete.TcLogParser.java

private void processItem(ZipFile logArchive, Node node, String projectName, XMLStreamWriter writer, String name)
        throws ParsingException, XMLStreamException {
    Node nodeInfo = NodeUtils.getRootDocumentNodeFromArchive(logArchive,
            NodeUtils.getTextProperty(node, "filename"));

    if (nodeInfo == null) {
        throw new ParsingException("Unable to obtain item node info.");
    }//from w ww  . jav  a 2  s.  co  m

    Node logDataRowNode = NodeUtils.findNamedNode(NodeUtils.findNamedNode(nodeInfo, "log data"), "row0");
    if (logDataRowNode == null) {
        throw new ParsingException("Unable to obtain log data->row0 node for item with name '" + name + "'.");
    }

    writer.writeStartElement("testcase");
    writer.writeAttribute("name", name);
    writer.writeAttribute("classname", suite + "." + projectName);

    long startTime = Utils.safeConvertDate(NodeUtils.getTextProperty(logDataRowNode, "start time"));
    long endTime = Utils.safeConvertDate(NodeUtils.getTextProperty(logDataRowNode, "end time"));
    long duration = endTime - startTime > 0 ? endTime - startTime : 0;

    writer.writeAttribute("time", Double.toString(duration / 1000f));

    if (checkFail(NodeUtils.getTextProperty(node, "status"))) {

        Node testDetailsNode = NodeUtils.getRootDocumentNodeFromArchive(logArchive,
                NodeUtils.getTextProperty(logDataRowNode, "details"));
        writer.writeStartElement("failure");

        List<String> messages = NodeUtils.getErrorMessages(testDetailsNode);
        if (errorOnWarnings) {
            messages.addAll(NodeUtils.getWarningMessages(testDetailsNode));
        }

        writer.writeAttribute("message", StringUtils.join(messages, "\n\n"));
        writer.writeEndElement(); //failure
    }
    writer.writeEndElement(); //testcase
}

From source file:com.github.fritaly.graphml4j.LabelStyle.java

void writeTo(XMLStreamWriter writer, String label) throws XMLStreamException {
    Validate.notNull(writer, "The given stream writer is null");

    // y:NodeLabel
    writer.writeStartElement("y:NodeLabel");
    writer.writeAttribute("alignement", textAlignment.getValue());
    writer.writeAttribute("autoSizePolicy", sizePolicy.getValue());
    writer.writeAttribute("fontFamily", fontFamily);
    writer.writeAttribute("fontSize", Integer.toString(fontSize));
    writer.writeAttribute("fontStyle", fontStyle.getValue());
    writer.writeAttribute("modelName", placement.getValue());
    writer.writeAttribute("modelPosition", position.getValue());

    if (borderDistance != 0.0f) {
        writer.writeAttribute("borderDistance", String.format("%.1f", borderDistance));
    }/*from   w w w  .  j  av a  2 s. c om*/
    if (rotationAngle != 0.0f) {
        writer.writeAttribute("rotationAngle", String.format("%.1f", rotationAngle));
    }

    if (backgroundColor != null) {
        writer.writeAttribute("backgroundColor", Utils.encode(backgroundColor));
    } else {
        writer.writeAttribute("hasBackgroundColor", "false");
    }
    if (lineColor != null) {
        writer.writeAttribute("lineColor", Utils.encode(lineColor));
    } else {
        writer.writeAttribute("hasLineColor", "false");
    }
    if (hasInsets()) {
        writer.writeAttribute("bottomInset", Integer.toString(bottomInset));
        writer.writeAttribute("topInset", Integer.toString(topInset));
        writer.writeAttribute("leftInset", Integer.toString(leftInset));
        writer.writeAttribute("rightInset", Integer.toString(rightInset));
    }

    writer.writeAttribute("textColor", Utils.encode(textColor));
    writer.writeAttribute("visible", Boolean.toString(visible));

    if (underlinedText) {
        writer.writeAttribute("underlinedText", Boolean.toString(underlinedText));
    }

    writer.writeCharacters(label);
    writer.writeEndElement(); // </y:NodeLabel>
}

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

private void encodeChildElementToStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter,
        IBase theElement, String childName, BaseRuntimeElementDefinition<?> childDef, String theExtensionUrl,
        boolean theIncludedResource, CompositeChildElement theParent)
        throws XMLStreamException, DataFormatException {
    if (theElement == null || theElement.isEmpty()) {
        if (isChildContained(childDef, theIncludedResource)) {
            // We still want to go in..
        } else {//from w  w  w  .  jav a  2  s .c  o  m
            return;
        }
    }

    writeCommentsPre(theEventWriter, theElement);

    switch (childDef.getChildType()) {
    case ID_DATATYPE: {
        IIdType value = (IIdType) theElement;
        String encodedValue = "id".equals(childName) ? value.getIdPart() : value.getValue();
        if (value != null) {
            theEventWriter.writeStartElement(childName);
            theEventWriter.writeAttribute("value", encodedValue);
            encodeExtensionsIfPresent(theResource, theEventWriter, theElement, theIncludedResource);
            theEventWriter.writeEndElement();
        }
        break;
    }
    case PRIMITIVE_DATATYPE: {
        IPrimitiveType<?> pd = (IPrimitiveType<?>) theElement;
        String value = pd.getValueAsString();
        if (value != null || super.hasExtensions(pd)) {
            theEventWriter.writeStartElement(childName);
            String elementId = getCompositeElementId(theElement);
            if (isNotBlank(elementId)) {
                theEventWriter.writeAttribute("id", elementId);
            }
            if (value != null) {
                theEventWriter.writeAttribute("value", value);
            }
            encodeExtensionsIfPresent(theResource, theEventWriter, theElement, theIncludedResource);
            theEventWriter.writeEndElement();
        }
        break;
    }
    case RESOURCE_BLOCK:
    case COMPOSITE_DATATYPE: {
        theEventWriter.writeStartElement(childName);
        String elementId = getCompositeElementId(theElement);
        if (isNotBlank(elementId)) {
            theEventWriter.writeAttribute("id", elementId);
        }
        if (isNotBlank(theExtensionUrl)) {
            theEventWriter.writeAttribute("url", theExtensionUrl);
        }
        encodeCompositeElementToStreamWriter(theResource, theElement, theEventWriter, theIncludedResource,
                theParent);
        theEventWriter.writeEndElement();
        break;
    }
    case CONTAINED_RESOURCE_LIST:
    case CONTAINED_RESOURCES: {
        /*
         * Disable per #103 for (IResource next : value.getContainedResources()) { if (getContainedResources().getResourceId(next) != null) { continue; }
         * theEventWriter.writeStartElement("contained"); encodeResourceToXmlStreamWriter(next, theEventWriter, true, fixContainedResourceId(next.getId().getValue()));
         * theEventWriter.writeEndElement(); }
         */
        for (IBaseResource next : getContainedResources().getContainedResources()) {
            IIdType resourceId = getContainedResources().getResourceId(next);
            theEventWriter.writeStartElement("contained");
            encodeResourceToXmlStreamWriter(next, theEventWriter, true,
                    fixContainedResourceId(resourceId.getValue()));
            theEventWriter.writeEndElement();
        }
        break;
    }
    case RESOURCE: {
        theEventWriter.writeStartElement(childName);
        IBaseResource resource = (IBaseResource) theElement;
        encodeResourceToXmlStreamWriter(resource, theEventWriter, false, true);
        theEventWriter.writeEndElement();
        break;
    }
    case PRIMITIVE_XHTML: {
        XhtmlDt dt = (XhtmlDt) theElement;
        if (dt.hasContent()) {
            encodeXhtml(dt, theEventWriter);
        }
        break;
    }
    case PRIMITIVE_XHTML_HL7ORG: {
        IBaseXhtml dt = (IBaseXhtml) theElement;
        if (dt.isEmpty()) {
            break;
        } else {
            // TODO: this is probably not as efficient as it could be
            XhtmlDt hdt = new XhtmlDt();
            hdt.setValueAsString(dt.getValueAsString());
            encodeXhtml(hdt, theEventWriter);
            break;
        }
    }
    case EXTENSION_DECLARED:
    case UNDECL_EXT: {
        throw new IllegalStateException("state should not happen: " + childDef.getName());
    }
    }

    writeCommentsPost(theEventWriter, theElement);

}

From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.opt.PerfTestTool.java

/**
 * StAX for efficient streaming XML writing.
 * //  www.  j ava  2s  .  c  o m
 * @throws IOException
 * @throws XMLStreamException 
 */
private static void writeProfile(String dname, String fname) throws IOException, XMLStreamException {
    //create initial directory and file 
    File dir = new File(dname);
    if (!dir.exists())
        dir.mkdir();
    File f = new File(fname);
    f.createNewFile();

    FileOutputStream fos = new FileOutputStream(f);

    try {
        //create document
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter xsw = xof.createXMLStreamWriter(fos);
        //TODO use an alternative way for intentation
        //xsw = new IndentingXMLStreamWriter( xsw ); //remove this line if no indenting required

        //write document content
        xsw.writeStartDocument();
        xsw.writeStartElement(XML_PROFILE);
        xsw.writeAttribute(XML_DATE, String.valueOf(new Date()));

        //foreach instruction (boundle of cost functions)
        for (Entry<Integer, HashMap<Integer, CostFunction>> inst : _profile.entrySet()) {
            int instID = inst.getKey();
            String instName = _regInst_IDNames.get(instID);

            xsw.writeStartElement(XML_INSTRUCTION);
            xsw.writeAttribute(XML_ID, String.valueOf(instID));
            xsw.writeAttribute(XML_NAME, instName.replaceAll(Lop.OPERAND_DELIMITOR, " "));

            //foreach testdef cost function
            for (Entry<Integer, CostFunction> cfun : inst.getValue().entrySet()) {
                int tdefID = cfun.getKey();
                PerfTestDef def = _regTestDef.get(tdefID);
                CostFunction cf = cfun.getValue();

                xsw.writeStartElement(XML_COSTFUNCTION);
                xsw.writeAttribute(XML_ID, String.valueOf(tdefID));
                xsw.writeAttribute(XML_MEASURE, def.getMeasure().toString());
                xsw.writeAttribute(XML_VARIABLE, def.getVariable().toString());
                xsw.writeAttribute(XML_INTERNAL_VARIABLES, serializeTestVariables(def.getInternalVariables()));
                xsw.writeAttribute(XML_DATAFORMAT, def.getDataformat().toString());
                xsw.writeCharacters(serializeParams(cf.getParams()));
                xsw.writeEndElement();// XML_COSTFUNCTION
            }

            xsw.writeEndElement(); //XML_INSTRUCTION
        }

        xsw.writeEndElement();//XML_PROFILE
        xsw.writeEndDocument();
        xsw.close();
    } finally {
        IOUtilFunctions.closeSilently(fos);
    }
}

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   www . j  a v a 2  s. com
    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 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  w  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:com.norconex.collector.http.client.impl.GenericHttpClientFactory.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/* w ww  .j  a va 2 s  . c  o m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("httpClientFactory");
        writer.writeAttribute("class", getClass().getCanonicalName());

        writeBoolElement(writer, "cookiesDisabled", cookiesDisabled);
        writeStringElement(writer, "authMethod", authMethod);
        writeStringElement(writer, "authUsername", authUsername);
        writeStringElement(writer, "authPassword", authPassword);
        writeStringElement(writer, "authUsernameField", authUsernameField);
        writeStringElement(writer, "authPasswordField", authPasswordField);
        writeStringElement(writer, "authURL", authURL);
        writeStringElement(writer, "authHostname", authHostname);
        writeIntElement(writer, "authPort", authPort);
        writeStringElement(writer, "authFormCharset", authFormCharset);
        writeStringElement(writer, "authWorkstation", authWorkstation);
        writeStringElement(writer, "authDomain", authDomain);
        writeStringElement(writer, "authRealm", authRealm);
        writeStringElement(writer, "proxyHost", proxyHost);
        writeIntElement(writer, "proxyPort", proxyPort);
        writeStringElement(writer, "proxyScheme", proxyScheme);
        writeStringElement(writer, "proxyUsername", proxyUsername);
        writeStringElement(writer, "proxyPassword", proxyPassword);
        writeStringElement(writer, "proxyRealm", proxyRealm);
        writer.writeEndElement();
        writeIntElement(writer, "connectionTimeout", connectionTimeout);
        writeIntElement(writer, "socketTimeout", socketTimeout);
        writeIntElement(writer, "connectionRequestTimeout", connectionRequestTimeout);
        writeStringElement(writer, "connectionCharset", connectionCharset);
        writeBoolElement(writer, "expectContinueEnabled", expectContinueEnabled);
        writeIntElement(writer, "maxRedirects", maxRedirects);
        writeStringElement(writer, "localAddress", localAddress);
        writeBoolElement(writer, "staleConnectionCheckDisabled", staleConnectionCheckDisabled);
        writeIntElement(writer, "maxConnections", maxConnections);

        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}