Search in sources :

Example 26 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class MoveResourceRecoveryTest method store.

private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException, URISyntaxException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final Collection test2 = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
        assertNotNull(test2);
        broker.saveCollection(transaction, test2);
        final String sample;
        try (final InputStream is = SAMPLES.getRomeoAndJulietSample()) {
            sample = InputStreamUtil.readString(is, UTF_8);
        }
        broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test2);
        final DocumentImpl doc = test2.getDocument(broker, TestConstants.TEST_XML_URI);
        assertNotNull(doc);
        broker.moveResource(transaction, doc, test, XmldbURI.create("new_test.xml"));
        broker.saveCollection(transaction, test);
        transact.commit(transaction);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) InputStream(java.io.InputStream) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 27 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class MoveCollectionRecoveryTest method store.

private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final String sample;
        try (final InputStream is = SAMPLES.getBiblioSample()) {
            assertNotNull(is);
            sample = InputStreamUtil.readString(is, UTF_8);
        }
        broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test);
        final Collection dest = broker.getOrCreateCollection(transaction, TestConstants.DESTINATION_COLLECTION_URI);
        assertNotNull(dest);
        broker.saveCollection(transaction, dest);
        broker.moveCollection(transaction, test, dest, XmldbURI.create("test3"));
        transact.commit(transaction);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) InputStream(java.io.InputStream) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 28 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class MarshallerTest method startDB.

@BeforeClass
public static void startDB() throws EXistException, DatabaseConfigurationException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection root = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        broker.saveCollection(transaction, root);
        broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(TEST_DOC), MimeType.XML_TYPE, root);
        transact.commit(transaction);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) BeforeClass(org.junit.BeforeClass)

Example 29 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class ResourceTest method setContentAsSourceXml.

@Test
public void setContentAsSourceXml() throws XMLDBException, SAXException, IOException, XpathException {
    final Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    assertNotNull(testCollection);
    final XMLResource doc = (XMLResource) testCollection.createResource("source.xml", "XMLResource");
    final String xml = "<test><title>Title1</title>" + "<para>Paragraph3</para>" + "<para>Paragraph4</para>" + "</test>";
    doc.setContent(new StringInputSource(xml));
    testCollection.storeResource(doc);
    final XMLResource newDoc = (XMLResource) testCollection.getResource("source.xml");
    final String newDocXml = (String) newDoc.getContent();
    assertXpathEvaluatesTo("Title1", "/test/title/text()", newDocXml);
    assertXpathEvaluatesTo("2", "count(/test/para)", newDocXml);
    assertXpathEvaluatesTo("Paragraph3", "/test/para[1]/text()", newDocXml);
    assertXpathEvaluatesTo("Paragraph4", "/test/para[2]/text()", newDocXml);
}
Also used : StringInputSource(org.exist.util.StringInputSource) Collection(org.xmldb.api.base.Collection) XMLResource(org.xmldb.api.modules.XMLResource)

Example 30 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class ResourceTest method setContentAsSourceBinary.

@Test
public void setContentAsSourceBinary() throws XMLDBException {
    final Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    assertNotNull(testCollection);
    final BinaryResource doc = (BinaryResource) testCollection.createResource("source.bin", "BinaryResource");
    final byte[] bin = "Stuff And Things".getBytes(UTF_8);
    doc.setContent(new StringInputSource(bin));
    testCollection.storeResource(doc);
    final BinaryResource newDoc = (BinaryResource) testCollection.getResource("source.bin");
    final byte[] newDocBin = (byte[]) newDoc.getContent();
    assertArrayEquals(bin, newDocBin);
}
Also used : StringInputSource(org.exist.util.StringInputSource) BinaryResource(org.xmldb.api.modules.BinaryResource) Collection(org.xmldb.api.base.Collection)

Aggregations

StringInputSource (org.exist.util.StringInputSource)72 Collection (org.exist.collections.Collection)57 Txn (org.exist.storage.txn.Txn)56 BrokerPool (org.exist.storage.BrokerPool)34 DBBroker (org.exist.storage.DBBroker)34 TransactionManager (org.exist.storage.txn.TransactionManager)27 XmldbURI (org.exist.xmldb.XmldbURI)17 Test (org.junit.Test)13 InputStream (java.io.InputStream)10 DocumentImpl (org.exist.dom.persistent.DocumentImpl)8 Sequence (org.exist.xquery.value.Sequence)7 CollectionConfigurationManager (org.exist.collections.CollectionConfigurationManager)5 EXistException (org.exist.EXistException)4 ManagedCollectionLock (org.exist.storage.lock.ManagedCollectionLock)4 LockException (org.exist.util.LockException)4 InputSource (org.xml.sax.InputSource)4 IOException (java.io.IOException)3 UnsynchronizedByteArrayOutputStream (org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)3 LockedDocument (org.exist.dom.persistent.LockedDocument)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3