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

📄 cmscopy.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsCopy.java,v $
 * Date   : $Date: 2006/03/27 14:52:18 $
 * Version: $Revision: 1.20 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.commons;

import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.CmsVfsException;
import org.opencms.file.CmsVfsResourceAlreadyExistsException;
import org.opencms.file.CmsVfsResourceNotFoundException;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.security.CmsPermissionSet;
import org.opencms.site.CmsSiteManager;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsMultiDialog;
import org.opencms.workplace.CmsWorkplaceSettings;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.Log;

/**
 * Provides methods for the copy resources dialog.<p> 
 * 
 * The following files use this class:
 * <ul>
 * <li>/commons/copy.jsp
 * </ul>
 * <p>
 *
 * @author  Andreas Zahner 
 * 
 * @version $Revision: 1.20 $ 
 * 
 * @since 6.0.0 
 */
public class CmsCopy extends CmsMultiDialog {

    /** Value for the action: copy the resource. */
    public static final int ACTION_COPY = 100;

    /** The dialog type. */
    public static final String DIALOG_TYPE = "copy";

    /** Request parameter name for the keep rights flag. */
    public static final String PARAM_KEEPRIGHTS = "keeprights";

    /** Request parameter name for the overwrite flag. */
    public static final String PARAM_OVERWRITE = "overwrite";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsCopy.class);

    private String m_paramCopymode;
    private String m_paramKeeprights;
    private String m_paramOverwrite;
    private String m_paramTarget;

    /**
     * Public constructor with JSP action element.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsCopy(CmsJspActionElement jsp) {

        super(jsp);
    }

    /**
     * Public constructor with JSP variables.<p>
     * 
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     */
    public CmsCopy(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        this(new CmsJspActionElement(context, req, res));
    }

    /**
     * Performs the copy action, will be called by the JSP page.<p>
     * 
     * @throws JspException if problems including sub-elements occur
     */
    public void actionCopy() throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        CmsResource resource = null;
        try {
            boolean isFolder = false;
            String source = (String)getResourceList().get(0);
            String target = CmsLinkManager.getAbsoluteUri(getParamTarget(), CmsResource.getParentFolder(source));
            if (! isMultiOperation()) {
                resource = getCms().readResource(source, CmsResourceFilter.ALL);
                isFolder = resource.isFolder();
            } else {
                resource = getCms().readResource(target, CmsResourceFilter.ALL);
                if (! resource.isFolder()) {
                    // no folder selected for multi operation, throw exception
                    throw new CmsVfsException(Messages.get().container(Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1, target));
                }
            }
            if (performDialogOperation()) {
                // if no exception is caused and "true" is returned copy operation was successful
                if (isMultiOperation() || isFolder) {
                    // set request attribute to reload the explorer tree view
                    List folderList = new ArrayList(1);
                    String targetParent = CmsResource.getParentFolder(target);
                    folderList.add(targetParent);
                    getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
                }
                actionCloseDialog();
            } else {
                // "false" returned, display "please wait" screen
                getJsp().include(FILE_DIALOG_SCREEN_WAIT);
            }
        } catch (Throwable e) {
            // check if this exception requires a confirmation or error screen for single resource operations
            if (! isMultiOperation() && (e instanceof CmsVfsResourceAlreadyExistsException) && !(resource.isFolder())) {
                // file copy but file already exists, now check target file type
                int targetType = -1;
                boolean restoreSiteRoot = false;
                try {
                    if (CmsSiteManager.getSiteRoot(getParamTarget()) != null) {
                        getCms().getRequestContext().saveSiteRoot();
                        getCms().getRequestContext().setSiteRoot("/");
                        restoreSiteRoot = true;
                    }
                    CmsResource targetRes = getCms().readResource(getParamTarget());
                    targetType = targetRes.getTypeId();
                } catch (CmsException e2) {
                    // can usually be ignored
                    if (LOG.isInfoEnabled()) {
                        LOG.info(e2.getLocalizedMessage());
                    }
                } finally {
                    if (restoreSiteRoot) {
                        getCms().getRequestContext().restoreSiteRoot();
                    }
                }
                if (resource.getTypeId() == targetType) {
                    // file type of target is the same as source, show confirmation dialog
                    setParamMessage(CmsStringUtil.escapeHtml(key(Messages.GUI_COPY_CONFIRM_OVERWRITE_2, new Object[] {
                        getParamResource(),
                        getParamTarget()})));
                    getJsp().include(FILE_DIALOG_SCREEN_CONFIRM);
                } else {
                    // file type is different, create error message
                    includeErrorpage(this, e);
                }
            } else {
                // error during copy, show error dialog
                includeErrorpage(this, e);
            }
        }
    }

    /**
     * Builds the input radio buttons to select between preserving links or creating new resources when copying.<p>
     * 
     * @return the HTML code for the radio buttons
     */
    public String buildRadioCopyMode() {

        StringBuffer retValue = new StringBuffer(256);

        // check if the current resource is a folder for single operation
        boolean isFolder = isOperationOnFolder();
        String checkedAttr = " checked=\"checked\"";

        if (isMultiOperation() || isFolder) {
            // for multi resource operations or folders, show an additional option "preserve links"
            int defaultMode = getSettings().getUserSettings().getDialogCopyFolderMode();
            retValue.append("<input type=\"radio\" name=\"copymode\" value=\"");
            retValue.append(CmsResource.COPY_AS_SIBLING);
            retValue.append("\"");
            if (defaultMode == CmsResource.COPY_AS_SIBLING) {
                retValue.append(checkedAttr);
            }
            retValue.append("> ");
            String msgKey;
            if (isMultiOperation()) {
                msgKey = Messages.GUI_COPY_MULTI_CREATE_SIBLINGS_0;
            } else {
                msgKey = Messages.GUI_COPY_CREATE_SIBLINGS_0;
            }
            retValue.append(key(msgKey));
            retValue.append("<br>\n");
            retValue.append("<input type=\"radio\" name=\"copymode\" value=\"");
            retValue.append(CmsResource.COPY_PRESERVE_SIBLING);
            retValue.append("\"");
            if (defaultMode == CmsResource.COPY_PRESERVE_SIBLING) {
                retValue.append(checkedAttr);
            }
            retValue.append("> ");
            retValue.append(key(Messages.GUI_COPY_ALL_NO_SIBLINGS_0));
            retValue.append("<br>\n");
            retValue.append("<input type=\"radio\" name=\"copymode\" value=\"");
            retValue.append(CmsResource.COPY_AS_NEW);
            retValue.append("\"");
            if (defaultMode == CmsResource.COPY_AS_NEW) {
                retValue.append(checkedAttr);
            }
            retValue.append("> ");
            retValue.append(key(Messages.GUI_COPY_ALL_0));
            retValue.append("<br>\n");

            if (isMultiOperation()) {
                // show overwrite option for multi resource copy
                retValue.append(dialogSpacer());
                retValue.append("<input type=\"checkbox\" name=\"");
                retValue.append(PARAM_OVERWRITE);
                retValue.append("\" value=\"true\"> ");
                retValue.append(key(Messages.GUI_COPY_MULTI_OVERWRITE_0));
                retValue.append("<br>\n");
            }
        } else {
            // for files, show copy option "copy as sibling" and "copy as new resource"
            int defaultMode = getSettings().getUserSettings().getDialogCopyFileMode();
            retValue.append("<input type=\"radio\" name=\"copymode\" value=\"");
            retValue.append(CmsResource.COPY_AS_SIBLING);
            retValue.append("\"");
            if (defaultMode == CmsResource.COPY_AS_SIBLING) {
                retValue.append(checkedAttr);
            }
            retValue.append("> ");

⌨️ 快捷键说明

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