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);
}
}
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);
}
}
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());
}
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);
}
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());
}
Aggregations