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.predic8.membrane.core.interceptor.balancer.JSESSIONIDExtractor.java

@Override
public void write(XMLStreamWriter out) throws XMLStreamException {

    out.writeStartElement("jSessionIdExtractor");
    out.writeEndElement();
}

From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java

public static void write(List<Scale> modeList, String fileName) {
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xtw = null;

    // <mode>
    // <name>Peruvian tritonic 2</name>
    // <interval>3</interval>
    // <interval>4</interval>
    // <interval>5</interval>
    // </mode>

    String ns = "http://rockhoppertech.com/modes-1.0";

    // StringWriter sw = new StringWriter();
    try {/*from  ww  w.j  av a2 s  .  c om*/
        xtw = xof.createXMLStreamWriter(new FileWriter(fileName));
        // xtw = xof.createXMLStreamWriter(sw);
        xtw.writeComment("all elements here are explicitly in the mode namespace");
        xtw.writeStartDocument("utf-8", "1.0");
        xtw.setPrefix("modes", ns);
        xtw.writeStartElement(ns, "modes");
        xtw.writeNamespace("modes", ns);

        for (Scale scale : modeList) {
            // xtw.writeStartElement(ns, "mode");
            xtw.writeStartElement("mode");

            // xtw.writeStartElement(ns, "name");
            xtw.writeStartElement("name");
            xtw.writeCharacters(scale.getName());
            xtw.writeEndElement();

            // xtw.writeStartElement(ns, "intervals");
            // xtw.writeStartElement(ns, "interval");
            xtw.writeStartElement("intervals");
            int[] intervals = scale.getIntervals();
            for (int i = 0; i < intervals.length; i++) {
                xtw.writeStartElement("interval");
                xtw.writeCharacters("" + intervals[i]);
                xtw.writeEndElement();
            }
            xtw.writeEndElement(); // intervals

            xtw.writeEndElement(); // mode
        }

        xtw.writeEndElement(); // modes
        xtw.writeEndDocument();
        xtw.flush();
        xtw.close();
        // System.err.println(sw.toString());

    } catch (XMLStreamException | IOException e) {
        logger.error(e.getLocalizedMessage(), e);
        e.printStackTrace();
    }

}

From source file:com.predic8.membrane.core.interceptor.cbr.Case.java

@Override
public void write(XMLStreamWriter out) throws XMLStreamException {

    out.writeStartElement("case");

    out.writeAttribute("xPath", xPath);
    out.writeAttribute("url", url);

    out.writeEndElement();
}

From source file:eu.scape_project.planning.xml.ProjectExportAction.java

/**
 * Dumps binary data to provided file. It results in an XML file with a
 * single element: data./*w  w  w  .  j  av a 2  s .c o  m*/
 * 
 * @param id
 * @param data
 * @param f
 * @param encoder
 * @throws IOException
 */
private static void writeBinaryData(int id, InputStream data, File f) throws IOException {

    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {
        XMLStreamWriter writer = factory.createXMLStreamWriter(new FileWriter(f));

        writer.writeStartDocument(PlanXMLConstants.ENCODING, "1.0");
        writer.writeStartElement("data");
        writer.writeAttribute("id", "" + id);

        Base64InputStream base64EncodingIn = new Base64InputStream(data, true,
                PlanXMLConstants.BASE64_LINE_LENGTH, PlanXMLConstants.BASE64_LINE_BREAK);

        OutputStream out = new WriterOutputStream(new XMLStreamContentWriter(writer),
                PlanXMLConstants.ENCODING);
        // read the binary data and encode it on the fly
        IOUtils.copy(base64EncodingIn, out);
        out.flush();

        // all data is written - end 
        writer.writeEndElement();
        writer.writeEndDocument();

        writer.flush();
        writer.close();

    } catch (XMLStreamException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.norconex.committer.gsa.GsaCommitter.java

@Override
protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("feedUrl");
    writer.writeCharacters(getFeedUrl());
    writer.writeEndElement();
}

From source file:com.flexive.shared.media.impl.FxMediaImageMagickEngine.java

/**
 * Parse an identify stdOut result (from in) and convert it to an XML content
 *
 * @param in identify response/*from w w  w  .j  av  a 2  s .  c  om*/
 * @return XML content
 * @throws XMLStreamException on errors
 * @throws IOException        on errors
 */
public static String parse(InputStream in) throws XMLStreamException, IOException {
    StringWriter sw = new StringWriter(2000);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
    writer.writeStartDocument();

    int lastLevel = 0, level, lastNonValueLevel = 1;
    boolean valueEntry;
    String curr = null;
    String[] entry;
    try {
        while ((curr = br.readLine()) != null) {
            level = getLevel(curr);
            if (level == 0 && curr.startsWith("Image:")) {
                writer.writeStartElement("Image");
                entry = curr.split(": ");
                if (entry.length >= 2)
                    writer.writeAttribute("source", entry[1]);
                lastLevel = level;
                continue;
            }
            if (!(valueEntry = pNumeric.matcher(curr).matches())) {
                while (level < lastLevel--)
                    writer.writeEndElement();
                lastNonValueLevel = level;
            } else
                level = lastNonValueLevel + 1;
            if (curr.endsWith(":")) {
                writer.writeStartElement(
                        curr.substring(0, curr.lastIndexOf(':')).trim().replaceAll("[ :]", "-"));
                lastLevel = level + 1;
                continue;
            } else if (pColormap.matcher(curr).matches()) {
                writer.writeStartElement(
                        curr.substring(0, curr.lastIndexOf(':')).trim().replaceAll("[ :]", "-"));
                writer.writeAttribute("colors", curr.split(": ")[1].trim());
                lastLevel = level + 1;
                continue;
            }
            entry = curr.split(": ");
            if (entry.length == 2) {
                if (!valueEntry) {
                    writer.writeStartElement(entry[0].trim().replaceAll("[ :]", "-"));
                    writer.writeCharacters(entry[1]);
                    writer.writeEndElement();
                } else {
                    writer.writeEmptyElement("value");
                    writer.writeAttribute("key", entry[0].trim().replaceAll("[ :]", "-"));
                    writer.writeAttribute("data", entry[1]);
                    //                        writer.writeEndElement();
                }
            } else {
                //                    System.out.println("unknown line: "+curr);
            }
            lastLevel = level;
        }
    } catch (Exception e) {
        LOG.error("Error at [" + curr + "]:" + e.getMessage(), e);
    }
    writer.writeEndDocument();
    writer.flush();
    writer.close();
    return sw.getBuffer().toString();
}

From source file:com.predic8.membrane.core.interceptor.balancer.XMLElementSessionIdExtractor.java

@Override
public void write(XMLStreamWriter out) throws XMLStreamException {

    out.writeStartElement("xmlSessionIdExtractor");

    out.writeAttribute("localName", localName);
    out.writeAttribute("namespace", namespace);

    out.writeEndElement();
}

From source file:com.pocketsoap.salesforce.soap.SoapRequestEntity.java

protected void writeElementString(XMLStreamWriter w, String elemNamespace, String elemName, String elemValue)
        throws XMLStreamException {
    if (elemValue == null)
        return;//  w w w  . j av a2  s.  co  m
    w.writeStartElement(elemNamespace, elemName);
    w.writeCharacters(elemValue);
    w.writeEndElement();
}

From source file:org.unitedinternet.cosmo.dav.CosmoDavException.java

protected void writeContent(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement(NS_COSMO, "internal-server-error");
    if (getMessage() != null) {
        writer.writeCharacters(getMessage());
    }/*  w w w .  j a  va2 s .co  m*/
    writer.writeEndElement();
}

From source file:org.maodian.flyingcat.xmpp.codec.BindCodec.java

@Override
public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException {
    Bind bind = (Bind) object;/* ww  w .  j a va  2s . co m*/
    xmlsw.writeStartElement("bind");
    xmlsw.writeDefaultNamespace(XmppNamespace.BIND);

    xmlsw.writeStartElement("jid");
    xmlsw.writeCharacters(bind.getJabberId());

    xmlsw.writeEndElement();
    xmlsw.writeEndElement();
}