001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.commons;
029
030import org.opencms.configuration.CmsDefaultUserSettings;
031import org.opencms.configuration.preferences.CmsBuiltinPreference.SelectOptions;
032import org.opencms.configuration.preferences.CmsStartViewPreference;
033import org.opencms.db.CmsUserSettings;
034import org.opencms.db.CmsUserSettings.CmsSearchResultStyle;
035import org.opencms.db.CmsUserSettings.UploadVariant;
036import org.opencms.file.CmsObject;
037import org.opencms.file.CmsProject;
038import org.opencms.file.CmsPropertyDefinition;
039import org.opencms.file.CmsResource;
040import org.opencms.file.CmsResource.CmsResourceCopyMode;
041import org.opencms.file.CmsResource.CmsResourceDeleteMode;
042import org.opencms.file.CmsResourceFilter;
043import org.opencms.file.CmsUser;
044import org.opencms.i18n.CmsEncoder;
045import org.opencms.i18n.CmsLocaleManager;
046import org.opencms.jsp.CmsJspActionElement;
047import org.opencms.loader.CmsLoaderException;
048import org.opencms.main.CmsContextInfo;
049import org.opencms.main.CmsException;
050import org.opencms.main.CmsLog;
051import org.opencms.main.OpenCms;
052import org.opencms.report.I_CmsReport;
053import org.opencms.security.CmsPasswordInfo;
054import org.opencms.site.CmsSite;
055import org.opencms.synchronize.CmsSynchronizeSettings;
056import org.opencms.util.CmsStringUtil;
057import org.opencms.widgets.CmsCalendarWidget;
058import org.opencms.workplace.CmsTabDialog;
059import org.opencms.workplace.CmsWorkplace;
060import org.opencms.workplace.CmsWorkplaceManager;
061import org.opencms.workplace.CmsWorkplaceMessages;
062import org.opencms.workplace.CmsWorkplaceSettings;
063import org.opencms.workplace.editors.CmsWorkplaceEditorConfiguration;
064import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
065import org.opencms.workplace.galleries.A_CmsAjaxGallery;
066
067import java.io.IOException;
068import java.util.ArrayList;
069import java.util.Collections;
070import java.util.Enumeration;
071import java.util.HashMap;
072import java.util.Iterator;
073import java.util.List;
074import java.util.Locale;
075import java.util.Map;
076import java.util.SortedMap;
077import java.util.TreeMap;
078
079import javax.servlet.ServletException;
080import javax.servlet.http.HttpServletRequest;
081import javax.servlet.http.HttpServletResponse;
082import javax.servlet.http.HttpSession;
083import javax.servlet.jsp.JspException;
084import javax.servlet.jsp.PageContext;
085
086import org.apache.commons.logging.Log;
087
088/**
089 * Provides methods for the user preferences dialog. <p>
090 *
091 * The following files use this class:
092 * <ul>
093 * <li>/commons/preferences.jsp
094 * </ul>
095 * <p>
096 *
097 * @since 6.0.0
098 */
099public class CmsPreferences extends CmsTabDialog {
100
101    /** Value for the action: change the password. */
102    public static final int ACTION_CHPWD = 202;
103
104    /** Value for the action: show error screen. */
105    public static final int ACTION_ERROR = 203;
106
107    /** Value for the action: reload the workplace. */
108    public static final int ACTION_RELOAD = 201;
109
110    /** Request parameter value for the action: change the password. */
111    public static final String DIALOG_CHPWD = "chpwd";
112
113    /** Request parameter value for the action: reload the workplace. */
114    public static final String DIALOG_RELOAD = "reload";
115
116    /** The dialog type. */
117    public static final String DIALOG_TYPE = "preferences";
118
119    /** Request parameter name for global gallery settings. */
120    public static final String INPUT_PRESELECT = "preselect";
121
122    /** Request parameter name for the dialog copy file siblings default setting. */
123    public static final String PARAM_DIALOGS_COPYFILEMODE = "tabdicopyfilemode";
124
125    /** Request parameter name for the dialog copy folder siblings default setting. */
126    public static final String PARAM_DIALOGS_COPYFOLDERMODE = "tabdicopyfoldermode";
127
128    /** Request parameter name for the dialog delete file siblings default setting. */
129    public static final String PARAM_DIALOGS_DELETEFILEMODE = "tabdideletefilemode";
130
131    /** Request parameter name for the dialog permissions show inherited permissions. */
132    public static final String PARAM_DIALOGS_PERMISSIONS_EXPANDINHERITED = "tabdipermissionsexpandinherited";
133
134    /** Request parameter name for the dialog permissions show current users permissions. */
135    public static final String PARAM_DIALOGS_PERMISSIONS_EXPANDUSER = "tabdipermissionsexpanduser";
136
137    /** Request parameter name for the dialog permissions default inheritance behavior on folders. */
138    public static final String PARAM_DIALOGS_PERMISSIONS_INHERITONFOLDER = "tabdipermissionsinheritonfolder";
139
140    /** Request parameter name for the dialog publish file siblings default setting. */
141    public static final String PARAM_DIALOGS_PUBLISHFILEMODE = "tabdipublishfilemode";
142
143    /** Request parameter name for the dialog show lock. */
144    public static final String PARAM_DIALOGS_SHOWLOCK = "tabdishowlock";
145
146    /** Request parameter name for the direct edit button style. */
147    public static final String PARAM_DIRECTEDIT_BUTTONSTYLE = "tabeddirecteditbuttonstyle";
148
149    /** Request parameter name for the editor button style. */
150    public static final String PARAM_EDITOR_BUTTONSTYLE = "tabedbuttonstyle";
151
152    /** Request parameter name for the explorer button style. */
153    public static final String PARAM_EXPLORER_BUTTONSTYLE = "tabexbuttonstyle";
154
155    /** Request parameter name for the explorer file date created. */
156    public static final String PARAM_EXPLORER_FILEDATECREATED = "tabexfiledatecreated";
157
158    /** Request parameter name for the explorer file date expired. */
159    public static final String PARAM_EXPLORER_FILEDATEEXPIRED = "tabexfiledateexpired";
160
161    /** Request parameter name for the explorer file date last modified. */
162    public static final String PARAM_EXPLORER_FILEDATELASTMODIFIED = "tabexfiledatelastmodified";
163
164    /** Request parameter name for the explorer file date released. */
165    public static final String PARAM_EXPLORER_FILEDATERELEASED = "tabexfiledatereleased";
166
167    /** Request parameter name for the explorer file entry number. */
168    public static final String PARAM_EXPLORER_FILEENTRIES = "tabexfileentries";
169
170    /** Request parameter name for the explorer file locked by. */
171    public static final String PARAM_EXPLORER_FILELOCKEDBY = "tabexfilelockedby";
172
173    /** Request parameter name for the explorer file navtext. */
174    public static final String PARAM_EXPLORER_FILENAVTEXT = "tabexfilenavtext";
175
176    /** Request parameter name for the explorer file permissions. */
177    public static final String PARAM_EXPLORER_FILEPERMISSIONS = "tabexfilepermissions";
178
179    /** Request parameter name for the explorer file size. */
180    public static final String PARAM_EXPLORER_FILESIZE = "tabexfilesize";
181
182    /** Request parameter name for the explorer file state. */
183    public static final String PARAM_EXPLORER_FILESTATE = "tabexfilestate";
184
185    /** Request parameter name for the explorer file title. */
186    public static final String PARAM_EXPLORER_FILETITLE = "tabexfiletitle";
187
188    /** Request parameter name for the explorer file type. */
189    public static final String PARAM_EXPLORER_FILETYPE = "tabexfiletype";
190
191    /** Request parameter name for the explorer file user created. */
192    public static final String PARAM_EXPLORER_FILEUSERCREATED = "tabexfileusercreated";
193
194    /** Request parameter name for the explorer file user last modified. */
195    public static final String PARAM_EXPLORER_FILEUSERLASTMODIFIED = "tabexfileuserlastmodified";
196
197    /** Request parameter name for the workplace search result list style. */
198    public static final String PARAM_EXPLORER_SEARCH_RESULT = "tabexworkplacesearchresult";
199
200    /** Request parameter name for the new password. */
201    public static final String PARAM_NEWPASSWORD = "newpassword";
202
203    /** Request parameter name for the old password. */
204    public static final String PARAM_OLDPASSWORD = "oldpassword";
205
206    /** Request parameter name prefix for the preferred editors. */
207    public static final String PARAM_PREFERREDEDITOR_PREFIX = "tabedprefed_";
208
209    /** Request parameter name prefix for the preferred editors. */
210    public static final String PARAM_STARTGALLERY_PREFIX = "tabgastartgallery_";
211
212    /** Request parameter name for the workplace button style. */
213    public static final String PARAM_WORKPLACE_BUTTONSTYLE = "tabwpbuttonstyle";
214
215    /** Request parameter name for the workplace start folder. */
216    public static final String PARAM_WORKPLACE_FOLDER = "tabwpfolder";
217
218    /** Request parameter name for the workplace language. */
219    public static final String PARAM_WORKPLACE_LANGUAGE = "tabwplanguage";
220
221    /** Request parameter name for the user language. */
222    public static final String PARAM_WORKPLACE_LISTALLPROJECTS = "tabwplistallprojects";
223
224    /** Request parameter name for the workplace project. */
225    public static final String PARAM_WORKPLACE_PROJECT = "tabwpproject";
226
227    /** Request parameter name for the workplace report type. */
228    public static final String PARAM_WORKPLACE_REPORTTYPE = "tabwpreporttype";
229
230    /** Request parameter name for the workplace explorer view restriction. */
231    public static final String PARAM_WORKPLACE_RESTRICTEXPLORERVIEW = "tabwprestrictexplorerview";
232
233    /** Request parameter name for the workplace show publish notification. */
234    public static final String PARAM_WORKPLACE_SHOWPUBLISHNOTIFICATION = "tabwpshowpublishnotification";
235
236    /** Request parameter name for the workplace start site. */
237    public static final String PARAM_WORKPLACE_SITE = "tabwpsite";
238
239    /** Request parameter name for the user language. */
240    public static final String PARAM_WORKPLACE_TIMEWARP = "tabwptimewarp";
241
242    /** Request parameter name for the workplace to choose the upload variant. */
243    public static final String PARAM_WORKPLACE_UPLOADVARIANT = "tabwpuploadvariant";
244
245    /** Request parameter name for the workplace view. */
246    public static final String PARAM_WORKPLACE_VIEW = "tabwpview";
247
248    /** The log object for this class. */
249    private static final Log LOG = CmsLog.getLog(CmsPreferences.class);
250
251    /** The old password. */
252    private String m_paramNewPassword;
253
254    /** The new password. */
255    private String m_paramOldPassword;
256
257    /** User settings object used to store the dialog field values. */
258    private CmsUserSettings m_userSettings;
259
260    /**
261     * Public constructor with JSP action element.<p>
262     *
263     * @param jsp an initialized JSP action element
264     */
265    public CmsPreferences(CmsJspActionElement jsp) {
266
267        super(jsp);
268    }
269
270    /**
271     * Public constructor with JSP variables.<p>
272     *
273     * @param context the JSP page context
274     * @param req the JSP request
275     * @param res the JSP response
276     */
277    public CmsPreferences(PageContext context, HttpServletRequest req, HttpServletResponse res) {
278
279        this(new CmsJspActionElement(context, req, res));
280    }
281
282    /**
283     * Gets the options for the language selector.<p>
284     *
285     * @param setLocale the locale for the select options
286     * @param prevLocale the locale currently set
287     *
288     * @return the options for the language selector
289     */
290    public static SelectOptions getOptionsForLanguageStatic(Locale setLocale, Locale prevLocale) {
291
292        // get available locales from the workplace manager
293        List<Locale> locales = OpenCms.getWorkplaceManager().getLocales();
294        List<String> options = new ArrayList<String>(locales.size());
295        List<String> values = new ArrayList<String>(locales.size());
296        int checkedIndex = 0;
297        int counter = 0;
298        Iterator<Locale> i = locales.iterator();
299        while (i.hasNext()) {
300            Locale currentLocale = i.next();
301            // add all locales to the select box
302            String language = currentLocale.getDisplayLanguage(setLocale);
303            if (CmsStringUtil.isNotEmpty(currentLocale.getCountry())) {
304                language = language + " (" + currentLocale.getDisplayCountry(setLocale) + ")";
305            }
306            if (CmsStringUtil.isNotEmpty(currentLocale.getVariant())) {
307                language = language + " (" + currentLocale.getDisplayVariant(setLocale) + ")";
308            }
309            options.add(language);
310            values.add(currentLocale.toString());
311            if (prevLocale.toString().equals(currentLocale.toString())) {
312                // mark the currently active locale
313                checkedIndex = counter;
314            }
315            counter++;
316        }
317        SelectOptions selectOptions = new SelectOptions(options, values, checkedIndex);
318        return selectOptions;
319    }
320
321    /**
322     * Gets the options for the project selector.<p>
323     *
324     * @param cms  the CMS context
325     * @param startProject the start project
326     * @param  locale the locale
327     *
328     * @return the options for the project selector
329     */
330    public static SelectOptions getProjectSelectOptionsStatic(CmsObject cms, String startProject, Locale locale) {
331
332        List<CmsProject> allProjects;
333        try {
334            String ouFqn = "";
335            CmsUserSettings settings = new CmsUserSettings(cms);
336            if (!settings.getListAllProjects()) {
337                ouFqn = cms.getRequestContext().getCurrentUser().getOuFqn();
338            }
339            allProjects = OpenCms.getOrgUnitManager().getAllAccessibleProjects(
340                cms,
341                ouFqn,
342                settings.getListAllProjects());
343        } catch (CmsException e) {
344            // should usually never happen
345            if (LOG.isErrorEnabled()) {
346                LOG.error(e.getLocalizedMessage(), e);
347            }
348            allProjects = Collections.emptyList();
349        }
350
351        boolean singleOu = true;
352        String ouFqn = null;
353        Iterator<CmsProject> itProjects = allProjects.iterator();
354        while (itProjects.hasNext()) {
355            CmsProject prj = itProjects.next();
356            if (prj.isOnlineProject()) {
357                // skip the online project
358                continue;
359            }
360            if (ouFqn == null) {
361                // set the first ou
362                ouFqn = prj.getOuFqn();
363            }
364            if (!ouFqn.equals(prj.getOuFqn())) {
365                // break if one different ou is found
366                singleOu = false;
367                break;
368            }
369        }
370
371        List<String> options = new ArrayList<String>(allProjects.size());
372        List<String> values = new ArrayList<String>(allProjects.size());
373        int checkedIndex = 0;
374
375        for (int i = 0, n = allProjects.size(); i < n; i++) {
376            CmsProject project = allProjects.get(i);
377            String projectName = project.getSimpleName();
378            if (!singleOu && !project.isOnlineProject()) {
379                try {
380                    projectName = projectName
381                        + " - "
382                        + OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, project.getOuFqn()).getDisplayName(
383                            locale);
384                } catch (CmsException e) {
385                    projectName = projectName + " - " + project.getOuFqn();
386                }
387            }
388            options.add(projectName);
389            values.add(project.getName());
390            if (startProject.equals(project.getName())) {
391                checkedIndex = i;
392            }
393        }
394        SelectOptions selectOptions = new SelectOptions(options, values, checkedIndex);
395        return selectOptions;
396    }
397
398    /**
399     * Gets the options for the site selector.<p>
400     *
401     * @param cms the CMS context
402     * @param wpSite the selected site
403     * @param locale the locale for the select options
404     *
405     * @return the options for the site selector
406     */
407    public static SelectOptions getSiteSelectOptionsStatic(CmsObject cms, String wpSite, Locale locale) {
408
409        List<String> options = new ArrayList<String>();
410        List<String> values = new ArrayList<String>();
411        int selectedIndex = 0;
412
413        List<CmsSite> sites = OpenCms.getSiteManager().getAvailableSites(
414            cms,
415            true,
416            false,
417            cms.getRequestContext().getOuFqn());
418        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(wpSite) && !wpSite.endsWith("/")) {
419            wpSite += "/";
420        }
421
422        Iterator<CmsSite> i = sites.iterator();
423        int pos = 0;
424        while (i.hasNext()) {
425            CmsSite site = i.next();
426            String siteRoot = site.getSiteRoot();
427            if (!siteRoot.endsWith("/")) {
428                siteRoot += "/";
429            }
430            values.add(siteRoot);
431            options.add(CmsWorkplace.substituteSiteTitleStatic(site.getTitle(), locale));
432            if (siteRoot.equals(wpSite)) {
433                // this is the user's currently chosen site
434                selectedIndex = pos;
435            }
436            pos++;
437        }
438
439        if (sites.size() < 1) {
440            // no site found, assure that at least the current site is shown in the selector
441            String siteRoot = cms.getRequestContext().getSiteRoot();
442            CmsSite site = OpenCms.getSiteManager().getSiteForSiteRoot(siteRoot);
443            if (!siteRoot.endsWith("/")) {
444                siteRoot += "/";
445            }
446            String title = "";
447            if (site != null) {
448                title = site.getTitle();
449            }
450            values.add(siteRoot);
451            options.add(title);
452        }
453        SelectOptions selectOptions = new SelectOptions(options, values, selectedIndex);
454        return selectOptions;
455    }
456
457    /**
458     * Performs the change password action.<p>
459     *
460     * @throws JspException if inclusion of error element fails
461     */
462    public void actionChangePassword() throws JspException {
463
464        // save initialized instance of this class in request attribute for included sub-elements
465        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
466        String newPwd = getParamNewPassword();
467        String oldPwd = getParamOldPassword();
468        // set the action parameter, reset the password parameters
469        setAction(ACTION_DEFAULT);
470        setParamOldPassword(null);
471        setParamNewPassword(null);
472
473        try {
474            CmsPasswordInfo pwdInfo = new CmsPasswordInfo(getCms());
475            pwdInfo.setCurrentPwd(oldPwd);
476            pwdInfo.setNewPwd(newPwd);
477            pwdInfo.setConfirmation(newPwd);
478            pwdInfo.applyChanges();
479        } catch (Throwable e) {
480            // failed setting the new password, show error dialog
481            setAction(ACTION_ERROR);
482            includeErrorpage(this, e);
483        }
484    }
485
486    /**
487     * Performs the save operation of the modified user settings.<p>
488     */
489    public void actionSave() {
490
491        HttpServletRequest request = getJsp().getRequest();
492        // save initialized instance of this class in request attribute for included sub-elements
493        request.setAttribute(SESSION_WORKPLACE_CLASS, this);
494
495        // special case: set the preferred editor settings in the user settings object
496        CmsUserSettings userSettings = new CmsUserSettings(getSettings().getUser());
497        // first set the old preferred editors
498        m_userSettings.setEditorSettings(userSettings.getEditorSettings());
499        // also set the old start gallery settings
500        m_userSettings.setStartGalleriesSetting(userSettings.getStartGalleriesSettings());
501        // then set the old synchronization settings
502        m_userSettings.setSynchronizeSettings(userSettings.getSynchronizeSettings());
503        Enumeration<String> en = request.getParameterNames();
504        while (en.hasMoreElements()) {
505            // search all request parameters for the presence of the preferred editor parameters
506            String paramName = en.nextElement();
507            if (paramName.startsWith(PARAM_PREFERREDEDITOR_PREFIX)) {
508                String paramValue = request.getParameter(paramName);
509                if ((paramValue != null) && !INPUT_DEFAULT.equals(paramValue.trim())) {
510                    // set selected editor for this resource type
511                    m_userSettings.setPreferredEditor(
512                        paramName.substring(PARAM_PREFERREDEDITOR_PREFIX.length()),
513                        CmsEncoder.decode(paramValue));
514                } else {
515                    // reset preferred editor for this resource type
516                    m_userSettings.setPreferredEditor(paramName.substring(PARAM_PREFERREDEDITOR_PREFIX.length()), null);
517                }
518            } else if (paramName.startsWith(PARAM_STARTGALLERY_PREFIX)) {
519                String paramValue = request.getParameter(paramName);
520                if (paramValue != null) {
521                    // set the selected start gallery for the gallery type
522                    m_userSettings.setStartGallery(
523                        paramName.substring(PARAM_STARTGALLERY_PREFIX.length()),
524                        CmsEncoder.decode(paramValue));
525                }
526            }
527        }
528
529        // set the current user in the settings object
530        m_userSettings.setUser(getSettings().getUser());
531        m_userSettings.setAdditionalPreferencesFrom(userSettings);
532
533        try {
534            // write the user settings to the db
535            m_userSettings.save(getCms());
536        } catch (CmsException e) {
537            // should usually never happen
538            if (LOG.isInfoEnabled()) {
539                LOG.info(e.getLocalizedMessage());
540            }
541        }
542
543        // update the preferences and project after saving
544        updatePreferences(getCms(), getJsp().getRequest());
545
546        try {
547            String projectName = m_userSettings.getStartProject();
548            CmsProject project = getCms().readProject(projectName);
549            getCms().getRequestContext().setCurrentProject(project);
550            getSettings().setProject(project.getUuid());
551        } catch (Exception e) {
552            // should usually never happen
553            LOG.error(e.getLocalizedMessage());
554        }
555
556        // now determine if the dialog has to be closed or not
557        try {
558            if (DIALOG_SET.equals(getParamAction())) {
559                // after "set" action, leave dialog open
560                Map<String, String[]> params = new HashMap<String, String[]>();
561                params.put(PARAM_TAB, new String[] {String.valueOf(getActiveTab())});
562                params.put(PARAM_SETPRESSED, new String[] {Boolean.TRUE.toString()});
563                sendForward(getJsp().getRequestContext().getUri(), params);
564            } else {
565                // forward to dialog with action set to reload the workplace
566                Map<String, String[]> params = new HashMap<String, String[]>();
567                params.put(PARAM_ACTION, new String[] {DIALOG_RELOAD});
568                sendForward(getJsp().getRequestContext().getUri(), params);
569            }
570        } catch (IOException e) {
571            // error during forward, do nothing
572            if (LOG.isInfoEnabled()) {
573                LOG.info(e.getLocalizedMessage());
574            }
575        } catch (ServletException e) {
576            // error during forward, do nothing
577            if (LOG.isInfoEnabled()) {
578                LOG.info(e.getLocalizedMessage());
579            }
580        }
581    }
582
583    /**
584     * Builds the html for the default copy file mode select box.<p>
585     *
586     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
587     * @return the html for the default copy file mode select box
588     */
589    public String buildSelectCopyFileMode(String htmlAttributes) {
590
591        List<String> options = new ArrayList<String>(2);
592        options.add(key(Messages.GUI_PREF_COPY_AS_SIBLING_0));
593        options.add(key(Messages.GUI_COPY_AS_NEW_0));
594        List<String> values = new ArrayList<String>(2);
595        values.add(CmsResource.COPY_AS_SIBLING.toString());
596        values.add(CmsResource.COPY_AS_NEW.toString());
597        int selectedIndex = values.indexOf(getParamTabDiCopyFileMode());
598        return buildSelect(htmlAttributes, options, values, selectedIndex);
599    }
600
601    /**
602     * Builds the html for the default copy folder mode select box.<p>
603     *
604     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
605     * @return the html for the default copy folder mode select box
606     */
607    public String buildSelectCopyFolderMode(String htmlAttributes) {
608
609        List<String> options = new ArrayList<String>(3);
610        options.add(key(Messages.GUI_PREF_COPY_AS_SIBLINGS_0));
611        options.add(key(Messages.GUI_PREF_PRESERVE_SIBLINGS_RESOURCES_0));
612        options.add(key(Messages.GUI_PREF_COPY_AS_NEW_0));
613        List<String> values = new ArrayList<String>(3);
614        values.add(CmsResource.COPY_AS_SIBLING.toString());
615        values.add(CmsResource.COPY_PRESERVE_SIBLING.toString());
616        values.add(CmsResource.COPY_AS_NEW.toString());
617        int selectedIndex = values.indexOf(getParamTabDiCopyFolderMode());
618        return buildSelect(htmlAttributes, options, values, selectedIndex);
619    }
620
621    /**
622     * Builds the html for the default delete file mode select box.<p>
623     *
624     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
625     * @return the html for the default delete file mode select box
626     */
627    public String buildSelectDeleteFileMode(String htmlAttributes) {
628
629        List<String> options = new ArrayList<String>(2);
630        options.add(key(Messages.GUI_PREF_PRESERVE_SIBLINGS_0));
631        options.add(key(Messages.GUI_PREF_DELETE_SIBLINGS_0));
632        List<String> values = new ArrayList<String>(2);
633        values.add(String.valueOf(CmsResource.DELETE_PRESERVE_SIBLINGS));
634        values.add(String.valueOf(CmsResource.DELETE_REMOVE_SIBLINGS));
635        int selectedIndex = values.indexOf(getParamTabDiDeleteFileMode());
636        return buildSelect(htmlAttributes, options, values, selectedIndex);
637    }
638
639    /**
640     * Builds the html for the direct edit button style select box.<p>
641     *
642     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
643     * @return the html for the direct edit button style select box
644     */
645    public String buildSelectDirectEditButtonStyle(String htmlAttributes) {
646
647        int selectedIndex = Integer.parseInt(getParamTabEdDirectEditButtonStyle());
648        return buildSelectButtonStyle(htmlAttributes, selectedIndex);
649    }
650
651    /**
652     * Builds the html for the editor button style select box.<p>
653     *
654     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
655     * @return the html for the editor button style select box
656     */
657    public String buildSelectEditorButtonStyle(String htmlAttributes) {
658
659        int selectedIndex = Integer.parseInt(getParamTabEdButtonStyle());
660        return buildSelectButtonStyle(htmlAttributes, selectedIndex);
661    }
662
663    /**
664     * Builds the html for the explorer button style select box.<p>
665     *
666     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
667     * @return the html for the explorer button style select box
668     */
669    public String buildSelectExplorerButtonStyle(String htmlAttributes) {
670
671        int selectedIndex = Integer.parseInt(getParamTabExButtonStyle());
672        return buildSelectButtonStyle(htmlAttributes, selectedIndex);
673    }
674
675    /**
676     * Builds the html for the explorer number of entries per page select box.<p>
677     *
678     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
679     * @return the html for the explorer number of entries per page select box
680     */
681    public String buildSelectExplorerFileEntries(String htmlAttributes) {
682
683        String emptyOption = OpenCms.getWorkplaceManager().getDefaultUserSettings().getExplorerFileEntryOptions();
684        if (CmsStringUtil.isEmptyOrWhitespaceOnly(emptyOption)) {
685            emptyOption = "50,100,200,300,400,500";
686        }
687        // remove all non digits without ','
688        emptyOption = emptyOption.replaceAll("[^0-9|^,]", "");
689        // remove all empty entries
690        emptyOption = emptyOption.replaceAll(",,", ",");
691        List<String> opts = CmsStringUtil.splitAsList(emptyOption, ",", true);
692        opts.add(key(Messages.GUI_LABEL_UNLIMITED_0));
693        opts.remove("0");
694        List<String> vals = CmsStringUtil.splitAsList(emptyOption, ",", true);
695        vals.add("" + Integer.MAX_VALUE);
696        vals.remove("0");
697        int selectedIndex = 2;
698        for (int i = 0; i < vals.size(); i++) {
699            if (vals.get(i).equals(getParamTabExFileEntries())) {
700                selectedIndex = i;
701                break;
702            }
703        }
704        return buildSelect(htmlAttributes, opts, vals, selectedIndex);
705    }
706
707    /**
708     * Builds the html for the language select box of the start settings.<p>
709     *
710     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
711     * @return the html for the language select box
712     */
713    public String buildSelectLanguage(String htmlAttributes) {
714
715        SelectOptions selectOptions = getOptionsForLanguage();
716        return buildSelect(htmlAttributes, selectOptions);
717    }
718
719    /**
720     * Builds the html for the preferred editors select boxes of the editor settings.<p>
721     *
722     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
723     * @return the html for the preferred editors select boxes
724     */
725    public String buildSelectPreferredEditors(String htmlAttributes) {
726
727        StringBuffer result = new StringBuffer(1024);
728        HttpServletRequest request = getJsp().getRequest();
729        if (htmlAttributes != null) {
730            htmlAttributes += " name=\"" + PARAM_PREFERREDEDITOR_PREFIX;
731        }
732        Map<String, SortedMap<Float, CmsWorkplaceEditorConfiguration>> resourceEditors = OpenCms.getWorkplaceManager().getWorkplaceEditorManager().getConfigurableEditors();
733        if (resourceEditors != null) {
734            // first: iterate over the resource types and consider order from configuration
735            Iterator<String> i = resourceEditors.keySet().iterator();
736
737            SortedMap<Float, String> rankResources = new TreeMap<Float, String>();
738            while (i.hasNext()) {
739                String currentResourceType = i.next();
740                CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
741                    currentResourceType);
742                rankResources.put(Float.valueOf(settings.getNewResourceOrder()), currentResourceType);
743            }
744
745            while (rankResources.size() > 0) {
746                // get editor configuration with lowest order
747                Float keyVal = rankResources.firstKey();
748                String currentResourceType = rankResources.get(keyVal);
749
750                SortedMap<Float, CmsWorkplaceEditorConfiguration> availableEditors = resourceEditors.get(
751                    currentResourceType);
752                if ((availableEditors != null) && (availableEditors.size() > 0)) {
753                    String preSelection = computeEditorPreselection(request, currentResourceType);
754                    List<String> options = new ArrayList<String>(availableEditors.size() + 1);
755                    List<String> values = new ArrayList<String>(availableEditors.size() + 1);
756                    options.add(key(Messages.GUI_PREF_EDITOR_BEST_0));
757                    values.add(INPUT_DEFAULT);
758                    // second: iteration over the available editors for the resource type
759                    int selectedIndex = 0;
760                    int counter = 1;
761                    while (availableEditors.size() > 0) {
762                        Float key = availableEditors.lastKey();
763                        CmsWorkplaceEditorConfiguration conf = availableEditors.get(key);
764                        options.add(keyDefault(conf.getEditorLabel(), conf.getEditorLabel()));
765                        values.add(conf.getEditorUri());
766                        if (conf.getEditorUri().equals(preSelection)) {
767                            selectedIndex = counter;
768                        }
769                        counter++;
770                        availableEditors.remove(key);
771                    }
772
773                    // create the table row for the current resource type
774                    result.append("<tr>\n\t<td style=\"white-space: nowrap;\">");
775                    String localizedName = keyDefault("label.editor.preferred." + currentResourceType, "");
776                    if (CmsStringUtil.isEmpty(localizedName)) {
777                        localizedName = CmsWorkplaceMessages.getResourceTypeName(this, currentResourceType);
778                    }
779                    result.append(localizedName);
780                    result.append("</td>\n\t<td>");
781                    result.append(
782                        buildSelect(htmlAttributes + currentResourceType + "\"", options, values, selectedIndex));
783                    result.append("</td>\n</tr>\n");
784                }
785                rankResources.remove(keyVal);
786            }
787        }
788        return result.toString();
789    }
790
791    /**
792     * Builds the html for the project select box of the start settings.<p>
793     *
794     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
795     * @return the html for the project select box
796     */
797    public String buildSelectProject(String htmlAttributes) {
798
799        SelectOptions selectOptions = getProjectSelectOptions();
800        return buildSelect(htmlAttributes, selectOptions);
801
802    }
803
804    /**
805     * Builds the html for the default publish siblings mode select box.<p>
806     *
807     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
808     * @return the html for the default publish siblings mode select box
809     */
810    public String buildSelectPublishSiblings(String htmlAttributes) {
811
812        List<String> options = new ArrayList<String>(2);
813        options.add(key(Messages.GUI_PREF_PUBLISH_SIBLINGS_0));
814        options.add(key(Messages.GUI_PREF_PUBLISH_ONLY_SELECTED_0));
815        List<String> values = new ArrayList<String>(2);
816        values.add(CmsStringUtil.TRUE);
817        values.add(CmsStringUtil.FALSE);
818        int selectedIndex = values.indexOf(getParamTabDiPublishFileMode());
819        return buildSelect(htmlAttributes, options, values, selectedIndex);
820    }
821
822    /**
823     * Builds the html for the workplace report type select box.<p>
824     *
825     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
826     * @return the html for the workplace report type select box
827     */
828    public String buildSelectReportType(String htmlAttributes) {
829
830        List<String> options = new ArrayList<String>(2);
831        options.add(key(Messages.GUI_LABEL_SIMPLE_0));
832        options.add(key(Messages.GUI_LABEL_EXTENDED_0));
833        String[] vals = new String[] {I_CmsReport.REPORT_TYPE_SIMPLE, I_CmsReport.REPORT_TYPE_EXTENDED};
834        List<String> values = new ArrayList<String>(java.util.Arrays.asList(vals));
835        int selectedIndex = 0;
836        if (I_CmsReport.REPORT_TYPE_EXTENDED.equals(getParamTabWpReportType())) {
837            selectedIndex = 1;
838        }
839        return buildSelect(htmlAttributes, options, values, selectedIndex);
840    }
841
842    /**
843     * Builds the html for the workplace start site select box.<p>
844     *
845     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
846     * @return the html for the workplace start site select box
847     */
848    public String buildSelectSite(String htmlAttributes) {
849
850        SelectOptions selectOptions = getSiteSelectOptions();
851
852        return buildSelect(htmlAttributes, selectOptions);
853    }
854
855    /**
856     * Builds the HTML for the start galleries settings as select boxes.<p>
857     *
858     * @param htmlAttributes optional HTML attributes for the &lgt;select&gt; tag
859     * @return the HTML for start galleries select boxes
860     */
861    public String buildSelectStartGalleries(String htmlAttributes) {
862
863        StringBuffer result = new StringBuffer(1024);
864        HttpServletRequest request = getJsp().getRequest();
865        // set the attributes for the select tag
866        if (htmlAttributes != null) {
867            htmlAttributes += " name=\"" + PARAM_STARTGALLERY_PREFIX;
868        }
869        Map<String, A_CmsAjaxGallery> galleriesTypes = OpenCms.getWorkplaceManager().getGalleries();
870        if (galleriesTypes != null) {
871
872            // sort the galleries by localized name
873            Map<String, String> localizedGalleries = new TreeMap<String, String>();
874            for (Iterator<String> i = galleriesTypes.keySet().iterator(); i.hasNext();) {
875                String currentGalleryType = i.next();
876                String localizedName = CmsWorkplaceMessages.getResourceTypeName(this, currentGalleryType);
877                localizedGalleries.put(localizedName, currentGalleryType);
878            }
879
880            for (Iterator<Map.Entry<String, String>> i = localizedGalleries.entrySet().iterator(); i.hasNext();) {
881                Map.Entry<String, String> entry = i.next();
882                // first: retrieve the gallery type
883                String currentGalleryType = entry.getValue();
884                // second: retrieve the gallery type id
885                int currentGalleryTypeId = 0;
886                try {
887                    currentGalleryTypeId = OpenCms.getResourceManager().getResourceType(currentGalleryType).getTypeId();
888                } catch (CmsLoaderException e) {
889                    // resource type not found, log error
890                    if (LOG.isErrorEnabled()) {
891                        LOG.error(e.getLocalizedMessage(), e);
892                    }
893                    continue;
894                }
895                // third: get the available galleries for this gallery type id
896                List<CmsResource> availableGalleries = A_CmsAjaxGallery.getGalleries(currentGalleryTypeId, getCms());
897
898                // forth: fill the select box
899                List<String> options = new ArrayList<String>(availableGalleries.size() + 2);
900                List<String> values = new ArrayList<String>(availableGalleries.size() + 2);
901                options.add(key(Messages.GUI_PREF_STARTGALLERY_PRESELECT_0));
902                values.add(INPUT_DEFAULT);
903                options.add(key(Messages.GUI_PREF_STARTGALLERY_NONE_0));
904                values.add(INPUT_NONE);
905
906                String savedValue = computeStartGalleryPreselection(request, currentGalleryType);
907                int counter = 2;
908                int selectedIndex = 0;
909                Iterator<CmsResource> iGalleries = availableGalleries.iterator();
910                while (iGalleries.hasNext()) {
911                    CmsResource res = iGalleries.next();
912                    String rootPath = res.getRootPath();
913                    String sitePath = getCms().getSitePath(res);
914                    // select the value
915                    if ((savedValue != null) && (savedValue.equals(rootPath))) {
916                        selectedIndex = counter;
917                    }
918                    counter++;
919                    // gallery title
920                    String title = "";
921                    try {
922                        // read the gallery title
923                        title = getCms().readPropertyObject(
924                            sitePath,
925                            CmsPropertyDefinition.PROPERTY_TITLE,
926                            false).getValue("");
927                    } catch (CmsException e) {
928                        // error reading title property
929                        if (LOG.isErrorEnabled()) {
930                            LOG.error(e.getLocalizedMessage(), e);
931                        }
932                    }
933                    options.add(title.concat(" (").concat(sitePath).concat(")"));
934                    values.add(rootPath);
935
936                }
937                // select the value
938                if ((savedValue != null) && savedValue.equals(INPUT_NONE)) {
939                    selectedIndex = 1;
940                }
941
942                // create the table row for the current resource type
943                result.append("<tr>\n\t<td style=\"white-space: nowrap;\">");
944
945                result.append(entry.getKey());
946                result.append("</td>\n\t<td>");
947                result.append(buildSelect(htmlAttributes + currentGalleryType + "\"", options, values, selectedIndex));
948                result.append("</td>\n</tr>\n");
949
950            }
951
952        }
953        return result.toString();
954    }
955
956    /**
957     * Builds the html for the workplace start site select box.<p>
958     *
959     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
960     * @return the html for the workplace start site select box
961     */
962    public String buildSelectUpload(String htmlAttributes) {
963
964        List<String> options = new ArrayList<String>();
965        List<String> values = new ArrayList<String>();
966        int selectedIndex = 0;
967        int pos = 0;
968
969        UploadVariant currentVariant = getParamTabWpUploadVariant();
970        for (UploadVariant variant : UploadVariant.values()) {
971
972            values.add(variant.toString());
973            options.add(getUploadVariantMessage(variant));
974
975            if (variant.equals(currentVariant)) {
976                selectedIndex = pos;
977            }
978            pos++;
979        }
980        return buildSelect(htmlAttributes, options, values, selectedIndex);
981    }
982
983    /**
984     * Returns a html select box filled with the views accessible by the current user.<p>
985     *
986     * @param htmlAttributes attributes that will be inserted into the generated html
987     * @return a html select box filled with the views accessible by the current user
988     */
989    public String buildSelectView(String htmlAttributes) {
990
991        SelectOptions optionBean = CmsStartViewPreference.getViewSelectOptions(getCms(), getParamTabWpView());
992        return buildSelect(htmlAttributes, optionBean);
993    }
994
995    /**
996     * Builds the html for the workplace button style select box.<p>
997     *
998     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
999     * @return the html for the workplace button style select box
1000     */
1001    public String buildSelectWorkplaceButtonStyle(String htmlAttributes) {
1002
1003        int selectedIndex = Integer.parseInt(getParamTabWpButtonStyle());
1004        return buildSelectButtonStyle(htmlAttributes, selectedIndex);
1005    }
1006
1007    /**
1008     * Builds the html for the workplace search result list type select box.<p>
1009     *
1010     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
1011     * @return the html for the workplace search result list type select box
1012     */
1013    public String buildSelectWorkplaceSearchResult(String htmlAttributes) {
1014
1015        List<String> options = new ArrayList<String>(3);
1016        List<String> values = new ArrayList<String>(3);
1017        int checkedIndex = 0;
1018
1019        // add all styles to the select box
1020        options.add(key(CmsSearchResultStyle.STYLE_EXPLORER.getKey()));
1021        values.add(CmsSearchResultStyle.STYLE_EXPLORER.getMode());
1022        if (getParamTabExWorkplaceSearchResult().equals(CmsSearchResultStyle.STYLE_EXPLORER.toString())) {
1023            // mark the currently active locale
1024            checkedIndex = 0;
1025        }
1026        options.add(key(CmsSearchResultStyle.STYLE_LIST_WITH_EXCERPTS.getKey()));
1027        values.add(CmsSearchResultStyle.STYLE_LIST_WITH_EXCERPTS.getMode());
1028        if (getParamTabExWorkplaceSearchResult().equals(CmsSearchResultStyle.STYLE_LIST_WITH_EXCERPTS.toString())) {
1029            // mark the currently active locale
1030            checkedIndex = 1;
1031        }
1032        options.add(key(CmsSearchResultStyle.STYLE_LIST_WITHOUT_EXCERPTS.getKey()));
1033        values.add(CmsSearchResultStyle.STYLE_LIST_WITHOUT_EXCERPTS.getMode());
1034        if (getParamTabExWorkplaceSearchResult().equals(CmsSearchResultStyle.STYLE_LIST_WITHOUT_EXCERPTS.toString())) {
1035            // mark the currently active locale
1036            checkedIndex = 2;
1037        }
1038
1039        return buildSelect(htmlAttributes, options, values, checkedIndex);
1040    }
1041
1042    /**
1043     * Builds the html code for the static user information table (tab 4).<p>
1044     *
1045     * @return the html code for the static user information table
1046     */
1047    public String buildUserInformation() {
1048
1049        StringBuffer result = new StringBuffer(512);
1050        CmsUser user = getSettings().getUser();
1051
1052        result.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n");
1053        result.append("<tr>\n");
1054        result.append("\t<td style=\"width: 25%;\">");
1055        result.append(key(Messages.GUI_LABEL_USER_0));
1056        result.append("</td>\n");
1057        result.append("\t<td class=\"textbold\" style=\"width: 25%;\">");
1058        result.append(user.getName());
1059        result.append("</td>\n");
1060        result.append("\t<td style=\"width: 25%;\">");
1061        result.append(key(Messages.GUI_LABEL_EMAIL_0));
1062        result.append("</td>\n");
1063        result.append("\t<td class=\"textbold\" style=\"width: 25%;\">");
1064        result.append(user.getEmail());
1065        result.append("</td>\n");
1066        result.append("</tr>\n");
1067
1068        result.append("<tr>\n");
1069        result.append("\t<td>");
1070        result.append(key(Messages.GUI_LABEL_LASTNAME_0));
1071        result.append("</td>\n");
1072        result.append("\t<td class=\"textbold\">");
1073        result.append(user.getLastname());
1074        result.append("</td>\n");
1075        result.append("\t<td rowspan=\"3\" style=\"vertical-align: top;\">");
1076        result.append(key(Messages.GUI_INPUT_ADRESS_0));
1077        result.append("</td>\n");
1078
1079        String address = user.getAddress();
1080
1081        result.append("\t<td rowspan=\"3\" class=\"textbold\" style=\"vertical-align: top;\">");
1082        result.append(address);
1083        result.append("</td>\n");
1084        result.append("</tr>\n");
1085
1086        result.append("<tr>\n");
1087        result.append("\t<td>");
1088        result.append(key(Messages.GUI_LABEL_FIRSTNAME_0));
1089        result.append("</td>\n");
1090        result.append("\t<td class=\"textbold\">");
1091        result.append(user.getFirstname());
1092        result.append("</td>\n");
1093        result.append("</tr>\n");
1094
1095        result.append("<tr>\n");
1096        result.append("\t<td>");
1097        result.append(key(Messages.GUI_LABEL_DESCRIPTION_0));
1098        result.append("</td>\n");
1099        result.append("\t<td class=\"textbold\">");
1100        result.append(user.getDescription(getLocale()));
1101        result.append("</td>\n");
1102        result.append("</tr>\n");
1103        result.append("</table>\n");
1104
1105        return result.toString();
1106    }
1107
1108    /**
1109     * Creates the HTML JavaScript and stylesheet includes required by the calendar for the head of the page.<p>
1110     *
1111     * @return the necessary HTML code for the js and stylesheet includes
1112     *
1113     * @deprecated use {@link CmsCalendarWidget#calendarIncludes(java.util.Locale)}, this is just here so that old JSP still work
1114     */
1115    @Deprecated
1116    public String calendarIncludes() {
1117
1118        return CmsCalendarWidget.calendarIncludes(getLocale());
1119    }
1120
1121    /**
1122     * Generates the HTML to initialize the JavaScript calendar element on the end of a page.<p>
1123     *
1124     * @param inputFieldId the ID of the input field where the date is pasted to
1125     * @param triggerButtonId the ID of the button which triggers the calendar
1126     * @param align initial position of the calendar popup element
1127     * @param singleClick if true, a single click selects a date and closes the calendar, otherwise calendar is closed by doubleclick
1128     * @param weekNumbers show the week numbers in the calendar or not
1129     * @param mondayFirst show monday as first day of week
1130     * @param dateStatusFunc name of the function which determines if/how a date should be disabled
1131     * @param showTime true if the time selector should be shown, otherwise false
1132     * @return the HTML code to initialize a calendar poup element
1133     *
1134     * @deprecated use {@link CmsCalendarWidget#calendarInit(org.opencms.i18n.CmsMessages, String, String, String, boolean, boolean, boolean, String, boolean)}, this is just here so that old JSP still work
1135     */
1136    @Deprecated
1137    public String calendarInit(
1138        String inputFieldId,
1139        String triggerButtonId,
1140        String align,
1141        boolean singleClick,
1142        boolean weekNumbers,
1143        boolean mondayFirst,
1144        String dateStatusFunc,
1145        boolean showTime) {
1146
1147        return CmsCalendarWidget.calendarInit(
1148            getMessages(),
1149            inputFieldId,
1150            triggerButtonId,
1151            align,
1152            singleClick,
1153            weekNumbers,
1154            mondayFirst,
1155            dateStatusFunc,
1156            showTime);
1157    }
1158
1159    /**
1160     * Gets the select options for the language selector.<p>
1161     *
1162     * @return the select options
1163     */
1164    public SelectOptions getOptionsForLanguage() {
1165
1166        return getOptionsForLanguageStatic(getSettings().getUserSettings().getLocale(), m_userSettings.getLocale());
1167    }
1168
1169    /**
1170     * Returns the new password value.<p>
1171     *
1172     * @return the new password value
1173     */
1174    public String getParamNewPassword() {
1175
1176        return m_paramNewPassword;
1177    }
1178
1179    /**
1180     * Returns the old password value. <p>
1181     *
1182     * @return the old password value
1183     */
1184    public String getParamOldPassword() {
1185
1186        return m_paramOldPassword;
1187    }
1188
1189    /**
1190     * Returns the "copy file default" setting.<p>
1191     *
1192     * @return the "copy file default" setting
1193     */
1194    public String getParamTabDiCopyFileMode() {
1195
1196        return "" + m_userSettings.getDialogCopyFileMode();
1197    }
1198
1199    /**
1200     * Returns the "copy folder default" setting.<p>
1201     *
1202     * @return the "copy folder default" setting
1203     */
1204    public String getParamTabDiCopyFolderMode() {
1205
1206        return "" + m_userSettings.getDialogCopyFolderMode();
1207    }
1208
1209    /**
1210     * Returns the "delete file default" setting.<p>
1211     *
1212     * @return the "delete file default" setting
1213     */
1214    public String getParamTabDiDeleteFileMode() {
1215
1216        return "" + m_userSettings.getDialogDeleteFileMode();
1217    }
1218
1219    /**
1220     * Returns the "expand inherited permissions" default setting.<p>
1221     *
1222     * @return the "expand inherited permissions" default setting
1223     */
1224    public String getParamTabDiPermissionsExpandInherited() {
1225
1226        return isParamEnabled(m_userSettings.getDialogExpandInheritedPermissions());
1227    }
1228
1229    /**
1230     * Returns the "expand current users permissions" default setting.<p>
1231     *
1232     * @return the "expand current users permissions" default setting
1233     */
1234    public String getParamTabDiPermissionsExpandUser() {
1235
1236        return isParamEnabled(m_userSettings.getDialogExpandUserPermissions());
1237    }
1238
1239    /**
1240     * Returns the "inherit permissions on folders" default setting.<p>
1241     *
1242     * @return the "inherit permissions on folders" default setting
1243     */
1244    public String getParamTabDiPermissionsInheritOnFolder() {
1245
1246        return isParamEnabled(m_userSettings.getDialogPermissionsInheritOnFolder());
1247    }
1248
1249    /**
1250     * Returns the "publish file siblings default" setting.<p>
1251     *
1252     * @return the "publish file siblings default" setting
1253     */
1254    public String getParamTabDiPublishFileMode() {
1255
1256        return "" + m_userSettings.getDialogPublishSiblings();
1257    }
1258
1259    /**
1260     * Returns the "display lock dialog" setting.<p>
1261     *
1262     * @return <code>"true"</code> if the "display lock dialog" input field is checked, otherwise ""
1263     */
1264    public String getParamTabDiShowLock() {
1265
1266        return isParamEnabled(m_userSettings.getDialogShowLock());
1267    }
1268
1269    /**
1270     * Returns the "editor button style" setting.<p>
1271     *
1272     * @return the "editor button style" setting
1273     */
1274    public String getParamTabEdButtonStyle() {
1275
1276        return "" + m_userSettings.getEditorButtonStyle();
1277    }
1278
1279    /**
1280     * Returns the "direct edit button style" setting.<p>
1281     *
1282     * @return the "direct edit button style" setting
1283     */
1284    public String getParamTabEdDirectEditButtonStyle() {
1285
1286        return "" + m_userSettings.getDirectEditButtonStyle();
1287    }
1288
1289    /**
1290     * Returns the "explorer button style" setting.<p>
1291     *
1292     * @return the "explorer button style" setting
1293     */
1294    public String getParamTabExButtonStyle() {
1295
1296        return "" + m_userSettings.getExplorerButtonStyle();
1297    }
1298
1299    /**
1300     * Returns the "display file creation date" setting.<p>
1301     *
1302     * @return <code>"true"</code> if the file creation date input field is checked, otherwise ""
1303     */
1304    public String getParamTabExFileDateCreated() {
1305
1306        return isParamEnabled(m_userSettings.showExplorerFileDateCreated());
1307    }
1308
1309    /**
1310     * Returns the "display file date expired" setting.<p>
1311     *
1312     * @return <code>"true"</code> if the file date expired input field is checked, otherwise ""
1313     */
1314    public String getParamTabExFileDateExpired() {
1315
1316        return isParamEnabled(m_userSettings.showExplorerFileDateExpired());
1317    }
1318
1319    /**
1320     * Returns the "display file last modification date" setting.<p>
1321     *
1322     * @return <code>"true"</code> if the file last modification date input field is checked, otherwise ""
1323     */
1324    public String getParamTabExFileDateLastModified() {
1325
1326        return isParamEnabled(m_userSettings.showExplorerFileDateLastModified());
1327    }
1328
1329    /**
1330     * Returns the "display file date released" setting.<p>
1331     *
1332     * @return <code>"true"</code> if the file date released input field is checked, otherwise ""
1333     */
1334    public String getParamTabExFileDateReleased() {
1335
1336        return isParamEnabled(m_userSettings.showExplorerFileDateReleased());
1337    }
1338
1339    /**
1340     * Returns the "explorer number of entries per page" setting.<p>
1341     *
1342     * @return the "explorer number of entries per page" setting
1343     */
1344    public String getParamTabExFileEntries() {
1345
1346        return "" + m_userSettings.getExplorerFileEntries();
1347    }
1348
1349    /**
1350     * Returns the "display file locked by" setting.<p>
1351     *
1352     * @return <code>"true"</code> if the file locked by input field is checked, otherwise ""
1353     */
1354    public String getParamTabExFileLockedBy() {
1355
1356        return isParamEnabled(m_userSettings.showExplorerFileLockedBy());
1357    }
1358
1359    /**
1360     * Returns the "display navtext" setting.<p>
1361     *
1362     * @return <code>"true"</code> if the file navtext input field is checked, otherwise ""
1363     */
1364    public String getParamTabExFileNavText() {
1365
1366        return isParamEnabled(m_userSettings.showExplorerFileNavText());
1367    }
1368
1369    /**
1370     * Returns the "display file permissions" setting.<p>
1371     *
1372     * @return <code>"true"</code> if the file permissions input field is checked, otherwise ""
1373     */
1374    public String getParamTabExFilePermissions() {
1375
1376        return isParamEnabled(m_userSettings.showExplorerFilePermissions());
1377    }
1378
1379    /**
1380     * Returns the "display file size" setting.<p>
1381     *
1382     * @return <code>"true"</code> if the file size input field is checked, otherwise ""
1383     */
1384    public String getParamTabExFileSize() {
1385
1386        return isParamEnabled(m_userSettings.showExplorerFileSize());
1387    }
1388
1389    /**
1390     * Returns the "display file state" setting.<p>
1391     *
1392     * @return <code>"true"</code> if the file state input field is checked, otherwise ""
1393     */
1394    public String getParamTabExFileState() {
1395
1396        return isParamEnabled(m_userSettings.showExplorerFileState());
1397    }
1398
1399    /**
1400     * Returns the "display file title" setting.<p>
1401     *
1402     * @return <code>"true"</code> if the file title input field is checked, otherwise ""
1403     */
1404    public String getParamTabExFileTitle() {
1405
1406        return isParamEnabled(m_userSettings.showExplorerFileTitle());
1407    }
1408
1409    /**
1410     * Returns the "display file type" setting.<p>
1411     *
1412     * @return <code>"true"</code> if the file type input field is checked, otherwise ""
1413     */
1414    public String getParamTabExFileType() {
1415
1416        return isParamEnabled(m_userSettings.showExplorerFileType());
1417    }
1418
1419    /**
1420     * Returns the "display file created by" setting.<p>
1421     *
1422     * @return <code>"true"</code> if the file created by input field is checked, otherwise ""
1423     */
1424    public String getParamTabExFileUserCreated() {
1425
1426        return isParamEnabled(m_userSettings.showExplorerFileUserCreated());
1427    }
1428
1429    /**
1430     * Returns the "display file last modified by" setting.<p>
1431     *
1432     * @return <code>"true"</code> if the file last modified by input field is checked, otherwise ""
1433     */
1434    public String getParamTabExFileUserLastModified() {
1435
1436        return isParamEnabled(m_userSettings.showExplorerFileUserLastModified());
1437    }
1438
1439    /**
1440     * Returns the "workplace search result style" setting.<p>
1441     *
1442     * @return the "workplace search result style" setting
1443     */
1444    public String getParamTabExWorkplaceSearchResult() {
1445
1446        return m_userSettings.getWorkplaceSearchViewStyle().toString();
1447    }
1448
1449    /**
1450     * Returns the "workplace button style" setting.<p>
1451     *
1452     * @return the "workplace button style" setting
1453     */
1454    public String getParamTabWpButtonStyle() {
1455
1456        return "" + m_userSettings.getWorkplaceButtonStyle();
1457    }
1458
1459    /**
1460     * Returns the "start folder" setting.<p>
1461     *
1462     * @return the "start folder" setting
1463     */
1464    public String getParamTabWpFolder() {
1465
1466        return m_userSettings.getStartFolder();
1467    }
1468
1469    /**
1470     * Returns the start language setting.<p>
1471     *
1472     * @return the start language setting
1473     */
1474    public String getParamTabWpLanguage() {
1475
1476        return m_userSettings.getLocale().toString();
1477    }
1478
1479    /**
1480     * Returns the "list all projects" setting.<p>
1481     *
1482     * @return <code>"true"</code> if the "list all projects" input is checked, otherwise ""
1483     */
1484    public String getParamTabWpListAllProjects() {
1485
1486        return isParamEnabled(m_userSettings.getListAllProjects());
1487    }
1488
1489    /**
1490     * Returns the start project setting.<p>
1491     *
1492     * @return the start project setting
1493     */
1494    public String getParamTabWpProject() {
1495
1496        return m_userSettings.getStartProject();
1497    }
1498
1499    /**
1500     * Returns the "workplace report type" setting.<p>
1501     *
1502     * @return the "workplace report type" setting
1503     */
1504    public String getParamTabWpReportType() {
1505
1506        return m_userSettings.getWorkplaceReportType();
1507    }
1508
1509    /**
1510     * Returns the "workplace restrict explorer view" setting.<p>
1511     *
1512     * @return the "workplace restrict explorer view" setting
1513     */
1514    public String getParamTabWpRestrictExplorerView() {
1515
1516        return "" + m_userSettings.getRestrictExplorerView();
1517    }
1518
1519    /**
1520     * Returns the "show publish notification" setting.<p>
1521     *
1522     * @return <code>"true"</code> if the "show publish notification" input is checked, otherwise ""
1523     */
1524    public String getParamTabWpShowPublishNotification() {
1525
1526        return isParamEnabled(m_userSettings.getShowPublishNotification());
1527    }
1528
1529    /**
1530     * Returns the "start site" setting.<p>
1531     *
1532     * @return the "start site" setting
1533     */
1534    public String getParamTabWpSite() {
1535
1536        return m_userSettings.getStartSite();
1537    }
1538
1539    /**
1540     * Get the "user timewparp" setting in form of a formatted date string.<p>
1541     *
1542     * If no timewarp has been chosen, a value "-" will be returned.<p>
1543     *
1544     * @return the "user timewarp" setting in form of a formatted date string
1545     */
1546    public String getParamTabWpTimeWarp() {
1547
1548        String result;
1549        if (m_userSettings.getTimeWarp() == CmsContextInfo.CURRENT_TIME) {
1550            result = "-";
1551        } else {
1552            result = CmsCalendarWidget.getCalendarLocalizedTime(
1553                getLocale(),
1554                getMessages(),
1555                m_userSettings.getTimeWarp());
1556        }
1557        return result;
1558    }
1559
1560    /**
1561     * Returns the upload variant setting.<p>
1562     *
1563     * @return <code>"applet"</code>, <code>"gwt"</code> or <code>"basic"</code>
1564     */
1565    public UploadVariant getParamTabWpUploadVariant() {
1566
1567        return m_userSettings.getUploadVariant();
1568    }
1569
1570    /**
1571     * Returns the start view setting.<p>
1572     *
1573     * @return the start view setting
1574     */
1575    public String getParamTabWpView() {
1576
1577        return m_userSettings.getStartView();
1578    }
1579
1580    /**
1581     * Gets the project select options.<p>
1582     *
1583     * @return the project select options
1584     */
1585    public SelectOptions getProjectSelectOptions() {
1586
1587        return getProjectSelectOptionsStatic(getCms(), m_userSettings.getStartProject(), getLocale());
1588    }
1589
1590    /**
1591     * Gets the site select options.<p>
1592     *
1593     * @return the site select options
1594     */
1595    public SelectOptions getSiteSelectOptions() {
1596
1597        return getSiteSelectOptionsStatic(
1598            getCms(),
1599            CmsWorkplace.getStartSiteRoot(getCms(), m_userSettings),
1600            getSettings().getUserSettings().getLocale());
1601    }
1602
1603    /**
1604     * @see org.opencms.workplace.CmsTabDialog#getTabParameterOrder()
1605     */
1606    @Override
1607    public List<String> getTabParameterOrder() {
1608
1609        ArrayList<String> orderList = new ArrayList<String>(5);
1610        orderList.add("tabwp");
1611        orderList.add("tabex");
1612        orderList.add("tabdi");
1613        orderList.add("tabed");
1614        orderList.add("tabga");
1615        orderList.add("tabup");
1616        return orderList;
1617    }
1618
1619    /**
1620     * @see org.opencms.workplace.CmsTabDialog#getTabs()
1621     */
1622    @Override
1623    public List<String> getTabs() {
1624
1625        ArrayList<String> tabList = new ArrayList<String>(6);
1626        tabList.add(key(Messages.GUI_PREF_PANEL_WORKPLACE_0));
1627        tabList.add(key(Messages.GUI_PREF_PANEL_EXPLORER_0));
1628        tabList.add(key(Messages.GUI_PREF_PANEL_DIALOGS_0));
1629        tabList.add(key(Messages.GUI_PREF_PANEL_EDITORS_0));
1630        tabList.add(key(Messages.GUI_PREF_PANEL_GALLERIES_0));
1631        tabList.add(key(Messages.GUI_PREF_PANEL_USER_0));
1632        return tabList;
1633    }
1634
1635    /**
1636     * Gets the timewarp parameter as a simple numeric string.<p>
1637     *
1638     * @return the timewarp parameter as a simple numeric string
1639     */
1640    public String getTimeWarpInt() {
1641
1642        return "" + m_userSettings.getTimeWarp();
1643    }
1644
1645    /**
1646     * Gets the internal user settings object.<p>
1647     *
1648     * @return the user settings object
1649     */
1650    public CmsUserSettings getUserSettings() {
1651
1652        return m_userSettings;
1653    }
1654
1655    /**
1656     * Helper method to add the "checked" attribute to an input field.<p>
1657     *
1658     * @param paramValue the parameter value, if <code>"true"</code>, the "checked" attribute will be returned
1659     * @return the "checked" attribute or an empty String
1660     */
1661    public String isChecked(String paramValue) {
1662
1663        if (Boolean.valueOf(paramValue).booleanValue()) {
1664            return " checked=\"checked\"";
1665        }
1666        return "";
1667    }
1668
1669    /**
1670     * Sets the new password value.<p>
1671     *
1672     * @param newPwd the new password value
1673     */
1674    public void setParamNewPassword(String newPwd) {
1675
1676        m_paramNewPassword = newPwd;
1677    }
1678
1679    /**
1680     * Sets the old password value.<p>
1681     *
1682     * @param oldPwd the old password value
1683     */
1684    public void setParamOldPassword(String oldPwd) {
1685
1686        m_paramOldPassword = oldPwd;
1687    }
1688
1689    /**
1690     * Sets the "copy file default" setting.<p>
1691     *
1692     * @param value the "copy file default" setting
1693     */
1694    public void setParamTabDiCopyFileMode(String value) {
1695
1696        try {
1697            m_userSettings.setDialogCopyFileMode(CmsResourceCopyMode.valueOf(Integer.parseInt(value)));
1698        } catch (Throwable t) {
1699            // should usually never happen
1700        }
1701    }
1702
1703    /**
1704     * Sets the "copy folder default" setting.<p>
1705     *
1706     * @param value the "copy folder default" setting
1707     */
1708    public void setParamTabDiCopyFolderMode(String value) {
1709
1710        try {
1711            m_userSettings.setDialogCopyFolderMode(CmsResourceCopyMode.valueOf(Integer.parseInt(value)));
1712        } catch (Throwable t) {
1713            // should usually never happen
1714        }
1715    }
1716
1717    /**
1718     * Sets the "delete file siblings default" setting.<p>
1719     *
1720     * @param value the "delete file siblings default" setting
1721     */
1722    public void setParamTabDiDeleteFileMode(String value) {
1723
1724        try {
1725            m_userSettings.setDialogDeleteFileMode(CmsResourceDeleteMode.valueOf(Integer.parseInt(value)));
1726        } catch (Throwable t) {
1727            // should usually never happen
1728        }
1729    }
1730
1731    /**
1732     * Sets the "expand inherited permissions" default setting.<p>
1733     *
1734     * @param value the "expand inherited permissions" default setting
1735     */
1736    public void setParamTabDiPermissionsExpandInherited(String value) {
1737
1738        m_userSettings.setDialogExpandInheritedPermissions(Boolean.valueOf(value).booleanValue());
1739    }
1740
1741    /**
1742     * Sets the "expand current users permissions" default setting.<p>
1743     *
1744     * @param value the "expand current users permissions" default setting
1745     */
1746    public void setParamTabDiPermissionsExpandUser(String value) {
1747
1748        m_userSettings.setDialogExpandUserPermissions(Boolean.valueOf(value).booleanValue());
1749    }
1750
1751    /**
1752     * Sets the "inherit permissions on folders" default setting.<p>
1753     *
1754     * @param value the "inherit permissions on folders" default setting
1755     */
1756    public void setParamTabDiPermissionsInheritOnFolder(String value) {
1757
1758        m_userSettings.setDialogPermissionsInheritOnFolder(Boolean.valueOf(value).booleanValue());
1759    }
1760
1761    /**
1762     * Sets the "publish file siblings default" setting.<p>
1763     *
1764     * @param value the "publish file siblings default" setting
1765     */
1766    public void setParamTabDiPublishFileMode(String value) {
1767
1768        m_userSettings.setDialogPublishSiblings(Boolean.valueOf(value).booleanValue());
1769    }
1770
1771    /**
1772     * Sets the "display lock dialog" setting.<p>
1773     *
1774     * @param value <code>"true"</code> to enable the "display lock dialog" setting, all others to disable
1775     */
1776    public void setParamTabDiShowLock(String value) {
1777
1778        m_userSettings.setDialogShowLock(Boolean.valueOf(value).booleanValue());
1779    }
1780
1781    /**
1782     * Sets the "editor button style" setting.<p>
1783     *
1784     * @param value a String representation of an int value to set the "editor button style" setting
1785     */
1786    public void setParamTabEdButtonStyle(String value) {
1787
1788        try {
1789            m_userSettings.setEditorButtonStyle(Integer.parseInt(value));
1790        } catch (Throwable t) {
1791            // should usually never happen
1792        }
1793    }
1794
1795    /**
1796     * Sets the "direct edit button style" setting.<p>
1797     *
1798     * @param value a String representation of an int value to set the "direct edit button style" setting
1799     */
1800    public void setParamTabEdDirectEditButtonStyle(String value) {
1801
1802        try {
1803            m_userSettings.setDirectEditButtonStyle(Integer.parseInt(value));
1804        } catch (Throwable t) {
1805            // should usually never happen
1806        }
1807    }
1808
1809    /**
1810     * Sets the "explorer button style" setting.<p>
1811     *
1812     * @param value a String representation of an int value to set the "explorer button style" setting
1813     */
1814    public void setParamTabExButtonStyle(String value) {
1815
1816        try {
1817            m_userSettings.setExplorerButtonStyle(Integer.parseInt(value));
1818        } catch (Throwable t) {
1819            // should usually never happen
1820        }
1821    }
1822
1823    /**
1824     * Sets the "display file creation date" setting.<p>
1825     *
1826     * @param value <code>"true"</code> to enable the "display file creation date" setting, all others to disable
1827     */
1828    public void setParamTabExFileDateCreated(String value) {
1829
1830        m_userSettings.setShowExplorerFileDateCreated(Boolean.valueOf(value).booleanValue());
1831    }
1832
1833    /**
1834     * Sets the "display file expired date" setting.<p>
1835     *
1836     * @param value <code>"true"</code> to enable the "display file expired date" setting, all others to disable
1837     */
1838    public void setParamTabExFileDateExpired(String value) {
1839
1840        m_userSettings.setShowExplorerFileDateExpired(Boolean.valueOf(value).booleanValue());
1841    }
1842
1843    /**
1844     * Sets the "display file last modification date" setting.<p>
1845     *
1846     * @param value <code>"true"</code> to enable the "display file last modification date" setting, all others to disable
1847     */
1848    public void setParamTabExFileDateLastModified(String value) {
1849
1850        m_userSettings.setShowExplorerFileDateLastModified(Boolean.valueOf(value).booleanValue());
1851    }
1852
1853    /**
1854     * Sets the "display file released date" setting.<p>
1855     *
1856     * @param value <code>"true"</code> to enable the "display file released date" setting, all others to disable
1857     */
1858    public void setParamTabExFileDateReleased(String value) {
1859
1860        m_userSettings.setShowExplorerFileDateReleased(Boolean.valueOf(value).booleanValue());
1861    }
1862
1863    /**
1864     * Sets the "explorer number of entries per page" setting.<p>
1865     *
1866     * @param value a String representation of an int value to set the "number of entries per page" setting
1867     */
1868    public void setParamTabExFileEntries(String value) {
1869
1870        try {
1871            m_userSettings.setExplorerFileEntries(Integer.parseInt(value));
1872        } catch (Throwable t) {
1873            // should usually never happen
1874        }
1875    }
1876
1877    /**
1878     * Sets the "display file locked by" setting.<p>
1879     *
1880     * @param value <code>"true"</code> to enable the "display file locked by" setting, all others to disable
1881     */
1882    public void setParamTabExFileLockedBy(String value) {
1883
1884        m_userSettings.setShowExplorerFileLockedBy(Boolean.valueOf(value).booleanValue());
1885    }
1886
1887    /**
1888     * Sets the "display file navtext" setting.<p>
1889     *
1890     * @param value <code>"true"</code> to enable the "display file navtext" setting, all others to disable
1891     */
1892    public void setParamTabExFileNavText(String value) {
1893
1894        m_userSettings.setShowExplorerFileNavText(Boolean.valueOf(value).booleanValue());
1895    }
1896
1897    /**
1898     * Sets the "display file permissions" setting.<p>
1899     *
1900     * @param value <code>"true"</code> to enable the "display file permissions" setting, all others to disable
1901     */
1902    public void setParamTabExFilePermissions(String value) {
1903
1904        m_userSettings.setShowExplorerFilePermissions(Boolean.valueOf(value).booleanValue());
1905    }
1906
1907    /**
1908     * Sets the "display file size" setting.<p>
1909     *
1910     * @param value <code>"true"</code> to enable the "display file size" setting, all others to disable
1911     */
1912    public void setParamTabExFileSize(String value) {
1913
1914        m_userSettings.setShowExplorerFileSize(Boolean.valueOf(value).booleanValue());
1915    }
1916
1917    /**
1918     * Sets the "display file state" setting.<p>
1919     *
1920     * @param value <code>"true"</code> to enable the "display file state" setting, all others to disable
1921     */
1922    public void setParamTabExFileState(String value) {
1923
1924        m_userSettings.setShowExplorerFileState(Boolean.valueOf(value).booleanValue());
1925    }
1926
1927    /**
1928     * Sets the "display file title" setting.<p>
1929     *
1930     * @param value <code>"true"</code> to enable the "display file title" setting, all others to disable
1931     */
1932    public void setParamTabExFileTitle(String value) {
1933
1934        m_userSettings.setShowExplorerFileTitle(Boolean.valueOf(value).booleanValue());
1935    }
1936
1937    /**
1938     * Sets the "display file type" setting.<p>
1939     *
1940     * @param value <code>"true"</code> to enable the "display file type" setting, all others to disable
1941     */
1942    public void setParamTabExFileType(String value) {
1943
1944        m_userSettings.setShowExplorerFileType(Boolean.valueOf(value).booleanValue());
1945    }
1946
1947    /**
1948     * Sets the "display file created by" setting.<p>
1949     *
1950     * @param value <code>"true"</code> to enable the "display file created by" setting, all others to disable
1951     */
1952    public void setParamTabExFileUserCreated(String value) {
1953
1954        m_userSettings.setShowExplorerFileUserCreated(Boolean.valueOf(value).booleanValue());
1955    }
1956
1957    /**
1958     * Sets the "display file last modified by" setting.<p>
1959     *
1960     * @param value <code>"true"</code> to enable the "display file last modified by" setting, all others to disable
1961     */
1962    public void setParamTabExFileUserLastModified(String value) {
1963
1964        m_userSettings.setShowExplorerFileUserLastModified(Boolean.valueOf(value).booleanValue());
1965    }
1966
1967    /**
1968     * Sets the "workplace search result style".<p>
1969     *
1970     * @param style the "workplace search result style" to set
1971     */
1972    public void setParamTabExWorkplaceSearchResult(String style) {
1973
1974        if (style == null) {
1975            style = OpenCms.getWorkplaceManager().getDefaultUserSettings().getWorkplaceSearchViewStyle().getMode();
1976        }
1977        m_userSettings.setWorkplaceSearchViewStyle(CmsSearchResultStyle.valueOf(style));
1978    }
1979
1980    /**
1981     * Sets the "workplace button style" setting.<p>
1982     *
1983     * @param value a String representation of an int value to set the "workplace button style" setting
1984     */
1985    public void setParamTabWpButtonStyle(String value) {
1986
1987        try {
1988            m_userSettings.setWorkplaceButtonStyle(Integer.parseInt(value));
1989        } catch (Throwable t) {
1990            // should usually never happen
1991        }
1992    }
1993
1994    /**
1995     * Sets the "start folder" setting.<p>
1996     *
1997     * @param value the start folder to show in the explorer view
1998     */
1999    public void setParamTabWpFolder(String value) {
2000
2001        // perform self - healing
2002        if (!getCms().existsResource(value, CmsResourceFilter.IGNORE_EXPIRATION)) {
2003            value = "/";
2004        }
2005        m_userSettings.setStartFolder(value);
2006    }
2007
2008    /**
2009     * Sets the start language setting.<p>
2010     *
2011     * @param value the start language setting
2012     */
2013    public void setParamTabWpLanguage(String value) {
2014
2015        m_userSettings.setLocale(CmsLocaleManager.getLocale(value));
2016    }
2017
2018    /**
2019     * Sets the "list all projects" flag.<p>
2020     *
2021     * @param value <code>"true"</code> to enable the "list all project" feature, all others to
2022     *        disable
2023     */
2024    public void setParamTabWpListAllProjects(String value) {
2025
2026        m_userSettings.setListAllProjects(Boolean.valueOf(value).booleanValue());
2027    }
2028
2029    /**
2030     * Sets the start project setting.<p>
2031     *
2032     * @param value the start project setting
2033     */
2034    public void setParamTabWpProject(String value) {
2035
2036        m_userSettings.setStartProject(value);
2037    }
2038
2039    /**
2040     * Sets the "workplace report type" setting.<p>
2041     *
2042     * @param value the "workplace report type" setting
2043     */
2044    public void setParamTabWpReportType(String value) {
2045
2046        if (I_CmsReport.REPORT_TYPE_SIMPLE.equals(value) || I_CmsReport.REPORT_TYPE_EXTENDED.equals(value)) {
2047            // set only if valid parameter value is found
2048            m_userSettings.setWorkplaceReportType(value);
2049        }
2050    }
2051
2052    /**
2053     * Sets the "workplace restrict explorer view" setting.<p>
2054     *
2055     * @param value the "workplace restrict explorer view" setting
2056     */
2057    public void setParamTabWpRestrictExplorerView(String value) {
2058
2059        m_userSettings.setRestrictExplorerView(Boolean.valueOf(value).booleanValue());
2060    }
2061
2062    /**
2063     * Sets the "show publish notification" setting.<p>
2064     *
2065     * @param value <code>"true"</code> to enable the "show publish notification" setting, all others to
2066     *        disable
2067     */
2068    public void setParamTabWpShowPublishNotification(String value) {
2069
2070        m_userSettings.setShowPublishNotification(Boolean.valueOf(value).booleanValue());
2071    }
2072
2073    /**
2074     * Sets the "start site" setting.<p>
2075     *
2076     * @param value the start site to show in the explorer view
2077     */
2078    public void setParamTabWpSite(String value) {
2079
2080        m_userSettings.setStartSite(value);
2081    }
2082
2083    /**
2084     * Sets the "user timewparp" setting.<p>
2085     *
2086     * To delete a timewarp setting for the current user, provide <code>"-"</code> as value.<p>
2087     *
2088     * @param value a String representation of an date in the formate as required by
2089     *      {@link CmsCalendarWidget#getCalendarDate(org.opencms.i18n.CmsMessages, String, boolean)}
2090     */
2091    public void setParamTabWpTimeWarp(String value) {
2092
2093        long datetimestamp = CmsContextInfo.CURRENT_TIME;
2094        // check for "delete value"
2095        if (CmsStringUtil.isNotEmpty(value) && !"-".equals(value)) {
2096            try {
2097                datetimestamp = CmsCalendarWidget.getCalendarDate(getMessages(), value, true);
2098            } catch (Exception e) {
2099                // reset timewarp setting in case of exception
2100            }
2101        }
2102        m_userSettings.setTimeWarp(datetimestamp);
2103    }
2104
2105    /**
2106     * Sets the upload variant setting.<p>
2107     *
2108     * @param value <code>"applet"</code>, <code>"basic"</code>,
2109     * <code>"gwt"</code>, <code>"true"</code> or <code>"false"</code>
2110     */
2111    public void setParamTabWpUploadVariant(String value) {
2112
2113        m_userSettings.setUploadVariant(value);
2114    }
2115
2116    /**
2117     * Sets the start view setting.<p>
2118     *
2119     * @param value the start view setting
2120     */
2121    public void setParamTabWpView(String value) {
2122
2123        m_userSettings.setStartView(value);
2124    }
2125
2126    /**
2127     * Sets the timewarp setting from a numeric string
2128     *
2129     * @param timewarp a numeric string containing the number of milliseconds since the epoch
2130     */
2131    public void setTimewarpInt(String timewarp) {
2132
2133        try {
2134            m_userSettings.setTimeWarp(Long.valueOf(timewarp).longValue());
2135        } catch (Exception e) {
2136            m_userSettings.setTimeWarp(-1);
2137        }
2138    }
2139
2140    /**
2141     * Sets the  user settings.<p>
2142     *
2143     * @param userSettings the user settings
2144     */
2145    public void setUserSettings(CmsDefaultUserSettings userSettings) {
2146
2147        m_userSettings = userSettings;
2148    }
2149
2150    /**
2151     * Updates the user preferences after changes have been made.<p>
2152     *
2153     * @param cms the current cms context
2154     * @param req the current http request
2155     */
2156    public void updatePreferences(CmsObject cms, HttpServletRequest req) {
2157
2158        HttpSession session = req.getSession(false);
2159        if (session == null) {
2160            return;
2161        }
2162        CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(
2163            CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
2164        if (settings == null) {
2165            return;
2166        }
2167        // keep old synchronize settings
2168        CmsSynchronizeSettings synchronizeSettings = settings.getUserSettings().getSynchronizeSettings();
2169        settings = CmsWorkplace.initWorkplaceSettings(cms, settings, true);
2170        settings.getUserSettings().setSynchronizeSettings(synchronizeSettings);
2171    }
2172
2173    /**
2174     * @see org.opencms.workplace.CmsWorkplace#checkRole()
2175     */
2176    @Override
2177    protected void checkRole() {
2178
2179        // this class is used internally for the new preferences dialog, which can also be used by non-workplace users.
2180    }
2181
2182    /**
2183     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
2184     */
2185    @Override
2186    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
2187
2188        // create an empty user settings object
2189        m_userSettings = new CmsUserSettings();
2190        // fill the parameter values in the get/set methods
2191        fillParamValues(request);
2192
2193        // get the active tab from request parameter or display first tab
2194        getActiveTab();
2195
2196        // set the dialog type
2197        setParamDialogtype(DIALOG_TYPE);
2198        // set the action for the JSP switch
2199        if (DIALOG_SET.equals(getParamAction())) {
2200            setAction(ACTION_SET);
2201        } else if (DIALOG_OK.equals(getParamAction())) {
2202            setAction(ACTION_OK);
2203        } else if (DIALOG_RELOAD.equals(getParamAction())) {
2204            setAction(ACTION_RELOAD);
2205        } else if (DIALOG_CANCEL.equals(getParamAction())) {
2206            setAction(ACTION_CANCEL);
2207        } else if (DIALOG_CHPWD.equals(getParamAction())) {
2208            setAction(ACTION_CHPWD);
2209        } else {
2210            if (!DIALOG_SWITCHTAB.equals(getParamAction())) {
2211                // first call of preferences dialog, fill param values with current settings
2212                fillUserSettings();
2213            }
2214
2215            setAction(ACTION_DEFAULT);
2216            // build title for preferences dialog
2217            setParamTitle(key(Messages.GUI_PREF_0));
2218        }
2219
2220    }
2221
2222    /**
2223     * Returns the values of all parameter methods of this workplace class instance.<p>
2224     *
2225     * This overwrites the super method because of the possible dynamic editor selection entries.<p>
2226     *
2227     * @return the values of all parameter methods of this workplace class instance
2228     *
2229     * @see org.opencms.workplace.CmsWorkplace#paramValues()
2230     */
2231    @Override
2232    protected Map<String, Object> paramValues() {
2233
2234        Map<String, Object> map = super.paramValues();
2235        HttpServletRequest request = getJsp().getRequest();
2236        Enumeration<?> en = request.getParameterNames();
2237        while (en.hasMoreElements()) {
2238            String paramName = (String)en.nextElement();
2239            if (paramName.startsWith(PARAM_PREFERREDEDITOR_PREFIX) || paramName.startsWith(PARAM_STARTGALLERY_PREFIX)) {
2240                String paramValue = request.getParameter(paramName);
2241                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(paramValue)) {
2242                    map.put(paramName, CmsEncoder.decode(paramValue));
2243                }
2244            }
2245        }
2246        return map;
2247    }
2248
2249    /**
2250     * Builds the HTML code for a select widget given a bean containing the select options
2251     *
2252     * @param htmlAttributes html attributes for the select widget
2253     * @param options the bean containing the select options
2254     *
2255     * @return the HTML for the select box
2256     */
2257    String buildSelect(String htmlAttributes, SelectOptions options) {
2258
2259        return buildSelect(htmlAttributes, options.getOptions(), options.getValues(), options.getSelectedIndex());
2260    }
2261
2262    /**
2263     * Builds the html for a common button style select box.<p>
2264     *
2265     * @param htmlAttributes optional html attributes for the &lgt;select&gt; tag
2266     * @param selectedIndex the index of the selected option
2267     * @return the html for the common button style select box
2268     */
2269    private String buildSelectButtonStyle(String htmlAttributes, int selectedIndex) {
2270
2271        List<String> options = new ArrayList<String>(3);
2272        options.add(key(Messages.GUI_PREF_BUTTONSTYLE_IMG_0));
2273        options.add(key(Messages.GUI_PREF_BUTTONSTYLE_IMGTXT_0));
2274        options.add(key(Messages.GUI_PREF_BUTTONSTYLE_TXT_0));
2275        String[] vals = new String[] {"0", "1", "2"};
2276        List<String> values = new ArrayList<String>(java.util.Arrays.asList(vals));
2277        return buildSelect(htmlAttributes, options, values, selectedIndex);
2278    }
2279
2280    /**
2281     * Returns the preferred editor preselection value either from the request, if not present, from the user settings.<p>
2282     *
2283     * @param request the current http servlet request
2284     * @param resourceType the preferred editors resource type
2285     * @return the preferred editor preselection value or null, if none found
2286     */
2287    private String computeEditorPreselection(HttpServletRequest request, String resourceType) {
2288
2289        // first check presence of the setting in request parameter
2290        String preSelection = request.getParameter(PARAM_PREFERREDEDITOR_PREFIX + resourceType);
2291        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(preSelection)) {
2292            return CmsEncoder.decode(preSelection);
2293        } else {
2294            // no value found in request, check current user settings (not the member!)
2295            CmsUserSettings userSettings = new CmsUserSettings(getSettings().getUser());
2296            return userSettings.getPreferredEditor(resourceType);
2297
2298        }
2299    }
2300
2301    /**
2302     * Returns the preferred editor preselection value either from the request, if not present, from the user settings.<p>
2303     *
2304     * @param request the current http servlet request
2305     * @param galleryType the preferred gallery type
2306     * @return the preferred editor preselection value or null, if none found
2307     */
2308    private String computeStartGalleryPreselection(HttpServletRequest request, String galleryType) {
2309
2310        // first check presence of the setting in request parameter
2311        String preSelection = request.getParameter(PARAM_STARTGALLERY_PREFIX + galleryType);
2312        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(preSelection)) {
2313            return CmsEncoder.decode(preSelection);
2314        } else {
2315            // no value found in request, check current user settings (not the member!)
2316            CmsUserSettings userSettings = new CmsUserSettings(getSettings().getUser());
2317            return userSettings.getStartGallery(galleryType);
2318
2319        }
2320    }
2321
2322    /**
2323     * Fills the parameter values according to the settings of the current user.<p>
2324     *
2325     * This method is called once when first displaying the preferences dialog.<p>
2326     */
2327    private void fillUserSettings() {
2328
2329        m_userSettings = new CmsUserSettings(getSettings().getUser());
2330    }
2331
2332    /**
2333     * Returns the message for a given upload variant.<p>
2334     *
2335     * @param variant the variant to get the message for
2336     *
2337     * @return the message
2338     */
2339    private String getUploadVariantMessage(UploadVariant variant) {
2340
2341        String message = null;
2342        switch (variant) {
2343            case basic:
2344                message = key(Messages.GUI_PREF_USE_UPLOAD_BASIC_0);
2345                break;
2346            case gwt:
2347                message = key(Messages.GUI_PREF_USE_UPLOAD_GWT_0);
2348                break;
2349            default:
2350                message = key(Messages.ERR_PREF_UPLOAD_VARIANT_NOT_FOUND_0);
2351                break;
2352        }
2353        return message;
2354    }
2355
2356    /**
2357     * Helper method for the request parameter methods to return a String depending on the boolean parameter.<p>
2358     *
2359     * @param isEnabled the boolean variable to check
2360     * @return <code>"true"</code> if isEnabled is true, otherwise ""
2361     */
2362    private String isParamEnabled(boolean isEnabled) {
2363
2364        if (isEnabled) {
2365            return CmsStringUtil.TRUE;
2366        }
2367        return "";
2368    }
2369}