📄 cmscopy.java
字号:
}
} else {
// for files, show copy option "copy as sibling" and "copy as new resource"
CmsResourceCopyMode defaultMode = getSettings().getUserSettings().getDialogCopyFileMode();
retValue.append("<input type=\"radio\" name=\"copymode\" value=\"");
retValue.append(CmsResource.COPY_AS_SIBLING.getMode());
retValue.append("\"");
if (defaultMode == CmsResource.COPY_AS_SIBLING) {
retValue.append(checkedAttr);
}
retValue.append("> ");
retValue.append(key(Messages.GUI_CREATE_SIBLING_0));
retValue.append("<br>\n");
retValue.append("<input type=\"radio\" name=\"copymode\" value=\"");
retValue.append(CmsResource.COPY_AS_NEW.getMode());
retValue.append("\"");
if (defaultMode == CmsResource.COPY_AS_NEW) {
retValue.append(checkedAttr);
}
retValue.append("> ");
retValue.append(key(Messages.GUI_COPY_AS_NEW_0));
retValue.append("<br>\n");
}
return retValue.toString();
}
/**
* Returns the value of the copymode parameter.<p>
*
* @return the value of the copymode parameter
*/
public String getParamCopymode() {
return m_paramCopymode;
}
/**
* Returns the value of the keeprights parameter.<p>
*
* @return the value of the keeprights parameter
*/
public String getParamKeeprights() {
return m_paramKeeprights;
}
/**
* 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 copymode parameter.<p>
*
* @param value the value of the copymode parameter
*/
public void setParamCopymode(String value) {
m_paramCopymode = value;
}
/**
* Sets the value of the "keeprights" parameter.<p>
*
* @param value the value of the "keeprights" parameter
*/
public void setParamKeeprights(String value) {
m_paramKeeprights = value;
}
/**
* 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 copy 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_COPY);
} 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 copy dialog
setDialogTitle(Messages.GUI_COPY_RESOURCE_1, Messages.GUI_COPY_MULTI_2);
}
}
/**
* Performs the resource copying.<p>
*
* @return true, if the resource was copied, otherwise false
* @throws CmsException if copying is not successful
*/
protected boolean performDialogOperation() throws CmsException {
// check if the current resource is a folder for single operation
boolean isFolder = isOperationOnFolder();
// on folder copy display "please wait" screen, not for simple file copy
if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) {
// return false, this will trigger the "please wait" screen
return false;
}
// get the copy mode from request parameter value
CmsResourceCopyMode copyMode = CmsResource.COPY_PRESERVE_SIBLING;
try {
copyMode = CmsResourceCopyMode.valueOf(Integer.parseInt(getParamCopymode()));
} catch (Exception e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
// check the overwrite options
boolean overwrite = Boolean.valueOf(getParamOverwrite()).booleanValue();
overwrite = ((isMultiOperation() && overwrite) || DIALOG_CONFIRMED.equals(getParamAction()));
// calculate the target name
String target = getParamTarget();
if (target == null) {
target = "";
}
String storedSiteRoot = null;
try {
// check if a site root was added to the target name
String sitePrefix = "";
if (OpenCms.getSiteManager().getSiteRoot(target) != null) {
String siteRootFolder = getCms().getRequestContext().getSiteRoot();
if (siteRootFolder.endsWith("/")) {
siteRootFolder = siteRootFolder.substring(0, siteRootFolder.length() - 1);
}
sitePrefix = siteRootFolder;
storedSiteRoot = getCms().getRequestContext().getSiteRoot();
getCms().getRequestContext().setSiteRoot("/");
}
Iterator i = getResourceList().iterator();
// iterate the resources to copy
while (i.hasNext()) {
String resName = (String)i.next();
try {
performSingleCopyOperation(resName, target, sitePrefix, copyMode, 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 occurred
checkMultiOperationException(Messages.get(), Messages.ERR_COPY_MULTI_0);
} finally {
// restore the site root
if (storedSiteRoot != null) {
getCms().getRequestContext().setSiteRoot(storedSiteRoot);
}
}
return true;
}
/**
* Performs the copy 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 copyMode the copy mode for siblings
* @param overwrite the overwrite flag
*
* @throws CmsException if copying the resource fails
*/
protected void performSingleCopyOperation(
String source,
String target,
String sitePrefix,
CmsResourceCopyMode copyMode,
boolean overwrite) throws CmsException {
// calculate the target name
String finalTarget = CmsLinkManager.getAbsoluteUri(target, CmsResource.getParentFolder(source));
if (finalTarget.equals(source) || (isMultiOperation() && finalTarget.startsWith(source))) {
throw new CmsVfsException(Messages.get().container(Messages.ERR_COPY_ONTO_ITSELF_1, finalTarget));
}
try {
CmsResource res = getCms().readResource(finalTarget, CmsResourceFilter.ALL);
if (res.isFolder()) {
// target folder already exists, so we add the current folder name
if (!finalTarget.endsWith("/")) {
finalTarget += "/";
}
finalTarget = finalTarget + CmsResource.getName(source);
}
} 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(finalTarget);
// delete existing target resource if selected or confirmed by the user
if (overwrite && getCms().existsResource(finalTarget)) {
checkLock(finalTarget);
getCms().deleteResource(finalTarget, CmsResource.DELETE_PRESERVE_SIBLINGS);
}
// copy the resource
getCms().copyResource(sitePrefix + source, finalTarget, copyMode);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -