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.jsp;
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 6.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_BAD_REQUEST_RESPONSE_0 = "ERR_BAD_REQUEST_RESPONSE_0";
072
073    /** Message constant for key in the resource bundle. */
074    public static final String ERR_COLLECTOR_NOT_FOUND_1 = "ERR_COLLECTOR_NOT_FOUND_1";
075
076    /** Message constant for key in the resource bundle. */
077    public static final String ERR_CONTAINER_PAGE_ELEMENT_RENDER_ERROR_2 = "ERR_CONTAINER_PAGE_ELEMENT_RENDER_ERROR_2";
078
079    /** Message constant for key in the resource bundle. */
080    public static final String ERR_CONTAINER_PAGE_NO_TYPE_3 = "ERR_CONTAINER_PAGE_NO_TYPE_3";
081
082    /** Message constant for key in the resource bundle. */
083    public static final String ERR_CONTAINER_PAGE_NOT_FOUND_3 = "ERR_CONTAINER_PAGE_NOT_FOUND_3";
084
085    /** Message constant for key in the resource bundle. */
086    public static final String ERR_DIRECT_EDIT_PROVIDER_1 = "ERR_DIRECT_EDIT_PROVIDER_1";
087
088    /** Message constant for key in the resource bundle. */
089    public static final String ERR_IMAGE_TAG_VFS_ACCESS_1 = "ERR_IMAGE_TAG_VFS_ACCESS_1";
090
091    /** Message constant for key in the resource bundle. */
092    public static final String ERR_INVALID_CONTAINER_PARENT_2 = "ERR_INVALID_CONTAINER_PARENT_2";
093
094    /** Message constant for key in the resource bundle. */
095    public static final String ERR_MISSING_CMS_CONTROLLER_1 = "ERR_MISSING_CMS_CONTROLLER_1";
096
097    /** Message constant for key in the resource bundle. */
098    public static final String ERR_NO_CUSTOM_BEAN_1 = "ERR_NO_CUSTOM_BEAN_1";
099
100    /** Message constant for key in the resource bundle. */
101    public static final String ERR_PARENTLESS_TAG_1 = "ERR_PARENTLESS_TAG_1";
102
103    /** Message constant for key in the resource bundle. */
104    public static final String ERR_PROCESS_TAG_1 = "ERR_PROCESS_TAG_1";
105
106    /** Message constant for key in the resource bundle. */
107    public static final String ERR_READING_REQUIRED_RESOURCE_1 = "ERR_READING_REQUIRED_RESOURCE_1";
108
109    /** Message constant for key in the resource bundle. */
110    public static final String ERR_RESOURCE_IS_NOT_RELEASE_OR_EXPIRED_1 = "ERR_RESOURCE_IS_NOT_RELEASE_OR_EXPIRED_1";
111
112    /** Message constant for key in the resource bundle. */
113    public static final String ERR_RUNTIME_1 = "ERR_RUNTIME_1";
114
115    /** Message constant for key in the resource bundle. */
116    public static final String ERR_TAG_CONTENTCHECK_WRONG_PARENT_0 = "ERR_TAG_CONTENTCHECK_WRONG_PARENT_0";
117
118    /** Message constant for key in the resource bundle. */
119    public static final String ERR_TAG_CONTENTLOAD_INDEX_SIZE_0 = "ERR_TAG_CONTENTLOAD_INDEX_SIZE_0";
120
121    /** Message constant for key in the resource bundle. */
122    public static final String ERR_TAG_CONTENTLOAD_MISSING_COLLECTOR_0 = "ERR_TAG_CONTENTLOAD_MISSING_COLLECTOR_0";
123
124    /** Message constant for key in the resource bundle. */
125    public static final String ERR_TAG_CONTENTLOAD_MISSING_PARAM_0 = "ERR_TAG_CONTENTLOAD_MISSING_PARAM_0";
126
127    /** Message constant for key in the resource bundle. */
128    public static final String ERR_TAG_INVALID_LOCALE_1 = "ERR_TAG_INVALID_LOCALE_1";
129
130    /** Message constant for key in the resource bundle. */
131    public static final String ERR_TAG_RESOURCELOAD_INDEX_SIZE_0 = "ERR_TAG_RESOURCELOAD_INDEX_SIZE_0";
132
133    /** Message constant for key in the resource bundle. */
134    public static final String ERR_TAG_RESOURCELOAD_MISSING_COLLECTOR_0 = "ERR_TAG_RESOURCELOAD_MISSING_COLLECTOR_0";
135
136    /** Message constant for key in the resource bundle. */
137    public static final String ERR_TAG_RESOURCELOAD_MISSING_PARAM_0 = "ERR_TAG_RESOURCELOAD_MISSING_PARAM_0";
138
139    /** Message constant for key in the resource bundle. */
140    public static final String ERR_XML_DOCUMENT_UNMARSHAL_1 = "ERR_XML_DOCUMENT_UNMARSHAL_1";
141
142    /** Message constant for key in the resource bundle. */
143    public static final String ERR_XSD_NO_TEMPLATE_FORMATTER_3 = "ERR_XSD_NO_TEMPLATE_FORMATTER_3";
144
145    /** Message constant for key in the resource bundle. */
146    public static final String GUI_ERR_ACTIONELEM_NOT_INIT_0 = "GUI_ERR_ACTIONELEM_NOT_INIT_0";
147
148    /** Message constant for key in the resource bundle. */
149    public static final String GUI_ERR_FILE_PROP_MISSING_2 = "GUI_ERR_FILE_PROP_MISSING_2";
150
151    /** Message constant for key in the resource bundle. */
152    public static final String GUI_ERR_GEN_LINK_1 = "GUI_ERR_GEN_LINK_1";
153
154    /** Message constant for key in the resource bundle. */
155    public static final String GUI_ERR_IMG_SCALE_2 = "GUI_ERR_IMG_SCALE_2";
156
157    /** Message constant for key in the resource bundle. */
158    public static final String GUI_ERR_INFO_PROP_READ_1 = "GUI_ERR_INFO_PROP_READ_1";
159
160    /** Message constant for key in the resource bundle. */
161    public static final String GUI_ERR_INVALID_INFO_PROP_0 = "GUI_ERR_INVALID_INFO_PROP_0";
162
163    /** Message constant for key in the resource bundle. */
164    public static final String GUI_ERR_INVALID_INFO_PROP_1 = "GUI_ERR_INVALID_INFO_PROP_1";
165
166    /** Message constant for key in the resource bundle. */
167    public static final String GUI_ERR_INVALID_USER_PROP_1 = "GUI_ERR_INVALID_USER_PROP_1";
168
169    /** Message constant for key in the resource bundle. */
170    public static final String GUI_ERR_TAG_ATTRIBUTE_INVALID_3 = "GUI_ERR_TAG_ATTRIBUTE_INVALID_3";
171
172    /** Message constant for key in the resource bundle. */
173    public static final String GUI_ERR_TAG_ATTRIBUTE_MISSING_2 = "GUI_ERR_TAG_ATTRIBUTE_MISSING_2";
174
175    /** Message constant for key in the resource bundle. */
176    public static final String GUI_ERR_USER_PROP_READ_1 = "GUI_ERR_USER_PROP_READ_1";
177
178    /** Message constant for key in the resource bundle. */
179    public static final String GUI_ERR_WORKPL_LABEL_READ_1 = "GUI_ERR_WORKPL_LABEL_READ_1";
180
181    /** Message constant for key in the resource bundle. */
182    public static final String GUI_LABEL_STACKTRACE_0 = "GUI_LABEL_STACKTRACE_0";
183
184    /** Message constant for key in the resource bundle. */
185    public static final String GUI_TAG_USER_ADDITIONALINFO_0 = "GUI_TAG_USER_ADDITIONALINFO_0";
186
187    /** Message constant for key in the resource bundle. */
188    public static final String GUI_TOOLBAR_ENABLE_EDIT_MODE_0 = "GUI_TOOLBAR_ENABLE_EDIT_MODE_0";
189
190    /** Message constant for key in the resource bundle. */
191    public static final String LOG_CONTAINER_NOT_FOUND_3 = "LOG_CONTAINER_NOT_FOUND_3";
192
193    /** Message constant for key in the resource bundle. */
194    public static final String LOG_DEBUG_INTERRUPTED_EXCEPTION_1 = "LOG_DEBUG_INTERRUPTED_EXCEPTION_1";
195
196    /** Message constant for key in the resource bundle. */
197    public static final String LOG_ERR_CONTENT_SHOW_1 = "LOG_ERR_CONTENT_SHOW_1";
198
199    /** Message constant for key in the resource bundle. */
200    public static final String LOG_ERR_JSP_BEAN_0 = "LOG_ERR_JSP_BEAN_0";
201
202    /** Message constant for key in the resource bundle. */
203    public static final String LOG_ERR_JSP_WRITE_0 = "LOG_ERR_JSP_WRITE_0";
204
205    /** Message constant for key in the resource bundle. */
206    public static final String LOG_LOGIN_FAILED_3 = "LOG_LOGIN_FAILED_3";
207
208    /** Message constant for key in the resource bundle. */
209    public static final String LOG_LOGIN_FAILED_DB_REASON_3 = "LOG_LOGIN_FAILED_DB_REASON_3";
210
211    /** Message constant for key in the resource bundle. */
212    public static final String LOG_LOGIN_FAILED_DISABLED_3 = "LOG_LOGIN_FAILED_DISABLED_3";
213
214    /** Message constant for key in the resource bundle. */
215    public static final String LOG_LOGIN_FAILED_NO_USER_3 = "LOG_LOGIN_FAILED_NO_USER_3";
216
217    /** Message constant for key in the resource bundle. */
218    public static final String LOG_LOGIN_FAILED_TEMP_DISABLED_5 = "LOG_LOGIN_FAILED_TEMP_DISABLED_5";
219
220    /** Message constant for key in the resource bundle. */
221    public static final String LOG_LOGIN_FAILED_WITH_MESSAGE_4 = "LOG_LOGIN_FAILED_WITH_MESSAGE_4";
222
223    /** Message constant for key in the resource bundle. */
224    public static final String LOG_LOGIN_SUCCESSFUL_3 = "LOG_LOGIN_SUCCESSFUL_3";
225
226    /** Message constant for key in the resource bundle. */
227    public static final String LOG_LOGOUT_SUCCESFUL_3 = "LOG_LOGOUT_SUCCESFUL_3";
228
229    /** Message constant for key in the resource bundle. */
230    public static final String LOG_MAXELEMENTS_NOT_SET_2 = "LOG_MAXELEMENTS_NOT_SET_2";
231
232    /** Message constant for key in the resource bundle. */
233    public static final String LOG_TAG_SEARCH_SEARCH_FAILED_0 = "LOG_TAG_SEARCH_SEARCH_FAILED_0";
234
235    /** Message constant for key in the resource bundle. */
236    public static final String LOG_WRONG_CONTAINER_MAXELEMENTS_3 = "LOG_WRONG_CONTAINER_MAXELEMENTS_3";
237
238    /** Message constant for key in the resource bundle. */
239    public static final String LOG_WRONG_CONTAINER_TYPE_4 = "LOG_WRONG_CONTAINER_TYPE_4";
240
241    /** Message constant for key in the resource bundle. */
242    public static final String LOG_WRONG_DEVICE_TYPE_2 = "LOG_WRONG_DEVICE_TYPE_2";
243
244    /** Name of the used resource bundle. */
245    private static final String BUNDLE_NAME = "org.opencms.jsp.messages";
246
247    /** Static instance member. */
248    private static final I_CmsMessageBundle INSTANCE = new Messages();
249
250    /**
251     * Hides the public constructor for this utility class.
252     * <p>
253     */
254    private Messages() {
255
256        // hide the constructor
257    }
258
259    /**
260     * Returns an instance of this localized message accessor.
261     * <p>
262     *
263     * @return an instance of this localized message accessor
264     */
265    public static I_CmsMessageBundle get() {
266
267        return INSTANCE;
268    }
269
270    /**
271     * Returns the String for the given CmsMessageContainer localized to the current user's locale
272     * if available or to the default locale else.
273     * <p>
274     *
275     * This method is needed for localization of non- {@link org.opencms.main.CmsException}
276     * instances that have to be thrown here due to API constraints (javax.servlet.jsp).
277     * <p>
278     *
279     * @param container A CmsMessageContainer containing the message to localize.
280     * @param cms the <code>CmsObject</code> belonging to the current user (e.g. obtained with
281     *            <code>CmsFlexController.getCmsObject(ServletRequest)</code>).
282     * @return the String for the given CmsMessageContainer localized to the current user's locale
283     *         if available or to the default locale else.
284     *         <p>
285     */
286    public static String getLocalizedMessage(CmsMessageContainer container, CmsObject cms) {
287
288        Locale locale;
289        if (cms != null) {
290            CmsRequestContext context = cms.getRequestContext();
291            locale = (context != null) ? context.getLocale() : Locale.getDefault();
292        } else {
293            locale = Locale.getDefault();
294        }
295        return container.key(locale);
296    }
297
298    /**
299     * Returns the String for the given CmsMessageContainer localized to the current user's locale
300     * if available or to the default locale else.
301     * <p>
302     *
303     * This method is needed for localization of non- {@link org.opencms.main.CmsException}
304     * instances that have to be thrown here due to API constraints (javax.servlet.jsp).
305     * <p>
306     *
307     * @param container A CmsMessageContainer containing the message to localize.
308     * @param context The page context that is known to any calling
309     *            {@link javax.servlet.jsp.tagext.TagSupport} instance (member
310     *            <code>pageContext</code>).
311     * @return the String for the given CmsMessageContainer localized to the current user's locale
312     *         if available or to the default locale else.
313     *         <p>
314     */
315    public static String getLocalizedMessage(CmsMessageContainer container, PageContext context) {
316
317        return Messages.getLocalizedMessage(container, context.getRequest());
318    }
319
320    /**
321     * Returns the String for the given CmsMessageContainer localized to the current user's locale
322     * if available or to the default locale else.
323     * <p>
324     *
325     * This method allows a static method ({@link CmsJspTagInfo#infoTagAction(String, javax.servlet.http.HttpServletRequest)})
326     * that has no <code>pageContext</code> in scope to lookup the locale at request time.
327     * <p>
328     *
329     * @see #getLocalizedMessage(CmsMessageContainer, PageContext)
330     * @param container A CmsMessageContainer containing the message to localize.
331     * @param request The current request.
332     * @return the String for the given CmsMessageContainer localized to the current user's locale
333     *         if available or to the default locale else.
334     *         <p>
335     */
336    public static String getLocalizedMessage(CmsMessageContainer container, ServletRequest request) {
337
338        CmsObject cms = CmsFlexController.getCmsObject(request);
339        return getLocalizedMessage(container, cms);
340
341    }
342
343    /**
344     * Returns the bundle name for this OpenCms package.
345     * <p>
346     *
347     * @return the bundle name for this OpenCms package
348     */
349    public String getBundleName() {
350
351        return BUNDLE_NAME;
352    }
353}