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:de.qucosa.webapi.v1.SearchResource.java

private ResponseEntity<String> scrollAndBuildResultList(SearchResponse searchResponse)
        throws XMLStreamException, ParseException {
    StringWriter sw = new StringWriter();
    XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw);

    SearchHits searchHits = searchResponse.getHits();

    w.writeStartDocument("UTF-8", "1.0");
    w.writeStartElement("Opus");
    {/*from   w ww.  j  a  v  a 2s .c  o m*/
        w.writeStartElement("SearchResult");
        {
            w.writeStartElement("Search");
            w.writeAttribute("hits", String.valueOf(searchHits.getTotalHits()));
            w.writeEndElement();
            w.writeStartElement("ResultList");
            w.writeNamespace(XLINK_NAMESPACE_PREFIX, XLINK_NAMESPACE);

            SearchResponse scrollResponse = searchResponse;
            int hitcount = 0;
            while (true) {
                hitcount = writeResultElements(w, searchHits, hitcount);
                scrollResponse = elasticSearchClient.prepareSearchScroll(scrollResponse.getScrollId())
                        .setScroll(new TimeValue(60, TimeUnit.SECONDS)).execute().actionGet();
                searchHits = scrollResponse.getHits();
                if (searchHits.getHits().length == 0) {
                    log.debug("Stop scrolling at hitcount: {}", hitcount);
                    break;
                }
            }

            w.writeEndElement();
        }
        w.writeEndElement();
    }
    w.writeEndElement();
    w.writeEndDocument();
    w.flush();

    log.debug(sw.toString());

    return new ResponseEntity<>(sw.toString(), HttpStatus.OK);
}

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

@Override
public void encode(Object object, XMLStreamWriter xmlsw) throws XMLStreamException {
    Roster roster = (Roster) object;// w ww .j ava 2 s. co  m
    xmlsw.writeStartElement("", "query", XmppNamespace.ROSTER);
    xmlsw.writeDefaultNamespace(XmppNamespace.ROSTER);
    writeAttributeIfNotBlank(xmlsw, "ver", roster.getVersion());
    for (Contact c : roster) {
        xmlsw.writeEmptyElement("", "item", XmppNamespace.ROSTER);
        writeRequiredAttribute(xmlsw, "jid", c.getJabberId());
        writeAttributeIfNotBlank(xmlsw, "name", c.getName());
        writeAttributeIfNotBlank(xmlsw, "subscription", c.getSubscription());
        writeAttributeIfNotBlank(xmlsw, "ask", c.getAsk());
    }
    xmlsw.writeEndElement();
}

From source file:com.concursive.connect.web.modules.api.services.BackupService.java

public boolean process(TransactionItem transactionItem, Connection db) throws Exception {

    LOG.debug("Backup requested...");

    // TODO: Fix cyclical/endless backups; need to keep an array of ids already archived
    // TODO: Fix if lookup value is -1, then a lookup is not needed

    DataRecordFactory factory = DataRecordFactory.INSTANCE;

    // Override the default response packet so that the returned data records
    // can be replayed using the RestoreService; stream the output
    PacketContext packetContext = transactionItem.getPacketContext();
    packetContext.setReturnType(PacketContext.RETURN_DATARECORDS);

    // Start with the original record(s) being backed up
    LOG.debug("Performing buildList query");
    Object object = transactionItem.getObject();
    if (object instanceof java.util.AbstractList || object instanceof java.util.AbstractMap) {
        Object result = TransactionItem.doExecute(transactionItem.getObject(), db, TransactionItem.SELECT,
                packetContext, "buildList");
        // TODO: check result
    } else {/* w  w w . j a  v a 2s .  com*/
        Object newObject = ObjectUtils.constructObject(object.getClass(), db, ObjectUtils.getParamAsInt(object,
                factory.retrieveUniqueField(transactionItem.getName() + "List")));
        transactionItem.setObject(newObject);
    }

    // Start backup recursion...
    //   Consider lower-memory options to stream records without holding in memory
    //   option 1: use pagedList to get x record(s) at a time
    //   option 2: consider queue for limiting backup requests and asynchronous backups

    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    OutputStream outputStream = null;
    if (packetContext.getOutputStream() == null) {
        outputStream = packetContext.getResponse().getOutputStream();
    } else {
        outputStream = packetContext.getOutputStream();
    }
    XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream, "utf-8");
    writer.writeStartDocument();
    writer.writeCharacters(System.getProperty("line.separator"));
    writer.writeStartElement("concursive");
    writer.writeCharacters(System.getProperty("line.separator"));

    ArrayList<String> addedRecords = new ArrayList<String>();
    addRecords(writer, transactionItem.getObject(), transactionItem, packetContext, db, addedRecords);
    writer.writeEndElement();
    writer.writeCharacters(System.getProperty("line.separator"));
    writer.flush();
    writer.close();

    return true;
}

From source file:com.norconex.committer.idol.IdolCommitter.java

@Override
protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("host");
    writer.writeCharacters(getHost());/*from   w  w  w  . j av a  2s. c om*/
    writer.writeEndElement();

    writer.writeStartElement("cfsPort");
    writer.writeCharacters(Integer.toString(getCfsPort()));
    writer.writeEndElement();

    writer.writeStartElement("indexPort");
    writer.writeCharacters(Integer.toString(getIndexPort()));
    writer.writeEndElement();

    writer.writeStartElement("databaseName");
    writer.writeCharacters(getDatabaseName());
    writer.writeEndElement();

    writer.writeStartElement("dreAddDataParams");
    for (String key : dreAddDataParams.keySet()) {
        writer.writeStartElement("param");
        writer.writeAttribute(key, key);
        writer.writeCharacters(dreAddDataParams.get(key));
        writer.writeEndElement();
    }
    writer.writeEndElement();

    writer.writeStartElement("dreDeleteRefParams");
    for (String key : dreDeleteRefParams.keySet()) {
        writer.writeStartElement("param");
        writer.writeAttribute(key, key);
        writer.writeCharacters(dreDeleteRefParams.get(key));
        writer.writeEndElement();
    }
    writer.writeEndElement();
}

From source file:com.norconex.collector.http.sitemap.impl.DefaultSitemapResolver.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*www .  j  ava 2  s .c  o  m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("sitemap");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeAttribute("lenient", Boolean.toString(lenient));
        if (sitemapLocations != null) {
            for (String location : sitemapLocations) {
                writer.writeStartElement("location");
                writer.writeCharacters(location);
                writer.writeEndElement();
            }
        }
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

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

@Override
protected HttpUriRequest createRequest() {
    final Writer body = new StringBuilderWriter();
    try {// w  w w .j  a  v  a2  s  .  co m
        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.writeStartElement("set");
        writer.writeStartElement("prop");
        writer.setPrefix(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE);
        writer.writeStartElement(XmlConstants.SUBVERSION_DAV_NAMESPACE, "log");
        writer.writeNamespace(XmlConstants.SUBVERSION_DAV_PREFIX, XmlConstants.SUBVERSION_DAV_NAMESPACE);
        writer.writeCharacters(message);
        writer.writeEndElement(); // log
        writer.writeEndElement(); // prop
        writer.writeEndElement(); // set
        writer.writeEndElement(); // propertyupdate
        writer.writeEndDocument();
        writer.close();
    } catch (final XMLStreamException e) {
        throw new SubversionException("could not create request body", e);
    }

    final URI uri = URIUtils.createURI(repository, resource);
    final DavTemplateRequest request = new DavTemplateRequest("PROPPATCH", uri);
    request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML));
    return request;
}

From source file:com.norconex.committer.idol.IdolCommitter.java

/**
 * Commits the addition operations.//from  ww w.j  a  v  a 2  s. com
 * @param addOperations additions
 */
public void dreAddData(List<IAddOperation> addOperations) {
    if (addOperations.isEmpty()) {
        return;
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Sending " + addOperations.size() + " documents for addition to " + createURL());
    }

    StringBuilder b = new StringBuilder();
    b.append(createURL());

    if (isCFS()) {
        b.append("action=ingest&adds=");
        StringWriter xml = new StringWriter();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        try {
            XMLStreamWriter writer = factory.createXMLStreamWriter(xml);
            writer.writeStartElement("adds");
            buildCfsXmlBatchContent(writer, addOperations);
            writer.writeEndElement();
            writer.flush();
            writer.close();
            b.append(URLEncoder.encode(xml.toString(), CharEncoding.UTF_8));
        } catch (Exception e) {
            throw new CommitterException("Cannot create XML.", e);
        }
        postToIDOL(b.toString(), StringUtils.EMPTY);
    } else {
        b.append("DREADDDATA?");
        QueryString qs = new QueryString();
        for (String key : dreAddDataParams.keySet()) {
            qs.addString(key, dreAddDataParams.get(key));
        }
        String addURL = qs.applyOnURL(b.toString());
        String idxBatch = buildIdxBatchContent(addOperations);
        postToIDOL(addURL, idxBatch);
    }
    if (LOG.isInfoEnabled()) {
        LOG.debug("Done sending additions to " + createURL());
    }
}

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

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {
    //Start Application Context
    writer.writeStartElement("ApplicationContext");

    //Write Structure
    if (!StringUtils.isEmpty(m_structure)) {
        writer.writeStartElement("Structure");
        writer.writeCData(m_structure);/* w  w  w . ja v  a  2s.c  om*/
        writer.writeEndElement();

    }

    //Write Default Instance
    if (!StringUtils.isEmpty(m_defaultInstance)) {
        FioranoStackSerializer.writeElement("DefaultInstance", m_defaultInstance, writer);
    }

    //Write Root Element
    if (!StringUtils.isEmpty(m_rootElement)) {
        FioranoStackSerializer.writeElement("RootElement", m_rootElement, writer);

    }

    //Write Root Element Namespace
    if (!StringUtils.isEmpty(m_rootElementNamespace)) {
        FioranoStackSerializer.writeElement("RootElementNamespace", m_rootElementNamespace, writer);

    }

    //Write Structure Type
    FioranoStackSerializer.writeElement("StructureType", String.valueOf(m_structureType), writer);

    //End Application Context
    writer.writeEndElement();

}

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

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

    writer.writeStartElement(ELEM_LOG_MANAGER);
    {/*from  www.ja  v  a2s .co m*/
        writer.writeAttribute(ATTR_LOGGER_CLASS, loggerClass);

        Iterator iter = props.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            writer.writeStartElement(ELEM_PARAM);
            {
                writer.writeAttribute(ATTR_PROPERTY_NAME, (String) entry.getKey());
                writer.writeCharacters((String) entry.getValue());
            }
            writer.writeEndElement();
        }
    }
    writer.writeEndElement();
}

From source file:de.huxhorn.sulky.plist.impl.PropertyListWriter.java

public void write(XMLStreamWriter writer, PropertyList object, boolean isRoot) throws XMLStreamException {
    if (isRoot) {
        writer.writeStartDocument("utf-8", "1.0");
        writer.writeCharacters("\n");
        writer.writeDTD(/*from   www. ja  v a2 s .c o m*/
                "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
        writer.writeCharacters("\n");
    }
    StaxUtilities.writeStartElement(writer, null, null, PLIST_NODE);
    StaxUtilities.writeAttribute(writer, false, null, null, PLIST_VERSION_ATTRIBUTE, PLIST_VERSION);

    if (object != null) {
        writeValue(writer, object.getRoot());
    }

    writer.writeEndElement();
    if (isRoot) {
        writer.writeEndDocument();
    }
}