Example usage for javax.xml.stream XMLOutputFactory createXMLStreamWriter

List of usage examples for javax.xml.stream XMLOutputFactory createXMLStreamWriter

Introduction

In this page you can find the example usage for javax.xml.stream XMLOutputFactory createXMLStreamWriter.

Prototype

public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;

Source Link

Document

Create a new XMLStreamWriter that writes to a JAXP result.

Usage

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

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {// w  w  w .j a  v  a2s . c  om
        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:com.norconex.collector.http.fetch.impl.DefaultDocumentFetcher.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/* w  w w .  j  ava2s .co  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);
    }
}

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  . j ava  2s  . 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:XMLWriteTest.java

/**
 * Saves the drawing in SVG format, using StAX
 *//*from   www .ja va 2 s.co m*/
public void saveStAX() throws FileNotFoundException, XMLStreamException {
    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;
    File f = chooser.getSelectedFile();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(new FileOutputStream(f));
    comp.writeDocument(writer);
    writer.close();
}

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

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from  w w  w .j  a  v  a2s. c  om
        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.core.impl.FileSystemCommitter.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {/*  w  ww . j av  a 2 s . c o m*/
        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:microsoft.exchange.webservices.data.core.EwsUtilities.java

/**
 * ./* ww w. ja v a2 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:com.norconex.commons.lang.xml.EnhancedXMLStreamWriter.java

public EnhancedXMLStreamWriter(Writer out, boolean writeBlanks) throws XMLStreamException {
    super();//from  ww  w  .j  a  v  a 2 s . co  m
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    writer = factory.createXMLStreamWriter(out);
    this.writeBlanks = writeBlanks;
}

From source file:com.norconex.collector.http.filter.impl.SegmentCountURLFilter.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//from w ww .j a  va2 s  .  co  m
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("filter");
        writer.writeAttribute("class", getClass().getCanonicalName());
        super.saveToXML(writer);
        writer.writeAttribute("count", Integer.toString(count));
        writer.writeAttribute("duplicate", Boolean.toString(duplicate));
        writer.writeAttribute("separator", separator);
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}

From source file:com.norconex.jef4.status.FileJobStatusStore.java

@Override
public void saveToXML(Writer out) throws IOException {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {//www. j a  va  2 s. c o  m
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);
        writer.writeStartElement("statusStore");
        writer.writeAttribute("class", getClass().getCanonicalName());
        writer.writeStartElement("statusDir");
        writer.writeCharacters(new File(statusDir).getAbsolutePath());
        writer.writeEndElement();
        writer.writeEndElement();
        writer.flush();
        writer.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
}