List of usage examples for java.util Locale toLanguageTag
public String toLanguageTag()
From source file:com.lehman.ic9.net.httpClient.java
/** * Updates the Javascript response object. * @param info is the Javascript response object to update. * @param resp is a ClosableHttpResponse object with the actual response. * @throws NoSuchMethodException Exception * @throws ScriptException Exception/* w ww.ja v a 2s. com*/ */ private void getResponseInfo(Map<String, Object> info, CloseableHttpResponse resp) throws NoSuchMethodException, ScriptException { // Locale Locale jloc = resp.getLocale(); info.put("locale", jloc.toLanguageTag()); info.put("protocol", resp.getProtocolVersion().toString()); info.put("protocolMajor", resp.getProtocolVersion().getMajor()); info.put("protocolMinor", resp.getProtocolVersion().getMinor()); info.put("statusLine", resp.getStatusLine().toString()); info.put("statusCode", resp.getStatusLine().getStatusCode()); info.put("statusReasonPhrase", resp.getStatusLine().getReasonPhrase()); // Headers. Map<String, Object> hmap = this.eng.newObj(null); Header hdrs[] = resp.getAllHeaders(); for (Header hdr : hdrs) { hmap.put(hdr.getName(), hdr.getValue()); } info.put("headers", hmap); // Cookies Object clist = this.eng.newList(); this.jsobj.put("cookies", clist); for (Cookie C : this.cs.getCookies()) { Object nc = this.getApacheCookie(C); this.eng.invokeMethod(clist, "push", nc); } }
From source file:org.daxplore.presenter.server.servlets.PresenterServlet.java
private String getPresenterHTML(PersistenceManager pm, String prefix, Locale locale, String baseurl, ServerPrefixProperties properties, String gaTemplate) throws InternalServerException, BadRequestException { String perspectives = "", groups = "", questions = ""; perspectives = TextFileStore.getFile(pm, prefix, "meta/perspectives", locale, ".json"); questions = TextFileStore.getFile(pm, prefix, "meta/questions", locale, ".json"); groups = TextFileStore.getFile(pm, prefix, "meta/groups", locale, ".json"); String prefixProperties = properties.toJson().toJSONString(); String pageTitle = SettingItemStore.getLocalizedProperty(pm, prefix, "properties/usertexts", locale, "page_title"); String[] arguments = { locale.toLanguageTag(), // {0} baseurl, // {1} pageTitle, // {2} perspectives, // {3} questions, // {4} groups, // {5} prefixProperties, // {6} gaTemplate // {7} };//w ww . j ava 2 s . c om if (presenterHtmlTemplate == null) { try { presenterHtmlTemplate = IOUtils .toString(getServletContext().getResourceAsStream("/templates/presentation.html")); } catch (IOException e) { throw new InternalServerException("Failed to load the embed html template", e); } } return MessageFormat.format(presenterHtmlTemplate, (Object[]) arguments); }
From source file:org.daxplore.presenter.server.servlets.PresenterServlet.java
private String getPrintHTML(PersistenceManager pm, String prefix, Locale locale, String serverPath, String queryString, String baseurl, String gaTemplate) throws InternalServerException, BadRequestException { LinkedList<EmbedFlag> flags = new LinkedList<>(); flags.add(EmbedFlag.LEGEND);//from w ww . j a va 2 s . co m flags.add(EmbedFlag.TRANSPARENT); flags.add(EmbedFlag.PRINT); String embedDefinition = new EmbedDefinition(flags).getAsString(); String pageTitle = SettingItemStore.getLocalizedProperty(pm, prefix, "properties/usertexts", locale, "page_title"); String[] arguments = { pageTitle, // {0} baseurl, // {1} gaTemplate, // {2} serverPath, // {3} queryString, // {4} locale.toLanguageTag(), // {5} prefix, // {6} embedDefinition, // {7} }; if (printHtmlTemplate == null) { try { printHtmlTemplate = IOUtils .toString(getServletContext().getResourceAsStream("/templates/print.html")); } catch (IOException e) { throw new InternalServerException("Failed to load print html template", e); } } return MessageFormat.format(printHtmlTemplate, (Object[]) arguments); }
From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixAPIv1.java
@GET @Produces(JSON_UTF8)/*w w w . j ava 2s . c o m*/ @Path("contacts") @FenixAPIPublic public String contacts() { Locale locale = I18N.getLocale(); String contactsFile = getFileInfo("/api/contacts.json"); JsonParser parser = new JsonParser(); JsonObject jObj = (JsonObject) parser.parse(contactsFile); if (Locale.UK.equals(locale)) { return jObj.get(locale.toLanguageTag()).toString(); } else { return jObj.get("pt-PT").toString(); } }
From source file:org.jivesoftware.openfire.websocket.XmppWebSocket.java
private void initiateSession(Element stanza) { String host = stanza.attributeValue("to"); StreamError streamError = null;/* ww w.j av a 2 s . c o m*/ Locale language = Locale .forLanguageTag(stanza.attributeValue(QName.get("lang", XMLConstants.XML_NS_URI), "en")); if (STREAM_FOOTER.equals(stanza.getName())) { // an error occurred while setting up the session Log.warn("Client closed stream before session was established"); } else if (!STREAM_HEADER.equals(stanza.getName())) { streamError = new StreamError(StreamError.Condition.unsupported_stanza_type); Log.warn("Closing session due to incorrect stream header. Tag: " + stanza.getName()); } else if (!FRAMING_NAMESPACE.equals(stanza.getNamespace().getURI())) { // Validate the stream namespace (https://tools.ietf.org/html/rfc7395#section-3.3.2) streamError = new StreamError(StreamError.Condition.invalid_namespace); Log.warn("Closing session due to invalid namespace in stream header. Namespace: " + stanza.getNamespace().getURI()); } else if (!validateHost(host)) { streamError = new StreamError(StreamError.Condition.host_unknown); Log.warn("Closing session due to incorrect hostname in stream header. Host: " + host); } else { // valid stream; initiate session xmppSession = SessionManager.getInstance().createClientSession(wsConnection, language); xmppSession.setSessionData("ws", Boolean.TRUE); } if (xmppSession == null) { closeStream(streamError); } else { openStream(language.toLanguageTag(), stanza.attributeValue("from")); configureStream(); } }
From source file:com.haulmont.cuba.web.LoginWindow.java
protected void login() { String login = loginField.getValue(); String password = passwordField.getValue() != null ? passwordField.getValue() : ""; if (StringUtils.isEmpty(login) || StringUtils.isEmpty(password)) { String message = messages.getMainMessage("loginWindow.emptyLoginOrPassword", resolvedLocale); Notification notification = new Notification(message, Type.WARNING_MESSAGE); notification.setDelayMsec(WebWindowManager.WARNING_NOTIFICATION_DELAY_MSEC); notification.show(ui.getPage()); return;/*from w w w .j a va2 s.c om*/ } if (!bruteForceProtectionCheck(login, app.getClientAddress())) { return; } try { Locale locale = getUserLocale(); app.setLocale(locale); PasswordEncryption passwordEncryption = AppBeans.get(PasswordEncryption.NAME); if (loginByRememberMe && rememberMeAllowed) { loginByRememberMe(login, password, locale); } else if (configuration.getConfig(WebAuthConfig.class).getExternalAuthentication()) { // try to login as externally authenticated user, fallback to regular authentication // we use resolved locale for error messages if (authenticateExternally(login, password, resolvedLocale)) { login = convertLoginString(login); ((ExternallyAuthenticatedConnection) connection).loginAfterExternalAuthentication(login, locale); } else { login(login, passwordEncryption.getPlainHash(password), locale); } } else { login(login, passwordEncryption.getPlainHash(password), locale); } // locale could be set on the server if (connection.getSession() != null) { app.setLocale(connection.getSession().getLocale()); if (globalConfig.getLocaleSelectVisible()) { app.addCookie(COOKIE_LOCALE, locale.toLanguageTag()); } } } catch (LoginException e) { log.info("Login failed: {}", e.toString()); String message = StringUtils.abbreviate(e.getMessage(), 1000); String bruteForceMsg = registerUnsuccessfulLoginAttempt(login, app.getClientAddress()); if (!Strings.isNullOrEmpty(bruteForceMsg)) { message = bruteForceMsg; } showLoginException(message); } catch (Exception e) { log.warn("Unable to login", e); showException(e); } }