📄 cmsmove.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsMove.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 move resources dialog.<p>
*
* The following files use this class:
* <ul>
* <li>/commons/move.jsp
* </ul>
* <p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.20 $
*
* @since 6.0.0
*/
public class CmsMove extends CmsMultiDialog {
/** Value for the action: move resource. */
public static final int ACTION_MOVE = 100;
/** The dialog type. */
public static final String DIALOG_TYPE = "move";
/** 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(CmsMove.class);
private String m_paramOverwrite;
private String m_paramTarget;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsMove(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 CmsMove(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Performs the move action, will be called by the JSP page.<p>
*
* @throws JspException if problems including sub-elements occur
*/
public void actionMove() 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_MOVE_MULTI_TARGET_NOFOLDER_1, target));
}
}
if (performDialogOperation()) {
// if no exception is caused and "true" is returned move operation was successful
if (isMultiOperation() || isFolder) {
// set request attribute to reload the explorer tree view
List folderList = new ArrayList(2);
String sourceParent = CmsResource.getParentFolder(source);
String targetParent = CmsResource.getParentFolder(target);
if (!targetParent.equals(sourceParent)) {
// update target folder if its not the same as the source folder
folderList.add(targetParent);
}
folderList.add(sourceParent);
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
if (! isMultiOperation() && (e instanceof CmsVfsResourceAlreadyExistsException) && !(resource.isFolder())) {
// file move 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 move, show error dialog
includeErrorpage(this, e);
}
}
}
/**
* Builds the available options when moving.<p>
*
* @return the HTML code for the options
*/
public String buildMoveOptions() {
StringBuffer retValue = new StringBuffer(256);
if (isMultiOperation()) {
// show overwrite option for multi resource moving
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");
retValue.append(dialogSpacer());
}
return retValue.toString();
}
/**
* Returns the current name of the resource without path information.<p>
*
* This is used to preset the input text field with the current resource name for single resource operations.<p>
*
* @return the current name of the resource without path information
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -