001/* 002 * Copyright 2002-2015 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.script; 018 019import org.springframework.web.servlet.view.UrlBasedViewResolver; 020 021/** 022 * Convenience subclass of {@link UrlBasedViewResolver} that supports 023 * {@link ScriptTemplateView} and custom subclasses of it. 024 * 025 * <p>The view class for all views created by this resolver can be specified 026 * via the {@link #setViewClass(Class)} property. 027 * 028 * <p><b>Note:</b> When chaining ViewResolvers this resolver will check for the 029 * existence of the specified template resources and only return a non-null 030 * View object if a template is actually found. 031 * 032 * @author Sebastien Deleuze 033 * @since 4.2 034 * @see ScriptTemplateConfigurer 035 */ 036public class ScriptTemplateViewResolver extends UrlBasedViewResolver { 037 038 /** 039 * Sets the default {@link #setViewClass view class} to {@link #requiredViewClass}: 040 * by default {@link ScriptTemplateView}. 041 */ 042 public ScriptTemplateViewResolver() { 043 setViewClass(requiredViewClass()); 044 } 045 046 /** 047 * A convenience constructor that allows for specifying {@link #setPrefix prefix} 048 * and {@link #setSuffix suffix} as constructor arguments. 049 * @param prefix the prefix that gets prepended to view names when building a URL 050 * @param suffix the suffix that gets appended to view names when building a URL 051 * @since 4.3 052 */ 053 public ScriptTemplateViewResolver(String prefix, String suffix) { 054 this(); 055 setPrefix(prefix); 056 setSuffix(suffix); 057 } 058 059 060 @Override 061 protected Class<?> requiredViewClass() { 062 return ScriptTemplateView.class; 063 } 064 065}