use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class TestEXistXMLSerialize method setUp.
@Before
public void setUp() throws Exception {
CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
Collection testCollection = service.createCollection(TEST_COLLECTION);
UserManagementService ums = (UserManagementService) testCollection.getService("UserManagementService", "1.0");
// change ownership to guest
Account guest = ums.getAccount(GUEST_DB_USER);
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod("rwxr-xr-x");
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class TestEXistXMLSerialize method serialize1.
@Test
public void serialize1() throws TransformerException, XMLDBException, ParserConfigurationException, SAXException, IOException, URISyntaxException {
Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
XMLResource resource = (XMLResource) testCollection.createResource(null, "XMLResource");
Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(Paths.get(testFile.toURI()).toFile());
resource.setContentAsDOM(doc);
testCollection.storeResource(resource);
resource = (XMLResource) testCollection.getResource(resource.getId());
assertNotNull(resource);
Node node = resource.getContentAsDOM();
node = node.getOwnerDocument();
// Attempting serialization
DOMSource source = new DOMSource(node);
try (final UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
StreamResult result = new StreamResult(out);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);
}
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class RemoteDBTest method removeCollection.
protected void removeCollection() {
try {
Collection rootCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION, "admin", "");
assertNotNull(rootCollection);
CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0");
cms.removeCollection(CHILD_COLLECTION);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class RemoteDBTest method setUpRemoteDatabase.
protected void setUpRemoteDatabase() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException {
// Connect to the DB
Class<?> cl = Class.forName(DB_DRIVER);
Database database = (Database) cl.newInstance();
assertNotNull(database);
DatabaseManager.registerDatabase(database);
// Get the root collection...
Collection rootCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION, "admin", "");
assertNotNull(rootCollection);
CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0");
// Creates the child collection
Collection childCollection = cms.createCollection(CHILD_COLLECTION);
assertNotNull(childCollection);
// ... and work from it
setCollection((RemoteCollection) childCollection);
assertNotNull(childCollection);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class SerializationTest method setUp.
@Before
public void setUp() throws XMLDBException {
final Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
final CollectionManagementService service = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
testCollection = service.createCollection(TEST_COLLECTION_NAME);
assertNotNull(testCollection);
final XMLResource res = (XMLResource) testCollection.createResource(XML_DOC_NAME, "XMLResource");
res.setContent(XML);
testCollection.storeResource(res);
}
Aggregations