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.tiles3; 018 019import org.apache.tiles.request.render.Renderer; 020 021import org.springframework.web.servlet.view.UrlBasedViewResolver; 022 023/** 024 * Convenience subclass of {@link UrlBasedViewResolver} that supports 025 * {@link TilesView} (i.e. Tiles definitions) and custom subclasses of it. 026 * 027 * @author Nicolas Le Bas 028 * @author Rossen Stoyanchev 029 * @author Juergen Hoeller 030 * @author Sebastien Deleuze 031 * @since 3.2 032 */ 033public class TilesViewResolver extends UrlBasedViewResolver { 034 035 private Renderer renderer; 036 037 private Boolean alwaysInclude; 038 039 040 public TilesViewResolver() { 041 setViewClass(requiredViewClass()); 042 } 043 044 045 /** 046 * This resolver requires {@link TilesView}. 047 */ 048 @Override 049 protected Class<?> requiredViewClass() { 050 return TilesView.class; 051 } 052 053 /** 054 * Set the {@link Renderer} to use. If not specified, a default 055 * {@link org.apache.tiles.renderer.DefinitionRenderer} will be used. 056 * @see TilesView#setRenderer(Renderer) 057 */ 058 public void setRenderer(Renderer renderer) { 059 this.renderer = renderer; 060 } 061 062 /** 063 * Specify whether to always include the view rather than forward to it. 064 * <p>Default is "false". Switch this flag on to enforce the use of a 065 * Servlet include, even if a forward would be possible. 066 * @since 4.1.2 067 * @see TilesView#setAlwaysInclude 068 */ 069 public void setAlwaysInclude(Boolean alwaysInclude) { 070 this.alwaysInclude = alwaysInclude; 071 } 072 073 074 @Override 075 protected TilesView buildView(String viewName) throws Exception { 076 TilesView view = (TilesView) super.buildView(viewName); 077 if (this.renderer != null) { 078 view.setRenderer(this.renderer); 079 } 080 if (this.alwaysInclude != null) { 081 view.setAlwaysInclude(this.alwaysInclude); 082 } 083 return view; 084 } 085 086}