Search in sources :

Example 26 with AnyURIValue

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;
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) XPathException(org.exist.xquery.XPathException) AnyURIValue(org.exist.xquery.value.AnyURIValue) Resource(org.xmldb.api.base.Resource) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 27 with AnyURIValue

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);
    }
}
Also used : XPathException(org.exist.xquery.XPathException) AnyURIValue(org.exist.xquery.value.AnyURIValue) Resource(org.xmldb.api.base.Resource) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService) StringValue(org.exist.xquery.value.StringValue)

Aggregations

AnyURIValue (org.exist.xquery.value.AnyURIValue)27 Sequence (org.exist.xquery.value.Sequence)14 XPathException (org.exist.xquery.XPathException)12 BrokerPool (org.exist.storage.BrokerPool)9 DBBroker (org.exist.storage.DBBroker)9 URI (java.net.URI)8 XmldbURI (org.exist.xmldb.XmldbURI)8 XQueryContext (org.exist.xquery.XQueryContext)8 CompiledXQuery (org.exist.xquery.CompiledXQuery)7 XQuery (org.exist.xquery.XQuery)7 StringValue (org.exist.xquery.value.StringValue)7 IOException (java.io.IOException)6 URISyntaxException (java.net.URISyntaxException)6 PermissionDeniedException (org.exist.security.PermissionDeniedException)6 Source (org.exist.source.Source)4 MimeType (org.exist.util.MimeType)4 Resource (org.xmldb.api.base.Resource)4 XMLDBException (org.xmldb.api.base.XMLDBException)4 Path (java.nio.file.Path)3 DBSource (org.exist.source.DBSource)3