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.workplace.editors.directedit;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsRequestContext;
032import org.opencms.flex.CmsFlexController;
033import org.opencms.i18n.A_CmsMessageBundle;
034import org.opencms.i18n.CmsMessageContainer;
035import org.opencms.i18n.I_CmsMessageBundle;
036
037import java.util.Locale;
038
039import javax.servlet.ServletRequest;
040import javax.servlet.jsp.PageContext;
041
042/**
043 * Convenience class to access the localized messages of this OpenCms package.
044 * <p>
045 *
046 *
047 * Additionally two utility methods for localization in the context of
048 * {@link javax.servlet.jsp.tagext.TagSupport} implementations of the <code>org.opencms.jsp</code>
049 * package are provided .
050 * <p>
051 *
052 * The <code>javax.servlet.jsp.tagext.TagSupport</code> API constraint only allows to throw
053 * certain <code>Exception</code> types which forbids to use {@link org.opencms.main.CmsException}
054 * which will be localized with the current user's locale at the time the request is evaluated.
055 * <p>
056 *
057 * At the same time <code>TagSupport</code> implementations may use their member
058 * <code>pageContext</code> to get the <code>CmsObject</code> and therefore the user request's
059 * locale.
060 * <p>
061 *
062 * These methods provided here factor out the localization of exception messages and return Strings
063 * for the <code>org.opencms.jsp</code> pacakge.
064 * <p>
065 *
066 * @since 9.0.0
067 */
068public final class Messages extends A_CmsMessageBundle {
069
070    /** Message constant for key in the resource bundle. */
071    public static final String ERR_DATE_SERIES_HANDLER_ADD_EXCEPTION_FAILED_0 = "ERR_DATE_SERIES_HANDLER_ADD_EXCEPTION_FAILED_0";
072
073    /** Message constant for key in the resource bundle. */
074    public static final String ERR_DATE_SERIES_HANDLER_ADD_EXCEPTION_FAILED_MISSING_DATE_0 = "ERR_DATE_SERIES_HANDLER_ADD_EXCEPTION_FAILED_MISSING_DATE_0";
075
076    /** Message constant for key in the resource bundle. */
077    public static final String ERR_DATE_SERIES_HANDLER_INVALID_DELETE_OPTION_1 = "ERR_DATE_SERIES_HANDLER_INVALID_DELETE_OPTION_1";
078
079    /** Message constant for key in the resource bundle. */
080    public static final String ERR_DATE_SERIES_HANDLER_EXTRACT_CONTENT_FAILED_0 = "ERR_DATE_SERIES_HANDLER_EXTRACT_CONTENT_FAILED_0";
081
082    /** Message constant for key in the resource bundle. */
083    public static final String ERR_DATE_SERIES_HANDLER_EXTRACT_CONTENT_FAILED_MISSING_DATE_0 = "ERR_DATE_SERIES_HANDLER_EXTRACT_CONTENT_FAILED_MISSING_DATE_0";
084
085    /** Message constant for key in the resource bundle. */
086    public static final String ERR_DATE_SERIES_HANDLER_INVALID_EDIT_OPTION_1 = "ERR_DATE_SERIES_HANDLER_INVALID_EDIT_OPTION_1";
087
088    /** Message constant for key in the resource bundle. */
089    public static final String GUI_CLICK_TO_ADD_ELEMENT_TO_EMPTY_LIST_0 = "GUI_CLICK_TO_ADD_ELEMENT_TO_EMPTY_LIST_0";
090
091    /** Message constant for key in the resource bundle. */
092    public static final String GUI_DATE_SERIES_HANDLER_EDIT_DIALOG_HEADING_0 = "GUI_DATE_SERIES_HANDLER_EDIT_DIALOG_HEADING_0";
093
094    /** Message constant for key in the resource bundle. */
095    public static final String GUI_DATE_SERIES_HANDLER_EDIT_DIALOG_INFO_1 = "GUI_DATE_SERIES_HANDLER_EDIT_DIALOG_INFO_1";
096
097    /** Message constant for key in the resource bundle. */
098    public static final String GUI_DATE_SERIES_HANDLER_EDIT_OPTION_SERIES_0 = "GUI_DATE_SERIES_HANDLER_EDIT_OPTION_SERIES_0";
099
100    /** Message constant for key in the resource bundle. */
101    public static final String GUI_DATE_SERIES_HANDLER_EDIT_OPTION_SERIES_HELP_ACTIVE_0 = "GUI_DATE_SERIES_HANDLER_EDIT_OPTION_SERIES_HELP_ACTIVE_0";
102
103    /** Message constant for key in the resource bundle. */
104    public static final String GUI_DATE_SERIES_HANDLER_EDIT_OPTION_INSTANCE_1 = "GUI_DATE_SERIES_HANDLER_EDIT_OPTION_INSTANCE_1";
105
106    /** Message constant for key in the resource bundle. */
107    public static final String GUI_DATE_SERIES_HANDLER_EDIT_OPTION_INSTANCE_HELP_ACTIVE_1 = "GUI_DATE_SERIES_HANDLER_EDIT_OPTION_INSTANCE_HELP_ACTIVE_1";
108
109    /** Message constant for key in the resource bundle. */
110    public static final String GUI_DATE_SERIES_HANDLER_EDIT_OPTION_INSTANCE_HELP_INACTIVE_1 = "GUI_DATE_SERIES_HANDLER_EDIT_OPTION_INSTANCE_HELP_INACTIVE_1";
111
112    /** Message constant for key in the resource bundle. */
113    public static final String GUI_DATE_SERIES_HANDLER_DELETE_DIALOG_HEADING_0 = "GUI_DATE_SERIES_HANDLER_DELETE_DIALOG_HEADING_0";
114
115    /** Message constant for key in the resource bundle. */
116    public static final String GUI_DATE_SERIES_HANDLER_DELETE_DIALOG_INFO_1 = "GUI_DATE_SERIES_HANDLER_DELETE_DIALOG_INFO_1";
117
118    /** Message constant for key in the resource bundle. */
119    public static final String GUI_DATE_SERIES_HANDLER_DELETE_OPTION_SERIES_0 = "GUI_DATE_SERIES_HANDLER_DELETE_OPTION_SERIES_0";
120
121    /** Message constant for key in the resource bundle. */
122    public static final String GUI_DATE_SERIES_HANDLER_DELETE_OPTION_SERIES_HELP_ACTIVE_0 = "GUI_DATE_SERIES_HANDLER_DELETE_OPTION_SERIES_HELP_ACTIVE_0";
123
124    /** Message constant for key in the resource bundle. */
125    public static final String GUI_DATE_SERIES_HANDLER_DELETE_OPTION_INSTANCE_1 = "GUI_DATE_SERIES_HANDLER_DELETE_OPTION_INSTANCE_1";
126
127    /** Message constant for key in the resource bundle. */
128    public static final String GUI_DATE_SERIES_HANDLER_DELETE_OPTION_INSTANCE_HELP_ACTIVE_1 = "GUI_DATE_SERIES_HANDLER_DELETE_OPTION_INSTANCE_HELP_ACTIVE_1";
129
130    /** Name of the used resource bundle. */
131    private static final String BUNDLE_NAME = "org.opencms.workplace.editors.directedit.messages";
132
133    /** Static instance member. */
134    private static final I_CmsMessageBundle INSTANCE = new Messages();
135
136    /**
137     * Hides the public constructor for this utility class.
138     * <p>
139     */
140    private Messages() {
141
142        // hide the constructor
143    }
144
145    /**
146     * Returns an instance of this localized message accessor.
147     * <p>
148     *
149     * @return an instance of this localized message accessor
150     */
151    public static I_CmsMessageBundle get() {
152
153        return INSTANCE;
154    }
155
156    /**
157     * Returns the String for the given CmsMessageContainer localized to the current user's locale
158     * if available or to the default locale else.
159     * <p>
160     *
161     * This method is needed for localization of non- {@link org.opencms.main.CmsException}
162     * instances that have to be thrown here due to API constraints (javax.servlet.jsp).
163     * <p>
164     *
165     * @param container A CmsMessageContainer containing the message to localize.
166     * @param cms the <code>CmsObject</code> belonging to the current user (e.g. obtained with
167     *            <code>CmsFlexController.getCmsObject(ServletRequest)</code>).
168     * @return the String for the given CmsMessageContainer localized to the current user's locale
169     *         if available or to the default locale else.
170     *         <p>
171     */
172    public static String getLocalizedMessage(CmsMessageContainer container, CmsObject cms) {
173
174        Locale locale;
175        if (cms != null) {
176            CmsRequestContext context = cms.getRequestContext();
177            locale = (context != null) ? context.getLocale() : Locale.getDefault();
178        } else {
179            locale = Locale.getDefault();
180        }
181        return container.key(locale);
182    }
183
184    /**
185     * Returns the String for the given CmsMessageContainer localized to the current user's locale
186     * if available or to the default locale else.
187     * <p>
188     *
189     * This method is needed for localization of non- {@link org.opencms.main.CmsException}
190     * instances that have to be thrown here due to API constraints (javax.servlet.jsp).
191     * <p>
192     *
193     * @param container A CmsMessageContainer containing the message to localize.
194     * @param context The page context that is known to any calling
195     *            {@link javax.servlet.jsp.tagext.TagSupport} instance (member
196     *            <code>pageContext</code>).
197     * @return the String for the given CmsMessageContainer localized to the current user's locale
198     *         if available or to the default locale else.
199     *         <p>
200     */
201    public static String getLocalizedMessage(CmsMessageContainer container, PageContext context) {
202
203        return Messages.getLocalizedMessage(container, context.getRequest());
204    }
205
206    /**
207     * Returns the String for the given CmsMessageContainer localized to the current user's locale
208     * if available or to the default locale else.
209     * <p>
210     *
211     * This method allows a static method ({@link org.opencms.jsp.CmsJspTagInfo#infoTagAction(String, javax.servlet.http.HttpServletRequest)})
212     * that has no <code>pageContext</code> in scope to lookup the locale at request time.
213     * <p>
214     *
215     * @see #getLocalizedMessage(CmsMessageContainer, PageContext)
216     * @param container A CmsMessageContainer containing the message to localize.
217     * @param request The current request.
218     * @return the String for the given CmsMessageContainer localized to the current user's locale
219     *         if available or to the default locale else.
220     *         <p>
221     */
222    public static String getLocalizedMessage(CmsMessageContainer container, ServletRequest request) {
223
224        CmsObject cms = CmsFlexController.getCmsObject(request);
225        return getLocalizedMessage(container, cms);
226
227    }
228
229    /**
230     * Returns the bundle name for this OpenCms package.
231     * <p>
232     *
233     * @return the bundle name for this OpenCms package
234     */
235    public String getBundleName() {
236
237        return BUNDLE_NAME;
238    }
239}