use of org.exist.dom.QName in project exist by eXist-db.
the class LuceneIndexTest method configuration.
@Test
public void configuration() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, LockException, IOException, XPathException, QName.IllegalQNameException {
final DocumentSet docs = configureAndStore(COLLECTION_CONFIG4, XML4, "test.xml");
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
checkIndex(docs, broker, new QName[] { new QName("a") }, "x", 1);
checkIndex(docs, broker, new QName[] { new QName("c") }, "x", 1);
final XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute(broker, "/test[ft:query(a, 'x')]", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
seq = xquery.execute(broker, "/test[ft:query(.//c, 'x')]", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
seq = xquery.execute(broker, "/test[ft:query(b, 'x')]", null);
assertNotNull(seq);
assertEquals(0, seq.getItemCount());
}
}
use of org.exist.dom.QName in project exist by eXist-db.
the class Query method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (contextItem != null)
contextSequence = contextItem.toSequence();
if (contextSequence != null && !contextSequence.isPersistentSet())
// in-memory docs won't have an index
return Sequence.EMPTY_SEQUENCE;
NodeSet result;
if (preselectResult == null) {
long start = System.currentTimeMillis();
Sequence input = getArgument(0).eval(contextSequence);
if (!(input instanceof VirtualNodeSet) && input.isEmpty())
result = NodeSet.EMPTY_SET;
else {
NodeSet inNodes = input.toNodeSet();
DocumentSet docs = inNodes.getDocumentSet();
LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
Item key = getKey(contextSequence, contextItem);
List<QName> qnames = null;
if (contextQName != null) {
qnames = new ArrayList<>(1);
qnames.add(contextQName);
}
QueryOptions options = parseOptions(this, contextSequence, contextItem, 3);
try {
if (key != null && Type.subTypeOf(key.getType(), Type.ELEMENT)) {
final Element queryXML = (Element) ((NodeValue) key).getNode();
result = index.query(getExpressionId(), docs, inNodes, qnames, queryXML, NodeSet.ANCESTOR, options);
} else {
final String query = key == null ? null : key.getStringValue();
result = index.query(getExpressionId(), docs, inNodes, qnames, query, NodeSet.ANCESTOR, options);
}
} catch (IOException | org.apache.lucene.queryparser.classic.ParseException e) {
throw new XPathException(this, e.getMessage());
}
}
if (context.getProfiler().traceFunctions()) {
context.getProfiler().traceIndexUsage(context, "lucene", this, PerformanceStats.BASIC_INDEX, System.currentTimeMillis() - start);
}
} else {
// DW: contextSequence can be null
contextStep.setPreloadedData(contextSequence.getDocumentSet(), preselectResult);
result = getArgument(0).eval(contextSequence).toNodeSet();
}
return result;
}
use of org.exist.dom.QName in project exist by eXist-db.
the class RpcConnection method getIndexedElements.
private List<List> getIndexedElements(final XmldbURI collUri, final boolean inclusive) throws EXistException, PermissionDeniedException {
return this.<List<List>>readCollection(collUri).apply((collection, broker, transaction) -> {
final Occurrences[] occurrences = broker.getElementIndex().scanIndexedElements(collection, inclusive);
final List<List> result = new ArrayList<>(occurrences.length);
for (final Occurrences occurrence : occurrences) {
final QName qname = (QName) occurrence.getTerm();
final List temp = new ArrayList(4);
temp.add(qname.getLocalPart());
temp.add(qname.getNamespaceURI());
temp.add(qname.getPrefix() == null ? "" : qname.getPrefix());
temp.add(occurrence.getOccurrences());
result.add(temp);
}
return result;
});
}
use of org.exist.dom.QName in project exist by eXist-db.
the class FunctionFunction method lookupFunction.
private FunctionCall lookupFunction(String funcName, int arity) throws XPathException {
// try to parse the qname
QName qname;
try {
qname = QName.parse(context, funcName, context.getDefaultFunctionNamespace());
} catch (final QName.IllegalQNameException e) {
throw new XPathException(this, ErrorCodes.XPST0081, "No namespace defined for prefix " + funcName);
}
// check if the function is from a module
final Module[] modules = context.getModules(qname.getNamespaceURI());
UserDefinedFunction func = null;
if (isEmpty(modules)) {
func = context.resolveFunction(qname, arity);
} else {
for (final Module module : modules) {
func = ((ExternalModule) module).getFunction(qname, arity, context);
if (func != null) {
if (module.isInternalModule()) {
logger.error("Cannot create a reference to an internal Java function");
throw new XPathException(this, "Cannot create a reference to an internal Java function");
}
break;
}
}
}
if (func == null) {
throw new XPathException(this, Messages.getMessage(Error.FUNC_NOT_FOUND, qname, Integer.toString(arity)));
}
final FunctionCall funcCall = new FunctionCall(context, func);
funcCall.setLocation(line, column);
return funcCall;
}
use of org.exist.dom.QName in project exist by eXist-db.
the class IdFunction method functionId.
/**
* Returns a document describing the accounts of the executing process
*
* @return An in-memory document describing the accounts
*/
private org.exist.dom.memtree.DocumentImpl functionId() throws XPathException {
context.pushDocumentContext();
try {
final MemTreeBuilder builder = context.getDocumentBuilder();
builder.startDocument();
builder.startElement(new QName("id", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
builder.startElement(new QName("real", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
subjectToXml(builder, context.getRealUser());
builder.endElement();
if (context.getRealUser().getId() != context.getEffectiveUser().getId()) {
builder.startElement(new QName("effective", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
subjectToXml(builder, context.getEffectiveUser());
builder.endElement();
}
builder.endElement();
builder.endDocument();
return builder.getDocument();
} finally {
context.popDocumentContext();
}
}
Aggregations