001/*
002 * Copyright 2012-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 *      http://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.boot.autoconfigure.thymeleaf;
018
019import java.nio.charset.Charset;
020
021import org.springframework.boot.context.properties.ConfigurationProperties;
022import org.springframework.util.MimeType;
023
024/**
025 * Properties for Thymeleaf.
026 *
027 * @author Stephane Nicoll
028 * @since 1.2.0
029 */
030@ConfigurationProperties(prefix = "spring.thymeleaf")
031public class ThymeleafProperties {
032
033        private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
034
035        private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
036
037        public static final String DEFAULT_PREFIX = "classpath:/templates/";
038
039        public static final String DEFAULT_SUFFIX = ".html";
040
041        /**
042         * Check that the template exists before rendering it (Thymeleaf 3+).
043         */
044        private boolean checkTemplate = true;
045
046        /**
047         * Check that the templates location exists.
048         */
049        private boolean checkTemplateLocation = true;
050
051        /**
052         * Prefix that gets prepended to view names when building a URL.
053         */
054        private String prefix = DEFAULT_PREFIX;
055
056        /**
057         * Suffix that gets appended to view names when building a URL.
058         */
059        private String suffix = DEFAULT_SUFFIX;
060
061        /**
062         * Template mode to be applied to templates. See also StandardTemplateModeHandlers.
063         */
064        private String mode = "HTML5";
065
066        /**
067         * Template encoding.
068         */
069        private Charset encoding = DEFAULT_ENCODING;
070
071        /**
072         * Content-Type value.
073         */
074        private MimeType contentType = DEFAULT_CONTENT_TYPE;
075
076        /**
077         * Enable template caching.
078         */
079        private boolean cache = true;
080
081        /**
082         * Order of the template resolver in the chain. By default, the template resolver is
083         * first in the chain. Order start at 1 and should only be set if you have defined
084         * additional "TemplateResolver" beans.
085         */
086        private Integer templateResolverOrder;
087
088        /**
089         * Comma-separated list of view names that can be resolved.
090         */
091        private String[] viewNames;
092
093        /**
094         * Comma-separated list of view names that should be excluded from resolution.
095         */
096        private String[] excludedViewNames;
097
098        /**
099         * Enable MVC Thymeleaf view resolution.
100         */
101        private boolean enabled = true;
102
103        public boolean isEnabled() {
104                return this.enabled;
105        }
106
107        public void setEnabled(boolean enabled) {
108                this.enabled = enabled;
109        }
110
111        public boolean isCheckTemplate() {
112                return this.checkTemplate;
113        }
114
115        public void setCheckTemplate(boolean checkTemplate) {
116                this.checkTemplate = checkTemplate;
117        }
118
119        public boolean isCheckTemplateLocation() {
120                return this.checkTemplateLocation;
121        }
122
123        public void setCheckTemplateLocation(boolean checkTemplateLocation) {
124                this.checkTemplateLocation = checkTemplateLocation;
125        }
126
127        public String getPrefix() {
128                return this.prefix;
129        }
130
131        public void setPrefix(String prefix) {
132                this.prefix = prefix;
133        }
134
135        public String getSuffix() {
136                return this.suffix;
137        }
138
139        public void setSuffix(String suffix) {
140                this.suffix = suffix;
141        }
142
143        public String getMode() {
144                return this.mode;
145        }
146
147        public void setMode(String mode) {
148                this.mode = mode;
149        }
150
151        public Charset getEncoding() {
152                return this.encoding;
153        }
154
155        public void setEncoding(Charset encoding) {
156                this.encoding = encoding;
157        }
158
159        public MimeType getContentType() {
160                return this.contentType;
161        }
162
163        public void setContentType(MimeType contentType) {
164                this.contentType = contentType;
165        }
166
167        public boolean isCache() {
168                return this.cache;
169        }
170
171        public void setCache(boolean cache) {
172                this.cache = cache;
173        }
174
175        public Integer getTemplateResolverOrder() {
176                return this.templateResolverOrder;
177        }
178
179        public void setTemplateResolverOrder(Integer templateResolverOrder) {
180                this.templateResolverOrder = templateResolverOrder;
181        }
182
183        public String[] getExcludedViewNames() {
184                return this.excludedViewNames;
185        }
186
187        public void setExcludedViewNames(String[] excludedViewNames) {
188                this.excludedViewNames = excludedViewNames;
189        }
190
191        public String[] getViewNames() {
192                return this.viewNames;
193        }
194
195        public void setViewNames(String[] viewNames) {
196                this.viewNames = viewNames;
197        }
198
199}