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);
}
}
}
}
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());
}
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());
}
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());
}
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;
}
Aggregations