Search in sources :

Example 1 with TaggedTryUnchecked

use of com.evolvedbinary.j8fu.Try.TaggedTryUnchecked in project exist by eXist-db.

the class MetadataFunctions method extractMetadataFromLocalResource.

private Sequence extractMetadataFromLocalResource(final XmldbURI docUri) throws XPathException {
    try (final LockedDocument lockedDoc = context.getBroker().getXMLResource(docUri, LockMode.READ_LOCK)) {
        if (lockedDoc != null && lockedDoc.getDocument() instanceof BinaryDocument) {
            final BinaryDocument binDoc = (BinaryDocument) lockedDoc.getDocument();
            final BrokerPool pool = context.getBroker().getBrokerPool();
            final BlobStore blobStore = pool.getBlobStore();
            try (final Txn transaction = pool.getTransactionManager().beginTransaction()) {
                final Sequence result = blobStore.with(transaction, binDoc.getBlobId(), blobFile -> TaggedTryUnchecked(XPathException.class, () -> exifToolExtract(blobFile))).get();
                transaction.commit();
                return result;
            }
        } else {
            throw new XPathException(this, "The binary document at " + docUri.toString() + " cannot be found.");
        }
    } catch (PermissionDeniedException | IOException | TransactionException e) {
        throw new XPathException(this, "Could not access binary document: " + e.getMessage(), e);
    }
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) LockMode(org.exist.storage.lock.Lock.LockMode) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) SequenceType(org.exist.xquery.value.SequenceType) FunctionParameterSequenceType(org.exist.xquery.value.FunctionParameterSequenceType) QName(org.exist.dom.QName) URISyntaxException(java.net.URISyntaxException) FunctionSignature(org.exist.xquery.FunctionSignature) PermissionDeniedException(org.exist.security.PermissionDeniedException) Cardinality(org.exist.xquery.Cardinality) BlobStore(org.exist.storage.blob.BlobStore) BasicFunction(org.exist.xquery.BasicFunction) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream) Source(org.exist.source.Source) FunctionReturnSequenceType(org.exist.xquery.value.FunctionReturnSequenceType) XmldbURI(org.exist.xmldb.XmldbURI) URI(java.net.URI) Path(java.nio.file.Path) XQueryContext(org.exist.xquery.XQueryContext) OutputStream(java.io.OutputStream) InputSource(org.xml.sax.InputSource) LockedDocument(org.exist.dom.persistent.LockedDocument) Type(org.exist.xquery.value.Type) IOException(java.io.IOException) TransactionException(org.exist.storage.txn.TransactionException) Logger(org.apache.logging.log4j.Logger) TaggedTryUnchecked(com.evolvedbinary.j8fu.Try.TaggedTryUnchecked) ModuleUtils(org.exist.xquery.modules.ModuleUtils) SAXException(org.xml.sax.SAXException) SourceFactory(org.exist.source.SourceFactory) Sequence(org.exist.xquery.value.Sequence) LogManager(org.apache.logging.log4j.LogManager) BinaryDocument(org.exist.dom.persistent.BinaryDocument) XPathException(org.exist.xquery.XPathException) InputStream(java.io.InputStream) TransactionException(org.exist.storage.txn.TransactionException) XPathException(org.exist.xquery.XPathException) LockedDocument(org.exist.dom.persistent.LockedDocument) PermissionDeniedException(org.exist.security.PermissionDeniedException) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) IOException(java.io.IOException) BrokerPool(org.exist.storage.BrokerPool) BlobStore(org.exist.storage.blob.BlobStore)

Aggregations

TaggedTryUnchecked (com.evolvedbinary.j8fu.Try.TaggedTryUnchecked)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 UnsynchronizedByteArrayOutputStream (org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 QName (org.exist.dom.QName)1 BinaryDocument (org.exist.dom.persistent.BinaryDocument)1 LockedDocument (org.exist.dom.persistent.LockedDocument)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 Source (org.exist.source.Source)1 SourceFactory (org.exist.source.SourceFactory)1 BrokerPool (org.exist.storage.BrokerPool)1 BlobStore (org.exist.storage.blob.BlobStore)1 LockMode (org.exist.storage.lock.Lock.LockMode)1 TransactionException (org.exist.storage.txn.TransactionException)1