Tabnine Logo
ThemeResolver
Code IndexAdd Tabnine to your IDE (free)

How to use
ThemeResolver
in
org.springframework.web.servlet

Best Java code snippets using org.springframework.web.servlet.ThemeResolver (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

/**
 * Retrieves the current theme from the given request, using the ThemeResolver
 * and ThemeSource bound to the request by the DispatcherServlet.
 * @param request current HTTP request
 * @return the current theme, or {@code null} if not found
 * @see #getThemeResolver
 */
@Nullable
public static Theme getTheme(HttpServletRequest request) {
  ThemeResolver themeResolver = getThemeResolver(request);
  ThemeSource themeSource = getThemeSource(request);
  if (themeResolver != null && themeSource != null) {
    String themeName = themeResolver.resolveThemeName(request);
    return themeSource.getTheme(themeName);
  }
  else {
    return null;
  }
}
origin: spring-projects/spring-framework

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws ServletException {
  String newTheme = request.getParameter(this.paramName);
  if (newTheme != null) {
    ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
    if (themeResolver == null) {
      throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
    }
    themeResolver.setThemeName(request, response, newTheme);
  }
  // Proceed in any case.
  return true;
}
origin: spring-projects/spring-framework

private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String defaultName) {
  // create mocks
  MockServletContext context = new MockServletContext();
  MockHttpServletRequest request = new MockHttpServletRequest(context);
  MockHttpServletResponse response = new MockHttpServletResponse();
  // check original theme
  String themeName = themeResolver.resolveThemeName(request);
  assertEquals(themeName, defaultName);
  // set new theme name
  try {
    themeResolver.setThemeName(request, response, TEST_THEME_NAME);
    if (!shouldSet)
      fail("should not be able to set Theme name");
    // check new theme namelocale
    themeName = themeResolver.resolveThemeName(request);
    assertEquals(TEST_THEME_NAME, themeName);
    themeResolver.setThemeName(request, response, null);
    themeName = themeResolver.resolveThemeName(request);
    assertEquals(themeName, defaultName);
  }
  catch (UnsupportedOperationException ex) {
    if (shouldSet)
      fail("should be able to set Theme name");
  }
}
origin: pl.edu.icm.synat/synat-portal-core

@Override
public void postHandle(HttpServletRequest request,
    HttpServletResponse response, Object handler,
    ModelAndView modelAndView) throws Exception {
  Locale locale = localeResolver.resolveLocale(request);
  userSettingsHolder.setLocale(locale);
  localeResolver.setLocale(request, response, locale);
  String themeName = themeResolver.resolveThemeName(request);
  userSettingsHolder.setTheme(themeName);
  themeResolver.setThemeName(request, response, themeName);
  final String timezone = timezoneResolver.resolveSetting(request);
  userSettingsHolder.setTimezone(timezone);
  timezoneResolver.setSetting(timezone);
}
origin: org.springframework/spring-webmvc

/**
 * Retrieves the current theme from the given request, using the ThemeResolver
 * and ThemeSource bound to the request by the DispatcherServlet.
 * @param request current HTTP request
 * @return the current theme, or {@code null} if not found
 * @see #getThemeResolver
 */
@Nullable
public static Theme getTheme(HttpServletRequest request) {
  ThemeResolver themeResolver = getThemeResolver(request);
  ThemeSource themeSource = getThemeSource(request);
  if (themeResolver != null && themeSource != null) {
    String themeName = themeResolver.resolveThemeName(request);
    return themeSource.getTheme(themeName);
  }
  else {
    return null;
  }
}
origin: spring-projects/spring-framework

/**
 * Change the current theme to the specified theme by name,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param themeName the name of the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(String themeName) {
  ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
  if (themeResolver == null) {
    throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
  }
  themeResolver.setThemeName(this.request, this.response, themeName);
  // Ask for re-resolution on next getTheme call.
  this.theme = null;
}
origin: spring-projects/spring-framework

  throw new ServletException("Incorrect ThemeResolver");
if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
  throw new ServletException("Incorrect theme name");
  throw new ServletException("Incorrect TimeZone");
if (!"theme2".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
  throw new ServletException("Incorrect theme name");
origin: spring-projects/spring-framework

/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(@Nullable Theme theme) {
  ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
  if (themeResolver == null) {
    throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
  }
  themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
  this.theme = theme;
}
origin: org.jtwig/jtwig-spring

@Override
public String resolve(String staticPrefix) {
  String themeName = themeResolver.resolveThemeName(getRequest());
  String path = new File(staticPrefix, themeName).getPath();
  if (staticPrefix.endsWith(File.separator)) {
    return path + File.separator;
  } else {
    return path;
  }
}
origin: org.springframework/spring-webmvc

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws ServletException {
  String newTheme = request.getParameter(this.paramName);
  if (newTheme != null) {
    ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
    if (themeResolver == null) {
      throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
    }
    themeResolver.setThemeName(request, response, newTheme);
  }
  // Proceed in any case.
  return true;
}
origin: org.fujion/fujion-core

@Override
public String resolveThemeName(HttpServletRequest request) {
  String themeName = getThemeName(request);
  Iterator<ThemeResolver> iter = themeResolvers.iterator();
  
  while (iter.hasNext() && !StringUtils.hasText(themeName)) {
    themeName = iter.next().resolveThemeName(request);
  }
  
  cacheThemeName(request, themeName);
  return StringUtils.hasText(themeName) ? themeName : defaultTheme;
}

origin: org.springframework/spring-webmvc

/**
 * Change the current theme to the specified theme by name,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param themeName the name of the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(String themeName) {
  ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
  if (themeResolver == null) {
    throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
  }
  themeResolver.setThemeName(this.request, this.response, themeName);
  // Ask for re-resolution on next getTheme call.
  this.theme = null;
}
origin: org.apereo.cas/cas-server-support-themes

@Override
public String resolveThemeName(final HttpServletRequest httpServletRequest) {
  val it = chain.iterator();
  while (it.hasNext()) {
    val r = it.next();
    LOGGER.trace("Attempting to resolve theme via [{}]", r.getClass().getSimpleName());
    val resolverTheme = r.resolveThemeName(httpServletRequest);
    if (!resolverTheme.equalsIgnoreCase(getDefaultThemeName())) {
      LOGGER.trace("Resolved theme [{}]", resolverTheme);
      return resolverTheme;
    }
  }
  LOGGER.trace("No specific theme could be found. Using default theme [{}}", getDefaultThemeName());
  return getDefaultThemeName();
}
origin: org.springframework/spring-webmvc

/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(@Nullable Theme theme) {
  ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
  if (themeResolver == null) {
    throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
  }
  themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
  this.theme = theme;
}
origin: com.blossom-project/blossom-ui-common

@ModelAttribute("currentTheme")
public Theme currentTheme(HttpServletRequest request) {
 return themeRegistry.getPluginFor(themeResolver.resolveThemeName(request), themeRegistry.getPluginFor(DEFAULT_THEME_NAME));
}
origin: org.fujion/fujion-core

@Override
public void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName) {
  themeName = StringUtils.hasText(themeName) ? themeName : defaultTheme;
  
  for (ThemeResolver themeResolver : themeResolvers) {
    themeResolver.setThemeName(request, response, themeName);
  }
}

origin: org.fujion/fujion-core

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) request;
  String themeName = themeResolver.resolveThemeName(httpRequest);
  Theme theme = ThemeRegistry.getInstance().get(themeName);
  if (theme != null) {
    String originalPath = httpRequest.getPathInfo();
    String requestPath = originalPath == null ? null : theme.translatePath(originalPath);
    if (requestPath != null) {
      requestPath = requestPath.isEmpty() ? "empty/" + originalPath : requestPath;
      httpRequest.getRequestDispatcher(requestPath).forward(httpRequest, response);
      return;
    }
  }
  chain.doFilter(request, response);
}
origin: apache/servicemix-bundles

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws ServletException {
  String newTheme = request.getParameter(this.paramName);
  if (newTheme != null) {
    ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
    if (themeResolver == null) {
      throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
    }
    themeResolver.setThemeName(request, response, newTheme);
  }
  // Proceed in any case.
  return true;
}
origin: com.lyncode/jtwig-spring

  private ResourceUrlResolver urlResolver() {
    if (themeResolver == null || !useThemeInViewPath) {
      return IdentityUrlResolver.INSTANCE;
    } else {
      return new ThemedResourceUrlResolver(themeResolver.resolveThemeName(getServletRequest()));
    }
  }
}
origin: apache/servicemix-bundles

/**
 * Change the current theme to the specified one,
 * storing the new theme name through the configured {@link ThemeResolver}.
 * @param theme the new theme
 * @see ThemeResolver#setThemeName
 */
public void changeTheme(Theme theme) {
  ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
  if (themeResolver == null) {
    throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
  }
  themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null));
  this.theme = theme;
}
org.springframework.web.servletThemeResolver

Javadoc

Interface for web-based theme resolution strategies that allows for both theme resolution via the request and theme modification via request and response.

This interface allows for implementations based on session, cookies, etc. The default implementation is org.springframework.web.servlet.theme.FixedThemeResolver, simply using a configured default theme.

Note that this resolver is only responsible for determining the current theme name. The Theme instance for the resolved theme name gets looked up by DispatcherServlet via the respective ThemeSource, i.e. the current WebApplicationContext.

Use org.springframework.web.servlet.support.RequestContext#getTheme()to retrieve the current theme in controllers or views, independent of the actual resolution strategy.

Most used methods

  • resolveThemeName
    Resolve the current theme name via the given request. Should return a default theme as fallback in a
  • setThemeName
    Set the current theme name to the given one.

Popular in Java

  • Parsing JSON documents to java classes using gson
  • putExtra (Intent)
  • requestLocationUpdates (LocationManager)
  • setScale (BigDecimal)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now