use of org.exist.xquery.value.Sequence in project exist by eXist-db.
the class XMLDBAbstractCollectionManipulator method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
if (0 == args.length) {
throw new XPathException(this, "Expected a collection as the argument " + (paramNumber + 1) + ".");
}
final boolean collectionNeedsClose = false;
Collection collection = null;
final Item item = args[paramNumber].itemAt(0);
if (Type.subTypeOf(item.getType(), Type.NODE)) {
final NodeValue node = (NodeValue) item;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Found node");
}
if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
final org.exist.collections.Collection internalCol = ((NodeProxy) node).getOwnerDocument().getCollection();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Found node");
}
try {
// TODO: use xmldbURI
collection = getLocalCollection(context, internalCol.getURI().toString());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Loaded collection {}", collection.getName());
}
} catch (final XMLDBException e) {
throw new XPathException(this, "Failed to access collection: " + internalCol.getURI(), e);
}
} else {
return Sequence.EMPTY_SEQUENCE;
}
}
if (collection == null) {
// Otherwise, just extract the name as a string:
final String collectionURI = args[paramNumber].getStringValue();
if (collectionURI != null) {
try {
collection = getCollection(context, collectionURI, Optional.empty(), Optional.empty());
} catch (final XMLDBException xe) {
if (errorIfAbsent) {
throw new XPathException(this, "Could not locate collection: " + collectionURI, xe);
}
collection = null;
}
}
if (collection == null && errorIfAbsent) {
throw new XPathException(this, "Unable to find collection: " + collectionURI);
}
}
Sequence s = Sequence.EMPTY_SEQUENCE;
try {
s = evalWithCollection(collection, args, contextSequence);
} finally {
if (collectionNeedsClose && collection != null) {
try {
collection.close();
} catch (final Exception e) {
throw new XPathException(this, "Unable to close collection", e);
}
}
}
return s;
}
use of org.exist.xquery.value.Sequence in project exist by eXist-db.
the class XMLDBMatchCollection method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Sequence result = Sequence.EMPTY_SEQUENCE;
final String regexp = args[0].getStringValue();
final List<String> collectionNames = context.getBroker().findCollectionsMatching(regexp);
if (!collectionNames.isEmpty()) {
result = copyListToValueSequence(collectionNames);
}
return result;
}
use of org.exist.xquery.value.Sequence in project exist by eXist-db.
the class SecurityManagerTest method removedGroupExists.
private boolean removedGroupExists(final DBBroker broker, final String groupName) throws XPathException, PermissionDeniedException {
final XQuery queryService = broker.getBrokerPool().getXQueryService();
final Sequence result = queryService.execute(broker, "declare namespace config='http://exist-db.org/Configuration'; collection('" + REMOVED_GROUPS_URI + "')//config:group[config:name eq '" + groupName + "']", null);
return result.getItemCount() == 1 && result.itemAt(0).toJavaObject(Boolean.class) == true;
}
use of org.exist.xquery.value.Sequence in project exist by eXist-db.
the class XqueryApiTest method createCol.
@Override
protected void createCol(final String collectionName, final String uid, final String pwd) throws ApiException {
final Sequence result = executeQuery(uid, pwd, "xmldb:create-collection('/db', '" + collectionName + "')");
assertEquals("/db/" + collectionName, serialize(result));
}
use of org.exist.xquery.value.Sequence in project exist by eXist-db.
the class FnCollectionSecurityTest method cannotAccessCollectionInCollectionHierarchyWithDeniedExecute.
@Test(expected = PermissionDeniedException.class)
public void cannotAccessCollectionInCollectionHierarchyWithDeniedExecute() throws EXistException, AuthenticationException, PermissionDeniedException, XPathException {
// as docTestUser1 user
final String query = "fn:collection('" + TEST_SUB_COLLECTION_1_1 + "')";
final BrokerPool pool = server.getBrokerPool();
final SecurityManager securityManager = pool.getSecurityManager();
final Subject testUser1 = securityManager.authenticate(TEST_USER_1, TEST_USER_1);
try (final DBBroker broker = pool.get(Optional.of(testUser1));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final XQuery xqueryService = pool.getXQueryService();
final Sequence result = xqueryService.execute(broker, query, null);
fail("Expected PermissionDeniedException via XPathException");
transaction.commit();
} catch (final XPathException e) {
if (e.getCause() != null && e.getCause() instanceof PermissionDeniedException) {
throw (PermissionDeniedException) e.getCause();
} else {
throw e;
}
}
}
Aggregations