001/* 002 * Copyright 2002-2014 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.view.tiles2; 018 019import org.springframework.web.servlet.view.AbstractUrlBasedView; 020import org.springframework.web.servlet.view.UrlBasedViewResolver; 021 022/** 023 * Convenience subclass of {@link org.springframework.web.servlet.view.UrlBasedViewResolver} 024 * that supports {@link TilesView} (i.e. Tiles definitions) and custom subclasses of it. 025 * 026 * <p>The view class for all views generated by this resolver can be specified 027 * via the "viewClass" property. See UrlBasedViewResolver's javadoc for details. 028 * 029 * <p><b>Note:</b> When chaining ViewResolvers, a TilesViewResolver will 030 * check for the existence of the specified template resources and only return 031 * a non-null View object if the template was actually found. 032 * 033 * <p><b>NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed 034 * as of Spring Framework 5.0.</b>. 035 * 036 * @author Juergen Hoeller 037 * @author Sebastien Deleuze 038 * @since 3.0 039 * @see #setViewClass 040 * @see #setPrefix 041 * @see #setSuffix 042 * @see #setRequestContextAttribute 043 * @see TilesView 044 * @deprecated as of Spring 4.2, in favor of Tiles 3 045 */ 046@Deprecated 047public class TilesViewResolver extends UrlBasedViewResolver { 048 049 private Boolean alwaysInclude; 050 051 052 public TilesViewResolver() { 053 setViewClass(requiredViewClass()); 054 } 055 056 057 /** 058 * This resolver requires {@link TilesView}. 059 */ 060 @Override 061 protected Class<?> requiredViewClass() { 062 return TilesView.class; 063 } 064 065 /** 066 * Specify whether to always include the view rather than forward to it. 067 * <p>Default is "false". Switch this flag on to enforce the use of a 068 * Servlet include, even if a forward would be possible. 069 * @since 4.1.2 070 * @see TilesView#setAlwaysInclude 071 */ 072 public void setAlwaysInclude(Boolean alwaysInclude) { 073 this.alwaysInclude = alwaysInclude; 074 } 075 076 077 @Override 078 protected AbstractUrlBasedView buildView(String viewName) throws Exception { 079 TilesView view = (TilesView) super.buildView(viewName); 080 if (this.alwaysInclude != null) { 081 view.setAlwaysInclude(this.alwaysInclude); 082 } 083 return view; 084 } 085 086}