Search in sources :

Example 96 with Collection

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

Example 97 with Collection

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);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Node(org.w3c.dom.Node) Collection(org.xmldb.api.base.Collection) Document(org.w3c.dom.Document) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Example 98 with Collection

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

Example 99 with Collection

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

Example 100 with Collection

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

Aggregations

Collection (org.xmldb.api.base.Collection)345 XMLResource (org.xmldb.api.modules.XMLResource)140 Test (org.junit.Test)115 Resource (org.xmldb.api.base.Resource)111 UserManagementService (org.exist.xmldb.UserManagementService)91 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)85 BinaryResource (org.xmldb.api.modules.BinaryResource)80 XMLDBException (org.xmldb.api.base.XMLDBException)68 ResourceSet (org.xmldb.api.base.ResourceSet)55 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)48 XPathQueryService (org.xmldb.api.modules.XPathQueryService)31 EXistResource (org.exist.xmldb.EXistResource)25 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)20 Before (org.junit.Before)20 URISyntaxException (java.net.URISyntaxException)18 Path (java.nio.file.Path)18 InputStream (java.io.InputStream)17 BuildException (org.apache.tools.ant.BuildException)14 XmldbURI (org.exist.xmldb.XmldbURI)13 Account (org.exist.security.Account)10