⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 davresourceimpl.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        try {            List l = new ArrayList(1);            l.add(prop);            alterProperties(l);            Map failure = propManager.alterProperties(getPropertyImportContext(l), 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;        }    }    /**     * @see DavResource#alterProperties(DavPropertySet, DavPropertyNameSet)     */    public MultiStatusResponse alterProperties(DavPropertySet setProperties,                                               DavPropertyNameSet removePropertyNames)            throws DavException {        List changeList = new ArrayList();        if (removePropertyNames != null) {            DavPropertyNameIterator it = removePropertyNames.iterator();            while (it.hasNext()) {                changeList.add(it.next());            }        }        if (setProperties != null) {            DavPropertyIterator it = setProperties.iterator();            while (it.hasNext()) {                changeList.add(it.next());            }        }        return alterProperties(changeList);    }    public MultiStatusResponse alterProperties(List 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 failures = propManager.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 resulte 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.*/            Iterator it = changeList.iterator();            while (it.hasNext()) {                Object o = it.next();                int statusCode;                if (failures.containsKey(o)) {                    Object error = failures.get(o);                    statusCode = (error instanceof RepositoryException)                        ? new JcrDavException((RepositoryException)o).getErrorCode()                        : DavServletResponse.SC_INTERNAL_SERVER_ERROR;                } else {                    statusCode = (failures.isEmpty()) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;                }                if (o instanceof DavProperty) {                    msr.add(((DavProperty) o).getName(), statusCode);                } else {                    msr.add((DavPropertyName) o, 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);        }    }    /**     * @see DavResource#getCollection()     */    public DavResource getCollection() {        DavResource parent = null;        if (getResourcePath() != null && !getResourcePath().equals("/")) {            String parentPath = Text.getRelativeParent(getResourcePath(), 1);            if (parentPath.equals("")) {                parentPath = "/";            }            DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), parentPath);            try {                parent = factory.createResource(parentloc, session);            } catch (DavException e) {                // should not occur            }        }        return parent;    }    /**     * @see DavResource#getMembers()     */    public DavResourceIterator getMembers() {        ArrayList list = new ArrayList();        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 occure            } catch (DavException e) {                // should not occure            }        }        return new DavResourceIteratorImpl(list);    }    /**     * 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);        }        // don't allow creation of nodes, that would be filtered out        if (isFilteredResource(member)) {            log.debug("Avoid creation of filtered resource: " + member.getDisplayName());            throw new DavException(DavServletResponse.SC_FORBIDDEN);        }        try {            String memberName = Text.getName(member.getLocator().getRepositoryPath());            ImportContext ctx = getImportContext(inputContext, memberName);            if (!ioManager.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());        }    }    /**     * @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);        }        try {            String itemPath = member.getLocator().getRepositoryPath();            Item memItem = getJcrSession().getItem(itemPath);            memItem.remove();            getJcrSession().save();            // make sure, non-jcr locks are removed, once the removal is completed            try {                if (!isJsrLockable()) {                    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            }        } catch (RepositoryException e) {            throw new JcrDavException(e);        }    }    /**     * @see DavResource#move(DavResource)     */    public void move(DavResource destination) throws DavException {        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        if (isLocked(this)) {            throw new DavException(DavServletResponse.SC_LOCKED);        }        if (isFilteredResource(destination)) {            throw new DavException(DavServletResponse.SC_FORBIDDEN);        }        // make sure, that src and destination belong to the same workspace        checkSameWorkspace(destination.getLocator());        try {            String destItemPath = destination.getLocator().getRepositoryPath();            getJcrSession().getWorkspace().move(locator.getRepositoryPath(), destItemPath);        } catch (RepositoryException e) {            throw new JcrDavException(e);        }    }    /**     * @see DavResource#copy(DavResource, boolean)     */    public void copy(DavResource destination, boolean shallow) throws DavException {        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        if (isLocked(destination)) {            throw new DavException(DavServletResponse.SC_LOCKED);        }        if (isFilteredResource(destination)) {            throw new DavException(DavServletResponse.SC_FORBIDDEN);        }        if (shallow && isCollection()) {            // TODO: currently no support for shallow copy; however this is            // only relevant if the source resource is a collection, because            // otherwise it doesn't make a difference            throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy.");        }        // make sure, that src and destination belong to the same workspace        checkSameWorkspace(destination.getLocator());        try {            String destItemPath = destination.getLocator().getRepositoryPath();            getJcrSession().getWorkspace().copy(locator.getRepositoryPath(), destItemPath);        } catch (PathNotFoundException e) {            // according to rfc 2518: missing parent            throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage());        } catch (RepositoryException e) {            throw new JcrDavException(e);        }    }    /**     * @param type     * @param scope     * @return true if type is {@link Type#WRITE} and scope is {@link Scope#EXCLUSIVE}     * @see DavResource#isLockable(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope)     */    public boolean isLockable(Type type, Scope scope) {        return Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope);    }    /**     * @see DavResource#hasLock(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope)     */    public boolean hasLock(Type type, Scope scope) {        return getLock(type, scope) != null;    }    /**     * @see DavResource#getLock(Type, Scope)     */    public ActiveLock getLock(Type type, Scope scope) {        ActiveLock lock = null;        if (exists() && Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope)) {            // try to retrieve the repository lock information first            try {                if (node.isLocked()) {                    Lock jcrLock = node.getLock();                    if (jcrLock != null && jcrLock.isLive()) {                        lock = new JcrActiveLock(jcrLock);                    }                }            } catch (RepositoryException e) {                // LockException (no lock applies) >> should never occur                // RepositoryException, AccessDeniedException or another error >> ignore            }            // could not retrieve a jcr-lock. test if a simple webdav lock is present.            if (lock == null) {                lock = lockManager.getLock(type, scope, this);            }        }        return lock;    }    /**     * @see org.apache.jackrabbit.webdav.DavResource#getLocks()     */    public ActiveLock[] getLocks() {        ActiveLock writeLock = getLock(Type.WRITE, Scope.EXCLUSIVE);        return (writeLock != null) ? new ActiveLock[]{writeLock} : new ActiveLock[0];    }    /**     * @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 (isJsrLockable()) {                try {                    // try to execute the lock operation                    Lock jcrLock = node.lock(lockInfo.isDeep(), false);                    if (jcrLock != null) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -