use of org.xmldb.api.base.Resource in project exist by eXist-db.
the class XMLDBMove 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 {
final XmldbURI destination = new AnyURIValue(args[1].itemAt(0).getStringValue()).toXmldbURI();
if (getSignature().getArgumentCount() == 3) {
final XmldbURI doc = new AnyURIValue(args[2].itemAt(0).getStringValue()).toXmldbURI();
try {
final Resource resource = collection.getResource(doc.toString());
if (resource == null) {
logger.error("Resource {} not found", doc);
throw new XPathException(this, "Resource " + doc + " not found");
}
final EXistCollectionManagementService service = (EXistCollectionManagementService) collection.getService("CollectionManagementService", "1.0");
service.moveResource(doc, destination, null);
} catch (final XMLDBException e) {
logger.error(e.getMessage());
throw new XPathException(this, "XMLDB exception caught: " + e.getMessage(), e);
}
} else {
try {
final EXistCollectionManagementService service = (EXistCollectionManagementService) collection.getService("CollectionManagementService", "1.0");
service.move(XmldbURI.xmldbUriFor(collection.getName()), destination, null);
} catch (final XMLDBException e) {
logger.error(e.getMessage());
throw new XPathException(this, "Cannot move collection: " + e.getMessage(), e);
} catch (final URISyntaxException e) {
logger.error(e.getMessage());
throw new XPathException(this, "URI exception: " + e.getMessage(), e);
}
}
return Sequence.EMPTY_SEQUENCE;
}
use of org.xmldb.api.base.Resource 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.Resource 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.Resource 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.Resource 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