📄 cmselementrename.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/CmsElementRename.java,v $
* Date : $Date: 2006/03/31 13:59:16 $
* Version: $Revision: 1.15 $
*
* 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.tools.content;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.I_CmsReport;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsReport;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.editors.CmsDialogElement;
import org.opencms.workplace.explorer.CmsNewResourceXmlPage;
import org.opencms.xml.CmsXmlException;
import org.opencms.xml.page.CmsXmlPage;
import org.opencms.xml.page.CmsXmlPageFactory;
import org.opencms.xml.types.CmsXmlHtmlValue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
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 change page element name dialog.<p>
*
* @author Armen Markarian
*
* @version $Revision: 1.15 $
*
* @since 6.0.0
*/
public class CmsElementRename extends CmsReport {
/** A constant representing the select option all templates. */
public static final String ALL = "ALL";
/** The dialog type. */
public static final String DIALOG_TYPE = "renameelement";
/** Request parameter name for the locale. */
public static final String PARAM_LOCALE = "locale";
/** Request parameter name for the new element name. */
public static final String PARAM_NEW_ELEMENT = "newelement";
/** Request parameter name for the old element name. */
public static final String PARAM_OLD_ELEMENT = "oldelement";
/** Request parameter name for the recursive search. */
public static final String PARAM_RECURSIVE = "recursive";
/** Request parameter name for the remove empty elements. */
public static final String PARAM_REMOVE_EMPTYELEMENTS = "removeemptyelements";
/** Request parameter name for the template. */
public static final String PARAM_TEMPLATE = "template";
/** Request parameter name for the validate new element. */
public static final String PARAM_VALIDATE_NEW_ELEMENT = "validatenewelement";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsElementRename.class);
/** the cms object. */
private CmsObject m_cms;
/** the error message. */
private String m_errorMessage;
/** the locale use for content definition. */
private String m_paramLocale;
/** The new page element name. */
private String m_paramNewElement;
/** The old page element name. */
private String m_paramOldElement;
/** The recursive parameter. */
private String m_paramRecursive;
/** the flag indicating to remove empty elements. */
private String m_paramRemoveEmptyElements;
/** the template use for all pages (optional). */
private String m_paramTemplate;
/** the flag indicating to remove empty elements. */
private String m_paramValidateNewElement;
/** the report for the output. */
private I_CmsReport m_report;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsElementRename(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Public constructor for testcase using.<p>
*
* @param jsp an initialized JSP action element
* @param cms the cms object
* @param resource the resource path
* @param recursive if true then do read recursive from the folder
* @param template the template
* @param locale the locale
* @param oldElement the old element name
* @param newElement the new element name
* @param removeEmptyElements if true then remove all invalid elements with no content
* @param validateNewElement if true then validate the new element before renaming
*/
public CmsElementRename(
CmsJspActionElement jsp,
CmsObject cms,
String resource,
String recursive,
String template,
String locale,
String oldElement,
String newElement,
String removeEmptyElements,
String validateNewElement) {
super(jsp);
m_cms = cms;
setParamResource(resource);
setParamRecursive(recursive);
setParamTemplate(template);
setParamLocale(locale);
setParamOldElement(oldElement);
setParamNewElement(newElement);
setParamRemoveEmptyElements(removeEmptyElements);
setParamValidateNewElement(validateNewElement);
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsElementRename(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Renames the element name on the specified resources.<p>
*
* @param report the cms report
*/
public void actionRename(I_CmsReport report) {
m_report = report;
List locales = OpenCms.getLocaleManager().getAvailableLocales();
List xmlPages = getXmlPages();
if (ALL.equals(getParamLocale())) {
Iterator i = locales.iterator();
while (i.hasNext()) {
Locale locale = (Locale)i.next();
performRenameOperation(xmlPages, locale);
}
} else {
performRenameOperation(xmlPages, CmsLocaleManager.getLocale(getParamLocale()));
}
}
/**
* Performs the move report, will be called by the JSP page.<p>
*
* @throws JspException if problems including sub-elements occur
*/
public void actionReport() throws JspException {
// save initialized instance of this class in request attribute for included sub-elements
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
switch (getAction()) {
case ACTION_REPORT_END:
actionCloseDialog();
break;
case ACTION_REPORT_UPDATE:
setParamAction(REPORT_UPDATE);
getJsp().include(FILE_REPORT_OUTPUT);
break;
case ACTION_REPORT_BEGIN:
case ACTION_CONFIRMED:
default:
CmsElementRenameThread thread = new CmsElementRenameThread(getCms(), this);
setParamAction(REPORT_BEGIN);
setParamThread(thread.getUUID().toString());
getJsp().include(FILE_REPORT_OUTPUT);
break;
}
}
/**
* Builds the html for the available locales select box.<p>
*
* @param attributes optional attributes for the <select> tag
*
* @return the html for the available locales select box
*/
public String buildSelectLocales(String attributes) {
List options = new ArrayList();
List values = new ArrayList();
List locales = OpenCms.getLocaleManager().getAvailableLocales();
int selectedIndex = -1;
if (locales == null) {
// no locales found, return empty String
return "";
} else {
// locales found, create option and value lists
CmsMessages messages = Messages.get().getBundle(getLocale());
options.add(messages.key(Messages.GUI_PLEASE_SELECT_0));
values.add("");
options.add(messages.key(Messages.GUI_BUTTON_ALL_0));
values.add(ALL);
if (ALL.equals(getParamLocale())) {
selectedIndex = 1;
}
Iterator i = locales.iterator();
int counter = 2;
while (i.hasNext()) {
Locale locale = (Locale)i.next();
String language = locale.getLanguage();
String displayLanguage = locale.getDisplayLanguage();
if (language.equals(getParamLocale())) {
selectedIndex = counter;
}
options.add(displayLanguage);
values.add(language);
counter++;
}
}
return CmsWorkplace.buildSelect(attributes, options, values, selectedIndex, false);
}
/**
* Builds the html for the template select box.<p>
*
* @param attributes optional attributes for the <select> tag
* @return the html for the template select box
*/
public String buildSelectTemplates(String attributes) {
List options = new ArrayList();
List values = new ArrayList();
TreeMap templates = null;
int selectedIndex = -1;
try {
// get all available templates
templates = CmsNewResourceXmlPage.getTemplates(getCms(), null);
} catch (CmsException e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
if (templates == null) {
// no templates found, return empty String
return "";
} else {
// templates found, create option and value lists
CmsMessages messages = Messages.get().getBundle(getLocale());
options.add(messages.key(Messages.GUI_PLEASE_SELECT_0));
values.add("");
options.add(messages.key(Messages.GUI_BUTTON_ALL_0));
values.add(ALL);
if (ALL.equals(getParamTemplate())) {
selectedIndex = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -