use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class TestCase method getResource.
public Resource getResource(Object r) throws XMLDBException {
LocalCollection collection = null;
Subject user = null;
LocalXMLResource res = null;
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
if (r instanceof NodeProxy) {
NodeProxy p = (NodeProxy) r;
res = new LocalXMLResource(user, pool, collection, p);
} else if (r instanceof Node) {
res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
res.setContentAsDOM((Node) r);
} else if (r instanceof AtomicValue) {
res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
res.setContent(r);
} else if (r instanceof LocalXMLResource)
res = (LocalXMLResource) r;
else
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "unknown object " + r.getClass());
try {
Field field = res.getClass().getDeclaredField("outputProperties");
field.setAccessible(true);
field.set(res, new Properties(defaultProperties));
} catch (Exception e) {
}
return res;
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class LuceneFieldConfig method checkCondition.
private boolean checkCondition(DBBroker broker, DocumentImpl document, NodeId nodeId) throws PermissionDeniedException, XPathException {
if (!condition.isPresent()) {
return true;
}
if (compiledCondition == null && isValid) {
compiledCondition = compile(broker, condition.get());
}
if (!isValid) {
return false;
}
final XQuery xquery = broker.getBrokerPool().getXQueryService();
final NodeProxy currentNode = new NodeProxy(document, nodeId);
try {
Sequence result = xquery.execute(broker, compiledCondition, currentNode);
return result != null && result.effectiveBooleanValue();
} catch (PermissionDeniedException | XPathException e) {
isValid = false;
throw e;
} finally {
compiledCondition.reset();
compiledCondition.getContext().reset();
}
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class AbstractFieldConfig method doBuild.
protected void doBuild(DBBroker broker, DocumentImpl document, NodeId nodeId, Document luceneDoc, CharSequence text) throws PermissionDeniedException, XPathException {
if (!expression.isPresent()) {
processText(text, luceneDoc);
return;
}
compile(broker);
if (!isValid) {
return;
}
final XQuery xquery = broker.getBrokerPool().getXQueryService();
final NodeProxy currentNode = new NodeProxy(document, nodeId);
try {
Sequence result = xquery.execute(broker, compiled, currentNode);
if (!result.isEmpty()) {
processResult(result, luceneDoc);
}
} catch (PermissionDeniedException | XPathException e) {
isValid = false;
throw e;
} finally {
compiled.reset();
compiled.getContext().reset();
}
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class DomEnhancingNodeProxyAdapter method create.
public static NodeProxy create(final NodeProxy nodeProxy) {
final Class<? extends Node>[] clazzes = getNodeClasses(nodeProxy);
// NoOp Callback is for NodeProxy calls
// NodeDispatched Callback is for the underlying Node calls
final Callback[] callbacks = { NoOp.INSTANCE, new NodeDispatcher(nodeProxy) };
final CallbackFilter callbackFilter = method -> {
final Class declaringClass = method.getDeclaringClass();
// look for nodes
boolean isMethodOnNode = false;
if (declaringClass.equals(Node.class)) {
isMethodOnNode = true;
} else {
// search parent interfaces
for (final Class iface : declaringClass.getInterfaces()) {
if (iface.equals(Node.class)) {
isMethodOnNode = true;
break;
}
}
}
if (isMethodOnNode) {
// The NodeDispatcher
return 1;
} else {
// The NoOp pass through
return 0;
}
};
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(NodeProxy.class);
enhancer.setInterfaces(clazzes);
enhancer.setCallbackFilter(callbackFilter);
enhancer.setCallbacks(callbacks);
return (NodeProxy) enhancer.create(new Class[] { NodeHandle.class }, new Object[] { nodeProxy });
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class FunResolveQName method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) 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);
}
}
final Sequence qnameSeq = args[0];
if (qnameSeq.isEmpty()) {
return EmptySequence.EMPTY_SEQUENCE;
} else {
context.pushInScopeNamespaces();
final String qnameString = args[0].getStringValue();
if (QName.isQName(qnameString) == VALID.val) {
try {
String prefix = QName.extractPrefix(qnameString);
if (prefix == null) {
prefix = "";
}
String uri = null;
final NodeValue node = (NodeValue) args[1].itemAt(0);
if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
NodeProxy proxy = (NodeProxy) node;
final NodeSet ancestors = proxy.getAncestors(contextId, true);
for (NodeProxy ancestor : ancestors) {
proxy = ancestor;
final ElementImpl e = (ElementImpl) proxy.getNode();
uri = findNamespaceURI(e, prefix);
if (uri != null) {
break;
}
}
} else {
NodeImpl next = (NodeImpl) node;
do {
uri = findNamespaceURI((org.exist.dom.memtree.ElementImpl) next, prefix);
if (uri != null) {
break;
} else {
next = (NodeImpl) next.getParentNode();
}
} while (next != null && next.getNodeType() == Node.ELEMENT_NODE);
}
if (uri == null && prefix != null && !prefix.isEmpty()) {
throw new XPathException(this, ErrorCodes.FONS0004, "No namespace found for prefix. No binding for prefix '" + prefix + "' was found.", args[0]);
}
final String localPart = QName.extractLocalName(qnameString);
final QName qn = new QName(localPart, uri, prefix);
final QNameValue result = new QNameValue(context, qn);
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
context.popInScopeNamespaces();
return result;
} catch (final QName.IllegalQNameException e) {
throw new XPathException(this, ErrorCodes.FOCA0002, "Invalid lexical value. '" + qnameString + "' is not a QName.", args[0]);
}
} else {
throw new XPathException(this, ErrorCodes.FOCA0002, "Invalid lexical value. '" + qnameString + "' is not a QName.", args[0]);
}
}
}
Aggregations