Search in sources :

Example 11 with Processor

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

the class XQueryEvaluatorSAXHandler method call.

@Override
public Void call() throws Exception {
    try {
        final Processor proc = new Processor(false);
        final Configuration config = proc.getUnderlyingConfiguration();
        final NodeInfo doc = new DocumentWrapper(mSession, config);
        final XQueryCompiler comp = proc.newXQueryCompiler();
        final XQueryExecutable exp = comp.compile(mExpression);
        final net.sf.saxon.s9api.XQueryEvaluator exe = exp.load();
        exe.setSource(doc);
        exe.run(new SAXDestination(mHandler));
        return null;
    } catch (final SaxonApiException e) {
        LOGGER.error("Saxon Exception: " + e.getMessage(), e);
        throw e;
    }
}
Also used : XQueryExecutable(net.sf.saxon.s9api.XQueryExecutable) DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) NodeInfo(net.sf.saxon.om.NodeInfo) XQueryCompiler(net.sf.saxon.s9api.XQueryCompiler) SAXDestination(net.sf.saxon.s9api.SAXDestination) SaxonApiException(net.sf.saxon.s9api.SaxonApiException)

Example 12 with Processor

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

the class XSLTEvaluator method call.

@Override
public OutputStream call() {
    final Processor proc = new Processor(false);
    final XsltCompiler comp = proc.newXsltCompiler();
    XsltExecutable exp;
    XdmNode source;
    try {
        final Configuration config = proc.getUnderlyingConfiguration();
        final NodeInfo doc = new DocumentWrapper(mSession, config);
        exp = comp.compile(new StreamSource(mStylesheet));
        source = proc.newDocumentBuilder().build(doc);
        if (mSerializer == null) {
            final Serializer out = new Serializer();
            out.setOutputProperty(Serializer.Property.METHOD, "xml");
            out.setOutputProperty(Serializer.Property.INDENT, "yes");
            out.setOutputStream(mOut);
            mSerializer = out;
        } else {
            mSerializer.setOutputStream(mOut);
        }
        final XsltTransformer trans = exp.load();
        trans.setInitialContextNode(source);
        trans.setDestination(mSerializer);
        trans.transform();
    } catch (final SaxonApiException e) {
        LOGGER.error("Saxon exception: " + e.getMessage(), e);
    } catch (final SirixException e) {
        LOGGER.error("TT exception: " + e.getMessage(), e);
    }
    return mOut;
}
Also used : DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) NodeInfo(net.sf.saxon.om.NodeInfo) StreamSource(javax.xml.transform.stream.StreamSource) XsltTransformer(net.sf.saxon.s9api.XsltTransformer) SirixException(org.sirix.exception.SirixException) XsltCompiler(net.sf.saxon.s9api.XsltCompiler) XdmNode(net.sf.saxon.s9api.XdmNode) SaxonApiException(net.sf.saxon.s9api.SaxonApiException) XsltExecutable(net.sf.saxon.s9api.XsltExecutable) Serializer(net.sf.saxon.s9api.Serializer)

Example 13 with Processor

use of net.sf.saxon.s9api.Processor 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)

Example 14 with Processor

use of net.sf.saxon.s9api.Processor in project jmeter by apache.

the class XPathUtilTest method testBug63033.

@Test
public void testBug63033() throws SaxonApiException {
    Processor p = new Processor(false);
    XPathCompiler c = p.newXPathCompiler();
    c.declareNamespace("age", "http://www.w3.org/2003/01/geo/wgs84_pos#");
    String xPathQuery = "//Employees/Employee[1]/age:ag";
    XPathExecutable e = c.compile(xPathQuery);
    XPathSelector selector = e.load();
    selector.setContextItem(p.newDocumentBuilder().build(new StreamSource(new StringReader(xmlDoc))));
    XdmValue nodes = selector.evaluate();
    XdmItem item = nodes.itemAt(0);
    assertEquals("<age:ag xmlns:age=\"http://www.w3.org/2003/01/geo/wgs84_pos#\">29</age:ag>", item.toString());
}
Also used : XdmValue(net.sf.saxon.s9api.XdmValue) Processor(net.sf.saxon.s9api.Processor) XPathCompiler(net.sf.saxon.s9api.XPathCompiler) XPathSelector(net.sf.saxon.s9api.XPathSelector) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) XPathExecutable(net.sf.saxon.s9api.XPathExecutable) XdmItem(net.sf.saxon.s9api.XdmItem) Test(org.junit.jupiter.api.Test)

Example 15 with Processor

use of net.sf.saxon.s9api.Processor in project jmeter by apache.

the class XPathQueryCacheLoader method load.

@Override
public XPathExecutable load(ImmutablePair<String, String> key) throws Exception {
    String xPathQuery = key.left;
    String namespacesString = key.right;
    Processor processor = XPathUtil.getProcessor();
    XPathCompiler xPathCompiler = processor.newXPathCompiler();
    List<String[]> namespacesList = XPathUtil.namespacesParse(namespacesString);
    log.debug("Parsed namespaces:{} into list of namespaces:{}", namespacesString, namespacesList);
    for (String[] namespaces : namespacesList) {
        xPathCompiler.declareNamespace(namespaces[0], namespaces[1]);
    }
    log.debug("Declared namespaces:{}, now compiling xPathQuery:{}", namespacesList, xPathQuery);
    return xPathCompiler.compile(xPathQuery);
}
Also used : Processor(net.sf.saxon.s9api.Processor) XPathCompiler(net.sf.saxon.s9api.XPathCompiler)

Aggregations

Processor (net.sf.saxon.s9api.Processor)15 NodeInfo (net.sf.saxon.om.NodeInfo)8 Configuration (net.sf.saxon.Configuration)7 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)7 StreamSource (javax.xml.transform.stream.StreamSource)5 Serializer (net.sf.saxon.s9api.Serializer)5 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)5 File (java.io.File)4 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)4 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)4 XsltCompiler (net.sf.saxon.s9api.XsltCompiler)4 XsltExecutable (net.sf.saxon.s9api.XsltExecutable)4 XsltTransformer (net.sf.saxon.s9api.XsltTransformer)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StringReader (java.io.StringReader)3 NameTest (net.sf.saxon.pattern.NameTest)3 XPathCompiler (net.sf.saxon.s9api.XPathCompiler)3 XdmItem (net.sf.saxon.s9api.XdmItem)3 XdmNode (net.sf.saxon.s9api.XdmNode)3