Spring Framework CookieLocaleResolver - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework CookieLocaleResolver class.

This code example shows how to use the following methods:determineDefaultLocale, getDefaultLocale
    @Resource(name = "blLocaleService") 
    private LocaleService localeService; 
     
    @Override 
    protected java.util.Locale determineDefaultLocale(HttpServletRequest request) { 
        java.util.Locale defaultLocale = getDefaultLocale(); 
        if (defaultLocale == null) { 
            Locale defaultBroadleafLocale = localeService.findDefaultLocale(); 
            if (defaultBroadleafLocale == null) { 
                return super.determineDefaultLocale(request); 
            } else { 
                return BroadleafRequestContext.convertLocaleToJavaLocale(defaultBroadleafLocale); 
            } 
        } 
        return defaultLocale; 
    } 
     
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:resolveLocale, setCookieName
        Locale lastKnownLocale = profileDao.retrieveLocale(orcidId); 
        if (lastKnownLocale != null) { 
 
            // have to read the cookie directly since spring has 
            // populated the request locale yet 
            CookieLocaleResolver clr = new CookieLocaleResolver(); 
            // must match <property name="cookieName" value="locale_v3" 
            // /> 
            clr.setCookieName("locale_v3"); 
            Locale cookieLocale = org.orcid.jaxb.model.message.Locale.fromValue(clr.resolveLocale(request).toString()); 
 
            // update the users preferences, so that 
            // send out emails in their last chosen language 
            if (!lastKnownLocale.equals(cookieLocale)) { 
                profileDao.updateLocale(orcidId, cookieLocale); 
            } 
        } 
    } 
 
    private String determineFullTargetUrlFromSavedRequest(HttpServletRequest request, HttpServletResponse response) { 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDefaultLocale, setCookieMaxAge, setCookieName
        return messageSource; 
    } 
 
    @Bean 
    public LocaleResolver localeResolver() { 
        CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); 
        cookieLocaleResolver.setCookieName("language"); 
        cookieLocaleResolver.setCookieMaxAge(-1); 
        cookieLocaleResolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); 
        return cookieLocaleResolver; 
    } 
 
    @Bean 
    public ViewResolver viewResolver() { 
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 
        viewResolver.setPrefix("/WEB-INF/jsp/"); 
        viewResolver.setSuffix(".jsp"); 
        return viewResolver; 
    } 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
import javax.servlet.http.HttpSession; 
 
import org.openmrs.api.context.Context; 
import org.springframework.web.servlet.i18n.CookieLocaleResolver; 
 
public class OpenmrsCookieLocaleResolver extends CookieLocaleResolver { 
	 
	public Locale resolveLocale(HttpServletRequest request) { 
		 
		Locale locale; 
		 
		locale = Context.getLocale(); 
		if (locale != null) { 
			return locale; 
		} 
		 
		//fall back to cookie that was set 
		return super.resolveLocale(request); 
	} 
	 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public class JcLocaleResolver extends CookieLocaleResolver { 
 
    private UserService userService; 
 
    public JcLocaleResolver(UserService userService) { 
        this.userService = userService; 
    } 
 
    /** 
     * Resolves user locale. If user is logged in locale will be read from database. If user is anonymous locale will be 
     * resolved form request and cookies using standard {@link CookieLocaleResolver} mechanism 
     * 
     * @param request HttpServletRequest 
     * @return user locale 
     */ 
    @Override 
    public Locale resolveLocale(HttpServletRequest request) { 
        Locale locale = (Locale)request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME); 
        if (locale != null) { 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setCookieName
 
@Configuration 
public class LocaleConfiguration { 
    @Bean 
    public LocaleResolver localeResolver() {
        CookieLocaleResolver resolver = new CookieLocaleResolver();
        resolver.setCookieName("locale");
        return resolver;
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 * Fetch the default language from the theme 
 * 
 * @author Gerald de Jong <geralddejong@gmail.com> 
 */ 
 
public class ThemeCookieLocaleResolver extends CookieLocaleResolver { 
 
    private Logger log = Logger.getLogger(getClass()); 
 
    @Autowired 
    private ThemeHandler themeHandler; 
 
    @Override 
    public String getCookieDomain() { 
        log.debug(String.format("Fetching cookie domain %s from theme, cookie name is %s", ThemeFilter.getTheme().getBaseUrl(), getCookieName())); 
        return ThemeFilter.getTheme().getBaseUrl(); 
    } 
 
    @Override 
    public String getCookieName() { 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
	 *  
	 * @return the {@link LocaleResolver} 
	 */ 
	@Bean 
	public LocaleResolver localeResolver() {
		return new CookieLocaleResolver();
	} 
 
	/** 
	 * To resolve message codes to actual messages we need a {@link MessageSource} implementation. The default 
	 * implementations use a {@link java.util.ResourceBundle} to parse the property files with the messages in it. 
	 * @return the {@link MessageSource} 
	 */ 
	@Bean 
	public MessageSource messageSource() {
		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
		messageSource.setBasenames(new String[] { "messages", "org.springframework.security.messages" });
		messageSource.setUseCodeAsDefaultMessage(true);
		return messageSource;
	} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework CookieLocaleResolver Methods: