View | Details | Raw Unified | Return to bug 46933
Collapse All | Expand All

(-)java/org/apache/tomcat/util/res/StringManager.java (-93 / +12 lines)
Lines 131-237 Link Here
131
     * @param args
131
     * @param args
132
     */
132
     */
133
133
134
    public String getString(String key, Object[] args) {
134
    public String getString(final String key,final Object... args) {
135
        String iString = null;
135
        String iString = null;
136
        String value = getString(key);
136
        String value = getString(key);
137
        if( value==null ) value=key;
137
138
138
        // this check for the runtime exception is some pre 1.1.6
139
        Object[] nonNullArgs = args == null ? new Object[1] : args;
139
        // VM's don't do an automatic toString() on the passed in
140
        for (int i=0; i < args.length; i++) {
140
        // objects and barf out
141
            if (args[i] == null) {
141
142
            	if (nonNullArgs == args){
142
        try {
143
            		nonNullArgs = args.clone();
143
            // ensure the arguments are not null so pre 1.2 VM's don't barf
144
            	}
144
            if(args==null){
145
                nonNullArgs[i] = "null";
145
                args = new Object[1];
146
            }
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=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();
168
        }
147
        }
148
        MessageFormat mf = new MessageFormat(value);
149
        mf.setLocale(locale);
150
        iString = mf.format(nonNullArgs, new StringBuffer(), null).toString();
169
        return iString;
151
        return iString;
170
    }
152
    }
171
153
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
    }
235
    // --------------------------------------------------------------
154
    // --------------------------------------------------------------
236
    // STATIC SUPPORT METHODS
155
    // STATIC SUPPORT METHODS
237
    // --------------------------------------------------------------
156
    // --------------------------------------------------------------

Return to bug 46933