use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class XmldbApiSecurityTest method createGroup.
@Override
protected void createGroup(String group_uid, String uid, String pwd) throws ApiException {
Collection col = null;
try {
col = DatabaseManager.getCollection(getBaseUri() + "/db", uid, pwd);
final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
Group group = new GroupAider("exist", group_uid);
ums.addGroup(group);
} 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.XMLDBException in project exist by eXist-db.
the class XmldbApiSecurityTest method createBinResource.
@Override
protected void createBinResource(String resourceUri, byte[] 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), BinaryResource.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.XMLDBException in project exist by eXist-db.
the class XmldbApiSecurityTest method chmodCol.
@Override
protected void chmodCol(final String collectionUri, final String mode, final String uid, final String pwd) throws ApiException {
Collection col = null;
try {
col = DatabaseManager.getCollection(getBaseUri() + collectionUri, uid, pwd);
final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
ums.chmod(mode);
} 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.XMLDBException in project exist by eXist-db.
the class RemoteDatabaseImplTest method testGetCollection.
@Test
public void testGetCollection() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException, SyntaxException, PermissionDeniedException {
Class<?> cl = Class.forName(DB_DRIVER);
Database database = (Database) cl.newInstance();
DatabaseManager.registerDatabase(database);
Collection rootCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION, "admin", "");
CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0");
Collection adminCollection = cms.createCollection(ADMIN_COLLECTION_NAME);
UserManagementService ums = (UserManagementService) rootCollection.getService("UserManagementService", "1.0");
if (ums != null) {
Permission p = ums.getPermissions(adminCollection);
p.setMode(Permission.USER_STRING + "=+read,+write," + Permission.GROUP_STRING + "=-read,-write," + Permission.OTHER_STRING + "=-read,-write");
ums.setPermissions(adminCollection, p);
Collection guestCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION + "/" + ADMIN_COLLECTION_NAME, "guest", "guest");
Resource resource = guestCollection.createResource("testguest", "BinaryResource");
resource.setContent("123".getBytes());
try {
guestCollection.storeResource(resource);
fail();
} catch (XMLDBException e) {
}
cms.removeCollection(ADMIN_COLLECTION_NAME);
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class XPathUtil method getNode.
/**
* Converts an XMLResource into a NodeProxy.
*
* @param broker The DBBroker to use to access the database
* @param xres The XMLResource to convert
* @return A NodeProxy for accessing the content represented by xres
* @throws XPathException if an XMLDBException is encountered
*/
public static final NodeProxy getNode(DBBroker broker, XMLResource xres) throws XPathException {
if (xres instanceof LocalXMLResource) {
final LocalXMLResource lres = (LocalXMLResource) xres;
try {
return lres.getNode();
} catch (final XMLDBException xe) {
throw new XPathException("Failed to convert LocalXMLResource to node: " + xe.getMessage());
}
}
DocumentImpl document;
try {
document = broker.getCollection(XmldbURI.xmldbUriFor(xres.getParentCollection().getName())).getDocument(broker, XmldbURI.xmldbUriFor(xres.getDocumentId()));
} catch (final URISyntaxException xe) {
throw new XPathException(xe);
} catch (final XMLDBException xe) {
throw new XPathException("Failed to get document for RemoteXMLResource: " + xe.getMessage());
} catch (final PermissionDeniedException pde) {
throw new XPathException("Failed to get document: " + pde.getMessage());
}
final NodeId nodeId = broker.getBrokerPool().getNodeFactory().createFromString(((RemoteXMLResource) xres).getNodeId());
return new NodeProxy(document, nodeId);
}
Aggregations