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

📄 cmsmove.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */
    public String getCurrentResourceName() {

        if (isMultiOperation()) {
            return "";
        }
        String resourceName = CmsResource.getName(getParamResource());
        if (resourceName.endsWith("/")) {
            resourceName = resourceName.substring(0, resourceName.length() - 1);
        }
        return resourceName;
    }
    
    /**
     * Returns the value of the overwrite parameter.<p>
     * 
     * @return the value of the overwrite parameter
     */
    public String getParamOverwrite() {

        return m_paramOverwrite;
    }

    /**
     * Returns the value of the target parameter, 
     * or null if this parameter was not provided.<p>
     * 
     * The target parameter selects the target name 
     * of the operation.<p>
     * 
     * @return the value of the target parameter
     */
    public String getParamTarget() {

        return m_paramTarget;
    }
    
    /**
     * Sets the value of the overwrite parameter.<p>
     * 
     * @param paramOverwrite the value of the overwrite parameter
     */
    public void setParamOverwrite(String paramOverwrite) {

        m_paramOverwrite = paramOverwrite;
    }

    /**
     * Sets the value of the target parameter.<p>
     * 
     * @param value the value to set
     */
    public void setParamTarget(String value) {

        m_paramTarget = value;
    }

    /**
     * @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);
        
        // check the required permissions to rename/move the resource       
        if (! checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
            // no write permissions for the resource, set cancel action to close dialog
            setParamAction(DIALOG_CANCEL);
        }
        
        // set the dialog type
        setParamDialogtype(DIALOG_TYPE);
        // set the action for the JSP switch 
        if (DIALOG_TYPE.equals(getParamAction())) {
            setAction(ACTION_MOVE);
        } else if (DIALOG_CONFIRMED.equals(getParamAction())) {
            setAction(ACTION_CONFIRMED);
        } else if (DIALOG_WAIT.equals(getParamAction())) {
            setAction(ACTION_WAIT);
        } else if (DIALOG_CANCEL.equals(getParamAction())) {
            setAction(ACTION_CANCEL);
        } else {
            setAction(ACTION_DEFAULT);
            // build title for move dialog     
            setDialogTitle(Messages.GUI_MOVE_RESOURCE_1, Messages.GUI_MOVE_MULTI_2);
        }
    }

    /**
     * Performs the resource moving.<p>
     * 
     * @return true, if the resource was successfully moved, otherwise false
     * @throws CmsException if moving is not successful
     */
    protected boolean performDialogOperation() throws CmsException {

        // check if the current resource is a folder for single operation
        boolean isFolder = isOperationOnFolder();
        // on folder move operation display "please wait" screen, not for simple file move operation
        if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) {
            // return false, this will trigger the "please wait" screen
            return false;
        }
        
        // check the overwrite options
        boolean overwrite = Boolean.valueOf(getParamOverwrite()).booleanValue();
        overwrite = ((isMultiOperation() && overwrite) || DIALOG_CONFIRMED.equals(getParamAction()));

        // get the target name
        String target = getParamTarget();
        if (target == null) {
            target = "";
        }

        boolean restoreSiteRoot = false;
        try {
            // check if a site root was added to the target name
            String sitePrefix = "";
            if (CmsSiteManager.getSiteRoot(target) != null) {
                String siteRootFolder = getCms().getRequestContext().getSiteRoot();
                if (siteRootFolder.endsWith("/")) {
                    siteRootFolder = siteRootFolder.substring(0, siteRootFolder.length() - 1);
                }
                sitePrefix = siteRootFolder;
                getCms().getRequestContext().saveSiteRoot();
                getCms().getRequestContext().setSiteRoot("/");
                restoreSiteRoot = true;
            }

            Iterator i = getResourceList().iterator();
            // iterate the resources to move
            while (i.hasNext()) {
                String resName = (String)i.next();
                try {
                    performSingleMoveOperation(resName, target, sitePrefix, overwrite);
                } catch (CmsException e) {
                    if (isMultiOperation()) {
                        // collect exceptions to create a detailed output
                        addMultiOperationException(e);
                    } else {
                        // for single operation, throw the exception immediately
                        throw e;
                    }
                }
            }
            // check if exceptions occured
            checkMultiOperationException(Messages.get(), Messages.ERR_MOVE_MULTI_0);
        } finally {
            if (restoreSiteRoot) {
                getCms().getRequestContext().restoreSiteRoot();
            }
        }
        return true;
    }
    
    /**
     * Performs the move operation for a single VFS resource.<p>
     * 
     * @param source the source VFS path
     * @param target the target VFS path
     * @param sitePrefix the site prefix
     * @param overwrite the overwrite flag
     * @throws CmsException if moving the resource fails
     */
    protected void performSingleMoveOperation(String source, String target, String sitePrefix, boolean overwrite)
    throws CmsException {

        // calculate the target name
        target = CmsLinkManager.getAbsoluteUri(target, CmsResource.getParentFolder(source));

        if (target.equals(source) || (isMultiOperation() && target.startsWith(source))) {
            throw new CmsVfsException(Messages.get().container(Messages.ERR_MOVE_ONTO_ITSELF_1, target));
        }

        try {
            CmsResource res = getCms().readResource(target, CmsResourceFilter.ALL);
            if (res.isFolder()) {
                // target folder already exists, so we add the current folder name
                if (! target.endsWith("/")) {
                    target += "/";
                }
                target = target + CmsResource.getName(source);
                if (target.endsWith("/")) {
                    target = target.substring(0, target.length() - 1);
                }
            }
        } catch (CmsVfsResourceNotFoundException e) {
            // target folder does not already exist, so target name is o.k.
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage());
            }
        }

        // set the target parameter value
        setParamTarget(target);
        
        // set the target parameter value
        setParamTarget(target);

        // delete existing target resource if selected or confirmed by the user
        if (getCms().existsResource(target, CmsResourceFilter.ALL)) {
            if (overwrite) {
                checkLock(target);
                getCms().deleteResource(target, CmsResource.DELETE_PRESERVE_SIBLINGS);
            } else {
                // throw exception to indicate that the target exists
                throw new CmsVfsResourceAlreadyExistsException(Messages.get().container(
                    Messages.ERR_MOVE_FAILED_TARGET_EXISTS_2,
                    source,
                    getJsp().getRequestContext().removeSiteRoot(target)));
            }
        }

        // lock resource if autolock is enabled
        checkLock(sitePrefix + source);
        // move the resource
        getCms().moveResource(sitePrefix + source, target);
    }
}

⌨️ 快捷键说明

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