Search in sources :

Example 86 with DavException

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

the class VersionResourceImpl method getVersionHistory.

/**
     * Returns the {@link VersionHistory} associated with the repository version.
     * Note: in contrast to a versionable node, the version history of a version
     * item is always represented by its nearest ancestor.
     *
     * @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
     * @see javax.jcr.Item#getParent()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = getVersionHistoryItem();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 87 with DavException

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

the class DavResourceImpl method bind.

/**
     * @see BindableResource#rebind(DavResource, DavResource)
     */
public void bind(DavResource collection, DavResource newBinding) throws DavException {
    if (!exists()) {
        //DAV:bind-source-exists
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
    }
    if (isLocked(collection)) {
        //DAV:locked-update-allowed?
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (isFilteredResource(newBinding)) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    checkSameWorkspace(collection.getLocator());
    try {
        if (!node.isNodeType(MIX_SHAREABLE)) {
            if (!node.canAddMixin(MIX_SHAREABLE)) {
                //DAV:binding-allowed
                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
            }
            node.addMixin(MIX_SHAREABLE);
            node.save();
        }
        Workspace workspace = session.getRepositorySession().getWorkspace();
        workspace.clone(workspace.getName(), node.getPath(), newBinding.getLocator().getRepositoryPath(), false);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
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) Workspace(javax.jcr.Workspace)

Example 88 with DavException

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

the class DavResourceImpl method getMembers.

/**
     * @see DavResource#getMembers()
     */
public DavResourceIterator getMembers() {
    ArrayList<DavResource> list = new ArrayList<DavResource>();
    if (exists() && isCollection()) {
        try {
            NodeIterator it = node.getNodes();
            while (it.hasNext()) {
                Node n = it.nextNode();
                if (!isFilteredItem(n)) {
                    DavResourceLocator resourceLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), n.getPath(), false);
                    DavResource childRes = factory.createResource(resourceLocator, session);
                    list.add(childRes);
                } else {
                    log.debug("Filtered resource '" + n.getName() + "'.");
                }
            }
        } catch (RepositoryException e) {
        // should not occur
        } catch (DavException e) {
        // should not occur
        }
    }
    return new DavResourceIteratorImpl(list);
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 89 with DavException

use of org.apache.jackrabbit.webdav.DavException 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 90 with DavException

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

the class DavResourceImpl method addMember.

/**
     * Adds a new member to this resource.
     *
     * @see DavResource#addMember(DavResource, org.apache.jackrabbit.webdav.io.InputContext)
     */
public void addMember(DavResource member, InputContext inputContext) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_CONFLICT);
    }
    if (isLocked(this) || isLocked(member)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    try {
        // item or if the new resource would be filtered out
        if (isFilteredResource(member) || node.getDefinition().isProtected()) {
            log.debug("Forbidden to add member: " + member.getDisplayName());
            throw new DavException(DavServletResponse.SC_FORBIDDEN);
        }
        String memberName = Text.getName(member.getLocator().getRepositoryPath());
        ImportContext ctx = getImportContext(inputContext, memberName);
        if (!config.getIOManager().importContent(ctx, member)) {
            // any changes should have been reverted in the importer
            throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        }
        // persist changes after successful import
        node.save();
    } catch (RepositoryException e) {
        log.error("Error while importing resource: " + e.toString());
        throw new JcrDavException(e);
    } catch (IOException e) {
        log.error("Error while importing resource: " + e.toString());
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ImportContext(org.apache.jackrabbit.server.io.ImportContext) PropertyImportContext(org.apache.jackrabbit.server.io.PropertyImportContext) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)129 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)51 HttpResponse (org.apache.http.HttpResponse)47 Element (org.w3c.dom.Element)29 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 DavResource (org.apache.jackrabbit.webdav.DavResource)21 ArrayList (java.util.ArrayList)19 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)17 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8 Document (org.w3c.dom.Document)8 Session (javax.jcr.Session)7 Version (javax.jcr.version.Version)7