use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class SelfSelector method match.
public NodeProxy match(DocumentImpl doc, NodeId nodeId) {
final NodeProxy p = new NodeProxy(doc, nodeId);
final NodeProxy contextNode = context.get(doc, nodeId);
if (contextNode != null) {
if (Expression.NO_CONTEXT_ID != contextId) {
p.deepCopyContext(contextNode, contextId);
} else {
p.addContextNode(contextId, p);
}
p.addMatches(contextNode);
return p;
} else {
return null;
}
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class GeneralComparison method nodeSetCompare.
/**
* Optimized implementation, which can be applied if the left operand returns a node set. In this case, the left expression is executed first. All
* matching context nodes are then passed to the right expression.
*
* @param nodes DOCUMENT ME!
* @param contextSequence DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws XPathException DOCUMENT ME!
*/
protected Sequence nodeSetCompare(NodeSet nodes, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().message(this, Profiler.OPTIMIZATION_FLAGS, "OPTIMIZATION CHOICE", "nodeSetCompare");
}
if (LOG.isTraceEnabled()) {
LOG.trace("No index: fall back to nodeSetCompare");
}
final long start = System.currentTimeMillis();
final NodeSet result = new NewArrayNodeSet();
final Collator collator = getCollator(contextSequence);
if ((contextSequence != null) && !contextSequence.isEmpty() && !contextSequence.getDocumentSet().contains(nodes.getDocumentSet())) {
for (final NodeProxy item : nodes) {
ContextItem context = item.getContext();
if (context == null) {
throw (new XPathException(this, "Internal error: context node missing"));
}
final AtomicValue lv = item.atomize();
do {
final Sequence rs = getRight().eval(context.getNode().toSequence());
for (final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
final AtomicValue rv = i2.nextItem().atomize();
if (compareAtomic(collator, lv, rv)) {
result.add(item);
}
}
} while ((context = context.getNextDirect()) != null);
}
} else {
for (final NodeProxy item : nodes) {
final AtomicValue lv = item.atomize();
final Sequence rs = getRight().eval(contextSequence);
for (final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
final AtomicValue rv = i2.nextItem().atomize();
if (compareAtomic(collator, lv, rv)) {
result.add(item);
}
}
}
}
if (context.getProfiler().traceFunctions()) {
context.getProfiler().traceIndexUsage(context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.NO_INDEX, System.currentTimeMillis() - start);
}
return (result);
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class Shared method getStreamSource.
public static StreamSource getStreamSource(Item item, XQueryContext context) throws XPathException, IOException {
final StreamSource streamSource = new StreamSource();
if (item.getType() == Type.JAVA_OBJECT) {
LOG.debug("Streaming Java object");
final Object obj = ((JavaObjectValue) item).getObject();
if (!(obj instanceof File)) {
throw new XPathException("Passed java object should be a File");
}
final File inputFile = (File) obj;
final InputStream is = new FileInputStream(inputFile);
streamSource.setInputStream(is);
streamSource.setSystemId(inputFile.toURI().toURL().toString());
} else if (item.getType() == Type.ANY_URI) {
LOG.debug("Streaming xs:anyURI");
// anyURI provided
String url = item.getStringValue();
// Fix URL
if (url.startsWith("/")) {
url = "xmldb:exist://" + url;
}
final InputStream is = new URL(url).openStream();
streamSource.setInputStream(is);
streamSource.setSystemId(url);
} else if (item.getType() == Type.ELEMENT || item.getType() == Type.DOCUMENT) {
LOG.debug("Streaming element or document node");
if (item instanceof NodeProxy) {
final NodeProxy np = (NodeProxy) item;
final String url = "xmldb:exist://" + np.getOwnerDocument().getBaseURI();
LOG.debug("Document detected, adding URL {}", url);
streamSource.setSystemId(url);
}
// Node provided
final DBBroker broker = context.getBroker();
final ConsumerE<ConsumerE<Serializer, IOException>, IOException> withSerializerFn = fn -> {
final Serializer serializer = broker.borrowSerializer();
try {
fn.accept(serializer);
} finally {
broker.returnSerializer(serializer);
}
};
final NodeValue node = (NodeValue) item;
final InputStream is = new NodeInputStream(context.getBroker().getBrokerPool(), withSerializerFn, node);
streamSource.setInputStream(is);
} else if (item.getType() == Type.BASE64_BINARY || item.getType() == Type.HEX_BINARY) {
LOG.debug("Streaming base64 binary");
final BinaryValue binary = (BinaryValue) item;
final byte[] data = binary.toJavaObject(byte[].class);
final InputStream is = new UnsynchronizedByteArrayInputStream(data);
streamSource.setInputStream(is);
if (item instanceof Base64BinaryDocument) {
final Base64BinaryDocument b64doc = (Base64BinaryDocument) item;
final String url = "xmldb:exist://" + b64doc.getUrl();
LOG.debug("Base64BinaryDocument detected, adding URL {}", url);
streamSource.setSystemId(url);
}
} else {
LOG.error("Wrong item type {}", Type.getTypeName(item.getType()));
throw new XPathException("wrong item type " + Type.getTypeName(item.getType()));
}
return streamSource;
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class FindLastModified method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
final NodeSet nodes = args[0].toNodeSet();
if (nodes.isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
final NodeSet result = new NewArrayNodeSet();
final DateTimeValue dtv = (DateTimeValue) args[1].itemAt(0);
final long lastModified = dtv.getDate().getTime();
for (final NodeProxy proxy : nodes) {
final DocumentImpl doc = proxy.getOwnerDocument();
final long modified = doc.getLastModified();
boolean matches;
if (this.isCalledAs("find-last-modified-since")) {
matches = modified > lastModified;
} else {
matches = modified <= lastModified;
}
if (matches) {
result.add(proxy);
}
}
return result;
}
Aggregations