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, 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.ui.login;
029
030import org.opencms.i18n.CmsResourceBundleLoader;
031import org.opencms.main.CmsLog;
032
033import java.util.Locale;
034import java.util.MissingResourceException;
035import java.util.ResourceBundle;
036
037import org.apache.commons.logging.Log;
038
039/**
040 * Helper class for getting localized messages for the 'lock inactive users' feature.<p>
041 *
042 * We are not just using the standard Messages class here because the messages are supposed to be customizable,
043 * and we do not want to lose the customizations if e.g. we install a new opencms.jar.<p>
044 */
045public class CmsInactiveUserMessages {
046
047    /** Logger instance for this class. */
048    private static final Log LOG = CmsLog.getLog(CmsInactiveUserMessages.class);
049
050    /**
051     * Text to display for the lockout screen.<p>
052     *
053     * @param locale the locale
054     *
055     * @return the localized text
056     */
057    public static String getLockoutText(Locale locale) {
058
059        return getMessage("inactiveusers.lockout.text", locale);
060    }
061
062    /**
063     * Gets the message for the given key and locale.<p>
064     *
065     * @param key the key
066     * @param locale the locale
067     * @return the localized text
068     */
069    public static String getMessage(String key, Locale locale) {
070
071        ResourceBundle bundle = null;
072        try {
073            bundle = CmsResourceBundleLoader.getBundle("org.opencms.inactiveusers.custom", locale);
074            return bundle.getString(key);
075        } catch (MissingResourceException e) {
076            LOG.info("Customization bundle not found: org.opencms.inactiveusers.custom", e);
077            bundle = CmsResourceBundleLoader.getBundle("org.opencms.ui.messages", locale);
078            return bundle.getString(key);
079        }
080    }
081
082    /**
083     * Gets the header text for the report mail.<p>
084     *
085     * @param locale the locale
086     * @return the localized text
087     */
088    public static String getReportHeader(Locale locale) {
089
090        return getMessage("inactiveusers.report.header", locale);
091    }
092
093    /**
094     * Gets the subject for the report mail.<p>
095     *
096     * @param locale the locale
097     *
098     * @return the localized text
099     */
100    public static String getReportSubject(Locale locale) {
101
102        return getMessage("inactiveusers.report.subject", locale);
103    }
104
105}