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:com.microsoft.tfs.core.memento.XMLMemento.java

/**
 * Saves this {@link Memento} as an XML Element in the given writer
 *
 * @param writer//from   ww  w .  jav a 2s .  c om
 *        the writer (must not be <code>null</code>)
 */
private void writeAsElement(final XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement(name);

    /*
     * Write all attributes as XML attributes.
     */
    for (final Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
        final Entry entry = (Entry) iterator.next();
        writer.writeAttribute((String) entry.getKey(), (String) entry.getValue());
    }

    /*
     * Write the text node if there is one.
     */
    if (textData != null) {
        writer.writeCharacters(textData);
    }

    /*
     * Write all children as elements.
     */
    for (final Iterator iterator = children.iterator(); iterator.hasNext();) {
        final XMLMemento child = (XMLMemento) iterator.next();
        child.writeAsElement(writer);
    }

    /*
     * Done with the element.
     */
    writer.writeEndElement();
}

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();
    }//from   ww  w  .ja  v  a  2  s. co  m
}

From source file:org.maodian.flyingcat.xmpp.state.StreamState.java

private void doHandle(XmppContext context, XMLStreamReader xmlsr, XMLStreamWriter xmlsw)
        throws XMLStreamException {
    xmlsr.nextTag();/*  w  w w .  j a v a2s.c  o  m*/
    QName qname = new QName(XmppNamespace.STREAM, "stream");
    if (!xmlsr.getName().equals(qname)) {
        throw new XmppException(StreamError.INVALID_NAMESPACE).set("QName", xmlsr.getName());
    }

    // throw exception if client version > 1.0
    BigDecimal version = new BigDecimal(xmlsr.getAttributeValue("", "version"));
    if (version.compareTo(SUPPORTED_VERSION) > 0) {
        throw new XmppException(StreamError.UNSUPPORTED_VERSION);
    }

    xmlsw.writeStartDocument();
    xmlsw.writeStartElement("stream", "stream", XmppNamespace.STREAM);
    xmlsw.writeNamespace("stream", XmppNamespace.STREAM);
    xmlsw.writeDefaultNamespace(XmppNamespace.CLIENT_CONTENT);

    xmlsw.writeAttribute("id", RandomStringUtils.randomAlphabetic(32));
    xmlsw.writeAttribute("version", "1.0");
    xmlsw.writeAttribute("from", "localhost");
    xmlsw.writeAttribute(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", "en");
    String from = xmlsr.getAttributeValue(null, "from");
    if (from != null) {
        xmlsw.writeAttribute("to", from);
    }

    // features
    xmlsw.writeStartElement(XmppNamespace.STREAM, "features");
    writeFeatures(xmlsw);
    xmlsw.writeEndElement();
}

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

private void writeTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, IdDt theIdDt)
        throws XMLStreamException {
    theEventWriter.writeStartElement(theElementName);
    if (StringUtils.isNotBlank(theIdDt.getValue())) {
        theEventWriter.writeCharacters(theIdDt.getValue());
    }/*  w  ww . j  av  a 2s. c  om*/
    theEventWriter.writeEndElement();
}

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();
    }//from  ww  w  .  j  a v a2s  .  c  o  m
}

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

private void writeTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, StringDt theStringDt)
        throws XMLStreamException {
    theEventWriter.writeStartElement(theElementName);
    if (StringUtils.isNotBlank(theStringDt.getValue())) {
        theEventWriter.writeCharacters(theStringDt.getValue());
    }//w w  w.  j ava  2s .  com
    theEventWriter.writeEndElement();
}

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

From source file:de.shadowhunt.subversion.internal.PropertiesUpdateOperation.java

@Override
protected HttpUriRequest createRequest() {
    final URI uri = URIUtils.createURI(repository, resource);
    final DavTemplateRequest request = new DavTemplateRequest("PROPPATCH", uri);

    if (lockToken != null) {
        request.addHeader("If", "<" + uri + "> (<" + lockToken + ">)");
    }/* w w  w . j a va 2s  .c  om*/

    final Writer body = new StringBuilderWriter();
    try {
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("propertyupdate");
        writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE);
        writer.setPrefix(XmlConstants.SUBVERSION_CUSTOM_PREFIX, XmlConstants.SUBVERSION_CUSTOM_NAMESPACE);
        writer.writeNamespace(XmlConstants.SUBVERSION_CUSTOM_PREFIX, XmlConstants.SUBVERSION_CUSTOM_NAMESPACE);
        writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE);
        writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE);
        writer.setPrefix(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE);
        writer.writeNamespace(XmlConstants.SUBVERSION_SVN_PREFIX, XmlConstants.SUBVERSION_SVN_NAMESPACE);
        writer.writeStartElement(type.action);
        writer.writeStartElement("prop");
        for (final ResourceProperty property : properties) {
            final String prefix = property.getType().getPrefix();
            if (type == Type.SET) {
                writer.writeStartElement(prefix, ResourcePropertyUtils.escapedKeyNameXml(property.getName()));
                writer.writeCharacters(property.getValue());
                writer.writeEndElement();
            } else {
                writer.writeEmptyElement(prefix, property.getName());
            }
        }
        writer.writeEndElement(); // prop
        writer.writeEndElement(); // set || delete
        writer.writeEndElement(); // propertyupdate
        writer.writeEndDocument();
        writer.close();
    } catch (final XMLStreamException e) {
        throw new SubversionException("could not create request body", e);
    }

    final String bodyWithMakers = body.toString();
    final String bodyWithoutMakers = ResourcePropertyUtils.filterMarker(bodyWithMakers);
    request.setEntity(new StringEntity(bodyWithoutMakers, CONTENT_TYPE_XML));
    return request;
}

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

private void writeBundleResourceLink(XMLStreamWriter theEventWriter, String theRel, StringDt theUrl)
        throws XMLStreamException {
    if (theUrl.isEmpty() == false) {
        theEventWriter.writeStartElement("link");
        theEventWriter.writeStartElement("relation");
        theEventWriter.writeAttribute("value", theRel);
        theEventWriter.writeEndElement();
        theEventWriter.writeStartElement("url");
        theEventWriter.writeAttribute("value", theUrl.getValue());
        theEventWriter.writeEndElement();
        theEventWriter.writeEndElement();
    }/* www.  j a  va2 s.co m*/
}

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

/**
 * Writes manageable properties file with the specified label
 * @param applicationFolderName event process folder
 * @param label environment label/*w  w  w.j  a v  a  2  s  .  co m*/
 * @throws FioranoException FioranoException
 * @throws XMLStreamException XMLStreamException
 */
public void writeManageableProperties(File applicationFolderName, Label label)
        throws FioranoException, XMLStreamException {
    File manageablePropertiesFile = getManageablePropertiesFile(applicationFolderName, label);
    if (!manageablePropertiesFile.exists())
        manageablePropertiesFile.getParentFile().mkdirs();

    XMLOutputFactory outputFactory = XMLUtils.getStaxOutputFactory();
    //        System.out.println(".....:"+outputFactory);
    //outputFactory.setProperty(XMLOutputFactory.INDENTATION, "/t");
    XMLStreamWriter writer = null;
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(manageablePropertiesFile);
        writer = outputFactory.createXMLStreamWriter(fos);
        writer.writeStartDocument();
        {

            writer.writeStartElement(ELEM_TARGET, ELEM_TARGET, Namespaces.URI_TARGET);
            writer.writeAttribute(XMLNS_TARGET, Namespaces.URI_TARGET);
            writer.writeAttribute(XMLNS_XSI, Namespaces.URI_XSI);
            writer.writeAttribute(XSI_LOCATION, Namespaces.URI_ENV_XSD);
            {
                for (ServiceInstance instance : getServiceInstances()) {
                    instance.writeManageableProperties(writer);
                }

            }
            writer.writeEndElement();
        }

        writer.writeEndDocument();

        writer.flush();
    } catch (XMLStreamException e) {
        throw new FioranoException(e);
    } catch (IOException e) {
        throw new FioranoException(e);
    } finally {
        try {
            if (writer != null)
                writer.close();
        } catch (XMLStreamException e) {
            // Ignore
        }

        try {
            if (fos != null)
                fos.close();
        } catch (IOException e) {
            // Ignore
        }
    }

}