use of org.xmldb.api.base.Collection 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.xmldb.api.base.Collection in project exist by eXist-db.
the class XmldbApiSecurityTest method createXmlResource.
@Override
protected void createXmlResource(String resourceUri, String content, String uid, String pwd) throws ApiException {
Collection col = null;
try {
col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
Resource resource = col.createResource(getResourceName(resourceUri), XMLResource.RESOURCE_TYPE);
resource.setContent(content);
col.storeResource(resource);
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
} finally {
if (col != null) {
try {
col.close();
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
}
}
}
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method ownerChownGidResource.
/**
* Owner can NOT change the owner gid of a resource
* to a group of which they are not a member
*
* As the user 'test1' attempt to change the
* ownership gid of /db/securityTest1/test.xml
* to 'guest' group
*/
@Test(expected = XMLDBException.class)
public void ownerChownGidResource() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final Resource resource = test.getResource("test.xml");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
// attempt to change gid ownership of /db/securityTest1/test.xml to the guest group
ums.chgrp(resource, "guest");
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method groupChmodResource_asOwner.
@Test
public void groupChmodResource_asOwner() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final Resource resource = test.getResource("test.xml");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
// grant myself all rights ;-)
ums.chmod(resource, 0777);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class XMLDBSecurityTest method worldChownResource.
/**
* only the owner or dba can chown a collection or resource
*/
@Test(expected = XMLDBException.class)
public void worldChownResource() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "guest", "guest");
final Resource resource = test.getResource("test.xml");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
// grant myself all rights ;-)
final Account test2 = ums.getAccount("guest");
ums.chown(resource, test2, "guest");
}
Aggregations