Search in sources :

Example 6 with Serializer

use of net.sf.saxon.s9api.Serializer in project sirix by sirixdb.

the class XMLReduce method reduce.

@Override
public void reduce(final DateWritable paramKey, final Iterable<Text> paramValue, final Context paramContext) throws IOException, InterruptedException {
    final StringBuilder builder = new StringBuilder("<root>");
    for (final Text event : paramValue) {
        System.out.println(event.toString());
        builder.append(event.toString());
    }
    builder.append("</root>");
    // System.out.println(builder.toString());
    final Processor proc = new Processor(false);
    final XsltCompiler compiler = proc.newXsltCompiler();
    try {
        final XsltExecutable exec = compiler.compile(new StreamSource(new File(STYLESHEET)));
        final XsltTransformer transform = exec.load();
        transform.setSource(new StreamSource(new StringReader(builder.toString())));
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final Serializer serializer = new Serializer();
        serializer.setOutputStream(out);
        transform.setDestination(serializer);
        transform.transform();
        final String value = out.toString();
        // System.out.println(value);
        paramContext.write(null, new Text(value));
    } catch (final SaxonApiException e) {
        LOGWRAPPER.error(e);
    }
}
Also used : Processor(net.sf.saxon.s9api.Processor) StreamSource(javax.xml.transform.stream.StreamSource) Text(org.apache.hadoop.io.Text) XsltCompiler(net.sf.saxon.s9api.XsltCompiler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SaxonApiException(net.sf.saxon.s9api.SaxonApiException) XsltExecutable(net.sf.saxon.s9api.XsltExecutable) XsltTransformer(net.sf.saxon.s9api.XsltTransformer) StringReader(java.io.StringReader) File(java.io.File) Serializer(net.sf.saxon.s9api.Serializer)

Aggregations

Serializer (net.sf.saxon.s9api.Serializer)6 Processor (net.sf.saxon.s9api.Processor)5 StreamSource (javax.xml.transform.stream.StreamSource)4 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)4 XsltCompiler (net.sf.saxon.s9api.XsltCompiler)4 XsltExecutable (net.sf.saxon.s9api.XsltExecutable)4 XsltTransformer (net.sf.saxon.s9api.XsltTransformer)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 OutputStream (java.io.OutputStream)2 Configuration (net.sf.saxon.Configuration)2 NodeInfo (net.sf.saxon.om.NodeInfo)2 XdmNode (net.sf.saxon.s9api.XdmNode)2 Test (org.junit.Test)2 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)2 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)1 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)1 Text (org.apache.hadoop.io.Text)1