use of org.exist.dom.persistent.NodeSet in project exist by eXist-db.
the class AlternativeStrings method eval.
@Override
public NodeSet eval(final NGramIndexWorker index, final DocumentSet docs, final List<QName> qnames, final NodeSet nodeSet, final int axis, final int expressionId) throws XPathException {
NodeSet result = new ExtArrayNodeSet();
for (String s : strings) {
result.addAll(nGramSearch.fixedStringSearch(index, docs, qnames, s, nodeSet, axis));
}
// ensure result is ready to use
result.iterate();
return result;
}
use of org.exist.dom.persistent.NodeSet in project exist by eXist-db.
the class FunDoctype method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
final MutableDocumentSet docs = new DefaultDocumentSet();
for (int i = 0; i < getArgumentCount(); i++) {
final Sequence seq = getArgument(i).eval(contextSequence, contextItem);
for (final SequenceIterator j = seq.iterate(); j.hasNext(); ) {
final String next = j.nextItem().getStringValue();
try {
context.getBroker().getXMLResourcesByDoctype(next, docs);
} catch (final PermissionDeniedException | LockException e) {
LOG.error(e.getMessage(), e);
throw new XPathException(this, e);
}
}
}
final NodeSet result = new ExtArrayNodeSet(1);
for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext(); ) {
result.add(new NodeProxy(i.next(), NodeId.DOCUMENT_NODE));
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.dom.persistent.NodeSet in project exist by eXist-db.
the class ArrayListValueSequence method toNodeSet.
@Override
public NodeSet toNodeSet() throws XPathException {
if (isEmpty) {
return NodeSet.EMPTY_SET;
}
// for this method to work, all items have to be nodes
if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
final NodeSet set = new NewArrayNodeSet();
for (int i = 0; i <= values.size(); i++) {
NodeValue v = (NodeValue) values.get(i);
if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
// found an in-memory document
final DocumentImpl doc;
if (v.getType() == Type.DOCUMENT) {
doc = (DocumentImpl) v;
} else {
doc = ((NodeImpl) v).getOwnerDocument();
}
if (doc == null) {
continue;
}
// make this document persistent: doc.makePersistent()
// returns a map of all root node ids mapped to the corresponding
// persistent node. We scan the current sequence and replace all
// in-memory nodes with their new persistent node objects.
final DocumentImpl expandedDoc = doc.expandRefs(null);
final org.exist.dom.persistent.DocumentImpl newDoc = expandedDoc.makePersistent();
if (newDoc != null) {
NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
for (int j = i; j <= values.size(); j++) {
v = (NodeValue) values.get(j);
if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
NodeImpl node = (NodeImpl) v;
final Document nodeOwnerDoc;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
nodeOwnerDoc = (Document) node;
} else {
nodeOwnerDoc = node.getOwnerDocument();
}
if (nodeOwnerDoc == doc) {
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
node = expandedDoc.getAttribute(node.getNodeNumber());
} else {
node = expandedDoc.getNode(node.getNodeNumber());
}
NodeId nodeId = node.getNodeId();
if (nodeId == null) {
throw new XPathException("Internal error: nodeId == null");
}
if (node.getNodeType() == Node.DOCUMENT_NODE) {
nodeId = rootId;
} else {
nodeId = rootId.append(nodeId);
}
final NodeProxy p = new NodeProxy(newDoc, nodeId, node.getNodeType());
// replace the node by the NodeProxy
values.set(j, p);
setHasChanged();
}
}
}
set.add((NodeProxy) values.get(i));
}
} else {
set.add((NodeProxy) v);
}
}
// }
return set;
} else {
throw new XPathException("Type error: the sequence cannot be converted into" + " a node set. Item type is " + Type.getTypeName(itemType));
}
}
use of org.exist.dom.persistent.NodeSet in project exist by eXist-db.
the class GMLIndexTest method lowLevelSearch.
@Test
public void lowLevelSearch() throws EXistException, SAXException, ParserConfigurationException, SpatialIndexException, IOException {
GMLHandlerJTS geometryHandler = new GeometryHandler();
GMLFilterGeometry geometryFilter = new GMLFilterGeometry(geometryHandler);
GMLFilterDocument handler = new GMLFilterDocument(geometryFilter);
final BrokerPool pool = server.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
AbstractGMLJDBCIndexWorker indexWorker = (AbstractGMLJDBCIndexWorker) broker.getIndexController().getWorkerByIndexId(AbstractGMLJDBCIndex.ID);
// Unplugged
if (indexWorker != null) {
SAXParserFactory factory = ExistSAXParserFactory.getSAXParserFactory();
factory.setNamespaceAware(true);
InputSource src = new InputSource(new StringReader(IN_MEMORY_GML));
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
SAXAdapter adapter = new SAXAdapter();
reader.setContentHandler(handler);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", adapter);
reader.parse(src);
Geometry EPSG4326_geometry = indexWorker.transformGeometry(currentGeometry, "osgb:BNG", "EPSG:4326");
assertNotNull(EPSG4326_geometry);
NodeSet ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.EQUALS);
assertTrue(ns.getLength() > 0);
ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.DISJOINT);
assertTrue(ns.getLength() > 0);
ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.INTERSECTS);
assertTrue(ns.getLength() > 0);
ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.TOUCHES);
// assertTrue(ns.getLength() > 0);
ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.CROSSES);
// assertTrue(ns.getLength() > 0);
ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.WITHIN);
assertTrue(ns.getLength() > 0);
ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.CONTAINS);
assertTrue(ns.getLength() > 0);
// ns = ((GMLIndexWorker)index.getWorker()).search(broker, EPSG4326_geometry, SpatialOperator.OVERLAPS);
// assertTrue(ns.getLength() > 0);
}
}
}
use of org.exist.dom.persistent.NodeSet in project exist by eXist-db.
the class FilteredExpression method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
Sequence result;
final Sequence seq = expression.eval(contextSequence, contextItem);
if (seq.isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final Predicate pred = predicates.get(0);
context.setContextSequencePosition(0, seq);
// If the predicate is known to return a node set, no special treatment is required.
if (abbreviated && (pred.getExecutionMode() != Predicate.ExecutionMode.NODE || !seq.isPersistentSet())) {
result = new ValueSequence();
if (seq.isPersistentSet()) {
final NodeSet contextSet = seq.toNodeSet();
final Sequence outerSequence = contextSet.getParents(getExpressionId());
for (final SequenceIterator i = outerSequence.iterate(); i.hasNext(); ) {
final NodeValue node = (NodeValue) i.nextItem();
final Sequence newContextSeq = contextSet.selectParentChild((NodeSet) node, NodeSet.DESCENDANT, getExpressionId());
final Sequence temp = processPredicate(outerSequence, newContextSeq);
result.addAll(temp);
}
} else {
final MemoryNodeSet nodes = seq.toMemNodeSet();
final Sequence outerSequence = nodes.getParents(new AnyNodeTest());
for (final SequenceIterator i = outerSequence.iterate(); i.hasNext(); ) {
final NodeValue node = (NodeValue) i.nextItem();
final Sequence newSet = nodes.getChildrenForParent((NodeImpl) node);
final Sequence temp = processPredicate(outerSequence, newSet);
result.addAll(temp);
}
}
} else {
result = processPredicate(contextSequence, seq);
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
Aggregations