public static XdmNode makeNode(NodeInfo node) { return new XdmNode(node); }
public static XdmNode makeNode(NodeInfo node) { return new XdmNode(node); }
public XdmNode getDocumentNode() { return new XdmNode(builder.getCurrentRoot()); } }
public XdmNode getDocumentNode() throws SaxonApiException { return new XdmNode(builder.getCurrentRoot()); } }
/** * Abstract method to be supplied by subclasses: output one item in the sequence. * * @param item the item to be written to the sequence */ public void write(Item item) throws XPathException { Location loc; if (locationId == null) { loc = ExplicitLocation.UNKNOWN_LOCATION; } else { loc = locationId.saveLocation(); } listener.message(new XdmNode((NodeInfo) item), terminate, loc); } }
/** * Abstract method to be supplied by subclasses: output one item in the sequence. * * @param item the item to be written to the sequence */ public void write(Item item) throws XPathException { Location loc; if (locationId == null) { loc = ExplicitLocation.UNKNOWN_LOCATION; } else { loc = locationId.saveLocation(); } listener.message(new XdmNode((NodeInfo) item), terminate, loc); } }
public boolean hasFocus(Collection<File> tests) { for (File test : tests) { if (test.exists()) { try { XdmNode node = new XdmNode( processor.getUnderlyingConfiguration().buildDocument(new StreamSource(test))); if (((XdmAtomicValue)xpathCompiler.evaluateSingle("exists(//scenario[@focus])", node)).getBooleanValue()) return true; } catch (SaxonApiException e) { } catch (XPathException e) { } } } return false; }
public XdmNode getDocumentNode() throws SaxonApiException { try { builder.close(); } catch (XPathException e) { throw new SaxonApiException(e); } return new XdmNode(builder.getCurrentRoot()); } }
public XdmNode getDocumentNode() throws SaxonApiException { try { builder.close(); } catch (XPathException e) { throw new SaxonApiException(e); } return new XdmNode(builder.getCurrentRoot()); } }
if (test.exists()) { try { XdmNode node = new XdmNode( processor.getUnderlyingConfiguration().buildDocument(new StreamSource(test))); if (((XdmAtomicValue)xpathCompiler.evaluateSingle("exists(//scenario[@focus])", node)).getBooleanValue())
protected static XdmValue wrap(ValueRepresentation value) { if (value == null) { return null; } else if (value instanceof NodeInfo) { return new XdmNode((NodeInfo)value); } else if (value instanceof AtomicValue) { return new XdmAtomicValue((AtomicValue)value); } else if (value instanceof EmptySequence) { return XdmEmptySequence.getInstance(); } else { return new XdmValue(value); } }
/** * Abstract method to be supplied by subclasses: output one item in the sequence. * * @param item the item to be written to the sequence */ public void write(Item item) throws XPathException { Location loc; if (locationId == null) { loc = ExplicitLocation.UNKNOWN_LOCATION; } else { loc = locationId.saveLocation(); } listener.message(new XdmNode((NodeInfo) item), new QName(errorCode), terminate, loc); } }
/** * Abstract method to be supplied by subclasses: output one item in the sequence. * * @param item the item to be written to the sequence */ public void write(Item item) throws XPathException { Location loc; if (locationId == null) { loc = ExplicitLocation.UNKNOWN_LOCATION; } else { loc = locationId.saveLocation(); } listener.message(new XdmNode((NodeInfo) item), new QName(errorCode), terminate, loc); } }
setInitialContextNode(new XdmNode((NodeInfo) source)); } else if (source instanceof DOMSource) { if (((DOMSource)source).getNode() == null) { DocumentImpl doc = new DocumentImpl(); doc.setConfiguration(controller.getConfiguration()); setInitialContextNode(new XdmNode(doc)); } else { NodeInfo n = processor.getUnderlyingConfiguration().unravel(source); setInitialContextNode(new XdmNode(n));
setInitialContextNode(new XdmNode((NodeInfo) source)); } else if (source instanceof DOMSource) { if (((DOMSource)source).getNode() == null) { DocumentImpl doc = new DocumentImpl(); doc.setConfiguration(controller.getConfiguration()); setInitialContextNode(new XdmNode(doc)); } else { NodeInfo n = processor.getUnderlyingConfiguration().unravel(source); setInitialContextNode(new XdmNode(n));
/** * Perform the query, returning the results as an XdmValue * @return an XdmValue representing the results of the query * @throws SaxonApiException if the query fails with a dynamic error */ public XdmValue evaluate() throws SaxonApiException { try { SequenceIterator iter = expression.iterator(context); ValueRepresentation result = SequenceExtent.makeSequenceExtent(iter); if (result instanceof NodeInfo) { return new XdmNode((NodeInfo)result); } else if (result instanceof AtomicValue) { return new XdmAtomicValue((AtomicValue)result); } else if (result instanceof EmptySequence) { return XdmEmptySequence.getInstance(); } else { return new XdmValue(result); } } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Set the source document for the query. * <p>If the source is an instance of {@link net.sf.saxon.om.NodeInfo}, the supplied node is used * directly as the context node of the query.</p> * <p>If the source is an instance of {@link javax.xml.transform.dom.DOMSource}, the DOM node identified * by the DOMSource is wrapped as a Saxon node, and this is then used as the context item</p> * <p>In all other cases a new Saxon tree is built, by calling * {@link net.sf.saxon.s9api.DocumentBuilder#build(javax.xml.transform.Source)}, and the document * node of this tree is then used as the context item for the query.</p> * * @param source the source document to act as the initial context item for the query. */ public void setSource(Source source) throws SaxonApiException { if (source instanceof NodeInfo) { setContextItem(new XdmNode((NodeInfo) source)); } else if (source instanceof DOMSource) { setContextItem(processor.newDocumentBuilder().wrap(source)); } else { setContextItem(processor.newDocumentBuilder().build(source)); } }
/** * Set the source document for the query. * <p>If the source is an instance of {@link net.sf.saxon.om.NodeInfo}, the supplied node is used * directly as the context node of the query.</p> * <p>If the source is an instance of {@link javax.xml.transform.dom.DOMSource}, the DOM node identified * by the DOMSource is wrapped as a Saxon node, and this is then used as the context item</p> * <p>In all other cases a new Saxon tree is built, by calling * {@link net.sf.saxon.s9api.DocumentBuilder#build(javax.xml.transform.Source)}, and the document * node of this tree is then used as the context item for the query.</p> * * @param source the source document to act as the initial context item for the query. */ public void setSource(Source source) throws SaxonApiException { if (source instanceof NodeInfo) { setContextItem(new XdmNode((NodeInfo) source)); } else if (source instanceof DOMSource) { setContextItem(processor.newDocumentBuilder().wrap(source)); } else { setContextItem(processor.newDocumentBuilder().build(source)); } }
public XdmNode highlight (Query query, NodeInfo node) throws XMLStreamException, SaxonApiException { if (needsPositions(query)) { // A partial workaround for highlighting element text queries with phrases query = replaceFields (query, textFieldName); } scorer = new QueryScorer(query); // grab all the text at once so Lucene's lame-ass highlighter can figure out if there are any // phrases in it... // TODO: is this the Analyzer we're looking for??? OR ... reimplement using different HL Analyzer defaultAnalyzer = new DefaultAnalyzer(); TokenStream textTokens = null; try { textTokens = defaultAnalyzer.tokenStream("xml_text", new CharSequenceReader("")); } catch (IOException e) { } init(new XmlTextTokenStream("xml_text", defaultAnalyzer, textTokens, new XdmNode (node), null, processor)); XmlReader xmlReader = new XmlReader (); xmlReader.addHandler(this); xmlReader.read(node); // setBaseURI (URI.create(node.getBaseURI())); if (getDocument().getUnderlyingNode() instanceof TinyDocumentImpl) { ((TinyDocumentImpl)getDocument().getUnderlyingNode()).setBaseURI(node.getSystemId()); } return getDocument(); }
@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; // Assuming the lux_xml field is configured to use the Lux TinyBinary xml format in the // 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); } } } } }