001/* 002 * Copyright 2002-2017 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.lang.Nullable; 022import org.springframework.web.servlet.view.UrlBasedViewResolver; 023 024/** 025 * Convenience subclass of {@link UrlBasedViewResolver} that supports 026 * {@link TilesView} (i.e. Tiles definitions) and custom subclasses of it. 027 * 028 * @author Nicolas Le Bas 029 * @author Rossen Stoyanchev 030 * @author Juergen Hoeller 031 * @author Sebastien Deleuze 032 * @since 3.2 033 */ 034public class TilesViewResolver extends UrlBasedViewResolver { 035 036 @Nullable 037 private Renderer renderer; 038 039 @Nullable 040 private Boolean alwaysInclude; 041 042 043 public TilesViewResolver() { 044 setViewClass(requiredViewClass()); 045 } 046 047 048 /** 049 * This resolver requires {@link TilesView}. 050 */ 051 @Override 052 protected Class<?> requiredViewClass() { 053 return TilesView.class; 054 } 055 056 /** 057 * Set the {@link Renderer} to use. If not specified, a default 058 * {@link org.apache.tiles.renderer.DefinitionRenderer} will be used. 059 * @see TilesView#setRenderer(Renderer) 060 */ 061 public void setRenderer(Renderer renderer) { 062 this.renderer = renderer; 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 TilesView buildView(String viewName) throws Exception { 079 TilesView view = (TilesView) super.buildView(viewName); 080 if (this.renderer != null) { 081 view.setRenderer(this.renderer); 082 } 083 if (this.alwaysInclude != null) { 084 view.setAlwaysInclude(this.alwaysInclude); 085 } 086 return view; 087 } 088 089}