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.view.velocity; 018 019import org.springframework.web.servlet.view.AbstractUrlBasedView; 020 021/** 022 * Convenience subclass of VelocityViewResolver, adding support 023 * for VelocityLayoutView and its properties. 024 * 025 * <p>See VelocityViewResolver's javadoc for general usage info. 026 * 027 * @author Juergen Hoeller 028 * @since 1.2.7 029 * @see VelocityViewResolver 030 * @see VelocityLayoutView 031 * @see #setLayoutUrl 032 * @see #setLayoutKey 033 * @see #setScreenContentKey 034 * @deprecated as of Spring 4.3, in favor of FreeMarker 035 */ 036@Deprecated 037public class VelocityLayoutViewResolver extends VelocityViewResolver { 038 039 private String layoutUrl; 040 041 private String layoutKey; 042 043 private String screenContentKey; 044 045 046 /** 047 * Requires VelocityLayoutView. 048 * @see VelocityLayoutView 049 */ 050 @Override 051 protected Class<?> requiredViewClass() { 052 return VelocityLayoutView.class; 053 } 054 055 /** 056 * Set the layout template to use. Default is "layout.vm". 057 * @param layoutUrl the template location (relative to the template 058 * root directory) 059 * @see VelocityLayoutView#setLayoutUrl 060 */ 061 public void setLayoutUrl(String layoutUrl) { 062 this.layoutUrl = layoutUrl; 063 } 064 065 /** 066 * Set the context key used to specify an alternate layout to be used instead 067 * of the default layout. Screen content templates can override the layout 068 * template that they wish to be wrapped with by setting this value in the 069 * template, for example:<br> 070 * {@code #set($layout = "MyLayout.vm" )} 071 * <p>The default key is "layout", as illustrated above. 072 * @param layoutKey the name of the key you wish to use in your 073 * screen content templates to override the layout template 074 * @see VelocityLayoutView#setLayoutKey 075 */ 076 public void setLayoutKey(String layoutKey) { 077 this.layoutKey = layoutKey; 078 } 079 080 /** 081 * Set the name of the context key that will hold the content of 082 * the screen within the layout template. This key must be present 083 * in the layout template for the current screen to be rendered. 084 * <p>Default is "screen_content": accessed in VTL as 085 * {@code $screen_content}. 086 * @param screenContentKey the name of the screen content key to use 087 * @see VelocityLayoutView#setScreenContentKey 088 */ 089 public void setScreenContentKey(String screenContentKey) { 090 this.screenContentKey = screenContentKey; 091 } 092 093 094 @Override 095 protected AbstractUrlBasedView buildView(String viewName) throws Exception { 096 VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName); 097 // Use not-null checks to preserve VelocityLayoutView's defaults. 098 if (this.layoutUrl != null) { 099 view.setLayoutUrl(this.layoutUrl); 100 } 101 if (this.layoutKey != null) { 102 view.setLayoutKey(this.layoutKey); 103 } 104 if (this.screenContentKey != null) { 105 view.setScreenContentKey(this.screenContentKey); 106 } 107 return view; 108 } 109 110}