本文整理汇总了Java中java.util.IllformedLocaleException类的典型用法代码示例。如果您正苦于以下问题:Java IllformedLocaleException类的具体用法?Java IllformedLocaleException怎么用?Java IllformedLocaleException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IllformedLocaleException类属于java.util包,在下文中一共展示了IllformedLocaleException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import java.util.IllformedLocaleException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DateProcessor create(Map<String, Processor.Factory> registry, String processorTag,
Map<String, Object> config) throws Exception {
String field = ConfigurationUtils.readStringProperty(TYPE, processorTag, config, "field");
String targetField = ConfigurationUtils.readStringProperty(TYPE, processorTag, config, "target_field", DEFAULT_TARGET_FIELD);
String timezoneString = ConfigurationUtils.readOptionalStringProperty(TYPE, processorTag, config, "timezone");
DateTimeZone timezone = timezoneString == null ? DateTimeZone.UTC : DateTimeZone.forID(timezoneString);
String localeString = ConfigurationUtils.readOptionalStringProperty(TYPE, processorTag, config, "locale");
Locale locale = Locale.ENGLISH;
if (localeString != null) {
try {
locale = (new Locale.Builder()).setLanguageTag(localeString).build();
} catch (IllformedLocaleException e) {
throw new IllegalArgumentException("Invalid language tag specified: " + localeString);
}
}
List<String> formats = ConfigurationUtils.readList(TYPE, processorTag, config, "formats");
return new DateProcessor(processorTag, timezone, locale, field, formats, targetField);
}
示例2: getLookupLocale
import java.util.IllformedLocaleException; //导入依赖的package包/类
/**
* Returns an instance of Locale used for service look up.
* The result Locale has no extensions except for ja_JP_JP
* and th_TH_TH
*
* @param locale the locale
* @return the locale used for service look up
*/
static Locale getLookupLocale(Locale locale) {
Locale lookupLocale = locale;
if (locale.hasExtensions()
&& !locale.equals(JRELocaleConstants.JA_JP_JP)
&& !locale.equals(JRELocaleConstants.TH_TH_TH)) {
// remove extensions
Builder locbld = new Builder();
try {
locbld.setLocale(locale);
locbld.clearExtensions();
lookupLocale = locbld.build();
} catch (IllformedLocaleException e) {
// A Locale with non-empty extensions
// should have well-formed fields except
// for ja_JP_JP and th_TH_TH. Therefore,
// it should never enter in this catch clause.
config(LocaleServiceProviderPool.class,
"A locale(" + locale + ") has non-empty extensions, but has illformed fields.");
// Fallback - script field will be lost.
lookupLocale = new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}
}
return lookupLocale;
}
示例3: filterOutUnsupportedTags
import java.util.IllformedLocaleException; //导入依赖的package包/类
private boolean filterOutUnsupportedTags(byte[] b) {
List<Locale> locales;
try {
locales = Arrays.asList(new String(b).split(" ")).stream()
.filter(tag -> !tag.isEmpty())
.map(IncludeLocalesPlugin::tagToLocale)
.collect(Collectors.toList());
} catch (IllformedLocaleException ile) {
// Seems not an available locales string literal.
return false;
}
byte[] filteredBytes = filterLocales(locales).stream()
.collect(Collectors.joining(" "))
.getBytes();
System.arraycopy(filteredBytes, 0, b, 0, filteredBytes.length);
Arrays.fill(b, filteredBytes.length, b.length, (byte)' ');
return true;
}
示例4: LiteralImpl
import java.util.IllformedLocaleException; //导入依赖的package包/类
public LiteralImpl(final String literal, final String languageTag) {
this.lexicalForm = Objects.requireNonNull(literal);
this.languageTag = Objects.requireNonNull(lowerCase(languageTag));
if (languageTag.isEmpty()) {
// TODO: Check against
// http://www.w3.org/TR/n-triples/#n-triples-grammar
throw new IllegalArgumentException("Language tag can't be null");
}
try {
new Locale.Builder().setLanguageTag(languageTag);
} catch (final IllformedLocaleException ex) {
throw new IllegalArgumentException("Invalid languageTag: " + languageTag, ex);
}
// System.out.println(aLocale);
this.dataType = Types.RDF_LANGSTRING;
}
示例5: main
import java.util.IllformedLocaleException; //导入依赖的package包/类
public static void main(String...a) {
try {
Locale.Builder locBuild = new Locale.Builder();
//locBuild.setLanguageTag("de-CH-x-phonebk");
locBuild.setLanguageTag("zh-cn-a-myext-x-private");
Locale lc = locBuild.build();
System.out.println("L:"+lc.getLanguage());
System.out.println("S:"+lc.getScript());
System.out.println("C:"+lc.getCountry());
System.out.println("V:"+lc.getVariant());
System.out.println(lc.toLanguageTag());
LangTag lang3 = LangTagParser.parse("zh-cn-a-myext-x-private") ;
System.out.println();
System.out.println(lang3.asString());
LangTag lang2 = LangTagParserAlt.parse("zh-cn-a-myext-x-private") ;
System.out.println();
System.out.println(lang2.asString());
} catch (IllformedLocaleException ex) {
ex.printStackTrace();
}
}
示例6: resolveLocale
import java.util.IllformedLocaleException; //导入依赖的package包/类
@Override
public Locale resolveLocale(HttpServletRequest request) {
Locale defaultLocale = Locale.getDefault();
String language = request.getParameter(LANGUAGE_QUERY_PARAMETER_NAME);
if (defaultLocale != null && language == null) {
return defaultLocale;
}
Locale resolvedLocale;
try {
resolvedLocale = new Locale.Builder().setLanguageTag(language).build();
} catch (IllformedLocaleException e) {
resolvedLocale = Locale.getDefault();
}
return resolvedLocale;
}
示例7: getLookupLocale
import java.util.IllformedLocaleException; //导入依赖的package包/类
/**
* Returns an instance of Locale used for service look up.
* The result Locale has no extensions except for ja_JP_JP
* and th_TH_TH
*
* @param locale the locale
* @return the locale used for service look up
*/
private static Locale getLookupLocale(Locale locale) {
Locale lookupLocale = locale;
Set<Character> extensions = locale.getExtensionKeys();
if (!extensions.isEmpty()
&& !locale.equals(locale_ja_JP_JP)
&& !locale.equals(locale_th_TH_TH)) {
// remove extensions
Builder locbld = new Builder();
try {
locbld.setLocale(locale);
locbld.clearExtensions();
lookupLocale = locbld.build();
} catch (IllformedLocaleException e) {
// A Locale with non-empty extensions
// should have well-formed fields except
// for ja_JP_JP and th_TH_TH. Therefore,
// it should never enter in this catch clause.
config("A locale(" + locale + ") has non-empty extensions, but has illformed fields.");
// Fallback - script field will be lost.
lookupLocale = new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}
}
return lookupLocale;
}
示例8: resolveApplicationLocale
import java.util.IllformedLocaleException; //导入依赖的package包/类
private Locale resolveApplicationLocale(String configuredLocale) {
Locale locale;
if (StringUtils.isNotBlank(configuredLocale)) {
try {
locale = new Locale.Builder().setLanguageTag(configuredLocale).build();
if (LocaleUtils.isAvailableLocale(locale)) {
LOGGER.debug("Setting application locale to configured {}", locale);
} else {
locale = getDefaultLocale();
LOGGER.debug("Locale {} is not available. Defaulting to {}", configuredLocale, getDefaultLocale());
}
} catch (IllformedLocaleException e) {
locale = getDefaultLocale();
LOGGER.warn(
"Error parsing configured application locale: {}. Defaulting to {}. Locale must be in the form \"en-US\" or \"fr-FR\"",
configuredLocale, getDefaultLocale());
}
} else {
locale = getDefaultLocale();
LOGGER.debug("Setting application locale to default value {}", getDefaultLocale());
}
LOGGER.info("Application locale set to: '{}'", locale);
return locale;
}
示例9: create
import java.util.IllformedLocaleException; //导入依赖的package包/类
@Override
public DateIndexNameProcessor create(Map<String, Processor.Factory> registry, String tag,
Map<String, Object> config) throws Exception {
String localeString = ConfigurationUtils.readOptionalStringProperty(TYPE, tag, config, "locale");
String timezoneString = ConfigurationUtils.readOptionalStringProperty(TYPE, tag, config, "timezone");
DateTimeZone timezone = timezoneString == null ? DateTimeZone.UTC : DateTimeZone.forID(timezoneString);
Locale locale = Locale.ENGLISH;
if (localeString != null) {
try {
locale = (new Locale.Builder()).setLanguageTag(localeString).build();
} catch (IllformedLocaleException e) {
throw new IllegalArgumentException("Invalid language tag specified: " + localeString);
}
}
List<String> dateFormatStrings = ConfigurationUtils.readOptionalList(TYPE, tag, config, "date_formats");
if (dateFormatStrings == null) {
dateFormatStrings = Collections.singletonList("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
}
List<Function<String, DateTime>> dateFormats = new ArrayList<>(dateFormatStrings.size());
for (String format : dateFormatStrings) {
DateFormat dateFormat = DateFormat.fromString(format);
dateFormats.add(dateFormat.getFunction(format, timezone, locale));
}
String field = ConfigurationUtils.readStringProperty(TYPE, tag, config, "field");
String indexNamePrefix = ConfigurationUtils.readStringProperty(TYPE, tag, config, "index_name_prefix", "");
String dateRounding = ConfigurationUtils.readStringProperty(TYPE, tag, config, "date_rounding");
String indexNameFormat = ConfigurationUtils.readStringProperty(TYPE, tag, config, "index_name_format", "yyyy-MM-dd");
return new DateIndexNameProcessor(tag, field, dateFormats, timezone, indexNamePrefix, dateRounding, indexNameFormat);
}
示例10: filterOutUnsupportedTags
import java.util.IllformedLocaleException; //导入依赖的package包/类
private boolean filterOutUnsupportedTags(byte[] b) {
List<Locale> locales;
List<String> originalTags = Arrays.asList(new String(b).split(" "));
try {
locales = originalTags.stream()
.filter(tag -> !tag.isEmpty())
.map(IncludeLocalesPlugin::tagToLocale)
.collect(Collectors.toList());
} catch (IllformedLocaleException ile) {
// Seems not an available locales string literal.
return false;
}
byte[] filteredBytes = filterLocales(locales).stream()
// Make sure the filtered language tags do exist in the
// original supported tags for compatibility codes, e.g., "iw"
.filter(originalTags::contains)
.collect(Collectors.joining(" "))
.getBytes();
if (filteredBytes.length > b.length) {
throw new InternalError("Size of filtered locales is bigger than the original one");
}
System.arraycopy(filteredBytes, 0, b, 0, filteredBytes.length);
Arrays.fill(b, filteredBytes.length, b.length, (byte)' ');
return true;
}
示例11: getValidLocaleFromCookie
import java.util.IllformedLocaleException; //导入依赖的package包/类
/**
* Get a valid locale from the cookie value.
*
* @param localeCookieValue
* @return a valid locale.
*/
String getValidLocaleFromCookie(String localeCookieValue) {
String validLocale;
try {
Locale localeFromCookie = new Locale.Builder().setLanguageTag(localeCookieValue).build();
validLocale = localeFromCookie.toLanguageTag();
} catch (NullPointerException | IllformedLocaleException e) {
logger.debug("Invalid localeCookieValue, fallback to en");
validLocale = "en";
}
return validLocale;
}
示例12: parse
import java.util.IllformedLocaleException; //导入依赖的package包/类
public static LangTag parse(String x) {
try {
locBuild.clear();
locBuild.setLanguageTag(x);
return asLangTag(locBuild);
} catch (IllformedLocaleException ex) {
return null;
}
}
示例13: canonical
import java.util.IllformedLocaleException; //导入依赖的package包/类
public static String canonical(String str) {
try {
// Does not do conversion of language for ISO 639 codes that have changed.
return locBuild.setLanguageTag(str).build().toLanguageTag();
} catch (IllformedLocaleException ex) {
return str;
}
}
示例14: run
import java.util.IllformedLocaleException; //导入依赖的package包/类
/** {@inheritDoc} */
public boolean run(final Context context, final Result proto,
final Map<String, Object> data) {
Result nr = new Result(proto);
nr.setCode("content");
nr.addNode("lang");
nr.setDocument("rfc7483");
nr.setReference("4.4");
String lang = Utils.getStringAttribute(context,
nr, "lang",
null,
data);
if (lang == null) {
return false;
}
Result vr = new Result(nr);
boolean res = true;
try {
new Locale.Builder().setLanguageTag(lang);
} catch (IllformedLocaleException e) {
vr.setStatus(Status.Failure);
vr.setInfo("invalid: " + e.toString());
res = false;
}
if (res) {
vr.setStatus(Status.Success);
vr.setInfo("valid");
}
context.addResult(vr);
return res;
}
示例15: KiWiHandler
import java.util.IllformedLocaleException; //导入依赖的package包/类
public KiWiHandler(KiWiStore store, KiWiLoaderConfiguration config) {
this.config = config;
this.store = store;
this.localeCache = CacheBuilder.newBuilder()
.maximumSize(100)
.build(new CacheLoader<String, Locale>() {
@Override
public Locale load(String lang) throws Exception {
try {
Locale.Builder builder = new Locale.Builder();
builder.setLanguageTag(lang);
return builder.build();
} catch (IllformedLocaleException ex) {
log.warn("malformed language literal (language: {})", lang);
return null;
}
}
});
if(config.isStatementExistanceCheck()) {
switch (store.getPersistence().getConfiguration().getRegistryStrategy()) {
case DATABASE:
log.info("KiWi Loader: database registry");
registry = new DBTripleRegistry(store);
break;
case CACHE:
log.info("KiWi Loader: cache registry");
registry = new CacheTripleRegistry(store.getPersistence().getCacheManager());
break;
case LOCAL:
log.info("KiWi Loader: in-memory registry");
registry = new LocalTripleRegistry();
break;
default:
log.info("KiWi Loader: in-memory registry");
registry = new LocalTripleRegistry();
}
}
log.info("KiWi Loader: namespaces {}", config.isIgnoreNamespaces() ? "ignored" : "enabled");
}