Here you can find the source of getFormat(String key, ResourceBundle bundle)
key
in the given resource bundle.
Parameter | Description |
---|---|
key | the key of the format string to retrieve |
bundle | the bundle to retrieve the format string from |
private static String getFormat(String key, ResourceBundle bundle)
//package com.java2s; /*// w w w . j a v a 2s. c o m * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; public class Main { /** * Get the format string associated with <code>key</code> in the * given resource bundle. If <code>key</code> is not present in * the bundle, a default format string is returned which will * identify the missing key when printed. * * @param key the key of the format string to retrieve * @param bundle the bundle to retrieve the format string from * @return the format string. */ private static String getFormat(String key, ResourceBundle bundle) { String fmt = "no text found: \"" + key + "\" {0}"; if (bundle != null) { try { fmt = bundle.getString(key); } catch (MissingResourceException e) { } } return fmt; } /** * Print out string according to resourceBundle format. * * @param key the key of the format string to retrieve * @param bundle the bundle to retrieve the format string from */ public static String getString(String key, ResourceBundle bundle) { return MessageFormat.format(getFormat(key, bundle), null); } /** * Print out string according to resourceBundle format. * * @param key the key of the format string to retrieve * @param bundle the bundle to retrieve the format string from * @param val the value to substitute into the {0} parameter */ public static String getString(String key, ResourceBundle bundle, Object val) { return MessageFormat.format(getFormat(key, bundle), new Object[] { val }); } /** * Print out string according to resourceBundle format. * * @param key the key of the format string to retrieve * @param bundle the bundle to retrieve the format string from * @param val1 the value to substitute into the {0} parameter * @param val2 the value to substitute into the {1} parameter */ public static String getString(String key, ResourceBundle bundle, Object val1, Object val2) { return MessageFormat.format(getFormat(key, bundle), new Object[] { val1, val2 }); } /** * Print out string according to resourceBundle format. * * @param key the key of the format string to retrieve * @param bundle the bundle to retrieve the format string from * @param val1 the value to substitute into the {0} parameter * @param val2 the value to substitute into the {1} parameter * @param val3 the value to substitute into the {2} parameter */ public static String getString(String key, ResourceBundle bundle, Object val1, Object val2, Object val3) { return MessageFormat.format(getFormat(key, bundle), new Object[] { val1, val2, val3 }); } }