List of usage examples for javax.servlet.http HttpServletRequest getLocale
public Locale getLocale();
Locale
that the client will accept content in, based on the Accept-Language header. From source file:io.adeptj.runtime.servlet.ErrorPages.java
private static void renderErrorPageForStatusCode(HttpServletRequest req, HttpServletResponse resp, String statusCode) {/* w w w .j av a2 s . c om*/ TemplateEngines.getDefault().render(TemplateContext.builder().request(req).response(resp) .locale(req.getLocale()).template(String.format(TEMPLATE_ERROR_RESOLVABLE, statusCode)).build()); }
From source file:fr.paris.lutece.plugins.asynchronousupload.util.JSONUtils.java
/** * Builds a json object with the error message. * @param request the request/*from w w w .ja va 2s . c o m*/ * @return the json object. */ public static JSONObject buildJsonErrorRemovingFile(HttpServletRequest request) { JSONObject json = new JSONObject(); json.element(JSONUtils.JSON_KEY_FORM_ERROR, I18nService.getLocalizedString(PROPERTY_MESSAGE_ERROR_REMOVING_FILE, request.getLocale())); return json; }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale.java
/** * Get the current Locale to use, which is the first of these to be found: * <ul>/*from ww w . j a v a 2 s . c o m*/ * <li>The forced Locale in the servlet context</li> * <li>The selected Locale in the session</li> * <li>The Locale from the request</li> * <li>The default Locale for the JVM</li> * </ul> */ public static Locale getCurrentLocale(HttpServletRequest req) { Locale overridingLocale = getOverridingLocale(req); if (overridingLocale != null) { return overridingLocale; } Locale requestLocale = req.getLocale(); if (requestLocale != null) { log.debug("Found locale in the request: " + requestLocale); return requestLocale; } log.debug("Using default locale: " + Locale.getDefault()); return Locale.getDefault(); }
From source file:com.ecyrd.jspwiki.preferences.Preferences.java
/** * Get Locale according to user-preference settings or the user browser locale * /*from w w w . j a va2 s .c o m*/ * @param context The context to examine. * @return a Locale object. * @since 2.8 */ public static Locale getLocale(WikiContext context) { Locale loc = null; String langSetting = Preferences.getPreference(context, "Language"); // // parse language and construct valid Locale object // if (langSetting != null) { String language = ""; String country = ""; String variant = ""; String[] res = StringUtils.split(langSetting, "-_"); if (res.length > 2) variant = res[2]; if (res.length > 1) country = res[1]; if (res.length > 0) { language = res[0]; loc = new Locale(language, country, variant); } } // otherwise try to find out the browser's preferred language setting, or use the JVM's default if (loc == null) { HttpServletRequest request = context.getHttpRequest(); loc = (request != null) ? request.getLocale() : Locale.getDefault(); } //log.info( "using locale "+loc.toString() ); return loc; }
From source file:com.nec.nsgui.action.cifs.CommonUtil.java
static public void setNoContentMsgInObj(Object obj, String protertyName, MessageResources msgResources, HttpServletRequest request) throws Exception { Object objValue;/*from ww w . j a va 2 s . co m*/ try { objValue = PropertyUtils.getProperty(obj, protertyName); } catch (Exception e) { throw e; } if (objValue.toString().equals("")) { PropertyUtils.setProperty(obj, protertyName, msgResources.getMessage(request.getLocale(), "cifs.shareDetial.nocontent")); } }
From source file:com.adeptj.runtime.servlet.ErrorPages.java
public static void renderOSGiErrorPage(HttpServletRequest req, HttpServletResponse resp) { Integer statusCode = (Integer) RequestUtil.getAttribute(req, ERROR_STATUS_CODE); if (RequestUtil.hasException(req) && Integer.valueOf(SC_INTERNAL_SERVER_ERROR).equals(statusCode)) { TemplateEngine.getInstance()//from w w w . j a v a 2s . c o m .render(TemplateContext.builder().request(req).response(resp).locale(req.getLocale()) .templateData(TemplateData.newTemplateData().put(KEY_STATUS_CODE, statusCode) .put(KEY_ERROR_MSG, RequestUtil.getAttribute(req, ERROR_MESSAGE)) .put(KEY_REQ_URI, RequestUtil.getAttribute(req, ERROR_REQUEST_URI)) .put(KEY_EXCEPTION, RequestUtil.getAttribute(req, ERROR_EXCEPTION))) .template(TEMPLATE_500).build()); } else if (Integer.valueOf(SC_INTERNAL_SERVER_ERROR).equals(statusCode)) { ErrorPages.render500Page(req, resp); } else if (Configs.of().undertow().getIntList(KEY_STATUS_CODES).contains(statusCode)) { ErrorPages.renderErrorPageForStatusCode(req, resp, String.valueOf(statusCode)); } }
From source file:io.adeptj.runtime.servlet.ErrorPages.java
public static void renderOSGiErrorPage(HttpServletRequest req, HttpServletResponse resp) { Integer statusCode = (Integer) RequestUtil.getAttribute(req, ERROR_STATUS_CODE); if (RequestUtil.hasException(req) && Integer.valueOf(SC_INTERNAL_SERVER_ERROR).equals(statusCode)) { TemplateEngines.getDefault()//w ww . j a v a 2s. c om .render(TemplateContext.builder().request(req).response(resp).locale(req.getLocale()) .contextObject(ContextObject.newContextObject().put(KEY_STATUS_CODE, statusCode) .put(KEY_ERROR_MSG, RequestUtil.getAttribute(req, ERROR_MESSAGE)) .put(KEY_REQ_URI, RequestUtil.getAttribute(req, ERROR_REQUEST_URI)) .put(KEY_EXCEPTION, RequestUtil.getAttribute(req, ERROR_EXCEPTION))) .template(TEMPLATE_500).build()); } else if (Integer.valueOf(SC_INTERNAL_SERVER_ERROR).equals(statusCode)) { ErrorPages.render500Page(req, resp); } else if (Configs.of().undertow().getIntList(KEY_STATUS_CODES).contains(statusCode)) { ErrorPages.renderErrorPageForStatusCode(req, resp, String.valueOf(statusCode)); } }
From source file:com.salesmanager.core.util.www.ajax.CustomerUtil.java
public static void setGeoLocationCustomerInformation(String country, String region, String city, String language) {// w w w .ja va 2 s. co m HttpServletRequest req = WebContextFactory.get().getHttpServletRequest(); HttpSession session = WebContextFactory.get().getSession(); try { log.info("Setting LOCALE Country -> " + country + " region -> " + region + " city -> " + city); if (!StringUtils.isBlank(country)) { CountryDescription desc = CountryUtil.getCountryByIsoCode(country, req.getLocale()); if (desc != null) { log.info(" Country Description -> " + desc.getCountryName()); Customer customer = SessionUtil.getCustomer(req); if (customer == null) { customer = new Customer(); } customer.setCountryName(desc.getCountryName()); customer.setCustomerBillingCountryName(desc.getCountryName()); customer.setCustomerBillingCountryId(desc.getId().getCountryId()); customer.setCustomerCountryId(desc.getId().getCountryId()); // get the zone Zone zone = CountryUtil.getZoneCodeByCode(region, req.getLocale()); if (zone != null) { customer.setCustomerBillingZoneId(zone.getZoneId()); customer.setStateProvinceName(zone.getZoneName()); customer.setCustomerZoneId(zone.getZoneId()); customer.setCustomerState(zone.getZoneName()); } MerchantStore store = SessionUtil.getMerchantStore(req); if (store != null) { customer.setMerchantId(store.getMerchantId()); } // set Locale Locale locale = LocaleUtil.getLocale(req); log.info("Actual locale (" + locale.toString()); String l = locale.getLanguage(); locale = new Locale(l, country); log.info("Setting locale (" + l + "_" + country + ")"); log.info("New locale (" + locale.toString() + ")"); LocaleUtil.setLocale(req, locale); customer.setLocale(locale); customer.setCustomerLang(locale.getLanguage()); SessionUtil.setCustomer(customer, req); } else { log.info("Setting default locale (1)"); Locale locale = LocaleUtil.getDefaultLocale(); LocaleUtil.setLocale(req, locale); } } } catch (Exception e) { log.error(e); } }
From source file:com.lm.lic.manager.util.GenUtil.java
/** * @param request/*from w ww .j a v a 2 s . co m*/ * @return */ public static String extractLocaleLang(HttpServletRequest request) { Locale locale = request.getLocale(); String lang = locale.getLanguage(); return lang; }
From source file:com.nec.nsgui.action.cifs.CommonUtil.java
/** * set the corresponding message for the specified Property of all the object in List * @param objList - the list of object/*from www .j a v a2 s .co m*/ * @param protertyName - the target Property * @param value_msgKey - the value and the corresponding message's key in the Resource file * @param msgResources - MessageResources * @param request - http servlet request */ static public void setMsgInObj(List objList, String protertyName, HashMap value_msgKey, MessageResources msgResources, HttpServletRequest request) throws Exception { int objNumbers = objList.size(); Object object; Object objValue; for (int i = 0; i < objNumbers; i++) { object = objList.get(i); try { objValue = PropertyUtils.getProperty(object, protertyName); } catch (Exception e) { throw e; } if (value_msgKey.containsKey(objValue)) { //need change the value to the corresponding message PropertyUtils.setProperty(object, protertyName, msgResources.getMessage(request.getLocale(), (String) value_msgKey.get(objValue.toString()))); } } }