本文整理汇总了Java中java.util.ResourceBundle.Control类的典型用法代码示例。如果您正苦于以下问题:Java Control类的具体用法?Java Control怎么用?Java Control使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Control类属于java.util.ResourceBundle包,在下文中一共展示了Control类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TestGetLocale
import java.util.ResourceBundle.Control; //导入依赖的package包/类
/**
* @bug 4108126
*/
public void TestGetLocale() {
// try to find TestResource_fr_CH. Should get fr_CH as its locale
ResourceBundle test = ResourceBundle.getBundle("TestResource",
new Locale("fr", "CH", ""));
Locale locale = test.getLocale();
if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);
// try to find TestResource_fr_BE, which doesn't exist. Should get fr as its locale
test = ResourceBundle.getBundle("TestResource",
new Locale("fr", "BE", ""));
locale = test.getLocale();
if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);
// try to find TestResource_iw_IL, which doesn't exist. Should get root locale
// as its locale
test = ResourceBundle.getBundle("TestResource",
new Locale("iw", "IL", ""),
Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
locale = test.getLocale();
if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
+ locale);
}
示例2: getTranslation
import java.util.ResourceBundle.Control; //导入依赖的package包/类
public String getTranslation(String code) {
if (bundle == null) {
Locale l = this.locale;
if (l == null) {
if (UI.getCurrent() != null) {
l = UI.getCurrent().getLocale();
} else {
l = Locale.getDefault();
}
}
if (useDefaultLocaleFallback) {
bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASENAME, l);
} else {
bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASENAME, l, Control.getNoFallbackControl(Control.FORMAT_PROPERTIES));
}
}
return bundle.getString(code);
}
示例3: getLocalizedProperty
import java.util.ResourceBundle.Control; //导入依赖的package包/类
public String getLocalizedProperty(String property, Locale locale)
{
Control control = Control.getControl(Control.FORMAT_PROPERTIES);
String value = null;
// we're not looking at the fallback locale to be consistent with JRResourcesUtil.loadResourceBundle
List<Locale> locales = control.getCandidateLocales(property, locale);
for (Locale candidate : locales)
{
String candidateString = candidate.toString();
String candidateProperty = candidateString.isEmpty() ? property : (property + "_" + candidateString);
String candidateValue = getProperty(candidateProperty);
if (candidateValue != null)// test for empty?
{
value = candidateValue;
break;
}
}
return value;
}
示例4: test_Remote_French
import java.util.ResourceBundle.Control; //导入依赖的package包/类
@Test
public void test_Remote_French() {
TestBundle testBundle = TEST_BUNDLES[0];
String bundleId = testBundle.id;
CloudResourceBundleControl ctrl = CloudResourceBundleControl.getInstance(
account, Control.TTL_DONT_CACHE, null, null, null, null);
ResourceBundle bundle = ResourceBundle.getBundle(bundleId, new Locale("fr"), ctrl);
for (Entry<String, String> entry : testBundle.strings.entrySet()) {
String key = entry.getKey();
try {
String frVal = bundle.getString(key);
assertNotNull("Test1 fr " + key + " value", frVal);
} catch (MissingResourceException e) {
fail("Test1 fr should contain " + key);
}
}
}
示例5: readLangs
import java.util.ResourceBundle.Control; //导入依赖的package包/类
private ValueMap<? extends LanguageTermDefinition> readLangs(Locale locale) {
ArrayList<LangTermValue> langs = new ArrayList<LangTermValue>();
// to read properties file in UTF-8 use PropertyResourceBundle(Reader)
Control control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES);
ResourceBundle rb = ResourceBundle.getBundle(BundleName.LANGUAGES_ISO639_2.toString(), locale, control);
for (String key : rb.keySet()) {
LangTermValue lt = new LangTermValue();
lt.setAuthority("iso639-2b");
lt.setType(CodeOrText.CODE);
lt.setValue(key);
lt.setTitle(rb.getString(key));
langs.add(lt);
}
Collections.sort(langs, new LangComparator(locale));
return new ValueMap<LangTermValue>(BundleName.LANGUAGES_ISO639_2.getValueMapId(), langs);
}
示例6: getResourceBundle
import java.util.ResourceBundle.Control; //导入依赖的package包/类
/**
*
* @param locale
* the Locale
* @return The ResourceBundle for the application and the locale. The default
* name of the properties file is the same as the application class
* name.
* @see MultiResourceBundle MultiResourceBundle to combine several
* ResourceBundle
*/
public ResourceBundle getResourceBundle(Locale locale) {
List<ResourceBundle> resourceBundles = new ArrayList<>();
Class<?> applicationClass = getClass();
do {
try {
String resourceBundleName = applicationClass.getName();
resourceBundles.add(ResourceBundle.getBundle(resourceBundleName, locale, Control.getNoFallbackControl(Control.FORMAT_PROPERTIES)));
} catch (MissingResourceException x) {
if (applicationClass == getInstance().getClass()) {
Logger logger = Logger.getLogger(Application.class.getName());
logger.warning("Missing the default ResourceBundle for " + this.getClass().getName());
logger.fine("The default ResourceBundle has the same name as the Application that is launched.");
logger.fine("See the MjExampleApplication.java and MjExampleApplication.properties");
}
}
applicationClass = applicationClass.getSuperclass();
} while (applicationClass != Application.class);
return new MultiResourceBundle(resourceBundles);
}
示例7: create
import java.util.ResourceBundle.Control; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* <p>This method will throw {@link ControlFactoryException} if the passed
* {@code args} are not empty or if the charset specified at
* {@code mapping.encoding()} is not valid.</p>
*
* @throws ControlFactoryException If {@code args.length != 0} or the charset
* provided at {@code mapping.encoding()} is not supported.
*/
@Override
public Control create(ResourceMapping mapping, String[] args) {
final Charset charset;
if (args.length != 0) {
throw new ControlFactoryException(
"This class has no additional parameters");
} else {
try {
charset = Charset.forName(mapping.encoding());
} catch (UnsupportedCharsetException e) {
throw new ControlFactoryException(String.format(
"Unsupported charset: %s", args[0]), e);
}
}
return new CharsetBundleControl(charset);
}
示例8: LocalizerFile
import java.util.ResourceBundle.Control; //导入依赖的package包/类
public LocalizerFile(final String localizerBase, final ClassLoader classLoader, final Control control) {
super();
if (log.isTraceEnabled()) log.trace(HelperLog.constructor(localizerBase, classLoader));
if (null == localizerBase) {
throw new RuntimeExceptionIsNull("localizerBase"); //$NON-NLS-1$
}
if (null == classLoader) {
throw new RuntimeExceptionIsNull("classLoader"); //$NON-NLS-1$
}
this.localizerBase = localizerBase;
this.classLoader = classLoader;
this.control = control;
setupBundle(getLocale());
}
示例9: getLocalizedSibling
import java.util.ResourceBundle.Control; //导入依赖的package包/类
@Override
public NodeRef getLocalizedSibling(NodeRef nodeRef)
{
Locale userLocale = I18NUtil.getLocale();
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
// Work out the base name we are working with
Pair<String, String> split = getExtension(name, false);
String base = split.getFirst();
String ext = split.getSecond();
NodeRef resultNodeRef = nodeRef;
// Search for siblings with the same name
Control resourceHelper = Control.getControl(Control.FORMAT_DEFAULT);
List<Locale> candidateLocales = resourceHelper.getCandidateLocales(base, userLocale);
for (Locale candidateLocale : candidateLocales)
{
String filename = resourceHelper.toBundleName(base, candidateLocale) + "." + ext;
// Attempt to find the file
NodeRef foundNodeRef = searchSimple(parentNodeRef, filename);
if (foundNodeRef != null) // TODO: Check for read permissions
{
resultNodeRef = foundNodeRef;
break;
}
}
// Done
return resultNodeRef;
}
示例10: getLookupLocales
import java.util.ResourceBundle.Control; //导入依赖的package包/类
/**
* Returns a list of candidate locales for service look up.
* @param locale the input locale
* @return the list of candidate locales for the given locale
*/
static List<Locale> getLookupLocales(Locale locale) {
// Note: We currently use the default implementation of
// ResourceBundle.Control.getCandidateLocales. The result
// returned by getCandidateLocales are already normalized
// (no extensions) for service look up.
List<Locale> lookupLocales = Control.getNoFallbackControl(Control.FORMAT_DEFAULT)
.getCandidateLocales("", locale);
return lookupLocales;
}
示例11: getResourceCache
import java.util.ResourceBundle.Control; //导入依赖的package包/类
/**
* Returns a Map of the known resources for the given locale.
*/
private Map<String, Object> getResourceCache(Locale l) {
Map<String, Object> values = resourceCache.get(l);
if (values == null) {
values = new TextAndMnemonicHashMap();
for (int i=resourceBundles.size()-1; i >= 0; i--) {
String bundleName = resourceBundles.get(i);
try {
Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
ResourceBundle b;
if (c != null) {
b = ResourceBundle.getBundle(bundleName, l, c);
} else {
b = ResourceBundle.getBundle(bundleName, l);
}
Enumeration keys = b.getKeys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (values.get(key) == null) {
Object value = b.getObject(key);
values.put(key, value);
}
}
} catch( MissingResourceException mre ) {
// Keep looking
}
}
resourceCache.put(l, values);
}
return values;
}
示例12: TestListResourceBundle
import java.util.ResourceBundle.Control; //导入依赖的package包/类
public void TestListResourceBundle() {
// load up the resource and check to make sure we got the right class
// (we don't define be_BY or be, so we fall back on the root default)
ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
new Locale("be", "BY"),
Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
if (!bundle.getClass().getName().equals("TestResource"))
errln("Expected TestResource, got " + bundle.getClass().getName());
doListResourceBundleTest(bundle);
}
示例13: setupBaseLocales
import java.util.ResourceBundle.Control; //导入依赖的package包/类
private static void setupBaseLocales(String localeList) {
Arrays.stream(localeList.split(","))
.map(Locale::forLanguageTag)
.map(l -> Control.getControl(Control.FORMAT_DEFAULT)
.getCandidateLocales("", l))
.forEach(BASE_LOCALES::addAll);
}
示例14: setupBaseLocales
import java.util.ResourceBundle.Control; //导入依赖的package包/类
private static void setupBaseLocales(String localeList) {
Arrays.stream(localeList.split(","))
.map(Locale::forLanguageTag)
.map(l -> Control.getControl(Control.FORMAT_DEFAULT)
.getCandidateLocales("", l))
.forEach(BASE_LOCALES::addAll);
}
示例15: toBundleName
import java.util.ResourceBundle.Control; //导入依赖的package包/类
@Override
protected String toBundleName(String baseName, Locale locale) {
// The resource bundle for Locale.JAPAN is loccated at jdk.test.resources
// in module "asiabundles".
String name = locale.equals(Locale.JAPAN) ? baseName : addRegion(baseName);
return Control.getControl(Control.FORMAT_DEFAULT).toBundleName(name, locale);
}