~james-page/ubuntu/natty/tomcat6/fix-662588

« back to all changes in this revision

Viewing changes to java/org/apache/tomcat/util/res/StringManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Iulian Udrea
  • Date: 2009-06-09 12:35:19 UTC
  • mfrom: (1.2.1 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090609123519-7owjbso5ttnka6ur
Tags: 6.0.20-1ubuntu1
[ Iulian Udrea ]
* Merge from debian unstable (LP: #385262), remaining changes:
  - debian/control, debian/rules: Use default-jdk to build
  - debian/control: Run using default-jre-headless by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 * <p>Please see the documentation for java.util.ResourceBundle for
43
43
 * more information.
44
44
 *
45
 
 * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (Tue, 24 Oct 2006) $
 
45
 * @version $Revision: 769384 $ $Date: 2009-04-28 15:14:14 +0200 (Tue, 28 Apr 2009) $
46
46
 *
47
47
 * @author James Duncan Davidson [duncan@eng.sun.com]
48
48
 * @author James Todd [gonzo@eng.sun.com]
131
131
     * @param args
132
132
     */
133
133
 
134
 
    public String getString(String key, Object[] args) {
135
 
        String iString = null;
 
134
    public String getString(final String key, final Object... args) {
136
135
        String value = getString(key);
137
 
 
138
 
        // this check for the runtime exception is some pre 1.1.6
139
 
        // VM's don't do an automatic toString() on the passed in
140
 
        // objects and barf out
141
 
 
142
 
        try {
143
 
            // ensure the arguments are not null so pre 1.2 VM's don't barf
144
 
            if(args==null){
145
 
                args = new Object[1];
146
 
            }
147
 
            
148
 
            Object[] nonNullArgs = args;
149
 
            for (int i=0; i<args.length; i++) {
150
 
                if (args[i] == null) {
151
 
                    if (nonNullArgs==args){
152
 
                        nonNullArgs=(Object[])args.clone();
153
 
                    }
154
 
                    nonNullArgs[i] = "null";
155
 
                }
156
 
            }
157
 
            if( value==null ) value=key;
158
 
            MessageFormat mf = new MessageFormat(value);
159
 
            mf.setLocale(locale);
160
 
            iString = mf.format(nonNullArgs, new StringBuffer(), null).toString();
161
 
        } catch (IllegalArgumentException iae) {
162
 
            StringBuffer buf = new StringBuffer();
163
 
            buf.append(value);
164
 
            for (int i = 0; i < args.length; i++) {
165
 
                buf.append(" arg[" + i + "]=" + args[i]);
166
 
            }
167
 
            iString = buf.toString();
 
136
        if (value == null) {
 
137
            value = key;
168
138
        }
169
 
        return iString;
170
 
    }
171
 
 
172
 
    /**
173
 
     * Get a string from the underlying resource bundle and format it
174
 
     * with the given object argument. This argument can of course be
175
 
     * a String object.
176
 
     *
177
 
     * @param key
178
 
     * @param arg
179
 
     */
180
 
 
181
 
    public String getString(String key, Object arg) {
182
 
        Object[] args = new Object[] {arg};
183
 
        return getString(key, args);
184
 
    }
185
 
 
186
 
    /**
187
 
     * Get a string from the underlying resource bundle and format it
188
 
     * with the given object arguments. These arguments can of course
189
 
     * be String objects.
190
 
     *
191
 
     * @param key
192
 
     * @param arg1
193
 
     * @param arg2
194
 
     */
195
 
 
196
 
    public String getString(String key, Object arg1, Object arg2) {
197
 
        Object[] args = new Object[] {arg1, arg2};
198
 
        return getString(key, args);
199
 
    }
200
 
    
201
 
    /**
202
 
     * Get a string from the underlying resource bundle and format it
203
 
     * with the given object arguments. These arguments can of course
204
 
     * be String objects.
205
 
     *
206
 
     * @param key
207
 
     * @param arg1
208
 
     * @param arg2
209
 
     * @param arg3
210
 
     */
211
 
 
212
 
    public String getString(String key, Object arg1, Object arg2,
213
 
                            Object arg3) {
214
 
        Object[] args = new Object[] {arg1, arg2, arg3};
215
 
        return getString(key, args);
216
 
    }
217
 
 
218
 
    /**
219
 
     * Get a string from the underlying resource bundle and format it
220
 
     * with the given object arguments. These arguments can of course
221
 
     * be String objects.
222
 
     *
223
 
     * @param key
224
 
     * @param arg1
225
 
     * @param arg2
226
 
     * @param arg3
227
 
     * @param arg4
228
 
     */
229
 
 
230
 
    public String getString(String key, Object arg1, Object arg2,
231
 
                            Object arg3, Object arg4) {
232
 
        Object[] args = new Object[] {arg1, arg2, arg3, arg4};
233
 
        return getString(key, args);
234
 
    }
 
139
 
 
140
        MessageFormat mf = new MessageFormat(value);
 
141
        mf.setLocale(locale);
 
142
        return mf.format(args, new StringBuffer(), null).toString();
 
143
    }
 
144
 
235
145
    // --------------------------------------------------------------
236
146
    // STATIC SUPPORT METHODS
237
147
    // --------------------------------------------------------------