use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class FileTaskTest method fileCleanup.
@After
public void fileCleanup() throws XMLDBException {
final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
service.removeCollection(TEST_COLLECTION_NAME);
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class AbstractXMLDBTask method mkcol.
protected final Collection mkcol(final Collection rootCollection, final String baseURI, String path, final String relPath) throws XMLDBException {
CollectionManagementService mgtService;
Collection current = rootCollection;
Collection collection;
String token;
// /TODO : use dedicated function in XmldbURI
final StringTokenizer tokenizer = new StringTokenizer(relPath, "/");
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
if (path != null) {
path = path + "/" + token;
} else {
path = "/" + token;
}
log("Get collection " + baseURI + path, Project.MSG_DEBUG);
collection = DatabaseManager.getCollection(baseURI + path, user, password);
if (collection == null) {
log("Create collection management service for collection " + current.getName(), Project.MSG_DEBUG);
mgtService = (CollectionManagementService) current.getService("CollectionManagementService", "1.0");
log("Create child collection " + token, Project.MSG_DEBUG);
current = mgtService.createCollection(token);
log("Created collection " + current.getName() + '.', Project.MSG_DEBUG);
} else {
current = collection;
}
}
return (current);
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBCreateTask method mkcol.
private Collection mkcol(final Collection root, final String base, /*String path,*/
final String relPath) throws XMLDBException, URISyntaxException {
CollectionManagementService mgtService;
Collection current = root;
Collection c;
XmldbURI baseUri = XmldbURI.xmldbUriFor(base);
final XmldbURI collPath = XmldbURI.xmldbUriFor(relPath);
log("BASEURI=" + baseUri, Project.MSG_DEBUG);
log("RELPATH=" + relPath, Project.MSG_DEBUG);
// log("PATH=" + path, Project.MSG_DEBUG);
final XmldbURI[] segments = collPath.getPathSegments();
for (final XmldbURI segment : segments) {
baseUri = baseUri.append(segment);
log("Get collection " + baseUri, Project.MSG_DEBUG);
c = DatabaseManager.getCollection(baseUri.toString(), user, password);
if (c == null) {
log("Create collection management service for collection " + current.getName(), Project.MSG_DEBUG);
mgtService = (CollectionManagementService) current.getService("CollectionManagementService", "1.0");
log("Create child collection " + segment);
current = mgtService.createCollection(segment.toString());
log("Created collection " + current.getName() + '.');
} else {
current = c;
}
}
return (current);
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XMLDBRemoveTask method execute.
@Override
public void execute() throws BuildException {
if (uri == null) {
throw (new BuildException("You have to specify an XMLDB collection URI"));
}
if ((resource == null) && (collection == null)) {
throw (new BuildException("Missing parameter: either resource or collection should be specified"));
}
registerDatabase();
try {
log("Get base collection: " + uri, Project.MSG_DEBUG);
final Collection base = DatabaseManager.getCollection(uri, user, password);
if (base == null) {
throw (new BuildException("Collection " + uri + " could not be found."));
}
if (resource != null) {
log("Removing resource: " + resource, Project.MSG_INFO);
final Resource res = base.getResource(resource);
if (res == null) {
final String msg = "Resource " + resource + " not found.";
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
} else {
base.removeResource(res);
}
} else {
log("Removing collection: " + collection, Project.MSG_INFO);
final CollectionManagementService service = (CollectionManagementService) base.getService("CollectionManagementService", "1.0");
service.removeCollection(collection);
}
} catch (final XMLDBException e) {
final String msg = "XMLDB exception during remove: " + e.getMessage();
if (failonerror) {
throw (new BuildException(msg, e));
} else {
log(msg, e, Project.MSG_ERR);
}
}
}
use of org.xmldb.api.modules.CollectionManagementService in project exist by eXist-db.
the class XmldbTaskTest method fileSetup.
@Before
public void fileSetup() throws XMLDBException {
final Collection col = existEmbeddedServer.createCollection(existEmbeddedServer.getRoot(), TEST_COLLECTION_NAME);
final Resource res = col.createResource(TEST_RESOURCE_NAME, XMLResource.RESOURCE_TYPE);
res.setContent("<test>hello <subject>world</subject></test>");
col.storeResource(res);
final Resource binResource = col.createResource(BIN_TEST_RESOURCE_NAME, BinaryResource.RESOURCE_TYPE);
binResource.setContent("blah blah");
col.storeResource(binResource);
final CollectionManagementService service = (CollectionManagementService) col.getService("CollectionManagementService", "1.0");
final Collection otherCol = service.createCollection(OTHER_TEST_COLLECTION_NAME);
final Resource otherRes = otherCol.createResource(OTHER_TEST_RESOURCE_NAME, XMLResource.RESOURCE_TYPE);
otherRes.setContent("<test>other</test>");
otherCol.storeResource(otherRes);
otherCol.close();
col.close();
}
Aggregations