Search in sources :

Example 6 with IndexController

use of org.exist.indexing.IndexController in project exist by eXist-db.

the class Serializer method setPrettyPrinter.

protected void setPrettyPrinter(Writer writer, boolean xmlDecl, NodeProxy root, boolean applyFilters) {
    outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, xmlDecl ? "no" : "yes");
    xmlout = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
    xmlout.setOutput(writer, outputProperties);
    if ("yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"))) {
        xinclude.setReceiver(xmlout);
        receiver = xinclude;
    } else {
        receiver = xmlout;
    }
    if (root != null && getHighlightingMode() != TAG_NONE) {
        final IndexController controller = broker.getIndexController();
        MatchListener listener = controller.getMatchListener(root);
        if (listener != null) {
            final MatchListener last = (MatchListener) listener.getLastInChain();
            last.setNextInChain(receiver);
            receiver = listener;
        }
    }
    if (root == null && applyFilters && customMatchListeners.getFirst() != null) {
        customMatchListeners.getLast().setNextInChain(receiver);
        receiver = customMatchListeners.getFirst();
    }
}
Also used : IndexController(org.exist.indexing.IndexController) MatchListener(org.exist.indexing.MatchListener)

Example 7 with IndexController

use of org.exist.indexing.IndexController in project exist by eXist-db.

the class Serializer method setupMatchListeners.

protected Receiver setupMatchListeners(NodeProxy p) {
    final Receiver oldReceiver = receiver;
    if (getHighlightingMode() != TAG_NONE) {
        final IndexController controller = broker.getIndexController();
        MatchListener listener = controller.getMatchListener(p);
        if (listener != null) {
            final MatchListener last = (MatchListener) listener.getLastInChain();
            last.setNextInChain(receiver);
            receiver = listener;
        }
    }
    return oldReceiver;
}
Also used : IndexController(org.exist.indexing.IndexController) Receiver(org.exist.util.serializer.Receiver) MatchListener(org.exist.indexing.MatchListener)

Example 8 with IndexController

use of org.exist.indexing.IndexController in project exist by eXist-db.

the class Serializer method setXSLHandler.

protected void setXSLHandler(NodeProxy root, boolean applyFilters) {
    if (templates != null && xslHandler != null) {
        final SAXResult result = new SAXResult();
        boolean processXInclude = "yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"));
        final ReceiverToSAX filter;
        if (processXInclude) {
            final Receiver xincludeReceiver = xinclude.getReceiver();
            if (xincludeReceiver != null && xincludeReceiver instanceof SAXSerializer) {
                filter = new ReceiverToSAX((SAXSerializer) xincludeReceiver);
            } else {
                filter = (ReceiverToSAX) xincludeReceiver;
            }
        } else {
            filter = (ReceiverToSAX) receiver;
        }
        result.setHandler(filter.getContentHandler());
        result.setLexicalHandler(filter.getLexicalHandler());
        filter.setLexicalHandler(xslHandler);
        filter.setContentHandler(xslHandler);
        xslHandler.setResult(result);
        if (processXInclude) {
            xinclude.setReceiver(new ReceiverToSAX(xslHandler));
            receiver = xinclude;
        } else {
            receiver = new ReceiverToSAX(xslHandler);
        }
    }
    if (root != null && getHighlightingMode() != TAG_NONE) {
        final IndexController controller = broker.getIndexController();
        MatchListener listener = controller.getMatchListener(root);
        if (listener != null) {
            final MatchListener last = (MatchListener) listener.getLastInChain();
            last.setNextInChain(receiver);
            receiver = listener;
        }
    }
    if (applyFilters && root == null && customMatchListeners.getFirst() != null) {
        customMatchListeners.getLast().setNextInChain(receiver);
        receiver = customMatchListeners.getFirst();
    }
}
Also used : SAXResult(javax.xml.transform.sax.SAXResult) ReceiverToSAX(org.exist.util.serializer.ReceiverToSAX) IndexController(org.exist.indexing.IndexController) Receiver(org.exist.util.serializer.Receiver) SAXSerializer(org.exist.util.serializer.SAXSerializer) MatchListener(org.exist.indexing.MatchListener)

Example 9 with IndexController

use of org.exist.indexing.IndexController in project exist by eXist-db.

the class MutableCollection method removeBinaryResource.

@Override
public void removeBinaryResource(final Txn transaction, final DBBroker broker, final DocumentImpl doc) throws PermissionDeniedException, LockException, TriggerException {
    if (doc == null) {
        // TODO should throw an exception!!! Otherwise we dont know if the document was removed
        return;
    }
    broker.getBrokerPool().getProcessMonitor().startJob(ProcessMonitor.ACTION_REMOVE_BINARY, doc.getFileURI());
    try (final ManagedCollectionLock collectionLock = lockManager.acquireCollectionWriteLock(path)) {
        if (!getPermissionsNoLock().validate(broker.getCurrentSubject(), Permission.WRITE)) {
            throw new PermissionDeniedException("Permission denied to write collection: " + path);
        }
        if (doc.getResourceType() != DocumentImpl.BINARY_FILE) {
            throw new PermissionDeniedException("document " + doc.getFileURI() + " is not a binary object");
        }
        try (final ManagedDocumentLock docUpdateLock = lockManager.acquireDocumentWriteLock(doc.getURI())) {
            try {
                final DocumentTriggers trigger = new DocumentTriggers(broker, transaction, null, this, broker.isTriggersEnabled() ? getConfiguration(broker) : null);
                trigger.beforeDeleteDocument(broker, transaction, doc);
                final IndexController indexController = broker.getIndexController();
                final StreamListener listener = indexController.getStreamListener(doc, StreamListener.ReindexMode.REMOVE_BINARY);
                try {
                    indexController.startIndexDocument(transaction, listener);
                    try {
                        broker.removeBinaryResource(transaction, (BinaryDocument) doc);
                    } catch (final IOException ex) {
                        throw new PermissionDeniedException("Cannot delete file: " + doc.getURI().toString() + ": " + ex.getMessage(), ex);
                    }
                    documents.remove(doc.getFileURI().lastSegmentString());
                } finally {
                    indexController.endIndexDocument(transaction, listener);
                }
                trigger.afterDeleteDocument(broker, transaction, doc.getURI());
            } finally {
                broker.getBrokerPool().getProcessMonitor().endJob();
            }
            // NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
            collectionLock.close();
        }
    }
}
Also used : IndexController(org.exist.indexing.IndexController) PermissionDeniedException(org.exist.security.PermissionDeniedException) StreamListener(org.exist.indexing.StreamListener)

Example 10 with IndexController

use of org.exist.indexing.IndexController in project exist by eXist-db.

the class MutableCollection method addBinaryResource.

private BinaryDocument addBinaryResource(final Database db, final Txn transaction, final DBBroker broker, final BinaryDocument blob, final InputStream is, final String mimeType, @Deprecated final long size, final Date created, final Date modified, @Nullable final Permission permission, final DBBroker.PreserveType preserve, final DocumentImpl oldDoc, final ManagedCollectionLock collectionLock) throws EXistException, PermissionDeniedException, LockException, TriggerException, IOException {
    final DocumentTriggers trigger = new DocumentTriggers(broker, transaction, null, this, broker.isTriggersEnabled() ? getConfiguration(broker) : null);
    final XmldbURI docUri = blob.getFileURI();
    try {
        db.getProcessMonitor().startJob(ProcessMonitor.ACTION_STORE_BINARY, docUri);
        checkPermissionsForAddDocument(broker, oldDoc);
        checkCollectionConflict(docUri);
        // manageDocumentInformation(oldDoc, blob);
        if (!broker.preserveOnCopy(preserve)) {
            blob.copyOf(broker, blob, oldDoc);
        }
        blob.setMimeType(mimeType == null ? MimeType.BINARY_TYPE.getName() : mimeType);
        if (created != null) {
            blob.setCreated(created.getTime());
        }
        if (modified != null) {
            blob.setLastModified(modified.getTime());
        }
        if (oldDoc == null) {
            trigger.beforeCreateDocument(broker, transaction, blob.getURI());
        } else {
            trigger.beforeUpdateDocument(broker, transaction, oldDoc);
        }
        if (oldDoc != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("removing old document db entry{}", oldDoc.getFileURI());
            }
            if (!broker.preserveOnCopy(preserve)) {
                updateModificationTime(blob);
            }
            // remove the old document
            broker.removeResource(transaction, oldDoc);
        }
        if (permission != null) {
            blob.setPermissions(permission);
        }
        // store the binary content (create/replace)
        broker.storeBinaryResource(transaction, blob, is);
        addDocument(transaction, broker, blob, oldDoc);
        final IndexController indexController = broker.getIndexController();
        final StreamListener listener = indexController.getStreamListener(blob, StreamListener.ReindexMode.STORE);
        indexController.startIndexDocument(transaction, listener);
        try {
            broker.storeXMLResource(transaction, blob);
        } finally {
            indexController.endIndexDocument(transaction, listener);
        }
        if (oldDoc == null) {
            trigger.afterCreateDocument(broker, transaction, blob);
        } else {
            trigger.afterUpdateDocument(broker, transaction, blob);
        }
        // NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
        collectionLock.close();
        return blob;
    } finally {
        broker.getBrokerPool().getProcessMonitor().endJob();
    }
}
Also used : IndexController(org.exist.indexing.IndexController) XmldbURI(org.exist.xmldb.XmldbURI) StreamListener(org.exist.indexing.StreamListener)

Aggregations

IndexController (org.exist.indexing.IndexController)17 EXistException (org.exist.EXistException)12 StreamListener (org.exist.indexing.StreamListener)9 NodeId (org.exist.numbering.NodeId)4 MatchListener (org.exist.indexing.MatchListener)3 Txn (org.exist.storage.txn.Txn)3 QName (org.exist.dom.QName)2 Receiver (org.exist.util.serializer.Receiver)2 SAXResult (javax.xml.transform.sax.SAXResult)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 ReceiverToSAX (org.exist.util.serializer.ReceiverToSAX)1 SAXSerializer (org.exist.util.serializer.SAXSerializer)1 XmldbURI (org.exist.xmldb.XmldbURI)1 org.w3c.dom (org.w3c.dom)1