001/*
002 * Copyright 2002-2013 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
022/**
023 * Interface for web-based theme resolution strategies that allows for
024 * both theme resolution via the request and theme modification via
025 * request and response.
026 *
027 * <p>This interface allows for implementations based on session,
028 * cookies, etc. The default implementation is
029 * {@link org.springframework.web.servlet.theme.FixedThemeResolver},
030 * simply using a configured default theme.
031 *
032 * <p>Note that this resolver is only responsible for determining the
033 * current theme name. The Theme instance for the resolved theme name
034 * gets looked up by DispatcherServlet via the respective ThemeSource,
035 * i.e. the current WebApplicationContext.
036 *
037 * <p>Use {@link org.springframework.web.servlet.support.RequestContext#getTheme()}
038 * to retrieve the current theme in controllers or views, independent
039 * of the actual resolution strategy.
040 *
041 * @author Jean-Pierre Pawlak
042 * @author Juergen Hoeller
043 * @since 17.06.2003
044 * @see org.springframework.ui.context.Theme
045 * @see org.springframework.ui.context.ThemeSource
046 */
047public interface ThemeResolver {
048
049        /**
050         * Resolve the current theme name via the given request.
051         * Should return a default theme as fallback in any case.
052         * @param request request to be used for resolution
053         * @return the current theme name
054         */
055        String resolveThemeName(HttpServletRequest request);
056
057        /**
058         * Set the current theme name to the given one.
059         * @param request request to be used for theme name modification
060         * @param response response to be used for theme name modification
061         * @param themeName the new theme name
062         * @throws UnsupportedOperationException if the ThemeResolver implementation
063         * does not support dynamic changing of the theme
064         */
065        void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName);
066
067}