Search in sources :

Example 56 with Resource

use of org.xmldb.api.base.Resource in project exist by eXist-db.

the class XQueryTriggerTest method documentBinaryDelete.

/**
 * test a trigger fired by a Binary Document Delete
 */
@Test
public void documentBinaryDelete() throws XMLDBException {
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    // this will fire the trigger
    final Resource res = testCollection.createResource(BINARY_DOCUMENT_NAME, "BinaryResource");
    final byte[] content = Base64.decodeBase64(BINARY_DOCUMENT_CONTENT);
    res.setContent(content);
    testCollection.storeResource(res);
    testCollection.removeResource(testCollection.getResource(BINARY_DOCUMENT_NAME));
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    service.setProperty(OutputKeys.INDENT, "no");
    ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(BEFORE + DELETE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + DELETE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(EVENTS);
    assertEquals(4, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger3'][@type = 'prepare'][collection = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "'][uri = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "/" + BINARY_DOCUMENT_NAME + "'][event = 'DELETE-DOCUMENT']/document");
// assertEquals(1, result.getSize());
// assertEquals("<document>" + BINARY_DOCUMENT_CONTENT + "</document>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 57 with Resource

use of org.xmldb.api.base.Resource in project exist by eXist-db.

the class ValueIndexTest method strings.

@Test
public void strings() throws XMLDBException, URISyntaxException {
    configureCollection(CONFIG_PATH);
    XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
    queryResource(service, ITEMS_FILENAME, "//item[@id = 'i2']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[name = 'Racing Bicycle']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[name > 'Racing Bicycle']", 4);
    queryResource(service, ITEMS_FILENAME, "//item[itemno = 3]", 1);
    queryResource(service, ITEMS_FILENAME, "//item[itemno eq 3]", 1);
    ResourceSet result = queryResource(service, ITEMS_FILENAME, "for $i in //item[stock <= 10] return $i/itemno", 5);
    for (long i = 0; i < result.getSize(); i++) {
        Resource res = result.getResource(i);
    }
    queryResource(service, ITEMS_FILENAME, "//item[stock > 20]", 1);
    queryResource(service, ITEMS_FILENAME, "declare namespace x=\"http://www.foo.com\"; //item[x:rating > 8.0]", 2);
    queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test = 123]", 1);
    queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test eq 123]", 1);
    queryResource(service, ITEMS_FILENAME, "//item[mixed = 'uneven']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[mixed eq 'uneven']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[mixed = 'external']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[fn:matches(mixed, 'un.*')]", 2);
    queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = false()]", 2);
    queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = true()]", 1);
    queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice eq true()]", 1);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 58 with Resource

use of org.xmldb.api.base.Resource in project exist by eXist-db.

the class ConcurrencyTest method storeDocs.

private void storeDocs(final String collectionName) throws XMLDBException, IOException, URISyntaxException {
    Collection collection = null;
    try {
        collection = existEmbeddedServer.createCollection(test, collectionName);
        final IndexQueryService iqs = (IndexQueryService) collection.getService("IndexQueryService", "1.0");
        iqs.configureCollection(COLLECTION_CONFIG1);
        for (final String sampleName : SAMPLES.getShakespeareXmlSampleNames()) {
            final Resource resource = collection.createResource(sampleName, XMLResource.RESOURCE_TYPE);
            try (final InputStream is = SAMPLES.getShakespeareSample(sampleName)) {
                resource.setContent(InputStreamUtil.readString(is, UTF_8));
            }
            collection.storeResource(resource);
        }
    } finally {
        if (collection != null) {
            collection.close();
        }
    }
}
Also used : InputStream(java.io.InputStream) IndexQueryService(org.exist.xmldb.IndexQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection)

Example 59 with Resource

use of org.xmldb.api.base.Resource in project exist by eXist-db.

the class CopyCollectionRecoveryTest method xmldbRead.

private void xmldbRead() throws XMLDBException {
    final org.xmldb.api.base.Collection test = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/destination/test3", "admin", "");
    assertNotNull(test);
    final Resource res = test.getResource("test_xmldb.xml");
    assertNotNull("Document should not be null", res);
    final org.xmldb.api.base.Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
    assertNotNull(root);
    final EXistCollectionManagementService mgr = (EXistCollectionManagementService) root.getService("CollectionManagementService", "1.0");
    assertNotNull(mgr);
    mgr.removeCollection("destination");
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Resource(org.xmldb.api.base.Resource) Database(org.xmldb.api.base.Database)

Example 60 with Resource

use of org.xmldb.api.base.Resource in project exist by eXist-db.

the class XmldbApiSecurityTest method chownRes.

@Override
protected void chownRes(final String resourceUri, final String owner_uid, final String group_gid, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
        final Resource resource = col.getResource(getResourceName(resourceUri));
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        ums.chown(resource, ums.getAccount(owner_uid), group_gid);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Aggregations

Resource (org.xmldb.api.base.Resource)173 XMLResource (org.xmldb.api.modules.XMLResource)126 Collection (org.xmldb.api.base.Collection)111 BinaryResource (org.xmldb.api.modules.BinaryResource)86 Test (org.junit.Test)77 UserManagementService (org.exist.xmldb.UserManagementService)52 ResourceSet (org.xmldb.api.base.ResourceSet)46 XMLDBException (org.xmldb.api.base.XMLDBException)38 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)32 EXistResource (org.exist.xmldb.EXistResource)27 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)25 XPathQueryService (org.xmldb.api.modules.XPathQueryService)18 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)16 Path (java.nio.file.Path)11 Database (org.xmldb.api.base.Database)11 XPathException (org.exist.xquery.XPathException)10 InputStream (java.io.InputStream)9 Source (javax.xml.transform.Source)9 BuildException (org.apache.tools.ant.BuildException)9 Diff (org.xmlunit.diff.Diff)9