Java Code Examples for javax.servlet.http.HttpServletRequest.getLocale()

The following are Jave code examples for showing how to use getLocale() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kettle_support_kettle8.0   File: IndexController.java   View Source Code Vote up 6 votes
@RequestMapping(value = ACTION_INDEX, method = RequestMethod.POST)
public String index(
		@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String username,
		Map<String, Object> map, HttpServletRequest request,
		HttpServletResponse response) {
	defaultLocale = request.getLocale();
	Shiro shiro = Shiro.get();
	if (null != shiro && null != username
			&& shiro.getEmail().equals(username)) {
		return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_REPOS
				+ ACTION_LIST;
	}
	String message = exception(request);
	map.put("message", message);
	map.put("username", username);
	return PAGE_INDEX;
}
 
Example 2
Project: Equella   File: UserPreferenceServiceImpl.java   View Source Code Vote up 6 votes
@Override
public Locale getPreferredLocale(HttpServletRequest request)
{
	Locale locale = null;
	if( CurrentInstitution.get() != null && !CurrentUser.isGuest() && !CurrentUser.getUserState().isSystem() )
	{
		// Is locale selected as a user preference?
		locale = getLocale();
	}
	if( locale == null && request != null )
	{
		// Is it part of the browser request?
		locale = request.getLocale();
	}
	if( locale == null )
	{
		return Locale.getDefault();
	}
	return locale;
}
 
Example 3
Project: lams   File: RequestProcessor.java   View Source Code Vote up 6 votes
/**
 * <p>Automatically select a <code>Locale</code> for the current user, if requested.
 * <strong>NOTE</strong> - configuring Locale selection will trigger
 * the creation of a new <code>HttpSession</code> if necessary.</p>
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 */
protected void processLocale(HttpServletRequest request,
                             HttpServletResponse response) {

    // Are we configured to select the Locale automatically?
    if (!moduleConfig.getControllerConfig().getLocale()) {
        return;
    }

    // Has a Locale already been selected?
    HttpSession session = request.getSession();
    if (session.getAttribute(Globals.LOCALE_KEY) != null) {
        return;
    }

    // Use the Locale returned by the servlet container (if any)
    Locale locale = request.getLocale();
    if (locale != null) {
        if (log.isDebugEnabled()) {
            log.debug(" Setting user locale '" + locale + "'");
        }
        session.setAttribute(Globals.LOCALE_KEY, locale);
    }

}
 
Example 4
Project: com-liferay-apio-architect   File: LanguageProvider.java   View Source Code Vote up 6 votes
@Override
public Language createContext(HttpServletRequest httpServletRequest) {
	return new Language() {

		@Override
		public Stream<Locale> getLocales() {
			Enumeration<Locale> locales = httpServletRequest.getLocales();

			return Collections.list(locales).stream();
		}

		@Override
		public Locale getPreferredLocale() {
			return httpServletRequest.getLocale();
		}

	};
}
 
Example 5
Project: cas-5.1.0   File: CasManagementWebAppConfiguration.java   View Source Code Vote up 5 votes
@Bean
public CookieLocaleResolver localeResolver() {
    return new CookieLocaleResolver() {
        @Override
        protected Locale determineDefaultLocale(final HttpServletRequest request) {
            final Locale locale = request.getLocale();
            if (StringUtils.isEmpty(casProperties.getMgmt().getDefaultLocale())
                    || !locale.getLanguage().equals(casProperties.getMgmt().getDefaultLocale())) {
                return locale;
            }
            return new Locale(casProperties.getMgmt().getDefaultLocale());
        }
    };
}
 
Example 6
Project: cas-5.1.0   File: CasWebAppConfiguration.java   View Source Code Vote up 5 votes
@Bean
public CookieLocaleResolver localeResolver() {
    final CookieLocaleResolver bean = new CookieLocaleResolver() {
        @Override
        protected Locale determineDefaultLocale(final HttpServletRequest request) {
            final Locale locale = request.getLocale();
            if (StringUtils.isBlank(casProperties.getLocale().getDefaultValue())
                    || !locale.getLanguage().equals(casProperties.getLocale().getDefaultValue())) {
                return locale;
            }
            return new Locale(casProperties.getLocale().getDefaultValue());
        }
    };
    return bean;
}
 
Example 7
Project: lams   File: AcceptLanguageHeaderResolver.java   View Source Code Vote up 5 votes
public Locale resolveLocale(final HttpServletRequest request) {

		if (Utils.isNotEmpty(request.getHeader("Accept-Language")))
			return request.getLocale();
		else
			return null;
	}
 
Example 8
Project: validator-web   File: GeneratedValidationJavaScriptHandler.java   View Source Code Vote up 5 votes
@Override
protected Locale getLocale(HttpServletRequest request) {
    String locale = request.getParameter(WebContext.PARAMETER_LOCALE);
    if (StringUtils.hasText(locale)) {
        try {
            return LocaleUtils.toLocale(locale);
        } catch (IllegalArgumentException e) { }
    }
    return request.getLocale();
}
 
Example 9
Project: validator-web   File: ValidatorContext.java   View Source Code Vote up 5 votes
private Locale getLocale() {
    final WebContext context = WebContextThreadStack.get();
    if (context == null) {
        return Locale.getDefault();
    }
    final HttpServletRequest request = context.getHttpServletRequest();
    final ValidatorConfig validatorConfig = this.validatorFactory.getValidatorConfig();
    final String locale = request.getParameter(validatorConfig.getLanguageParameterName());
    if (StringUtils.hasText(locale)) {
        try {
            return LocaleUtils.toLocale(locale);
        } catch (IllegalArgumentException e) { }
    }
    return request.getLocale();
}
 
Example 10
Project: kettle_support_kettle8.0   File: Messages.java   View Source Code Vote up 4 votes
public Locale resolveLocale(HttpServletRequest request) {
	defaultLocale = request.getLocale();
	return defaultLocale;
}
 
Example 11
Project: kettle_support_kettle8.0   File: LocaleServiceImpl.java   View Source Code Vote up 4 votes
public Locale resolveLocale(HttpServletRequest request) {
	defaultLocale = request.getLocale();
	return defaultLocale;
}
 
Example 12
Project: ralasafe   File: I18N.java   View Source Code Vote up 4 votes
public static I18N getWebInstance( HttpServletRequest req ) {
	locale=req.getLocale();
	ResourceBundle bundle=ResourceBundle.getBundle("Ralasafe_Web", locale);
	
	return new I18N( bundle );
}
 
Example 13
Project: gitplex-mit   File: ServletRequestCopy.java   View Source Code Vote up 4 votes
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}