KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > Messages


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/Messages.java,v $
3  * Date : $Date: 2006/10/26 12:25:35 $
4  * Version: $Revision: 1.22 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.jsp;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsRequestContext;
36 import org.opencms.flex.CmsFlexController;
37 import org.opencms.i18n.A_CmsMessageBundle;
38 import org.opencms.i18n.CmsMessageContainer;
39 import org.opencms.i18n.I_CmsMessageBundle;
40
41 import java.util.Locale JavaDoc;
42
43 import javax.servlet.ServletRequest JavaDoc;
44 import javax.servlet.jsp.PageContext JavaDoc;
45
46 /**
47  * Convenience class to access the localized messages of this OpenCms package.
48  * <p>
49  *
50  *
51  * Additionally two utility methods for localization in the context of
52  * {@link javax.servlet.jsp.tagext.TagSupport} implementations of the <code>org.opencms.jsp</code>
53  * package are provided .
54  * <p>
55  *
56  * The <code>javax.servlet.jsp.tagext.TagSupport</code> API constraint only allows to throw
57  * certain <code>Exception</code> types which forbids to use {@link org.opencms.main.CmsException}
58  * which will be localized with the current user's locale at the time the request is evaluated.
59  * <p>
60  *
61  * At the same time <code>TagSupport</code> implementations may use their member
62  * <code>pageContext</code> to get the <code>CmsObject</code> and therefore the user request's
63  * locale.
64  * <p>
65  *
66  * These methods provided here factor out the localization of exception messages and return Strings
67  * for the <code>org.opencms.jsp</code> pacakge.
68  * <p>
69  *
70  * @author Jan Baudisch
71  *
72  * @version $Revision: 1.22 $
73  *
74  * @since 6.0.0
75  */

76 public final class Messages extends A_CmsMessageBundle {
77
78     /** Message constant for key in the resource bundle. */
79     public static final String JavaDoc ERR_BAD_REQUEST_RESPONSE_0 = "ERR_BAD_REQUEST_RESPONSE_0";
80
81     /** Message constant for key in the resource bundle. */
82     public static final String JavaDoc ERR_COLLECTOR_NOT_FOUND_1 = "ERR_COLLECTOR_NOT_FOUND_1";
83
84     /** Message constant for key in the resource bundle. */
85     public static final String JavaDoc ERR_DIRECT_EDIT_PROVIDER_1 = "ERR_DIRECT_EDIT_PROVIDER_1";
86
87     /** Message constant for key in the resource bundle. */
88     public static final String JavaDoc ERR_IMAGE_TAG_VFS_ACCESS_1 = "ERR_IMAGE_TAG_VFS_ACCESS_1";
89
90     /** Message constant for key in the resource bundle. */
91     public static final String JavaDoc ERR_MISSING_CMS_CONTROLLER_1 = "ERR_MISSING_CMS_CONTROLLER_1";
92
93     /** Message constant for key in the resource bundle. */
94     public static final String JavaDoc ERR_PARENTLESS_TAG_1 = "ERR_PARENTLESS_TAG_1";
95
96     /** Message constant for key in the resource bundle. */
97     public static final String JavaDoc ERR_PROCESS_TAG_1 = "ERR_PROCESS_TAG_1";
98
99     /** Message constant for key in the resource bundle. */
100     public static final String JavaDoc ERR_RUNTIME_1 = "ERR_RUNTIME_1";
101
102     /** Message constant for key in the resource bundle. */
103     public static final String JavaDoc ERR_TAG_CONTENTCHECK_WRONG_PARENT_0 = "ERR_TAG_CONTENTCHECK_WRONG_PARENT_0";
104
105     /** Message constant for key in the resource bundle. */
106     public static final String JavaDoc ERR_TAG_CONTENTLOAD_INDEX_SIZE_0 = "ERR_TAG_CONTENTLOAD_INDEX_SIZE_0";
107
108     /** Message constant for key in the resource bundle. */
109     public static final String JavaDoc ERR_TAG_CONTENTLOAD_MISSING_COLLECTOR_0 = "ERR_TAG_CONTENTLOAD_MISSING_COLLECTOR_0";
110
111     /** Message constant for key in the resource bundle. */
112     public static final String JavaDoc ERR_TAG_CONTENTLOAD_MISSING_PARAM_0 = "ERR_TAG_CONTENTLOAD_MISSING_PARAM_0";
113
114     /** Message constant for key in the resource bundle. */
115     public static final String JavaDoc ERR_XML_DOCUMENT_UNMARSHAL_1 = "ERR_XML_DOCUMENT_UNMARSHAL_1";
116
117     /** Message constant for key in the resource bundle. */
118     public static final String JavaDoc GUI_ERR_ACTIONELEM_NOT_INIT_0 = "GUI_ERR_ACTIONELEM_NOT_INIT_0";
119
120     /** Message constant for key in the resource bundle. */
121     public static final String JavaDoc GUI_ERR_FILE_PROP_MISSING_2 = "GUI_ERR_FILE_PROP_MISSING_2";
122
123     /** Message constant for key in the resource bundle. */
124     public static final String JavaDoc GUI_ERR_GEN_LINK_1 = "GUI_ERR_GEN_LINK_1";
125
126     /** Message constant for key in the resource bundle. */
127     public static final String JavaDoc GUI_ERR_IMG_SCALE_2 = "GUI_ERR_IMG_SCALE_2";
128
129     /** Message constant for key in the resource bundle. */
130     public static final String JavaDoc GUI_ERR_INFO_PROP_READ_1 = "GUI_ERR_INFO_PROP_READ_1";
131
132     /** Message constant for key in the resource bundle. */
133     public static final String JavaDoc GUI_ERR_INVALID_INFO_PROP_0 = "GUI_ERR_INVALID_INFO_PROP_0";
134
135     /** Message constant for key in the resource bundle. */
136     public static final String JavaDoc GUI_ERR_INVALID_INFO_PROP_1 = "GUI_ERR_INVALID_INFO_PROP_1";
137
138     /** Message constant for key in the resource bundle. */
139     public static final String JavaDoc GUI_ERR_INVALID_USER_PROP_1 = "GUI_ERR_INVALID_USER_PROP_1";
140
141     /** Message constant for key in the resource bundle. */
142     public static final String JavaDoc GUI_ERR_TAG_ATTRIBUTE_INVALID_3 = "GUI_ERR_TAG_ATTRIBUTE_INVALID_3";
143
144     /** Message constant for key in the resource bundle. */
145     public static final String JavaDoc GUI_ERR_TAG_ATTRIBUTE_MISSING_2 = "GUI_ERR_TAG_ATTRIBUTE_MISSING_2";
146
147     /** Message constant for key in the resource bundle. */
148     public static final String JavaDoc GUI_ERR_USER_PROP_READ_1 = "GUI_ERR_USER_PROP_READ_1";
149
150     /** Message constant for key in the resource bundle. */
151     public static final String JavaDoc GUI_ERR_WORKPL_LABEL_READ_1 = "GUI_ERR_WORKPL_LABEL_READ_1";
152
153     /** Message constant for key in the resource bundle. */
154     public static final String JavaDoc GUI_TAG_USER_ADDITIONALINFO_0 = "GUI_TAG_USER_ADDITIONALINFO_0";
155
156     /** Message constant for key in the resource bundle. */
157     public static final String JavaDoc LOG_DEBUG_INTERRUPTED_EXCEPTION_1 = "LOG_DEBUG_INTERRUPTED_EXCEPTION_1";
158
159     /** Message constant for key in the resource bundle. */
160     public static final String JavaDoc LOG_ERR_CONTENT_SHOW_1 = "LOG_ERR_CONTENT_SHOW_1";
161
162     /** Message constant for key in the resource bundle. */
163     public static final String JavaDoc LOG_ERR_JSP_BEAN_0 = "LOG_ERR_JSP_BEAN_0";
164
165     /** Message constant for key in the resource bundle. */
166     public static final String JavaDoc LOG_ERR_JSP_WRITE_0 = "LOG_ERR_JSP_WRITE_0";
167
168     /** Message constant for key in the resource bundle. */
169     public static final String JavaDoc LOG_LOGIN_FAILED_3 = "LOG_LOGIN_FAILED_3";
170
171     /** Message constant for key in the resource bundle. */
172     public static final String JavaDoc LOG_LOGIN_FAILED_DB_REASON_3 = "LOG_LOGIN_FAILED_DB_REASON_3";
173
174     /** Message constant for key in the resource bundle. */
175     public static final String JavaDoc LOG_LOGIN_FAILED_DISABLED_3 = "LOG_LOGIN_FAILED_DISABLED_3";
176
177     /** Message constant for key in the resource bundle. */
178     public static final String JavaDoc LOG_LOGIN_FAILED_NO_USER_3 = "LOG_LOGIN_FAILED_NO_USER_3";
179
180     /** Message constant for key in the resource bundle. */
181     public static final String JavaDoc LOG_LOGIN_FAILED_TEMP_DISABLED_5 = "LOG_LOGIN_FAILED_TEMP_DISABLED_5";
182
183     /** Message constant for key in the resource bundle. */
184     public static final String JavaDoc LOG_LOGIN_FAILED_WITH_MESSAGE_4 = "LOG_LOGIN_FAILED_WITH_MESSAGE_4";
185
186     /** Message constant for key in the resource bundle. */
187     public static final String JavaDoc LOG_LOGIN_SUCCESSFUL_3 = "LOG_LOGIN_SUCCESSFUL_3";
188
189     /** Message constant for key in the resource bundle. */
190     public static final String JavaDoc LOG_LOGOUT_SUCCESFUL_3 = "LOG_LOGOUT_SUCCESFUL_3";
191
192     /** Name of the used resource bundle. */
193     private static final String JavaDoc BUNDLE_NAME = "org.opencms.jsp.messages";
194
195     /** Static instance member. */
196     private static final I_CmsMessageBundle INSTANCE = new Messages();
197
198     /**
199      * Hides the public constructor for this utility class.
200      * <p>
201      */

202     private Messages() {
203
204         // hide the constructor
205
}
206
207     /**
208      * Returns an instance of this localized message accessor.
209      * <p>
210      *
211      * @return an instance of this localized message accessor
212      */

213     public static I_CmsMessageBundle get() {
214
215         return INSTANCE;
216     }
217
218     /**
219      * Returns the String for the given CmsMessageContainer localized to the current user's locale
220      * if available or to the default locale else.
221      * <p>
222      *
223      * This method is needed for localization of non- {@link org.opencms.main.CmsException}
224      * instances that have to be thrown here due to API constraints (javax.servlet.jsp).
225      * <p>
226      *
227      * @param container A CmsMessageContainer containing the message to localize.
228      * @param cms the <code>CmsObject</code> belonging to the current user (e.g. obtained with
229      * <code>CmsFlexController.getCmsObject(ServletRequest)</code>).
230      * @return the String for the given CmsMessageContainer localized to the current user's locale
231      * if available or to the default locale else.
232      * <p>
233      */

234     public static String JavaDoc getLocalizedMessage(CmsMessageContainer container, CmsObject cms) {
235
236         Locale JavaDoc locale;
237         if (cms != null) {
238             CmsRequestContext context = cms.getRequestContext();
239             locale = (context != null) ? context.getLocale() : Locale.getDefault();
240         } else {
241             locale = Locale.getDefault();
242         }
243         return container.key(locale);
244     }
245
246     /**
247      * Returns the String for the given CmsMessageContainer localized to the current user's locale
248      * if available or to the default locale else.
249      * <p>
250      *
251      * This method is needed for localization of non- {@link org.opencms.main.CmsException}
252      * instances that have to be thrown here due to API constraints (javax.servlet.jsp).
253      * <p>
254      *
255      * @param container A CmsMessageContainer containing the message to localize.
256      * @param context The page context that is known to any calling
257      * {@link javax.servlet.jsp.tagext.TagSupport} instance (member
258      * <code>pageContext</code>).
259      * @return the String for the given CmsMessageContainer localized to the current user's locale
260      * if available or to the default locale else.
261      * <p>
262      */

263     public static String JavaDoc getLocalizedMessage(CmsMessageContainer container, PageContext JavaDoc context) {
264
265         return Messages.getLocalizedMessage(container, context.getRequest());
266     }
267
268     /**
269      * Returns the String for the given CmsMessageContainer localized to the current user's locale
270      * if available or to the default locale else.
271      * <p>
272      *
273      * This method allows a static method ({@link CmsJspTagInfo#infoTagAction(String, javax.servlet.http.HttpServletRequest)})
274      * that has no <code>pageContext</code> in scope to lookup the locale at request time.
275      * <p>
276      *
277      * @see #getLocalizedMessage(CmsMessageContainer, PageContext)
278      * @param container A CmsMessageContainer containing the message to localize.
279      * @param request The current request.
280      * @return the String for the given CmsMessageContainer localized to the current user's locale
281      * if available or to the default locale else.
282      * <p>
283      */

284     public static String JavaDoc getLocalizedMessage(CmsMessageContainer container, ServletRequest JavaDoc request) {
285
286         CmsObject cms = CmsFlexController.getCmsObject(request);
287         return getLocalizedMessage(container, cms);
288
289     }
290
291     /**
292      * Returns the bundle name for this OpenCms package.
293      * <p>
294      *
295      * @return the bundle name for this OpenCms package
296      */

297     public String JavaDoc getBundleName() {
298
299         return BUNDLE_NAME;
300     }
301 }
Popular Tags