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

📄 cmslock.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                } catch (CmsException e) {
                    // error reading a resource, should usually never happen
                    if (LOG.isErrorEnabled()) {
                        LOG.error(e.getLocalizedMessage(getLocale()), e);
                    }
                }
                if (Boolean.valueOf(getParamIncluderelated()).booleanValue()) {
                    addLockedRelatedResources(resName, getNonBlockingFilter(), lockedResources);
                }
            }
            // get blocking resources needs the locked resources
            m_lockedResources = new ArrayList(lockedResources);
            lockedResources.addAll(getBlockingLockedResources());
            // create the locked resources list again, with the blocking locked resources
            m_lockedResources = new ArrayList(lockedResources);
            Collections.sort(m_lockedResources);
        }
        return m_lockedResources;
    }

    /**
     * Returns the filter to get all non blocking locks.<p>
     *
     * @return the filter to get all non blocking locks
     */
    public CmsLockFilter getNonBlockingFilter() {

        if (m_nonBlockingFilter == null) {
            m_nonBlockingFilter = CmsLockFilter.FILTER_ALL;
            m_nonBlockingFilter = m_nonBlockingFilter.filterLockableByUser(getCms().getRequestContext().currentUser());
            m_nonBlockingFilter = m_nonBlockingFilter.filterSharedExclusive();
        }
        return m_nonBlockingFilter;
    }

    /**
     * Returns the 'include unpublished related resources' parameter value.<p>
     *
     * @return the 'include unpublished related resources' parameter value
     */
    public String getParamIncluderelated() {

        return m_paramIncluderelated;
    }

    /**
     * Returns the project id parameter value.<p>
     *
     * @return the project id parameter value
     */
    public String getParamProjectid() {

        return m_paramProjectid;
    }

    /**
     * Returns the 'show own locked resources' parameter value.<p>
     *
     * @return the 'show own locked resources' parameter value
     */
    public String getParamShowownlocks() {

        return m_paramShowownlocks;
    }

    /**
     * Sets the filter to get all blocking locks.<p>
     *
     * @param blockingFilter the filter to set
     */
    public void setBlockingFilter(CmsLockFilter blockingFilter) {

        m_blockingFilter = blockingFilter;
        // reset blocking locks count
        m_blockingLocks = -1;
        // reset locked resources
        m_lockedResources = null;
    }

    /**
     * Sets the filter to get all non blocking locks.<p>
     *
     * @param nonBlockingFilter the filter to set
     */
    public void setNonBlockingFilter(CmsLockFilter nonBlockingFilter) {

        m_nonBlockingFilter = nonBlockingFilter;
        // reset locked resources
        m_lockedResources = null;
    }

    /**
     * Sets the 'include unpublished related resources' parameter value.<p>
     *
     * @param paramIncluderelated the 'include unpublished related resources' parameter value to set
     */
    public void setParamIncluderelated(String paramIncluderelated) {

        m_paramIncluderelated = paramIncluderelated;
    }

    /**
     * Sets the project id parameter value.<p>
     *
     * @param projectid the project id parameter value to set
     */
    public void setParamProjectid(String projectid) {

        m_paramProjectid = projectid;
    }

    /**
     * Sets the 'show own locked resources' parameter value.<p>
     *
     * @param paramShowownlocks the 'show own locked resources' parameter value to set
     */
    public void setParamShowownlocks(String paramShowownlocks) {

        m_paramShowownlocks = paramShowownlocks;
    }

    /**
     * Determines whether to show the lock dialog depending on the users settings and the dilaog type.<p>
     * 
     * In case of locking a folder, a confirmation dialog is needed if any sub resources are already locked.<p>
     * 
     * @return true if dialogs should be shown, otherwise false
     */
    public boolean showConfirmation() {

        boolean showConfirmation = getSettings().getUserSettings().getDialogShowLock();
        if (DIALOG_TYPE_LOCK.equals(getParamDialogtype())) {
            // in case of locking resources, check if there are locked sub resources in the selected folder(s)
            showConfirmation = showConfirmation || (getLockedResources().size() > 0);
        }
        return showConfirmation;
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        // fill the parameter values in the get/set methods
        fillParamValues(request);

        // set the action for the JSP switch 
        if (DIALOG_CONFIRMED.equals(getParamAction())) {
            setAction(ACTION_CONFIRMED);
        } else if (DIALOG_CANCEL.equals(getParamAction())) {
            setAction(ACTION_CANCEL);
        } else if (DIALOG_WAIT.equals(getParamAction())) {
            setAction(ACTION_WAIT);
        } else {
            switch (getDialogAction(getCms())) {
                case TYPE_LOCK:
                    setDialogTitle(Messages.GUI_LOCK_RESOURCE_1, Messages.GUI_LOCK_MULTI_LOCK_2);
                    setParamDialogtype(DIALOG_TYPE_LOCK);
                    // check the required permissions to lock/unlock
                    if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
                        // no write permissions for the resource, set cancel action to close dialog
                        setAction(ACTION_CANCEL);
                        return;
                    }
                    break;
                case TYPE_LOCKCHANGE:
                    setDialogTitle(Messages.GUI_LOCK_STEAL_1, Messages.GUI_LOCK_MULTI_STEAL_2);
                    setParamDialogtype(DIALOG_TYPE_UNLOCK);
                    break;
                case TYPE_UNLOCK:
                    setDialogTitle(Messages.GUI_LOCK_UNLOCK_1, Messages.GUI_LOCK_MULTI_UNLOCK_2);
                    setParamDialogtype(DIALOG_TYPE_UNLOCK);
                    break;
                case TYPE_LOCKS:
                default:
                    setDialogTitle(Messages.GUI_LOCK_LOCKS_1, Messages.GUI_LOCK_MULTI_LOCKS_2);
                    setParamDialogtype(DIALOG_TYPE_LOCKS);
            }
            // set action depending on user settings
            if ((getDialogAction(getCms()) == TYPE_LOCKS) || showConfirmation()) {
                // show confirmation dialog
                setAction(ACTION_DEFAULT);
            } else {
                // lock/unlock resource without confirmation
                setAction(ACTION_SUBMIT_NOCONFIRMATION);
            }
        }

        if (getParamResource() == null && getParamResourcelist() == null) {
            // this if in case of publish project
            setParamResource("/");
        }

    }

    /**
     * Performs the lock/unlock/steal lock operation.<p>
     * 
     * @return true, if the operation was performed, otherwise false
     * @throws CmsException if operation is not successful
     */
    protected boolean performDialogOperation() throws CmsException {

        //on multi resource operation display "please wait" screen
        if (isMultiOperation() && !DIALOG_WAIT.equals(getParamAction())) {
            return false;
        }
        // determine action to perform (lock, unlock, change lock)
        int dialogAction = getDialogAction(getCms());

        // now perform the operation on the resource(s)
        Iterator i = getResourceList().iterator();
        while (i.hasNext()) {
            String resName = (String)i.next();
            try {
                performSingleResourceOperation(resName, dialogAction);
            } catch (CmsException e) {
                // collect exceptions to create a detailed output
                addMultiOperationException(e);
            }
        }
        // generate the error message for exception
        String message;
        if (dialogAction == TYPE_LOCK) {
            message = Messages.ERR_LOCK_MULTI_0;
        } else {
            message = Messages.ERR_UNLOCK_MULTI_0;
        }
        checkMultiOperationException(Messages.get(), message);

        return true;
    }

    /**
     * Performs the lock state operation on a single resource.<p>
     * 
     * @param resourceName the resource name to perform the operation on
     * @param dialogAction the lock action: lock, unlock or change lock
     * @throws CmsException if the operation fails
     */
    protected void performSingleResourceOperation(String resourceName, int dialogAction) throws CmsException {

        // store original name to use for lock action 
        String originalResourceName = resourceName;
        CmsResource res = getCms().readResource(resourceName, CmsResourceFilter.ALL);
        if (res.isFolder() && !resourceName.endsWith("/")) {
            resourceName += "/";
        }
        org.opencms.lock.CmsLock lock = getCms().getLock(res);
        // perform action depending on dialog uri
        switch (dialogAction) {
            case TYPE_LOCKCHANGE:
            case TYPE_LOCK:
                if (lock.isNullLock()) {
                    getCms().lockResource(originalResourceName);
                } else if (!lock.isExclusiveOwnedBy(getCms().getRequestContext().currentUser())
                    || !lock.isInProject(getCms().getRequestContext().currentProject())) {
                    getCms().changeLock(resourceName);
                }
                break;
            case TYPE_UNLOCK:
            default:
                if (lock.isNullLock()) {
                    break;
                }
                if (lock.isOwnedBy(getCms().getRequestContext().currentUser())) {
                    getCms().unlockResource(resourceName);
                }
        }
    }

    /**
     * Returns a set of locked unpublished related resources.<p>
     * 
     * @param resName the resource to check the related resources for
     * @param filter the lock filter to use
     * @param lockedResources a set of site relative paths, of locked resources to exclude
     */
    private void addLockedRelatedResources(String resName, CmsLockFilter filter, Set lockedResources) {

        try {
            // get and iterate over all related resources
            Iterator itRelations = getCms().getRelationsForResource(
                resName,
                CmsRelationFilter.TARGETS.filterStrong().filterIncludeChildren()).iterator();
            while (itRelations.hasNext()) {
                CmsRelation relation = (CmsRelation)itRelations.next();
                CmsResource target = relation.getTarget(getCms(), CmsResourceFilter.ALL);
                // we are interested just in unpublished resources
                if (target.getState().isUnchanged()) {
                    continue;
                }
                String targetName = getCms().getSitePath(target);
                // if already selected
                if (lockedResources.contains(targetName) || lockedResources.contains(targetName + "*")) {
                    continue;
                }
                if (m_lockedResources != null) {
                    if (m_lockedResources.contains(targetName) || m_lockedResources.contains(targetName + "*")) {
                        continue;
                    }
                }
                org.opencms.lock.CmsLock lock = getCms().getLock(targetName);
                if (!lock.isUnlocked() && filter.match("/", lock)) {
                    // just add resources that may come in question
                    lockedResources.add(targetName + "*");
                }
            }
        } catch (CmsException e) {
            // error reading a resource, should usually never happen
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(getLocale()), e);
            }
        }
    }
}

⌨️ 快捷键说明

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