001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet; 018 019import javax.servlet.http.HttpServletRequest; 020import javax.servlet.http.HttpServletResponse; 021 022import org.springframework.lang.Nullable; 023 024/** 025 * Interface for web-based theme resolution strategies that allows for 026 * both theme resolution via the request and theme modification via 027 * request and response. 028 * 029 * <p>This interface allows for implementations based on session, 030 * cookies, etc. The default implementation is 031 * {@link org.springframework.web.servlet.theme.FixedThemeResolver}, 032 * simply using a configured default theme. 033 * 034 * <p>Note that this resolver is only responsible for determining the 035 * current theme name. The Theme instance for the resolved theme name 036 * gets looked up by DispatcherServlet via the respective ThemeSource, 037 * i.e. the current WebApplicationContext. 038 * 039 * <p>Use {@link org.springframework.web.servlet.support.RequestContext#getTheme()} 040 * to retrieve the current theme in controllers or views, independent 041 * of the actual resolution strategy. 042 * 043 * @author Jean-Pierre Pawlak 044 * @author Juergen Hoeller 045 * @since 17.06.2003 046 * @see org.springframework.ui.context.Theme 047 * @see org.springframework.ui.context.ThemeSource 048 */ 049public interface ThemeResolver { 050 051 /** 052 * Resolve the current theme name via the given request. 053 * Should return a default theme as fallback in any case. 054 * @param request the request to be used for resolution 055 * @return the current theme name 056 */ 057 String resolveThemeName(HttpServletRequest request); 058 059 /** 060 * Set the current theme name to the given one. 061 * @param request the request to be used for theme name modification 062 * @param response the response to be used for theme name modification 063 * @param themeName the new theme name ({@code null} or empty to reset it) 064 * @throws UnsupportedOperationException if the ThemeResolver implementation 065 * does not support dynamic changing of the theme 066 */ 067 void setThemeName(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable String themeName); 068 069}