📄 cmspreferences.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsPreferences.java,v $
* Date : $Date: 2007-08-29 13:30:25 $
* Version: $Revision: 1.36 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 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.db.CmsUserSettings;
import org.opencms.db.CmsUserSettings.CmsSearchResultStyle;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.file.CmsResource.CmsResourceCopyMode;
import org.opencms.file.CmsResource.CmsResourceDeleteMode;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsContextInfo;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.I_CmsReport;
import org.opencms.security.CmsPasswordInfo;
import org.opencms.site.CmsSite;
import org.opencms.synchronize.CmsSynchronizeSettings;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.CmsCalendarWidget;
import org.opencms.workplace.CmsTabDialog;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceManager;
import org.opencms.workplace.CmsWorkplaceMessages;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.CmsWorkplaceView;
import org.opencms.workplace.editors.CmsWorkplaceEditorConfiguration;
import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
/**
* Provides methods for the user preferences dialog. <p>
*
* The following files use this class:
* <ul>
* <li>/commons/preferences.jsp
* </ul>
* <p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.36 $
*
* @since 6.0.0
*/
public class CmsPreferences extends CmsTabDialog {
/** Value for the action: change the password. */
public static final int ACTION_CHPWD = 202;
/** Value for the action: show error screen. */
public static final int ACTION_ERROR = 203;
/** Value for the action: reload the workplace. */
public static final int ACTION_RELOAD = 201;
/** Request parameter value for the action: change the password. */
public static final String DIALOG_CHPWD = "chpwd";
/** Request parameter value for the action: reload the workplace. */
public static final String DIALOG_RELOAD = "reload";
/** The dialog type. */
public static final String DIALOG_TYPE = "preferences";
/** Request parameter name prefix for the preferred editors. */
public static final String INPUT_DEFAULT = "default";
/** Request parameter name for the dialog copy file siblings default setting. */
public static final String PARAM_DIALOGS_COPYFILEMODE = "tabdicopyfilemode";
/** Request parameter name for the dialog copy folder siblings default setting. */
public static final String PARAM_DIALOGS_COPYFOLDERMODE = "tabdicopyfoldermode";
/** Request parameter name for the dialog delete file siblings default setting. */
public static final String PARAM_DIALOGS_DELETEFILEMODE = "tabdideletefilemode";
/** Request parameter name for the dialog permissions show inherited permissions. */
public static final String PARAM_DIALOGS_PERMISSIONS_EXPANDINHERITED = "tabdipermissionsexpandinherited";
/** Request parameter name for the dialog permissions show current users permissions. */
public static final String PARAM_DIALOGS_PERMISSIONS_EXPANDUSER = "tabdipermissionsexpanduser";
/** Request parameter name for the dialog permissions default inheritance behaviour on folders. */
public static final String PARAM_DIALOGS_PERMISSIONS_INHERITONFOLDER = "tabdipermissionsinheritonfolder";
/** Request parameter name for the dialog publish file siblings default setting. */
public static final String PARAM_DIALOGS_PUBLISHFILEMODE = "tabdipublishfilemode";
/** Request parameter name for the dialog show lock. */
public static final String PARAM_DIALOGS_SHOWLOCK = "tabdishowlock";
/** Request parameter name for the direct edit button style. */
public static final String PARAM_DIRECTEDIT_BUTTONSTYLE = "tabeddirecteditbuttonstyle";
/** Request parameter name for the editor button style. */
public static final String PARAM_EDITOR_BUTTONSTYLE = "tabedbuttonstyle";
/** Request parameter name for the explorer button style. */
public static final String PARAM_EXPLORER_BUTTONSTYLE = "tabexbuttonstyle";
/** Request parameter name for the explorer file date created. */
public static final String PARAM_EXPLORER_FILEDATECREATED = "tabexfiledatecreated";
/** Request parameter name for the explorer file date expired. */
public static final String PARAM_EXPLORER_FILEDATEEXPIRED = "tabexfiledateexpired";
/** Request parameter name for the explorer file date last modified. */
public static final String PARAM_EXPLORER_FILEDATELASTMODIFIED = "tabexfiledatelastmodified";
/** Request parameter name for the explorer file date released. */
public static final String PARAM_EXPLORER_FILEDATERELEASED = "tabexfiledatereleased";
/** Request parameter name for the explorer file entry number. */
public static final String PARAM_EXPLORER_FILEENTRIES = "tabexfileentries";
/** Request parameter name for the explorer file locked by. */
public static final String PARAM_EXPLORER_FILELOCKEDBY = "tabexfilelockedby";
/** Request parameter name for the explorer file navtext. */
public static final String PARAM_EXPLORER_FILENAVTEXT = "tabexfilenavtext";
/** Request parameter name for the explorer file permissions. */
public static final String PARAM_EXPLORER_FILEPERMISSIONS = "tabexfilepermissions";
/** Request parameter name for the explorer file size. */
public static final String PARAM_EXPLORER_FILESIZE = "tabexfilesize";
/** Request parameter name for the explorer file state. */
public static final String PARAM_EXPLORER_FILESTATE = "tabexfilestate";
/** Request parameter name for the explorer file title. */
public static final String PARAM_EXPLORER_FILETITLE = "tabexfiletitle";
/** Request parameter name for the explorer file type. */
public static final String PARAM_EXPLORER_FILETYPE = "tabexfiletype";
/** Request parameter name for the explorer file user created. */
public static final String PARAM_EXPLORER_FILEUSERCREATED = "tabexfileusercreated";
/** Request parameter name for the explorer file user last modified. */
public static final String PARAM_EXPLORER_FILEUSERLASTMODIFIED = "tabexfileuserlastmodified";
/** Request parameter name for the workplace search result list style. */
public static final String PARAM_EXPLORER_SEARCH_RESULT = "tabexworkplacesearchresult";
/** Request parameter name for the new password. */
public static final String PARAM_NEWPASSWORD = "newpassword";
/** Request parameter name for the old password. */
public static final String PARAM_OLDPASSWORD = "oldpassword";
/** Request parameter name prefix for the preferred editors. */
public static final String PARAM_PREFERREDEDITOR_PREFIX = "tabedprefed_";
/** Request parameter name for the workplace button style. */
public static final String PARAM_WORKPLACE_BUTTONSTYLE = "tabwpbuttonstyle";
/** Request parameter name for the workplace start folder. */
public static final String PARAM_WORKPLACE_FOLDER = "tabwpfolder";
/** Request parameter name for the workplace language. */
public static final String PARAM_WORKPLACE_LANGUAGE = "tabwplanguage";
/** Request parameter name for the workplace project. */
public static final String PARAM_WORKPLACE_PROJECT = "tabwpproject";
/** Request parameter name for the workplace report type. */
public static final String PARAM_WORKPLACE_REPORTTYPE = "tabwpreporttype";
/** Request parameter name for the workplace explorer view restriction. */
public static final String PARAM_WORKPLACE_RESTRICTEXPLORERVIEW = "tabwprestrictexplorerview";
/** Request parameter name for the workplace show publish notification. */
public static final String PARAM_WORKPLACE_SHOWPUBLISHNOTIFICATION = "tabwpshowpublishnotification";
/** Request parameter name for the workplace start site. */
public static final String PARAM_WORKPLACE_SITE = "tabwpsite";
/** Request parameter name for the user language. */
public static final String PARAM_WORKPLACE_TIMEWARP = "tabwptimewarp";
/** Request parameter name for the workplace use upload applet. */
public static final String PARAM_WORKPLACE_USEUPLOADAPPLET = "tabwpuseuploadapplet";
/** Request parameter name for the workplace view. */
public static final String PARAM_WORKPLACE_VIEW = "tabwpview";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsPreferences.class);
/** The old password. */
private String m_paramNewPassword;
/** The new password. */
private String m_paramOldPassword;
/** User settings object used to store the dialog field values. */
private CmsUserSettings m_userSettings;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsPreferences(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 CmsPreferences(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Performs the change password action.<p>
*
* @throws JspException if inclusion of error element fails
*/
public void actionChangePassword() throws JspException {
// save initialized instance of this class in request attribute for included sub-elements
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
String newPwd = getParamNewPassword();
String oldPwd = getParamOldPassword();
// set the action parameter, reset the password parameters
setAction(ACTION_DEFAULT);
setParamOldPassword(null);
setParamNewPassword(null);
try {
CmsPasswordInfo pwdInfo = new CmsPasswordInfo(getCms());
pwdInfo.setCurrentPwd(oldPwd);
pwdInfo.setNewPwd(newPwd);
pwdInfo.setConfirmation(newPwd);
pwdInfo.applyChanges();
} catch (Throwable e) {
// failed setting the new password, show error dialog
setAction(ACTION_ERROR);
includeErrorpage(this, e);
}
}
/**
* Performs the save operation of the modified user settings.<p>
*/
public void actionSave() {
HttpServletRequest request = getJsp().getRequest();
// save initialized instance of this class in request attribute for included sub-elements
request.setAttribute(SESSION_WORKPLACE_CLASS, this);
// special case: set the preferred editor settings in the user settings object
CmsUserSettings userSettings = new CmsUserSettings(getSettings().getUser());
// first set the old preferred editors
m_userSettings.setEditorSettings(userSettings.getEditorSettings());
// then set the old synchronization settings
m_userSettings.setSynchronizeSettings(userSettings.getSynchronizeSettings());
Enumeration en = request.getParameterNames();
while (en.hasMoreElements()) {
// search all request parameters for the presence of the preferred editor parameters
String paramName = (String)en.nextElement();
if (paramName.startsWith(PARAM_PREFERREDEDITOR_PREFIX)) {
String paramValue = request.getParameter(paramName);
if ((paramValue != null) && !INPUT_DEFAULT.equals(paramValue.trim())) {
// set selected editor for this resource type
m_userSettings.setPreferredEditor(
paramName.substring(PARAM_PREFERREDEDITOR_PREFIX.length()),
CmsEncoder.decode(paramValue));
} else {
// reset preferred editor for this resource type
m_userSettings.setPreferredEditor(paramName.substring(PARAM_PREFERREDEDITOR_PREFIX.length()), null);
}
}
}
// set the current user in the settings object
m_userSettings.setUser(getSettings().getUser());
try {
// write the user settings to the db
m_userSettings.save(getCms());
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
// update the preferences and project after saving
updatePreferences(getCms(), getJsp().getRequest());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -