@Override public Cookie[] getCookies() { return instance.getCookies(); }
private static Cookie getCookieByName(final String name) { // Fetch all cookies from the request final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies(); if (cookies != null) { // Iterate to find cookie by its name for (final Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return cookie; } } } return null; }
private static Cookie getCookieByName(final String name) { // Fetch all cookies from the request final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies(); if (cookies != null) { // Iterate to find cookie by its name for (final Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return cookie; } } } return null; }
/** * Get Locale for i18n. * * @return String as locales */ private static String[] getLocaleChain() { String[] localeChain = null; // Fetch all cookies from the request final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies(); if (cookies == null) { return localeChain; } for (final Cookie c : cookies) { if (c.getName().equals(SPUIDefinitions.COOKIE_NAME) && !c.getValue().isEmpty()) { localeChain = c.getValue().split("#"); break; } } return localeChain; }
/** * Get Locale for i18n. * * @return String as locales */ private static String[] getLocaleChain() { String[] localeChain = null; // Fetch all cookies from the request final Cookie[] cookies = VaadinService.getCurrentRequest().getCookies(); if (cookies == null) { return localeChain; } for (final Cookie c : cookies) { if (c.getName().equals(SPUIDefinitions.COOKIE_NAME) && !c.getValue().isEmpty()) { localeChain = c.getValue().split("#"); break; } } return localeChain; }
@Override public Optional<Cookie> getRequestCookie(String name) { ObjectUtils.argumentNotNull(name, "Cookie name must be not null"); javax.servlet.http.Cookie[] cookies = request.getCookies(); if (cookies != null) { for (javax.servlet.http.Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return Optional.of(Cookie.builder().name(cookie.getName()).value(cookie.getValue()) .version(cookie.getVersion()).path(cookie.getPath()).domain(cookie.getDomain()).build()); } } } return Optional.empty(); }
@Override public Optional<Cookie> getRequestCookie(String name) { ObjectUtils.argumentNotNull(name, "Cookie name must be not null"); javax.servlet.http.Cookie[] cookies = request.getCookies(); if (cookies != null) { for (javax.servlet.http.Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return Optional.of(Cookie.builder().name(cookie.getName()).value(cookie.getValue()) .version(cookie.getVersion()).path(cookie.getPath()).domain(cookie.getDomain()).build()); } } } return Optional.empty(); }
@Override public String getTheme(UICreateEvent event) { // get theme from cookies before app ui initialized for smooth theme enabling WebConfig webConfig = configuration.getConfig(WebConfig.class); GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); String appWindowTheme = webConfig.getAppWindowTheme(); String userAppTheme = getCookieValue(event.getRequest().getCookies(), App.APP_THEME_COOKIE_PREFIX + globalConfig.getWebContextName()); if (userAppTheme != null) { if (!Objects.equals(userAppTheme, appWindowTheme)) { // check theme support ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME); Set<String> supportedThemes = themeRepository.getAvailableThemes(); if (supportedThemes.contains(userAppTheme)) { return userAppTheme; } } } return super.getTheme(event); }