Java Code Examples for org.apache.cxf.jaxrs.utils.HttpUtils#getLocale()

The following examples show how to use org.apache.cxf.jaxrs.utils.HttpUtils#getLocale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpHeadersImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public List<Locale> getAcceptableLanguages() {
    List<String> ls = getListValues(HttpHeaders.ACCEPT_LANGUAGE);
    if (ls.isEmpty()) {
        return Collections.singletonList(new Locale("*"));
    }

    List<Locale> newLs = new ArrayList<>();
    Map<Locale, Float> prefs = new HashMap<>();
    for (String l : ls) {
        String[] pair = l.split(";");

        Locale locale = HttpUtils.getLocale(pair[0].trim());

        newLs.add(locale);
        if (pair.length > 1) {
            String[] pair2 = pair[1].split("=");
            if (pair2.length > 1) {
                prefs.put(locale, JAXRSUtils.getMediaTypeQualityFactor(pair2[1].trim()));
            } else {
                prefs.put(locale, 1F);
            }
        } else {
            prefs.put(locale, 1F);
        }
    }
    if (newLs.size() <= 1) {
        return newLs;
    }

    Collections.sort(newLs, new AcceptLanguageComparator(prefs));
    return newLs;

}
 
Example 2
Source File: ResponseImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Locale getLanguage() {
    Object header = metadata.getFirst(HttpHeaders.CONTENT_LANGUAGE);
    return header == null || header instanceof Locale ? (Locale)header
        : HttpUtils.getLocale(header.toString());
}
 
Example 3
Source File: HttpHeadersImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Locale getLanguage() {
    List<String> values = getListValues(HttpHeaders.CONTENT_LANGUAGE);
    return values.isEmpty() ? null : HttpUtils.getLocale(values.get(0).trim());
}