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.reactive.config;
018
019import org.springframework.util.Assert;
020import org.springframework.web.reactive.result.view.UrlBasedViewResolver;
021
022/**
023 * Assist with configuring properties of a {@link UrlBasedViewResolver}.
024 *
025 * @author Rossen Stoyanchev
026 * @since 5.0
027 */
028public class UrlBasedViewResolverRegistration {
029
030        private final UrlBasedViewResolver viewResolver;
031
032
033        public UrlBasedViewResolverRegistration(UrlBasedViewResolver viewResolver) {
034                Assert.notNull(viewResolver, "ViewResolver must not be null");
035                this.viewResolver = viewResolver;
036        }
037
038
039        /**
040         * Set the prefix that gets prepended to view names when building a URL.
041         * @see UrlBasedViewResolver#setPrefix
042         */
043        public UrlBasedViewResolverRegistration prefix(String prefix) {
044                this.viewResolver.setPrefix(prefix);
045                return this;
046        }
047
048        /**
049         * Set the suffix that gets appended to view names when building a URL.
050         * @see UrlBasedViewResolver#setSuffix
051         */
052        public UrlBasedViewResolverRegistration suffix(String suffix) {
053                this.viewResolver.setSuffix(suffix);
054                return this;
055        }
056
057        /**
058         * Set the view class that should be used to create views.
059         * @see UrlBasedViewResolver#setViewClass
060         */
061        public UrlBasedViewResolverRegistration viewClass(Class<?> viewClass) {
062                this.viewResolver.setViewClass(viewClass);
063                return this;
064        }
065
066        /**
067         * Set the view names (or name patterns) that can be handled by this view
068         * resolver. View names can contain simple wildcards such that 'my*', '*Report'
069         * and '*Repo*' will all match the view name 'myReport'.
070         * @see UrlBasedViewResolver#setViewNames
071         */
072        public UrlBasedViewResolverRegistration viewNames(String... viewNames) {
073                this.viewResolver.setViewNames(viewNames);
074                return this;
075        }
076
077        protected UrlBasedViewResolver getViewResolver() {
078                return this.viewResolver;
079        }
080
081}