use of org.exist.xquery.value.AnyURIValue in project exist by eXist-db.
the class XMLDBRemove method evalWithCollection.
/* (non-Javadoc)
* @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
*/
public Sequence evalWithCollection(Collection collection, Sequence[] args, Sequence contextSequence) throws XPathException {
if (getSignature().getArgumentCount() == 2) {
final String doc = new AnyURIValue(args[1].itemAt(0).getStringValue()).toXmldbURI().toString();
try {
final Resource resource = collection.getResource(doc);
if (resource == null) {
logger.error("Resource {} not found", doc);
throw new XPathException(this, "Resource " + doc + " not found");
}
collection.removeResource(resource);
} catch (final XMLDBException e) {
logger.error(e.getMessage());
throw new XPathException(this, "XMLDB exception caught: " + e.getMessage(), e);
}
} else {
try {
final CollectionManagementService service = (CollectionManagementService) collection.getService("CollectionManagementService", "1.0");
service.removeCollection(collection.getName());
} catch (final XMLDBException e) {
logger.error("Cannot remove collection: {}", e.getMessage());
throw new XPathException(this, "Cannot remove collection: " + e.getMessage(), e);
}
}
return Sequence.EMPTY_SEQUENCE;
}
use of org.exist.xquery.value.AnyURIValue in project exist by eXist-db.
the class XMLDBHasLock method evalWithCollection.
public Sequence evalWithCollection(Collection collection, Sequence[] args, Sequence contextSequence) throws XPathException {
try {
final UserManagementService ums = (UserManagementService) collection.getService("UserManagementService", "1.0");
final Resource res = collection.getResource(new AnyURIValue(args[1].getStringValue()).toXmldbURI().toString());
if (res != null) {
final String lockUser = ums.hasUserLock(res);
if (lockUser != null && isCalledAs("clear-lock")) {
ums.unlockResource(res);
}
return lockUser == null ? Sequence.EMPTY_SEQUENCE : new StringValue(lockUser);
} else {
logger.error("Unable to locate resource {}", args[1].getStringValue());
throw new XPathException(this, "Unable to locate resource " + args[1].getStringValue());
}
} catch (final XMLDBException e) {
logger.error("Failed to retrieve user lock");
throw new XPathException(this, "Failed to retrieve user lock", e);
}
}
Aggregations