Search in sources :

Example 16 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class DavResourceImpl method alterProperty.

private void alterProperty(PropEntry prop) throws DavException {
    if (isLocked(this)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        List<? extends PropEntry> list = Collections.singletonList(prop);
        alterProperties(list);
        Map<? extends PropEntry, ?> failure = config.getPropertyManager().alterProperties(getPropertyImportContext(list), isCollection());
        if (failure.isEmpty()) {
            node.save();
        } else {
            node.refresh(false);
            // TODO: retrieve specific error from failure-map
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        // revert any changes made so far
        JcrDavException je = new JcrDavException(e);
        try {
            node.refresh(false);
        } catch (RepositoryException re) {
        // should not happen...
        }
        throw je;
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException)

Example 17 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class RootCollection method getMembers.

/**
 * Returns an iterator over the member resources, which are all
 * workspace resources available.
 *
 * @return members of this collection
 * @see org.apache.jackrabbit.webdav.DavResource#getMembers()
 */
@Override
public DavResourceIterator getMembers() {
    List<DavResource> memberList = new ArrayList();
    try {
        String[] wsNames = getRepositorySession().getWorkspace().getAccessibleWorkspaceNames();
        for (String wsName : wsNames) {
            String wspPath = "/" + wsName;
            DavResourceLocator childLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), wspPath, wspPath);
            memberList.add(createResourceFromLocator(childLoc));
        }
    } catch (RepositoryException e) {
        log.error(e.getMessage());
    } catch (DavException e) {
        // should never occur
        log.error(e.getMessage());
    }
    return new DavResourceIteratorImpl(memberList);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 18 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class DavResourceImpl method removeMember.

/**
 * @see DavResource#removeMember(DavResource)
 */
public void removeMember(DavResource member) throws DavException {
    if (!exists() || !member.exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (isLocked(this) || isLocked(member)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    // don't allow removal of nodes, that would be filtered out
    if (isFilteredResource(member)) {
        log.debug("Avoid removal of filtered resource: " + member.getDisplayName());
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    DeleteManager dm = config.getDeleteManager();
    dm.delete(new DeleteContextImpl(getJcrSession()), member);
    // make sure, non-jcr locks are removed, once the removal is completed
    try {
        if (!isJcrLockable()) {
            ActiveLock lock = getLock(Type.WRITE, Scope.EXCLUSIVE);
            if (lock != null) {
                lockManager.releaseLock(lock.getToken(), member);
            }
        }
    } catch (DavException e) {
    // since check for 'locked' exception has been performed before
    // ignore any error here
    }
}
Also used : DeleteManager(org.apache.jackrabbit.server.io.DeleteManager) DeleteContextImpl(org.apache.jackrabbit.server.io.DeleteContextImpl) 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)

Example 19 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class DeltaVResourceImpl method getReferenceResources.

/**
 * Return an array of <code>DavResource</code> objects that are referenced
 * by the property with the specified name.
 *
 * @param hrefPropertyName
 * @return array of <code>DavResource</code>s
 * @throws DavException
 * @see DeltaVResource#getReferenceResources(org.apache.jackrabbit.webdav.property.DavPropertyName)
 */
public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
    DavProperty<?> prop = getProperty(hrefPropertyName);
    List<DavResource> resources = new ArrayList<DavResource>();
    if (prop != null && prop instanceof HrefProperty) {
        HrefProperty hp = (HrefProperty) prop;
        // process list of hrefs
        for (String href : hp.getHrefs()) {
            DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), href);
            resources.add(createResourceFromLocator(locator));
        }
    } else {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return resources.toArray(new DavResource[resources.size()]);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 20 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class ResourceFactoryImpl method createResource.

/**
 * Create a new <code>DavResource</code> from the given locator and webdav
 * session.
 *
 * @param locator
 * @param session
 * @return
 * @throws DavException
 * @see DavResourceFactory#createResource(DavResourceLocator, DavSession)
 */
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
    try {
        Node node = getNode(session, locator);
        DavResource resource = createResource(node, locator, session);
        resource.addLockManager(lockMgr);
        return resource;
    } catch (RepositoryException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)157 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)61 HttpResponse (org.apache.http.HttpResponse)47 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavResource (org.apache.jackrabbit.webdav.DavResource)30 Element (org.w3c.dom.Element)29 ArrayList (java.util.ArrayList)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)18 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)14 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)10 Test (org.junit.Test)9 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8