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:microsoft.exchange.webservices.data.core.EwsUtilities.java

/**
 * .//w  ww  .  ja  v a  2 s  .c o m
 *
 * @param entryKind the entry kind
 * @param logEntry  the log entry
 * @return the string
 * @throws XMLStreamException the XML stream exception
 * @throws IOException signals that an I/O exception has occurred.
 */
public static String formatLogMessage(String entryKind, String logEntry)
        throws XMLStreamException, IOException {
    String lineSeparator = System.getProperty("line.separator");
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(outStream);
    EwsUtilities.writeTraceStartElement(writer, entryKind, false);
    writer.writeCharacters(lineSeparator);
    writer.writeCharacters(logEntry);
    writer.writeCharacters(lineSeparator);
    writer.writeEndElement();
    writer.writeCharacters(lineSeparator);
    writer.flush();
    writer.close();
    outStream.flush();
    String formattedLogMessage = outStream.toString();
    formattedLogMessage = formattedLogMessage.replaceAll("'", "'");
    formattedLogMessage = formattedLogMessage.replaceAll(""", "\"");
    formattedLogMessage = formattedLogMessage.replaceAll(">", ">");
    formattedLogMessage = formattedLogMessage.replaceAll("&lt;", "<");
    formattedLogMessage = formattedLogMessage.replaceAll("&amp;", "&");
    outStream.close();
    return formattedLogMessage;
}

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(/*  w ww.  j av a2s .  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();
    }
}

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

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*from   w ww  .j a v  a 2s.c  om*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("httpHeadersFetcher");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("validStatusCodes");
        writer.writeCharacters(StringUtils.join(validStatusCodes, ","));
        writer.writeEndElement();
        writer.writeStartElement("headersPrefix");
        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:com.norconex.committer.solr.SolrCommitter.java

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

    writer.writeStartElement("solrUpdateURLParams");
    for (String name : updateUrlParams.keySet()) {
        writer.writeStartElement("param");
        writer.writeAttribute("name", name);
        writer.writeCharacters(updateUrlParams.get(name));
        writer.writeEndElement();
    }
    writer.writeEndElement();
}

From source file:com.norconex.committer.elasticsearch.ElasticsearchCommitter.java

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

    writer.writeStartElement("clusterName");
    writer.writeCharacters(clusterName);
    writer.writeEndElement();//from  ww  w. jav  a  2s  . c o  m

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

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

From source file:com.norconex.committer.elasticsearch_rest.ElasticsearchCommitter.java

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

    writer.writeStartElement("serverUrl");
    writer.writeCharacters(serverUrl);
    writer.writeEndElement();/*from www .ja va  2s  . c o m*/

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

    writer.writeStartElement("typeName");
    writer.writeCharacters(typeName);
    writer.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 va 2 s.  c om*/
        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.jef4.log.FileLogManager.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*from w w w .jav  a 2  s.c  om*/
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("logManager");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("logDir");
        writer.writeCharacters(new File(logdir).getAbsolutePath());
        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.core.impl.FileSystemCommitter.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from  w  w  w.  j av  a2s.  c om
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("committer");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("directory");
        writer.writeCharacters(directory);
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

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//w ww.ja v a  2  s  .  c  om
 * @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;
}