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

📄 davresourceimpl.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        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;    }    /**     * @see DavResource#refreshLock(LockInfo, String)     */    public ActiveLock refreshLock(LockInfo lockInfo, String lockToken) throws DavException {        if (!exists()) {            throw new DavException(DavServletResponse.SC_NOT_FOUND);        }        ActiveLock lock = getLock(lockInfo.getType(), lockInfo.getScope());        if (lock == null) {            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No lock with the given type/scope present on resource " + getResourcePath());        }        if (lock instanceof JcrActiveLock) {            try {                // refresh JCR lock and return the original lock object.                node.getLock().refresh();            } catch (RepositoryException e) {                throw new JcrDavException(e);            }        } else {            lock = lockManager.refreshLock(lockInfo, lockToken, this);        }        /* since lock has infinite lock (simple) or undefined timeout (jcr)           return the lock as retrieved from getLock. */        return lock;    }    /**     * @see DavResource#unlock(String)     */    public void unlock(String lockToken) throws DavException {        ActiveLock lock = getLock(Type.WRITE, Scope.EXCLUSIVE);        if (lock == null) {            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);        } else if (lock.isLockedByToken(lockToken)) {            if (lock instanceof JcrActiveLock) {                try {                    node.unlock();                } catch (RepositoryException e) {                    throw new JcrDavException(e);                }            } else {                lockManager.releaseLock(lockToken, this);            }        } else {            throw new DavException(DavServletResponse.SC_LOCKED);        }    }    /**     * @see DavResource#addLockManager(org.apache.jackrabbit.webdav.lock.LockManager)     */    public void addLockManager(LockManager lockMgr) {        this.lockManager = lockMgr;    }    /**     * @see org.apache.jackrabbit.webdav.DavResource#getFactory()     */    public DavResourceFactory getFactory() {        return factory;    }    /**     * @see org.apache.jackrabbit.webdav.DavResource#getSession()     */    public DavSession getSession() {        return session;    }    /**     * Returns the node that is wrapped by this resource.     *     * @return     */    protected Node getNode() {        return node;    }    /**     * Returns a new <code>ImportContext</code>     *     * @param inputCtx     * @param systemId     * @return     * @throws IOException     */    protected ImportContext getImportContext(InputContext inputCtx, String systemId) throws IOException {        return new ImportContextImpl(node, systemId, inputCtx);    }    /**     * Returns a new <code>ExportContext</code>     *     * @param outputCtx     * @return     * @throws IOException     */    protected ExportContext getExportContext(OutputContext outputCtx) throws IOException {        return new ExportContextImpl(node, outputCtx);    }    /**     * Returns a new <code>PropertyImportContext</code>.     *     * @param changeList     * @return     */    protected PropertyImportContext getPropertyImportContext(List changeList) {        return new ProperyImportCtx(changeList);    }    /**     * Returns a new <code>PropertyExportContext</code>.     *     * @return     */    protected PropertyExportContext getPropertyExportContext() {        return new PropertyExportCtx();    }    /**     * Returns true, if the underlying node is nodetype jcr:lockable,     * without checking its current lock status. If the node is not jcr-lockable     * an attempt is made to add the mix:lockable mixin type.     *     * @return true if this resource is lockable.     */    private boolean isJsrLockable() {        boolean lockable = false;        if (exists()) {            try {                lockable = node.isNodeType(MIX_LOCKABLE);                // not jcr-lockable: try to make the node jcr-lockable                if (!lockable && node.canAddMixin(MIX_LOCKABLE)) {                    node.addMixin(MIX_LOCKABLE);                    node.save();                    lockable = true;                }            } catch (RepositoryException e) {                // -> node is definitely not jcr-lockable.            }        }        return lockable;    }    /**     * Return true if this resource cannot be modified due to a write lock     * that is not owned by the given session.     *     * @return true if this resource cannot be modified due to a write lock     */    private boolean isLocked(DavResource res) {        ActiveLock lock = res.getLock(Type.WRITE, Scope.EXCLUSIVE);        if (lock == null) {            return false;        } else {            String[] sLockTokens = session.getLockTokens();            for (int i = 0; i < sLockTokens.length; i++) {                if (sLockTokens[i].equals(lock.getToken())) {                    return false;                }            }            return true;        }    }    private Session getJcrSession() {        return session.getRepositorySession();    }    private boolean isFilteredResource(DavResource resource) {        // TODO: filtered nodetypes should be checked as well in order to prevent problems.        return filter != null && filter.isFilteredItem(resource.getDisplayName(), getJcrSession());    }    private boolean isFilteredItem(Item item) {        return filter != null && filter.isFilteredItem(item);    }    private void checkSameWorkspace(DavResourceLocator otherLoc) throws DavException {        String wspname = getJcrSession().getWorkspace().getName();        if (!wspname.equals(otherLoc.getWorkspaceName())) {            throw new DavException(DavServletResponse.SC_FORBIDDEN, "Workspace mismatch: expected '" + wspname + "'; found: '" + otherLoc.getWorkspaceName() + "'");        }    }    //--------------------------------------------------------< inner class >---    /**     * ExportContext that writes the properties of this <code>DavResource</code>     * and provides not stream.     */    private class PropertyExportCtx extends AbstractExportContext implements PropertyExportContext {        private PropertyExportCtx() {            super(node, false, null);            // set defaults:            setCreationTime(IOUtil.UNDEFINED_TIME);            setModificationTime(IOUtil.UNDEFINED_TIME);        }        public OutputStream getOutputStream() {            return null;        }        public void setContentLanguage(String contentLanguage) {            if (contentLanguage != null) {                properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLANGUAGE, contentLanguage));            }        }        public void setContentLength(long contentLength) {            if (contentLength > IOUtil.UNDEFINED_LENGTH) {                properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, contentLength + ""));            }        }        public void setContentType(String mimeType, String encoding) {            String contentType = IOUtil.buildContentType(mimeType, encoding);            if (contentType != null) {                properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, contentType));            }        }        public void setCreationTime(long creationTime) {            String created = IOUtil.getCreated(creationTime);            properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, created));        }        public void setModificationTime(long modTime) {            if (modTime <= IOUtil.UNDEFINED_TIME) {                modificationTime = new Date().getTime();            } else {                modificationTime = modTime;            }            String lastModified = IOUtil.getLastModified(modificationTime);            properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, lastModified));        }        public void setETag(String etag) {            if (etag != null) {                properties.add(new DefaultDavProperty(DavPropertyName.GETETAG, etag));            }        }        public void setProperty(Object propertyName, Object propertyValue) {            if (propertyValue == null) {                log.warn("Ignore 'setProperty' for " + propertyName + "with null value.");                return;            }            if (propertyValue instanceof DavProperty) {                properties.add((DavProperty)propertyValue);            } else {                DavPropertyName pName;                if (propertyName instanceof DavPropertyName) {                    pName = (DavPropertyName)propertyName;                } else {                    // create property name with default DAV: namespace                    pName = DavPropertyName.create(propertyName.toString());                }                properties.add(new DefaultDavProperty(pName, propertyValue));            }        }    }    private class ProperyImportCtx implements PropertyImportContext {        private final IOListener ioListener = new DefaultIOListener(log);        private final List changeList;        private boolean completed;        private ProperyImportCtx(List changeList) {            this.changeList = changeList;        }        /**         * @see PropertyImportContext#getImportRoot()         */        public Item getImportRoot() {            return node;        }        /**         * @see PropertyImportContext#getChangeList()         */        public List getChangeList() {            return Collections.unmodifiableList(changeList);        }        public IOListener getIOListener() {            return ioListener;        }        public boolean hasStream() {            return false;        }        /**         * @see PropertyImportContext#informCompleted(boolean)         */        public void informCompleted(boolean success) {            checkCompleted();            completed = true;        }        /**         * @see PropertyImportContext#isCompleted()         */        public boolean isCompleted() {            return completed;        }        /**         * @throws IllegalStateException if the context is already completed.         * @see #isCompleted()         * @see #informCompleted(boolean)         */        private void checkCompleted() {            if (completed) {                throw new IllegalStateException("PropertyImportContext has already been consumed.");            }        }    }}

⌨️ 快捷键说明

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