use of org.restlet.data.Language in project qi4j-sdk by Qi4j.
the class ContextResourceClientFactory method setAcceptedLanguages.
public void setAcceptedLanguages(Language... acceptedLanguages) {
List<Preference<Language>> languages = new ArrayList<Preference<Language>>();
for (Language acceptedLanguage : acceptedLanguages) {
languages.add(new Preference<Language>());
}
info.setAcceptedLanguages(languages);
}
use of org.restlet.data.Language in project qi4j-sdk by Qi4j.
the class AbstractResponseWriter method getVariant.
protected Variant getVariant(Request request, List<Language> possibleLanguages, List<MediaType> possibleMediaTypes) {
Language language = request.getClientInfo().getPreferredLanguage(possibleLanguages);
if (language == null) {
language = possibleLanguages.get(0);
}
MediaType responseType = request.getClientInfo().getPreferredMediaType(possibleMediaTypes);
if (responseType == null && request.getClientInfo().getPreferredMediaType(Collections.singletonList(MediaType.ALL)) == MediaType.ALL) {
responseType = possibleMediaTypes.get(0);
}
Variant variant = new Variant(responseType, language);
variant.setCharacterSet(CharacterSet.UTF_8);
return variant;
}
use of org.restlet.data.Language in project qi4j-sdk by Qi4j.
the class ContextResource method getLocale.
protected Locale getLocale() {
Request request = Request.getCurrent();
List<Preference<Language>> preferenceList = request.getClientInfo().getAcceptedLanguages();
if (preferenceList.isEmpty()) {
return Locale.getDefault();
}
Language language = preferenceList.get(0).getMetadata();
String[] localeStr = language.getName().split("-");
Locale locale;
switch(localeStr.length) {
case 1:
locale = new Locale(localeStr[0]);
break;
case 2:
locale = new Locale(localeStr[0], localeStr[1]);
break;
case 3:
locale = new Locale(localeStr[0], localeStr[1], localeStr[2]);
break;
default:
locale = Locale.getDefault();
}
return locale;
}
use of org.restlet.data.Language in project OpenAM by OpenRock.
the class DeviceCodeVerificationResource method getTemplateRepresentation.
private Representation getTemplateRepresentation(String template, OAuth2Request request, String errorCode) {
TemplateRepresentation response = getTemplateFactory(getContext()).getTemplateRepresentation(template);
Map<String, String> dataModel = new HashMap<>();
dataModel.put("errorCode", errorCode);
dataModel.put("baseUrl", baseURLProviderFactory.get(request.<String>getParameter("realm")).getRootURL(ServletUtils.getRequest(getRequest())));
List<String> locale = new ArrayList<>();
for (Preference<Language> language : getRequest().getClientInfo().getAcceptedLanguages()) {
locale.add(language.getMetadata().getName());
}
dataModel.put("locale", oAuth2Utils.join(locale, " "));
dataModel.put("realm", request.<String>getParameter(OAuth2Constants.Params.REALM));
response.setDataModel(dataModel);
return response;
}
Aggregations