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.groovy;
018
019import java.util.Locale;
020
021import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
022
023/**
024 * Convenience subclass of @link AbstractTemplateViewResolver} that supports
025 * {@link GroovyMarkupView} (i.e. Groovy XML/XHTML markup templates) and
026 * custom subclasses of it.
027 *
028 * <p>The view class for all views created by this resolver can be specified
029 * via the {@link #setViewClass(Class)} property.
030 *
031 * <p><b>Note:</b> When chaining ViewResolvers this resolver will check for the
032 * existence of the specified template resources and only return a non-null
033 * View object if a template is actually found.
034 *
035 * @author Brian Clozel
036 * @since 4.1
037 * @see GroovyMarkupConfigurer
038 */
039public class GroovyMarkupViewResolver extends AbstractTemplateViewResolver {
040
041        /**
042         * Sets the default {@link #setViewClass view class} to {@link #requiredViewClass}:
043         * by default {@link GroovyMarkupView}.
044         */
045        public GroovyMarkupViewResolver() {
046                setViewClass(requiredViewClass());
047        }
048
049        /**
050         * A convenience constructor that allows for specifying {@link #setPrefix prefix}
051         * and {@link #setSuffix suffix} as constructor arguments.
052         * @param prefix the prefix that gets prepended to view names when building a URL
053         * @param suffix the suffix that gets appended to view names when building a URL
054         * @since 4.3
055         */
056        public GroovyMarkupViewResolver(String prefix, String suffix) {
057                this();
058                setPrefix(prefix);
059                setSuffix(suffix);
060        }
061
062
063        @Override
064        protected Class<?> requiredViewClass() {
065                return GroovyMarkupView.class;
066        }
067
068        /**
069         * This resolver supports i18n, so cache keys should contain the locale.
070         */
071        @Override
072        protected Object getCacheKey(String viewName, Locale locale) {
073                return viewName + '_' + locale;
074        }
075
076}