Search in sources :

Example 66 with Resource

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

the class RemoteCollectionTest method createResources.

private void createResources(ArrayList<String> names, String type) throws XMLDBException {
    for (String name : names) {
        Resource res = getCollection().createResource(name, type);
        if (type.equals("XMLResource")) {
            res.setContent(XML_CONTENT);
        } else {
            res.setContent(BINARY_CONTENT);
        }
        getCollection().storeResource(res);
    }
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource)

Example 67 with Resource

use of org.xmldb.api.base.Resource 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);
    }
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Database(org.xmldb.api.base.Database) Permission(org.exist.security.Permission) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) Test(org.junit.Test)

Example 68 with Resource

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

the class AnnotationsTest method annotationWithLiterals.

@Test
public void annotationWithLiterals() throws XMLDBException {
    final String TEST_VALUE_CONSTANT = "hello world";
    final String query = "declare namespace hello = 'http://world.com';\n" + "declare\n" + "%hello:world('a=b', 'b=c')\n" + "function local:hello() {\n" + "'" + TEST_VALUE_CONSTANT + "'\n" + "};\n" + "local:hello()";
    final XPathQueryService service = getQueryService();
    final ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    Resource res = result.getIterator().nextResource();
    assertEquals(TEST_VALUE_CONSTANT, res.getContent());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 69 with Resource

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

the class DuplicateAttributesTest method setup.

@BeforeClass
public static void setup() throws XMLDBException {
    final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
    testCollection = service.createCollection("test");
    assertNotNull(testCollection);
    Resource resource = testCollection.createResource("stored1.xml", "XMLResource");
    resource.setContent(STORED_DOC1);
    testCollection.storeResource(resource);
    resource = testCollection.createResource("stored2.xml", "XMLResource");
    resource.setContent(STORED_DOC2);
    testCollection.storeResource(resource);
    resource = testCollection.createResource("docdtd.xml", "XMLResource");
    resource.setContent(DOC_WITH_DTD);
    testCollection.storeResource(resource);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Resource(org.xmldb.api.base.Resource) BeforeClass(org.junit.BeforeClass)

Example 70 with Resource

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

the class UpdateReplaceTest method replaceOnlyChildWhereParentHasAttribute.

@Test
public void replaceOnlyChildWhereParentHasAttribute() throws XMLDBException {
    final String testDocName = "replaceOnlyChildWhereParentHasAttribute.xml";
    final String testDoc = "<Test><Content Foo=\"bar\"><A/></Content></Test>";
    final String updateQuery = "let $content := doc('/db/test/" + testDocName + "')/Test/Content\n" + "    let $legacy := $content/A\n" + "    return\n" + "      update replace $legacy with <AA/>,\n" + "    doc('/db/test/" + testDocName + "')/Test";
    final XQueryService xqueryService = storeXMLStringAndGetQueryService(testDocName, testDoc);
    final ResourceSet result = xqueryService.query(updateQuery);
    assertNotNull(result);
    assertEquals(1, result.getSize());
    final Resource res1 = result.getResource(0);
    assertNotNull(res1);
    assertEquals(XMLResource.RESOURCE_TYPE, res1.getResourceType());
    final Document doc = ((XMLResource) res1).getContentAsDOM().getOwnerDocument();
    final Source actual = Input.fromDocument(doc).build();
    final Source expected = Input.fromString("<Test><Content Foo='bar'><AA/></Content></Test>").build();
    final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
    assertFalse(diff.toString(), diff.hasDifferences());
}
Also used : Diff(org.xmlunit.diff.Diff) XQueryService(org.xmldb.api.modules.XQueryService) EXistResource(org.exist.xmldb.EXistResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Document(org.w3c.dom.Document) Source(javax.xml.transform.Source) Test(org.junit.Test)

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