Search in sources :

Example 6 with StringInputSource

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

the class SystemExportImportTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final CollectionConfigurationManager mgr = pool.getConfigurationManager();
        mgr.addConfiguration(transaction, broker, test, COLLECTION_CONFIG);
        broker.storeDocument(transaction, doc01uri.lastSegment(), new StringInputSource(XML1), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc02uri.lastSegment(), new StringInputSource(XML2), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc03uri.lastSegment(), new StringInputSource(XML3), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc11uri.lastSegment(), new StringInputSource(BINARY.getBytes(UTF_8)), MimeType.BINARY_TYPE, test);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 7 with StringInputSource

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

the class CollectionOrderTest method createDocuments.

private void createDocuments(final BrokerPool pool, final List<String> documentNames) throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    // create the documents
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final Collection testCollection = broker.openCollection(TEST_COLLECTION, Lock.LockMode.WRITE_LOCK)) {
            for (final String documentName : documentNames) {
                final String xml = "<document id='" + UUID.randomUUID().toString() + "'><name>" + documentName + "</name></document>";
                broker.storeDocument(transaction, XmldbURI.create(documentName), new StringInputSource(xml), MimeType.XML_TYPE, testCollection);
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Txn(org.exist.storage.txn.Txn)

Example 8 with StringInputSource

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

the class CollectionStoreTest method store.

@Test
public void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final Collection col = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI)) {
            broker.storeDocument(transaction, TEST_XML_DOC_URI, new StringInputSource(TEST_XML_DOC), MimeType.XML_TYPE, col);
            broker.saveCollection(transaction, col);
        }
        try (final Collection col = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.READ_LOCK)) {
            try (final LockedDocument lockedDoc = col.getDocumentWithLock(broker, TEST_XML_DOC_URI, LockMode.READ_LOCK)) {
                // NOTE: early release of collection lock inline with async locking
                col.close();
                if (lockedDoc != null) {
                    final Source expected = Input.fromString(TEST_XML_DOC).build();
                    final Source actual = Input.fromDocument(lockedDoc.getDocument()).build();
                    final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
                    assertFalse(diff.toString(), diff.hasDifferences());
                }
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Diff(org.xmlunit.diff.Diff) LockedDocument(org.exist.dom.persistent.LockedDocument) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 9 with StringInputSource

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

the class IndexerTest method store_preserve_ws_mixed_content_value.

private void store_preserve_ws_mixed_content_value(final boolean propValue, final String xml) throws PermissionDeniedException, IOException, EXistException, SAXException, LockException, AuthenticationException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    pool.getConfiguration().setProperty(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT, propValue);
    final TransactionManager txnMgr = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate("admin", "")));
        final Txn txn = txnMgr.beginTransaction()) {
        try (final Collection collection = broker.getOrCreateCollection(txn, TestConstants.TEST_COLLECTION_URI)) {
            broker.storeDocument(txn, TestConstants.TEST_XML_URI, new StringInputSource(xml), MimeType.XML_TYPE, collection);
            broker.flush();
            broker.saveCollection(txn, collection);
        }
        txnMgr.commit(txn);
    }
}
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)

Example 10 with StringInputSource

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

the class TestTrigger method configure.

public void configure(DBBroker broker, Txn transaction, org.exist.collections.Collection parent, Map<String, List<?>> parameters) throws TriggerException {
    super.configure(broker, transaction, parent, parameters);
    XmldbURI docPath = XmldbURI.create("messages.xml");
    final boolean triggersEnabled = broker.isTriggersEnabled();
    try {
        this.doc = parent.getDocument(broker, docPath);
        if (this.doc == null) {
            LOG.debug("creating new file for collection contents");
            // IMPORTANT: temporarily disable triggers on the collection.
            // We would end up in infinite recursion if we don't do that
            broker.setTriggersEnabled(false);
            broker.storeDocument(transaction, docPath, new StringInputSource(TEMPLATE), MimeType.XML_TYPE, parent);
            this.doc = parent.getDocument(broker, docPath);
        }
    } catch (Exception e) {
        throw new TriggerException(e.getMessage(), e);
    } finally {
        // restore triggers enabled setting
        broker.setTriggersEnabled(triggersEnabled);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) XmldbURI(org.exist.xmldb.XmldbURI)

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