📄 cmsrenameimages.java
字号:
*
* @return the value of the places parameter
*/
public String getParamPlaces() {
return m_paramPlaces;
}
/**
* Returns the value of the prefix parameter.<p>
*
* @return the value of the prefix parameter
*/
public String getParamPrefix() {
return m_paramPrefix;
}
/**
* Returns the value of the remove title parameter.<p>
*
* @return the value of the remove title parameter
*/
public String getParamRemovetitle() {
return m_paramRemovetitle;
}
/**
* Returns the value of the startcount parameter.<p>
*
* @return the value of the startcount parameter
*/
public String getParamStartcount() {
return m_paramStartcount;
}
/**
* Sets the value of the places parameter.<p>
*
* @param paramPlaces the value of the places parameter
*/
public void setParamPlaces(String paramPlaces) {
m_paramPlaces = paramPlaces;
}
/**
* Sets the value of the prefix parameter.<p>
*
* @param paramPrefix the value of the prefix parameter
*/
public void setParamPrefix(String paramPrefix) {
m_paramPrefix = paramPrefix;
}
/**
* Sets the value of the remove title parameter.<p>
*
* @param paramRemovetitle the value of the remove title parameter
*/
public void setParamRemovetitle(String paramRemovetitle) {
m_paramRemovetitle = paramRemovetitle;
}
/**
* Sets the value of the startcount parameter.<p>
*
* @param paramStartcount the value of the startcount parameter
*/
public void setParamStartcount(String paramStartcount) {
m_paramStartcount = paramStartcount;
}
/**
* @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 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_RENAMEIMAGES);
} 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 rename images dialog
Object[] args = new Object[] {getParamResource()};
setParamTitle(key(Messages.GUI_RENAMEIMAGES_TITLE_1, args));
}
}
/**
* Performs the rename images operation.<p>
*
* @return true, if the resources were successfully renamed, otherwise false
* @throws CmsException if renaming is not successful
*/
protected boolean performDialogOperation() throws CmsException {
// display "please wait" screen before renaming the images
if (!DIALOG_WAIT.equals(getParamAction())) {
// return false, this will trigger the "please wait" screen
return false;
}
// lock the image gallery folder
checkLock(getParamResource());
// get all image resources of the folder
CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(CmsResourceTypeImage.getStaticTypeId());
List images = getCms().readResources(getParamResource(), filter, false);
// determine start count
int count = 1;
try {
count = Integer.parseInt(getParamStartcount());
} catch (Exception e) {
// ignore this exception
}
// create number printer instance
PrintfFormat numberFormat = new PrintfFormat("%0." + getParamPlaces() + "d");
// create image galler folder name
String folder = getParamResource();
if (!folder.endsWith("/")) {
folder += "/";
}
Iterator i = images.iterator();
// loop over all image resource to change
while (i.hasNext()) {
CmsResource res = (CmsResource)i.next();
String oldName = CmsResource.getName(res.getRootPath());
CmsProperty titleProperty = getCms().readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TITLE, false);
String oldTitle = titleProperty.getValue();
// store image name suffix
int lastDot = oldName.lastIndexOf('.');
String suffix = "";
String oldNameWithoutSuffix = oldName;
if (lastDot > -1) {
suffix = oldName.substring(lastDot);
oldNameWithoutSuffix = oldName.substring(0, lastDot);
}
// determine new image name
String newName = "";
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamPrefix()) && !"null".equals(getParamPrefix())) {
newName += getParamPrefix();
}
// create image number
String imageNumber = numberFormat.sprintf(count);
newName += imageNumber + suffix;
if (!newName.equals(oldName)) {
// only rename resources which have a new resource name
if (getCms().existsResource(folder + newName, CmsResourceFilter.ALL)) {
// target resource exists, interrupt & show error
throw new CmsException(Messages.get().container(
Messages.ERR_MOVE_FAILED_TARGET_EXISTS_2,
getCms().getSitePath(res),
folder + newName));
}
// determine the new title property value
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(oldTitle)) {
if (oldTitle.equals(oldNameWithoutSuffix)) {
if (Boolean.valueOf(getParamRemovetitle()).booleanValue()) {
// remove the title property value
if (oldTitle.equals(titleProperty.getStructureValue())) {
titleProperty.setStructureValue(CmsProperty.DELETE_VALUE);
}
if (oldTitle.equals(titleProperty.getResourceValue())) {
titleProperty.setResourceValue(CmsProperty.DELETE_VALUE);
}
} else {
// set the title property to the new resource name
if (oldTitle.equals(titleProperty.getStructureValue())) {
titleProperty.setStructureValue(getParamPrefix() + imageNumber);
} else if (oldTitle.equals(titleProperty.getResourceValue())) {
titleProperty.setResourceValue(getParamPrefix() + imageNumber);
}
}
// write changed title property
getCms().writePropertyObject(getCms().getSitePath(res), titleProperty);
}
}
// now rename the resource
getCms().renameResource(folder + oldName, folder + newName);
}
// increase image counter
count++;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -