KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > jasper > compiler > Localizer


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package com.icesoft.jasper.compiler;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.MissingResourceException JavaDoc;
24
25 /**
26  * Class responsible for converting error codes to corresponding localized error
27  * messages.
28  *
29  * @author Jan Luehe
30  */

31 public class Localizer {
32
33 /*
34     private static final ResourceBundle bundle = ResourceBundle.getBundle(
35         "org.apache.jasper.resources.messages");
36 */

37
38     private static final Log log = LogFactory.getLog(Localizer.class);
39
40     /*
41     * Returns the localized error message corresponding to the given error
42     * code.
43     *
44     * If the given error code is not defined in the resource bundle for
45     * localized error messages, it is used as the error message.
46     *
47     * @param errCode Error code to localize
48     *
49     * @return Localized error message
50     */

51     public static String JavaDoc getMessage(String JavaDoc errCode) {
52         String JavaDoc errMsg = errCode;
53 /*
54     try {
55         errMsg = bundle.getString(errCode);
56     } catch (MissingResourceException e) {
57     }
58 */

59         return errMsg;
60     }
61
62     /*
63      * Returns the localized error message corresponding to the given error
64      * code.
65      *
66      * If the given error code is not defined in the resource bundle for
67      * localized error messages, it is used as the error message.
68      *
69      * @param errCode Error code to localize
70      * @param arg Argument for parametric replacement
71      *
72      * @return Localized error message
73      */

74     public static String JavaDoc getMessage(String JavaDoc errCode, String JavaDoc arg) {
75         return getMessage(errCode, new Object JavaDoc[]{arg});
76     }
77
78     /*
79      * Returns the localized error message corresponding to the given error
80      * code.
81      *
82      * If the given error code is not defined in the resource bundle for
83      * localized error messages, it is used as the error message.
84      *
85      * @param errCode Error code to localize
86      * @param arg1 First argument for parametric replacement
87      * @param arg2 Second argument for parametric replacement
88      *
89      * @return Localized error message
90      */

91     public static String JavaDoc getMessage(String JavaDoc errCode, String JavaDoc arg1, String JavaDoc arg2) {
92         return getMessage(errCode, new Object JavaDoc[]{arg1, arg2});
93     }
94
95     /*
96     * Returns the localized error message corresponding to the given error
97     * code.
98     *
99     * If the given error code is not defined in the resource bundle for
100     * localized error messages, it is used as the error message.
101     *
102     * @param errCode Error code to localize
103     * @param arg1 First argument for parametric replacement
104     * @param arg2 Second argument for parametric replacement
105     * @param arg3 Third argument for parametric replacement
106     *
107     * @return Localized error message
108     */

109     public static String JavaDoc getMessage(String JavaDoc errCode, String JavaDoc arg1, String JavaDoc arg2,
110                                     String JavaDoc arg3) {
111         return getMessage(errCode, new Object JavaDoc[]{arg1, arg2, arg3});
112     }
113
114     /*
115      * Returns the localized error message corresponding to the given error
116      * code.
117      *
118      * If the given error code is not defined in the resource bundle for
119      * localized error messages, it is used as the error message.
120      *
121      * @param errCode Error code to localize
122      * @param arg1 First argument for parametric replacement
123      * @param arg2 Second argument for parametric replacement
124      * @param arg3 Third argument for parametric replacement
125      * @param arg4 Fourth argument for parametric replacement
126      *
127      * @return Localized error message
128      */

129     public static String JavaDoc getMessage(String JavaDoc errCode, String JavaDoc arg1, String JavaDoc arg2,
130                                     String JavaDoc arg3, String JavaDoc arg4) {
131         return getMessage(errCode, new Object JavaDoc[]{arg1, arg2, arg3, arg4});
132     }
133
134     /*
135      * Returns the localized error message corresponding to the given error
136      * code.
137      *
138      * If the given error code is not defined in the resource bundle for
139      * localized error messages, it is used as the error message.
140      *
141      * @param errCode Error code to localize
142      * @param args Arguments for parametric replacement
143      *
144      * @return Localized error message
145      */

146     public static String JavaDoc getMessage(String JavaDoc errCode, Object JavaDoc[] args) {
147         String JavaDoc errMsg = errCode;
148         try {
149 // errMsg = bundle.getString(errCode);
150
if (args != null) {
151                 MessageFormat JavaDoc formatter = new MessageFormat JavaDoc(errMsg);
152                 errMsg = formatter.format(args);
153             }
154         } catch (MissingResourceException JavaDoc e) {
155             if (log.isDebugEnabled()) {
156                 log.debug(e.getMessage(), e);
157             }
158         }
159
160         return errMsg;
161     }
162 }
163
Popular Tags