001/* 002 * Copyright 2002-2009 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.freemarker; 018 019import org.springframework.web.servlet.view.AbstractTemplateViewResolver; 020 021/** 022 * Convenience subclass of {@link org.springframework.web.servlet.view.UrlBasedViewResolver} 023 * that supports {@link FreeMarkerView} (i.e. FreeMarker templates) and custom subclasses of it. 024 * 025 * <p>The view class for all views generated by this resolver can be specified 026 * via the "viewClass" property. See UrlBasedViewResolver's javadoc for details. 027 * 028 * <p><b>Note:</b> When chaining ViewResolvers, a FreeMarkerViewResolver will 029 * check for the existence of the specified template resources and only return 030 * a non-null View object if the template was actually found. 031 * 032 * @author Juergen Hoeller 033 * @since 1.1 034 * @see #setViewClass 035 * @see #setPrefix 036 * @see #setSuffix 037 * @see #setRequestContextAttribute 038 * @see #setExposeSpringMacroHelpers 039 * @see FreeMarkerView 040 */ 041public class FreeMarkerViewResolver extends AbstractTemplateViewResolver { 042 043 /** 044 * Sets the default {@link #setViewClass view class} to {@link #requiredViewClass}: 045 * by default {@link FreeMarkerView}. 046 */ 047 public FreeMarkerViewResolver() { 048 setViewClass(requiredViewClass()); 049 } 050 051 /** 052 * A convenience constructor that allows for specifying {@link #setPrefix prefix} 053 * and {@link #setSuffix suffix} as constructor arguments. 054 * @param prefix the prefix that gets prepended to view names when building a URL 055 * @param suffix the suffix that gets appended to view names when building a URL 056 * @since 4.3 057 */ 058 public FreeMarkerViewResolver(String prefix, String suffix) { 059 this(); 060 setPrefix(prefix); 061 setSuffix(suffix); 062 } 063 064 065 /** 066 * Requires {@link FreeMarkerView}. 067 */ 068 @Override 069 protected Class<?> requiredViewClass() { 070 return FreeMarkerView.class; 071 } 072 073}