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:com.norconex.committer.elasticsearch_rest.ElasticsearchCommitter.java

@Override
protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException {

    writer.writeStartElement("serverUrl");
    writer.writeCharacters(serverUrl);//from  w w  w.  j  av  a2  s.c  o m
    writer.writeEndElement();

    writer.writeStartElement("indexName");
    writer.writeCharacters(indexName);
    writer.writeEndElement();

    writer.writeStartElement("typeName");
    writer.writeCharacters(typeName);
    writer.writeEndElement();
}

From source file:com.norconex.collector.http.url.impl.GenericURLNormalizer.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from   www . jav a2  s . c o  m
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("urlNormalizer");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("normalizations");
        writer.writeCharacters(StringUtils.join(normalizations, ","));
        writer.writeEndElement();
        writer.writeStartElement("replacements");
        for (Replace replace : replaces) {
            writer.writeStartElement("replace");
            writer.writeStartElement("match");
            writer.writeCharacters(replace.getMatch());
            writer.writeEndElement();
            writer.writeStartElement("replacement");
            writer.writeCharacters(replace.getReplacement());
            writer.writeEndElement();
            writer.writeEndElement();
        }
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

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

protected void toJXMLString_1(XMLStreamWriter writer, boolean writeCDataSections)
        throws XMLStreamException, FioranoException {
    if (writeCDataSections)
        writeCDATAElement(writer, ELEM_JMS_SCRIPT, jmsScript);
    else {/* w  ww.j av  a 2  s. c  om*/
        if (jmsScriptFile != null) {
            writer.writeStartElement(ELEM_JMS_SCRIPT_FILE);
            writer.writeAttribute(ATTR_NAME, jmsScriptFile);
            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 {/* w  w  w. ja  v  a 2s  . 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:babel.content.pages.PageVersion.java

/**
 * To be called by ObjectWriter only./*ww  w .  ja  v  a2  s  . co  m*/
 * @throws XMLStreamException 
 */
public void persist(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement(XML_TAG_PAGEVERSION);

    if (m_verProps.numKeys() > 0) {
        m_verProps.persist(writer);
    }

    if (m_parseMeta.numKeys() > 0) {
        m_parseMeta.persist(writer);
    }

    if (m_contentMeta.numKeys() > 0) {
        m_contentMeta.persist(writer);
    }

    if (m_outLinks != null) {
        String anchor;

        writer.writeStartElement(XML_TAG_OUT_LINKS);

        for (Outlink outlink : m_outLinks) {
            writer.writeStartElement(XML_TAG_LINK);
            anchor = outlink.getAnchor();

            if ((anchor != null) && (anchor.length() != 0)) {
                writer.writeAttribute(XML_ATTRIB_ANCHOR, anchor);
            }

            writer.writeCharacters(outlink.getToUrl());
            writer.writeEndElement();
        }

        writer.writeEndElement();
    }

    if (m_content.length() > 0) {
        writer.writeStartElement(XML_TAG_CONTENT);
        writer.writeCharacters(new String(Base64.encodeBase64(m_content.getBytes())));
        //writer.writeCharacters(m_content);
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

From source file:com.norconex.committer.cloudsearch.CloudSearchCommitter.java

@Override
protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartElement("documentEndpoint");
    writer.writeCharacters(documentEndpoint);
    writer.writeEndElement();//w w  w.  j a va 2 s  .  c  om

    writer.writeStartElement("accessKey");
    writer.writeCharacters(accessKey);
    writer.writeEndElement();

    writer.writeStartElement("secretKey");
    writer.writeCharacters(secretKey);
    writer.writeEndElement();
}

From source file:com.tamingtext.tagrecommender.ExtractStackOverflowData.java

/** Extract as many as <code>limit</code> questions from the <code>reader</code>
 *  provided, writing them to <code>writer</code>.
 * @param reader//from w  w  w.  ja  v  a 2  s .  com
 * @param writer
 * @param limit
 * @return
 * @throws XMLStreamException
 */
protected int extractXMLData(XMLStreamReader reader, XMLStreamWriter writer, int limit)
        throws XMLStreamException {

    int questionCount = 0;
    int attrCount;
    boolean copyElement = false;

    writer.writeStartDocument();
    writer.writeStartElement("posts");
    writer.writeCharacters("\n");
    while (reader.hasNext() && questionCount < limit) {
        switch (reader.next()) {
        case XMLEvent.START_ELEMENT:
            if (reader.getLocalName().equals("row")) {
                attrCount = reader.getAttributeCount();
                for (int i = 0; i < attrCount; i++) {
                    // copy only the questions.
                    if (reader.getAttributeName(i).getLocalPart().equals("PostTypeId")
                            && reader.getAttributeValue(i).equals("1")) {
                        copyElement = true;
                        break;
                    }
                }

                if (copyElement) {
                    writer.writeCharacters("  ");
                    writer.writeStartElement("row");
                    for (int i = 0; i < attrCount; i++) {
                        writer.writeAttribute(reader.getAttributeName(i).getLocalPart(),
                                reader.getAttributeValue(i));
                    }
                    writer.writeEndElement();
                    writer.writeCharacters("\n");
                    copyElement = false;
                    questionCount++;
                }
            }
            break;
        }
    }
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.flush();
    writer.close();

    return questionCount;
}

From source file:com.fiorano.openesb.application.common.Param.java

public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException {
    //Start Param
    writer.writeStartElement("Param");
    writer.writeAttribute("name", m_paramName);
    writer.writeCharacters(m_paramValue);
    //End Param/*from   w w  w  . j a v a 2 s . c om*/
    writer.writeEndElement();
}

From source file:org.xmlsh.internal.commands.http.java

private void writeHeaders(String outv, StatusLine statusLine, Header[] allHeaders)
        throws XMLStreamException, SaxonApiException, CoreException, IOException {
    OutputPort out = mShell.getEnv().getOutputPort(outv);

    XMLStreamWriter sw = out.asXMLStreamWriter(getSerializeOpts());
    sw.writeStartDocument();// w w w.  j av a2  s  . co  m
    sw.writeStartElement("status");
    sw.writeAttribute("status-code", String.valueOf(statusLine.getStatusCode()));
    sw.writeAttribute("reason", statusLine.getReasonPhrase());
    sw.writeAttribute("protocol-version", statusLine.getProtocolVersion().toString());

    sw.writeEndElement();

    sw.writeStartElement("headers");
    for (Header header : allHeaders) {
        sw.writeStartElement("header");
        sw.writeAttribute("name", header.getName());
        sw.writeAttribute("value", header.getValue());
        sw.writeEndElement();
    }
    sw.writeEndElement();
    sw.writeEndDocument();
    sw.close();

}

From source file:de.qucosa.webapi.v1.SearchResource.java

private ResponseEntity<String> errorResponse(String message, HttpStatus status) throws XMLStreamException {
    StringWriter sw = new StringWriter();
    XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(sw);
    w.writeStartDocument("UTF-8", "1.0");
    w.writeStartElement("Opus");
    w.writeEmptyElement("SearchResult");
    w.writeStartElement("Error");
    w.writeAttribute("message", message);
    w.writeEndElement();//from w w w .  jav  a 2s  .  c  om
    w.writeEndElement();
    w.writeEndDocument();
    w.flush();
    return new ResponseEntity<>(sw.toString(), status);
}