Search in sources :

Example 1 with XdmItem

use of net.sf.saxon.s9api.XdmItem in project ddf by codice.

the class XpathFilterCollector method collect.

@Override
public void collect(int docId) throws IOException {
    Document doc = this.context.reader().document(docId);
    BytesRef binaryValue = doc.getBinaryValue(LUX_XML_FIELD_NAME);
    if (binaryValue != null) {
        byte[] bytes = binaryValue.bytes;
        // Lux update chain
        if (bytes.length > 4 && bytes[0] == 'T' && bytes[1] == 'I' && bytes[2] == 'N') {
            TinyBinary tb = new TinyBinary(bytes, TinyBinaryField.UTF8);
            XdmNode node = new XdmNode(tb.getTinyDocument(config));
            try {
                selector.setContextItem(node);
                XdmItem result = selector.evaluateSingle();
                if (result != null && result.size() > 0 && !(result.isAtomicValue() && !((XdmAtomicValue) result).getBooleanValue())) {
                    super.collect(docId);
                }
            } catch (SaxonApiException e) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to evaluate xpath: " + xpath, e);
            }
        }
    }
}
Also used : TinyBinary(lux.xml.tinybin.TinyBinary) Document(org.apache.lucene.document.Document) XdmNode(net.sf.saxon.s9api.XdmNode) SaxonApiException(net.sf.saxon.s9api.SaxonApiException) BytesRef(org.apache.lucene.util.BytesRef) SolrException(org.apache.solr.common.SolrException) XdmItem(net.sf.saxon.s9api.XdmItem)

Example 2 with XdmItem

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

the class TestNodeWrapperS9ApiXPath method testB.

@Test
public void testB() throws Exception {
    final XPathSelector selector = new XPathEvaluator.Builder("//b", mHolder.getSession()).build().call();
    final StringBuilder strBuilder = new StringBuilder();
    strBuilder.append("<result>");
    for (final XdmItem item : selector) {
        strBuilder.append(item.toString());
    }
    strBuilder.append("</result>");
    assertXMLEqual("expected pieces to be similar", "<result><b xmlns:p=\"ns\">foo<c xmlns:p=\"ns\"/></b><b xmlns:p=\"ns\" p:x=\"y\">" + "<c xmlns:p=\"ns\"/>bar</b></result>", strBuilder.toString());
}
Also used : XPathSelector(net.sf.saxon.s9api.XPathSelector) XdmItem(net.sf.saxon.s9api.XdmItem) Test(org.junit.Test)

Example 3 with XdmItem

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

the class TestNodeWrapperS9ApiXPath method testCountB.

@Test
public void testCountB() throws Exception {
    final XPathSelector selector = new XPathEvaluator.Builder("count(//b)", mHolder.getSession()).build().call();
    final StringBuilder sb = new StringBuilder();
    for (final XdmItem item : selector) {
        sb.append(item.getStringValue());
    }
    assertEquals("2", sb.toString());
}
Also used : XPathSelector(net.sf.saxon.s9api.XPathSelector) XdmItem(net.sf.saxon.s9api.XdmItem) Test(org.junit.Test)

Example 4 with XdmItem

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

the class TestNodeWrapperS9ApiXPath method testB2.

@Test
public void testB2() throws Exception {
    final XPathSelector selector = new XPathEvaluator.Builder("//b[2]", mHolder.getSession()).build().call();
    final StringBuilder strBuilder = new StringBuilder();
    for (final XdmItem item : selector) {
        strBuilder.append(item.toString());
    }
    assertXMLEqual("expected pieces to be similar", "<b xmlns:p=\"ns\" p:x=\"y\"><c xmlns:p=\"ns\"/>bar</b>", strBuilder.toString());
}
Also used : XPathSelector(net.sf.saxon.s9api.XPathSelector) XdmItem(net.sf.saxon.s9api.XdmItem) Test(org.junit.Test)

Example 5 with XdmItem

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

the class XPathEvaluator method call.

@Override
public XPathSelector call() throws Exception {
    final Processor proc = new Processor(false);
    final Configuration config = proc.getUnderlyingConfiguration();
    final NodeInfo doc = new DocumentWrapper(mSession, mRevision, config);
    final XPathCompiler xpath = proc.newXPathCompiler();
    final DocumentBuilder builder = proc.newDocumentBuilder();
    final XdmItem item = builder.wrap(doc);
    final XPathSelector selector = xpath.compile(mExpression).load();
    selector.setContextItem(item);
    return selector;
}
Also used : DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) XPathCompiler(net.sf.saxon.s9api.XPathCompiler) DocumentBuilder(net.sf.saxon.s9api.DocumentBuilder) NodeInfo(net.sf.saxon.om.NodeInfo) XPathSelector(net.sf.saxon.s9api.XPathSelector) XdmItem(net.sf.saxon.s9api.XdmItem)

Aggregations

XdmItem (net.sf.saxon.s9api.XdmItem)14 XPathSelector (net.sf.saxon.s9api.XPathSelector)9 Test (org.junit.Test)9 XdmValue (net.sf.saxon.s9api.XdmValue)6 StringReader (java.io.StringReader)3 Processor (net.sf.saxon.s9api.Processor)3 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)3 XdmNode (net.sf.saxon.s9api.XdmNode)3 XQueryEvaluator (org.sirix.saxon.evaluator.XQueryEvaluator)3 IOException (java.io.IOException)2 TransformerException (javax.xml.transform.TransformerException)2 SAXSource (javax.xml.transform.sax.SAXSource)2 XPathCompiler (net.sf.saxon.s9api.XPathCompiler)2 XPathExecutable (net.sf.saxon.s9api.XPathExecutable)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1