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