下面列出了java.util.ResourceBundle#Control ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Check that candidate locales list retrieved for zh__Hant and for zh__Hans
* do not have first candidate locale as zh_TW_Hant and zh_CN_Hans
* respectively.
*/
private static void testCandidateLocales() {
ResourceBundle.Control Control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);
Locale zh_Hant = Locale.forLanguageTag("zh-Hant");
Locale zh_Hans = Locale.forLanguageTag("zh-Hans");
List<Locale> zhHantCandidateLocs = Control.getCandidateLocales("", zh_Hant);
List<Locale> zhHansCandidateLocs = Control.getCandidateLocales("", zh_Hans);
if (!zhHantCandidateLocs.equals(ZH_HANT_CANDLOCS)) {
reportDifference(zhHantCandidateLocs, ZH_HANT_CANDLOCS, "zh_Hant");
}
if (!zhHansCandidateLocs.equals(ZH_HANS_CANDLOCS)) {
reportDifference(zhHansCandidateLocs, ZH_HANS_CANDLOCS, "zh_Hans");
}
}
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
@Test
public void testNewControl() {
SortedMap<String, Charset> charsetsSortedMap = Charset.availableCharsets();
for (String encoding : charsetsSortedMap.keySet()) {
ResourceBundle.Control control = PropertyResourceBundleControl.newControl(encoding);
Assert.assertNotNull(control);
}
}
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
public ResourceBundle.Control getControl(String baseName) {
System.out.println(getClass().getName()+".getControl called for " + baseName);
// Throws a NPE if baseName is null.
if (baseName.startsWith("com.foo.Xml")) {
System.out.println("\treturns " + XMLCONTROL);
return XMLCONTROL;
}
System.out.println("\treturns null");
return null;
}
public UTF8Bundle(ResourceBundle.Control control)
{
ctrl = control;
}
public void test_getCandidateLocales() throws Exception {
ResourceBundle.Control c = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);
assertEquals("[en_US, en, ]", c.getCandidateLocales("base", Locale.US).toString());
assertEquals("[de_CH, de, ]", c.getCandidateLocales("base", new Locale("de", "CH")).toString());
}
public static ResourceBundle.Control getControl(final List aList) {
return (ResourceBundle.Control) (Object) INSTANCE;
}
public static ResourceBundle.Control getNoFallbackControl(final List aList) {
return (ResourceBundle.Control) (Object) INSTANCE;
}
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* Returns a {@code ResourceBundle.Control} instance that is used
* to handle resource bundle loading for the given {@code
* baseName}. This method must return {@code null} if the given
* {@code baseName} isn't handled by this provider.
*
* @param baseName the base name of the resource bundle
* @return a {@code ResourceBundle.Control} instance,
* or {@code null} if the given {@code baseName} is not
* applicable to this provider.
* @throws NullPointerException if {@code baseName} is {@code null}
*/
public ResourceBundle.Control getControl(String baseName);
/**
* {@link ResourceBundle#getBundle(String, Locale, ClassLoader)} with specified encoding
*
* @param baseName
* the base name of the resource bundle, a fully qualified class name
* @param locale
* the locale for which a resource bundle is desired
* @param classLoader
* the class loader from which to load the resource bundle
* @param encoding
* the control which gives information for the resource bundle loading process
* @return
* @throws NullPointerException
* if <code>baseName</code>, <code>locale</code>, or <code>loader</code> is <code>null</code>
* @throws MissingResourceException
* if no resource bundle for the specified base name can be found
* @throws IllegalArgumentException
* if the given <code>control</code> doesn't perform properly (e.g., <code>control.getCandidateLocales</code>
* returns null.) Note that validation of <code>control</code> is performed as needed.
*/
public static ResourceBundle getBundle(String baseName, Locale locale, ClassLoader classLoader, String encoding) {
ResourceBundle.Control control = PropertyResourceBundleControl.newControl(encoding);
return ResourceBundle.getBundle(baseName, locale, classLoader, control);
}