Search in sources :

Example 11 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class DefaultHandler method delete.

/**
 * @see DeleteHandler#delete(DeleteContext, DavResource)
 */
public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException {
    try {
        String itemPath = member.getLocator().getRepositoryPath();
        Item item = deleteContext.getSession().getItem(itemPath);
        if (item instanceof Node) {
            ((Node) item).removeShare();
        } else {
            item.remove();
        }
        deleteContext.getSession().save();
        log.debug("default handler deleted {}", member.getResourcePath());
        return true;
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : Item(javax.jcr.Item) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 12 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class DavResourceImpl method lock.

/**
 * @see DavResource#lock(LockInfo)
 */
public ActiveLock lock(LockInfo lockInfo) throws DavException {
    ActiveLock lock = null;
    if (isLockable(lockInfo.getType(), lockInfo.getScope())) {
        // TODO: deal with existing locks, that may have been created, before the node was jcr-lockable...
        if (isJcrLockable()) {
            try {
                javax.jcr.lock.LockManager lockMgr = node.getSession().getWorkspace().getLockManager();
                long timeout = lockInfo.getTimeout();
                if (timeout == LockInfo.INFINITE_TIMEOUT) {
                    timeout = Long.MAX_VALUE;
                } else {
                    timeout = timeout / 1000;
                }
                // try to execute the lock operation
                Lock jcrLock = lockMgr.lock(node.getPath(), lockInfo.isDeep(), false, timeout, lockInfo.getOwner());
                if (jcrLock != null) {
                    lock = new JcrActiveLock(jcrLock);
                }
            } catch (RepositoryException e) {
                throw new JcrDavException(e);
            }
        } else {
            // create a new webdav lock
            lock = lockManager.createLock(lockInfo, this);
        }
    } else {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Unsupported lock type or scope.");
    }
    return lock;
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) RepositoryException(javax.jcr.RepositoryException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) SupportedLock(org.apache.jackrabbit.webdav.lock.SupportedLock)

Example 13 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class DavResourceImpl method alterProperties.

public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
    if (isLocked(this)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
    try {
        Map<? extends PropEntry, ?> failures = config.getPropertyManager().alterProperties(getPropertyImportContext(changeList), isCollection());
        if (failures.isEmpty()) {
            // save all changes together (reverted in case this fails)
            node.save();
        } else {
            // set/remove of at least a single prop failed: undo modifications.
            node.refresh(false);
        }
        /* loop over list of properties/names that were successfully altered
               and them to the multistatus response respecting the result of the
               complete action. in case of failure set the status to 'failed-dependency'
               in order to indicate, that altering those names/properties would
               have succeeded, if no other error occured.*/
        for (PropEntry propEntry : changeList) {
            int statusCode;
            if (failures.containsKey(propEntry)) {
                Object error = failures.get(propEntry);
                statusCode = (error instanceof RepositoryException) ? new JcrDavException((RepositoryException) error).getErrorCode() : DavServletResponse.SC_INTERNAL_SERVER_ERROR;
            } else {
                statusCode = (failures.isEmpty()) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;
            }
            if (propEntry instanceof DavProperty) {
                msr.add(((DavProperty<?>) propEntry).getName(), statusCode);
            } else {
                msr.add((DavPropertyName) propEntry, statusCode);
            }
        }
        return msr;
    } catch (RepositoryException e) {
        // revert any changes made so far an throw exception
        try {
            node.refresh(false);
        } catch (RepositoryException re) {
        // should not happen
        }
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException)

Example 14 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class SubscriptionManagerImpl method registerSubscription.

/**
 * Register the event listener defined by the given subscription to the
 * repository's observation manager.
 *
 * @param subscription
 * @param resource
 * @throws DavException
 */
private void registerSubscription(SubscriptionImpl subscription, ObservationResource resource) throws DavException {
    try {
        Session session = getRepositorySession(resource);
        ObservationManager oMgr = session.getWorkspace().getObservationManager();
        String itemPath = subscription.getLocator().getRepositoryPath();
        oMgr.addEventListener(subscription, subscription.getJcrEventTypes(), itemPath, subscription.isDeep(), subscription.getUuidFilters(), subscription.getNodetypeNameFilters(), subscription.isNoLocal());
    } catch (RepositoryException e) {
        log.error("Unable to register eventlistener: " + e.getMessage());
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ObservationManager(javax.jcr.observation.ObservationManager) RepositoryException(javax.jcr.RepositoryException) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session)

Example 15 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class SubscriptionManagerImpl method unregisterSubscription.

/**
 * Remove the event listener defined by the specified subscription from
 * the repository's observation manager and clean up the references present
 * on the <code>DavSession</code>.
 *
 * @param subscription
 * @param resource
 * @throws DavException
 */
private void unregisterSubscription(SubscriptionImpl subscription, ObservationResource resource) throws DavException {
    try {
        Session session = getRepositorySession(resource);
        session.getWorkspace().getObservationManager().removeEventListener(subscription);
        String sId = subscription.getSubscriptionId();
        // clean up any references
        subscriptions.remove(sId);
        resource.getSession().removeReference(sId);
    } catch (RepositoryException e) {
        log.error("Unable to remove eventlistener: " + e.getMessage());
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RepositoryException(javax.jcr.RepositoryException) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session)

Aggregations

RepositoryException (javax.jcr.RepositoryException)24 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)24 DavException (org.apache.jackrabbit.webdav.DavException)17 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)8 Node (javax.jcr.Node)6 Session (javax.jcr.Session)6 VersionHistory (javax.jcr.version.VersionHistory)6 JcrDavSession (org.apache.jackrabbit.webdav.jcr.JcrDavSession)5 DavResource (org.apache.jackrabbit.webdav.DavResource)4 DavSession (org.apache.jackrabbit.webdav.DavSession)3 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)3 ArrayList (java.util.ArrayList)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Item (javax.jcr.Item)1