Search in sources :

Example 1 with TinyBinary

use of lux.xml.tinybin.TinyBinary in project ddf by codice.

the class DynamicSchemaResolver method createTinyBinary.

private byte[] createTinyBinary(String xml) throws XMLStreamException, SaxonApiException {
    SaxonDocBuilder builder = new SaxonDocBuilder(processor);
    XmlReader xmlReader = new XmlReader();
    xmlReader.addHandler(builder);
    xmlReader.setStripNamespaces(true);
    xmlReader.read(IOUtils.toInputStream(xml));
    XdmNode node = builder.getDocument();
    TinyTree tinyTree = ((TinyDocumentImpl) node.getUnderlyingNode()).getTree();
    TinyBinary tinyBinary = new TinyBinary(tinyTree, StandardCharsets.UTF_8);
    return tinyBinary.getBytes();
}
Also used : TinyDocumentImpl(net.sf.saxon.tree.tiny.TinyDocumentImpl) TinyTree(net.sf.saxon.tree.tiny.TinyTree) TinyBinary(lux.xml.tinybin.TinyBinary) XmlReader(lux.xml.XmlReader) XdmNode(net.sf.saxon.s9api.XdmNode) SaxonDocBuilder(lux.xml.SaxonDocBuilder)

Example 2 with TinyBinary

use of lux.xml.tinybin.TinyBinary 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)

Aggregations

TinyBinary (lux.xml.tinybin.TinyBinary)2 XdmNode (net.sf.saxon.s9api.XdmNode)2 SaxonDocBuilder (lux.xml.SaxonDocBuilder)1 XmlReader (lux.xml.XmlReader)1 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)1 XdmItem (net.sf.saxon.s9api.XdmItem)1 TinyDocumentImpl (net.sf.saxon.tree.tiny.TinyDocumentImpl)1 TinyTree (net.sf.saxon.tree.tiny.TinyTree)1 Document (org.apache.lucene.document.Document)1 BytesRef (org.apache.lucene.util.BytesRef)1 SolrException (org.apache.solr.common.SolrException)1