本文整理汇总了Java中sun.util.locale.LanguageTag类的典型用法代码示例。如果您正苦于以下问题:Java LanguageTag类的具体用法?Java LanguageTag怎么用?Java LanguageTag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LanguageTag类属于sun.util.locale包,在下文中一共展示了LanguageTag类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataAccessForm
import sun.util.locale.LanguageTag; //导入依赖的package包/类
@GET
@Path("/form")
@Timed
public Mica.DataAccessFormDto getDataAccessForm(@QueryParam("lang") String lang) {
Optional<DataAccessForm> d = dataAccessFormService.find();
if(!d.isPresent()) throw NoSuchDataAccessFormException.withDefaultMessage();
DataAccessForm dataAccessForm = d.get();
Mica.DataAccessFormDto.Builder builder = Mica.DataAccessFormDto.newBuilder(dtos.asDto(dataAccessForm))
.clearProperties().clearPdfTemplates();
String langTag = !Strings.isNullOrEmpty(lang) ? Locale.forLanguageTag(lang).toLanguageTag() : LanguageTag.UNDETERMINED;
Map<String, LocalizedString> properties = dataAccessForm.getProperties().entrySet().stream()
.map(e -> Maps.immutableEntry(e.getKey(), new LocalizedString().forLanguageTag(langTag, e.getValue().get(langTag))))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
builder.addAllProperties(dtos.asDtoList(properties));
return builder.build();
}
示例2: localize
import sun.util.locale.LanguageTag; //导入依赖的package包/类
private String localize(Vocabulary vocabulary, String field, String locale) {
boolean process = true;
boolean localized = false;
if (vocabulary != null) {
localized = Boolean.valueOf(vocabulary.getAttributeValue("localized"));
process = localized || !vocabulary.hasTerms() && new VocabularyWrapper(vocabulary).isString();
}
if (process) {
Pattern pattern = Pattern.compile("\\." + LanguageTag.UNDETERMINED + "$");
Matcher matcher = pattern.matcher(field);
field = matcher.find()
? field.replace(LanguageTag.UNDETERMINED, locale)
: localized ? field + TAXO_SEPARATOR + locale : getSafeLocalizedField(field);
return indexFieldMapping.isAnalyzed(field) ? field + POSFIX_ANALYZED : field;
}
return field;
}
示例3: getStatus
import sun.util.locale.LanguageTag; //导入依赖的package包/类
private String getStatus(Mica.DatasetVariableSummaryDto summary, String locale) {
Optional<Mica.LocalizedStringDto> result = summary.getAttributesList().stream()
.filter(attribute -> namespaces.contains(attribute.getNamespace()) && attribute.getName().equals("status"))
.map(Mica.AttributeDto::getValuesList).flatMap(Collection::stream).filter(value -> {
String lang = value.getLang();
return locale.equals(lang) || LanguageTag.UNDETERMINED.equals(lang);
}).findFirst();
return result.isPresent() ? result.get().getValue() : EMPTY_STATUS;
}
示例4: coverageQuery
import sun.util.locale.LanguageTag; //导入依赖的package包/类
public MicaSearch.TaxonomiesCoverageDto coverageQuery(String rqlJoinQuery, boolean strict) throws IOException {
joinQuery = searcher.makeJoinQuery(rqlJoinQuery);
// Strict coverage means that coverage result is restricted to the terms specified in the variable query.
// If no variable query is specified, nothing is returned if strictness is applied, otherwise coverage of all terms is returned.
if (strict) {
restrictedTermsMap = joinQuery.getVariableQuery().getTaxonomyTermsMap();
// If do not need all the facets then we can restrict the variable aggregations to the ones matching these names.
if (!joinQuery.isWithFacets()) {
restrictedTermsMap.forEach((taxo, vocMap) -> vocMap.keySet().forEach(
voc -> joinQuery.getVariableQuery().getAggregations()
.add("attributes." + AttributeKey.getMapKey(voc, taxo) + "." +
LanguageTag.UNDETERMINED)));
}
}
// We need the aggregations internally for building the coverage result,
// but we may not need them in the final result
JoinQuery joinQueryWithFacets = new JoinQueryWrapperWithFacets(joinQuery);
MicaSearch.JoinQueryResultDto result = joinQueryExecutor.queryCoverage(joinQueryWithFacets);
List<MicaSearch.AggregationResultDto> aggregations = ungroupAggregations(
result.getVariableResultDto().getAggsList());
MicaSearch.TaxonomiesCoverageDto.Builder builder = MicaSearch.TaxonomiesCoverageDto.newBuilder()//
.setTotalCount(result.getVariableResultDto().getTotalCount()) //
.setTotalHits(result.getVariableResultDto().getTotalHits()) //
.addAllTaxonomies(getCoverages(aggregations))
.setQueryResult(result);
// Do not append the aggregations if no facets is requested
if (joinQuery.isWithFacets()) builder.setQueryResult(result);
return builder.build();
}
示例5: getLocalizedFields
import sun.util.locale.LanguageTag; //导入依赖的package包/类
protected List<String> getLocalizedFields(String... fieldNames) {
List<String> fields = Lists.newArrayList();
Stream.concat(micaConfigService.getConfig().getLocalesAsString().stream(), Stream.of(LanguageTag.UNDETERMINED))
.forEach(locale -> Arrays.stream(fieldNames)
.forEach(f -> fields.add(f + "." + locale + ".analyzed")));
return fields;
}
示例6: getFields
import sun.util.locale.LanguageTag; //导入依赖的package包/类
private List<String> getFields(String locale, String... fieldNames) {
List<String> fields = Lists.newArrayList("name.analyzed");
List<String> locales = Lists.newArrayList();
if (Strings.isNullOrEmpty(locale)) {
locales.addAll(micaConfigService.getConfig().getLocalesAsString());
locales.add(LanguageTag.UNDETERMINED);
} else {
locales.add(locale);
}
locales.forEach(local -> Arrays.stream(fieldNames).forEach(f -> fields.add(f + "." + local + ".analyzed")));
return fields;
}
示例7: getPdf
import sun.util.locale.LanguageTag; //导入依赖的package包/类
@GET
@Timed
@Path("/_pdf")
public Response getPdf(@PathParam("id") String id, @QueryParam("lang") String lang) {
subjectAclService.checkPermission("/data-access-request", "VIEW", id);
if(Strings.isNullOrEmpty(lang)) lang = LanguageTag.UNDETERMINED;
return Response.ok(dataAccessRequestService.getRequestPdf(id, lang))
.header("Content-Disposition", "attachment; filename=\"" + "data-access-request-" + id + ".pdf" + "\"").build();
}
示例8: put
import sun.util.locale.LanguageTag; //导入依赖的package包/类
@Override
public String put(@Nullable String locale, String value) {
if(Strings.isNullOrEmpty(value)) return null;
return super.put(locale == null ? LanguageTag.UNDETERMINED : Locale.forLanguageTag(locale).toLanguageTag(), value);
}
示例9: getUndetermined
import sun.util.locale.LanguageTag; //导入依赖的package包/类
/**
* Get the value for the undetermined language.
*
* @return null if not found
*/
@JsonIgnore
@Nullable
public String getUndetermined() {
return get(LanguageTag.UNDETERMINED);
}
示例10: getDataAccessPdf
import sun.util.locale.LanguageTag; //导入依赖的package包/类
@GET
@Path("/pdf")
public FileResource getDataAccessPdf(@QueryParam("lang") String lang) {
Optional<DataAccessForm> d = dataAccessFormService.find();
if(!d.isPresent()) throw NoSuchDataAccessFormException.withDefaultMessage();
DataAccessForm dataAccessForm = d.get();
Locale locale = Locale.forLanguageTag(!Strings.isNullOrEmpty(lang) ? Locale.forLanguageTag(lang).toLanguageTag() : LanguageTag.UNDETERMINED);
if (!dataAccessForm.getPdfTemplates().containsKey(locale)) throw NoSuchDataAccessFormException.withDefaultMessage();
fileResource.setAttachment(dataAccessForm.getPdfTemplates().get(locale));
return fileResource;
}
示例11: setLanguageTag
import sun.util.locale.LanguageTag; //导入依赖的package包/类
/**
* Resets the Builder to match the provided IETF BCP 47
* language tag. Discards the existing state. Null and the
* empty string cause the builder to be reset, like {@link
* #clear}. Grandfathered tags (see {@link
* Locale#forLanguageTag}) are converted to their canonical
* form before being processed. Otherwise, the language tag
* must be well-formed (see {@link Locale}) or an exception is
* thrown (unlike <code>Locale.forLanguageTag</code>, which
* just discards ill-formed and following portions of the
* tag).
*
* @param languageTag the language tag
* @return This builder.
* @throws IllformedLocaleException if <code>languageTag</code> is ill-formed
* @see Locale#forLanguageTag(String)
*/
public Builder setLanguageTag(String languageTag) {
ParseStatus sts = new ParseStatus();
LanguageTag tag = LanguageTag.parse(languageTag, sts);
if (sts.isError()) {
throw new IllformedLocaleException(sts.getErrorMessage(), sts.getErrorIndex());
}
localeBuilder.setLanguageTag(tag);
return this;
}