001/* 002 * Copyright 2002-2012 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 java.util.Locale; 020 021/** 022 * Interface to be implemented by objects that can resolve views by name. 023 * 024 * <p>View state doesn't change during the running of the application, 025 * so implementations are free to cache views. 026 * 027 * <p>Implementations are encouraged to support internationalization, 028 * i.e. localized view resolution. 029 * 030 * @author Rod Johnson 031 * @author Juergen Hoeller 032 * @see org.springframework.web.servlet.view.InternalResourceViewResolver 033 * @see org.springframework.web.servlet.view.ResourceBundleViewResolver 034 * @see org.springframework.web.servlet.view.XmlViewResolver 035 */ 036public interface ViewResolver { 037 038 /** 039 * Resolve the given view by name. 040 * <p>Note: To allow for ViewResolver chaining, a ViewResolver should 041 * return {@code null} if a view with the given name is not defined in it. 042 * However, this is not required: Some ViewResolvers will always attempt 043 * to build View objects with the given name, unable to return {@code null} 044 * (rather throwing an exception when View creation failed). 045 * @param viewName name of the view to resolve 046 * @param locale Locale in which to resolve the view. 047 * ViewResolvers that support internationalization should respect this. 048 * @return the View object, or {@code null} if not found 049 * (optional, to allow for ViewResolver chaining) 050 * @throws Exception if the view cannot be resolved 051 * (typically in case of problems creating an actual View object) 052 */ 053 View resolveViewName(String viewName, Locale locale) throws Exception; 054 055}