Example usage for javax.xml.stream XMLStreamWriter writeCharacters

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

Introduction

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

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

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

@Override
protected HttpUriRequest createRequest() {
    final Writer body = new StringBuilderWriter();
    try {//  w  w w. j  a v a  2 s.co m
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("log-report");
        writer.writeDefaultNamespace(XmlConstants.SVN_NAMESPACE);
        writer.writeStartElement("start-revision");
        writer.writeCharacters(start.toString());
        writer.writeEndElement(); // start-revision
        writer.writeStartElement("end-revision");
        writer.writeCharacters(end.toString());
        writer.writeEndElement(); // end-revision
        if (limit > 0) {
            writer.writeStartElement("limit");
            writer.writeCharacters(Integer.toString(limit));
            writer.writeEndElement(); // limit
        }
        writer.writeEmptyElement("discover-changed-paths");
        writer.writeEmptyElement("all-revprops");
        writer.writeEmptyElement("path");
        writer.writeEndElement(); // log-report
        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("REPORT", uri);
    request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML));
    return request;
}

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

private void save(XMLStreamWriter writer, DataRecord record, String recordId, Object object,
        PacketContext context) throws Exception {
    // Data record
    writer.writeCharacters("  ");
    writer.writeStartElement("dataRecord");
    writer.writeAttribute("name", record.getName());
    writer.writeAttribute("id", recordId);
    writer.writeCharacters(System.getProperty("line.separator"));
    // Data fields
    for (DataField thisField : record) {
        writer.writeCharacters("    ");
        writer.writeStartElement(thisField.getName());
        if (thisField.getValue() != null) {
            if (StringUtils.countLines(thisField.getValue()) > 1) {
                writer.writeCData(thisField.getValue());
            } else {
                writer.writeCharacters(thisField.getValue());
            }//  w  w w .  j a v a  2 s .  c om
        } else {
            writer.writeCharacters(DataRecord.NULL);
        }
        writer.writeEndElement();
        writer.writeCharacters(System.getProperty("line.separator"));
    }

    // If this is a file, stream it too
    if (object instanceof FileItem) {
        // Find the file in the filesystem
        File file = new File(context.getBaseFilePath()
                + DateUtils.getDatePath(record.getValueAsTimestamp("modified")) + record.getValue("filename"));
        if (!file.exists()) {
            LOG.error("File not found: " + file.getAbsolutePath());
        } else {
            // If there is a fileAttachment, then attach it as base64
            writer.writeCharacters("    ");
            writer.writeStartElement("fileAttachment");
            // Convert to base64 and append
            writer.writeCData(new String(Base64.encodeBase64(FileUtils.getBytesFromFile(file), true)));
            // Close the element
            writer.writeEndElement();
            writer.writeCharacters(System.getProperty("line.separator"));
        }
    }

    // Close the record
    writer.writeCharacters("  ");
    writer.writeEndElement();
    writer.writeCharacters(System.getProperty("line.separator"));
}

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

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/* w  ww .j  ava2s  .  c  o  m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("urlExtractor");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("maxURLLength");
        writer.writeCharacters(Integer.toString(maxURLLength));
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

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

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

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

From source file:com.norconex.collector.core.filter.impl.ExtensionReferenceFilter.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*from  www .  ja v  a 2  s.  c o m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("filter");
        writer.writeAttribute("class", getClass().getCanonicalName());
        saveToXML(writer);
        writer.writeAttribute("caseSensitive", Boolean.toString(caseSensitive));
        writer.writeCharacters(extensions);
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:com.norconex.collector.core.filter.impl.RegexReferenceFilter.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*from   ww  w . j a  v  a 2s .  co  m*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("filter");
        writer.writeAttribute("class", getClass().getCanonicalName());
        super.saveToXML(writer);
        writer.writeAttribute("caseSensitive", Boolean.toString(caseSensitive));
        writer.writeCharacters(regex == null ? "" : regex);
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:com.norconex.collector.http.robot.impl.DefaultRobotsMetaProvider.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from   ww w  .  j  av  a 2  s.co m
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("robotsMeta");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("headersPrefix");
        if (headersPrefix != null) {
            writer.writeCharacters(headersPrefix);
        }
        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.ResolveOperation.java

@Override
protected HttpUriRequest createRequest() {
    final Writer body = new StringBuilderWriter();
    try {/*from  w  ww  .  ja va2s .  c o m*/
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("get-locations");
        writer.writeDefaultNamespace(XmlConstants.SVN_NAMESPACE);
        writer.writeEmptyElement("path");
        writer.writeStartElement("peg-revision");
        writer.writeCharacters(revision.toString());
        writer.writeEndElement(); // peg-revision
        writer.writeStartElement("location-revision");
        writer.writeCharacters(expected.toString());
        writer.writeEndElement(); // location-revision
        writer.writeEndElement(); //get-locations
        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("REPORT", uri);
    request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML));
    return request;
}

From source file:com.adobe.acs.commons.wcm.impl.SiteMapServlet.java

private void writeElement(final XMLStreamWriter stream, final String elementName, final String text)
        throws XMLStreamException {
    stream.writeStartElement(NS, elementName);
    stream.writeCharacters(text);
    stream.writeEndElement();/* ww  w . j a va2 s  .c  om*/
}

From source file:com.norconex.collector.http.fetch.impl.DefaultDocumentFetcher.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from ww  w  .  j a  va 2  s .c o m
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("httpDocumentFetcher");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("validStatusCodes");
        if (validStatusCodes != null) {
            writer.writeCharacters(StringUtils.join(validStatusCodes));
        }
        writer.writeEndElement();
        writer.writeStartElement("headersPrefix");
        if (headersPrefix != null) {
            writer.writeCharacters(headersPrefix);
        }
        writer.writeEndElement();
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}