Search in sources :

Example 1 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) After(org.junit.After)

Example 2 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) StringTokenizer(java.util.StringTokenizer) Collection(org.xmldb.api.base.Collection)

Example 3 with CollectionManagementService

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) XmldbURI(org.exist.xmldb.XmldbURI)

Example 4 with CollectionManagementService

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);
        }
    }
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 5 with CollectionManagementService

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();
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) Before(org.junit.Before)

Aggregations

CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)148 Collection (org.xmldb.api.base.Collection)84 XMLResource (org.xmldb.api.modules.XMLResource)33 Resource (org.xmldb.api.base.Resource)25 Before (org.junit.Before)23 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)21 After (org.junit.After)21 Test (org.junit.Test)19 UserManagementService (org.exist.xmldb.UserManagementService)14 ResourceSet (org.xmldb.api.base.ResourceSet)14 BinaryResource (org.xmldb.api.modules.BinaryResource)13 XPathQueryService (org.xmldb.api.modules.XPathQueryService)9 Account (org.exist.security.Account)7 IndexQueryService (org.exist.xmldb.IndexQueryService)6 AfterClass (org.junit.AfterClass)6 Database (org.xmldb.api.base.Database)6 XMLDBException (org.xmldb.api.base.XMLDBException)6 Path (java.nio.file.Path)5 BeforeClass (org.junit.BeforeClass)5 InputStream (java.io.InputStream)4