use of org.exist.util.StringInputSource in project exist by eXist-db.
the class ConstructedNodesRecoveryTest method storeTestDocument.
private void storeTestDocument(final DBBroker broker, final TransactionManager transact, final String documentName) throws PermissionDeniedException, IOException, SAXException, LockException, EXistException {
// create a transaction
try (final Txn transaction = transact.beginTransaction()) {
// get the test collection
final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
// store test document
broker.storeDocument(transaction, XmldbURI.create(documentName), new StringInputSource(testDocument), MimeType.XML_TYPE, root);
// commit the transaction
transact.commit(transaction);
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class EmbeddedBinariesTest method storeBinaryFile.
@Override
protected void storeBinaryFile(final XmldbURI filePath, final byte[] content) throws Exception {
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
try (final ManagedCollectionLock collectionLock = brokerPool.getLockManager().acquireCollectionWriteLock(filePath.removeLastSegment())) {
final Collection collection = broker.getOrCreateCollection(transaction, filePath.removeLastSegment());
broker.storeDocument(transaction, filePath.lastSegment(), new StringInputSource(content), MimeType.BINARY_TYPE, collection);
broker.saveCollection(transaction, collection);
}
transaction.commit();
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class ExampleTrigger method afterCreateDocument.
@Override
public void afterCreateDocument(DBBroker broker, Txn txn, DocumentImpl document) throws TriggerException {
if (document.getFileURI().toString().contains("copied")) {
LOG.info("Prevent recreation of document {}", document.getFileURI().toString());
return;
}
LOG.info("Created document {}", document.getDocumentURI());
final byte[] data = "<a>dummy data</a>".getBytes();
final XmldbURI newDocumentURI = XmldbURI.create(document.getFileURI().toString() + "-copied.xml");
try (final Collection collection = broker.openCollection(document.getCollection().getURI(), Lock.LockMode.WRITE_LOCK)) {
// Stream into database
broker.storeDocument(txn, newDocumentURI, new StringInputSource(data), MimeType.XML_TYPE, collection);
} catch (Exception e) {
LOG.error(e);
throw new TriggerException(e);
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class FnDocSecurityTest method createDocument.
private static void createDocument(final DBBroker broker, final Txn transaction, final String collectionUri, final String docName, final String content, final String modeStr) throws PermissionDeniedException, LockException, SAXException, EXistException, IOException, SyntaxException {
try (final Collection collection = broker.openCollection(XmldbURI.create(collectionUri), Lock.LockMode.WRITE_LOCK)) {
broker.storeDocument(transaction, XmldbURI.create(docName), new StringInputSource(content), MimeType.XML_TYPE, collection);
PermissionFactory.chmod_str(broker, transaction, XmldbURI.create(collectionUri).append(docName), Optional.of(modeStr), Optional.empty());
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class DirtyShutdownTest method storeRepeatedly.
public void storeRepeatedly() {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
Collection root;
try (final Txn transaction = transact.beginTransaction()) {
root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
transact.commit(transaction);
}
final String data;
try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
final InputStream is = SAMPLES.getMacbethSample()) {
os.write(is);
data = new String(os.toByteArray(), UTF_8);
}
for (int i = 0; i < 50; i++) {
try (final Txn transaction = transact.beginTransaction()) {
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(data), MimeType.XML_TYPE, root);
transact.commit(transaction);
}
}
} catch (final PermissionDeniedException | EXistException | SAXException | LockException | IOException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
Aggregations