001/* 002 * Copyright 2012-2018 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; 020import java.nio.charset.StandardCharsets; 021import java.util.List; 022 023import org.springframework.boot.context.properties.ConfigurationProperties; 024import org.springframework.http.MediaType; 025import org.springframework.util.MimeType; 026import org.springframework.util.unit.DataSize; 027 028/** 029 * Properties for Thymeleaf. 030 * 031 * @author Stephane Nicoll 032 * @author Brian Clozel 033 * @author Daniel Fernández 034 * @author Kazuki Shimizu 035 * @since 1.2.0 036 */ 037@ConfigurationProperties(prefix = "spring.thymeleaf") 038public class ThymeleafProperties { 039 040 private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; 041 042 public static final String DEFAULT_PREFIX = "classpath:/templates/"; 043 044 public static final String DEFAULT_SUFFIX = ".html"; 045 046 /** 047 * Whether to check that the template exists before rendering it. 048 */ 049 private boolean checkTemplate = true; 050 051 /** 052 * Whether to check that the templates location exists. 053 */ 054 private boolean checkTemplateLocation = true; 055 056 /** 057 * Prefix that gets prepended to view names when building a URL. 058 */ 059 private String prefix = DEFAULT_PREFIX; 060 061 /** 062 * Suffix that gets appended to view names when building a URL. 063 */ 064 private String suffix = DEFAULT_SUFFIX; 065 066 /** 067 * Template mode to be applied to templates. See also Thymeleaf's TemplateMode enum. 068 */ 069 private String mode = "HTML"; 070 071 /** 072 * Template files encoding. 073 */ 074 private Charset encoding = DEFAULT_ENCODING; 075 076 /** 077 * Whether to 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 (patterns allowed) that can be resolved. 090 */ 091 private String[] viewNames; 092 093 /** 094 * Comma-separated list of view names (patterns allowed) that should be excluded from 095 * resolution. 096 */ 097 private String[] excludedViewNames; 098 099 /** 100 * Enable the SpringEL compiler in SpringEL expressions. 101 */ 102 private boolean enableSpringElCompiler; 103 104 /** 105 * Whether hidden form inputs acting as markers for checkboxes should be rendered 106 * before the checkbox element itself. 107 */ 108 private boolean renderHiddenMarkersBeforeCheckboxes = false; 109 110 /** 111 * Whether to enable Thymeleaf view resolution for Web frameworks. 112 */ 113 private boolean enabled = true; 114 115 private final Servlet servlet = new Servlet(); 116 117 private final Reactive reactive = new Reactive(); 118 119 public boolean isEnabled() { 120 return this.enabled; 121 } 122 123 public void setEnabled(boolean enabled) { 124 this.enabled = enabled; 125 } 126 127 public boolean isCheckTemplate() { 128 return this.checkTemplate; 129 } 130 131 public void setCheckTemplate(boolean checkTemplate) { 132 this.checkTemplate = checkTemplate; 133 } 134 135 public boolean isCheckTemplateLocation() { 136 return this.checkTemplateLocation; 137 } 138 139 public void setCheckTemplateLocation(boolean checkTemplateLocation) { 140 this.checkTemplateLocation = checkTemplateLocation; 141 } 142 143 public String getPrefix() { 144 return this.prefix; 145 } 146 147 public void setPrefix(String prefix) { 148 this.prefix = prefix; 149 } 150 151 public String getSuffix() { 152 return this.suffix; 153 } 154 155 public void setSuffix(String suffix) { 156 this.suffix = suffix; 157 } 158 159 public String getMode() { 160 return this.mode; 161 } 162 163 public void setMode(String mode) { 164 this.mode = mode; 165 } 166 167 public Charset getEncoding() { 168 return this.encoding; 169 } 170 171 public void setEncoding(Charset encoding) { 172 this.encoding = encoding; 173 } 174 175 public boolean isCache() { 176 return this.cache; 177 } 178 179 public void setCache(boolean cache) { 180 this.cache = cache; 181 } 182 183 public Integer getTemplateResolverOrder() { 184 return this.templateResolverOrder; 185 } 186 187 public void setTemplateResolverOrder(Integer templateResolverOrder) { 188 this.templateResolverOrder = templateResolverOrder; 189 } 190 191 public String[] getExcludedViewNames() { 192 return this.excludedViewNames; 193 } 194 195 public void setExcludedViewNames(String[] excludedViewNames) { 196 this.excludedViewNames = excludedViewNames; 197 } 198 199 public String[] getViewNames() { 200 return this.viewNames; 201 } 202 203 public void setViewNames(String[] viewNames) { 204 this.viewNames = viewNames; 205 } 206 207 public boolean isEnableSpringElCompiler() { 208 return this.enableSpringElCompiler; 209 } 210 211 public void setEnableSpringElCompiler(boolean enableSpringElCompiler) { 212 this.enableSpringElCompiler = enableSpringElCompiler; 213 } 214 215 public boolean isRenderHiddenMarkersBeforeCheckboxes() { 216 return this.renderHiddenMarkersBeforeCheckboxes; 217 } 218 219 public void setRenderHiddenMarkersBeforeCheckboxes( 220 boolean renderHiddenMarkersBeforeCheckboxes) { 221 this.renderHiddenMarkersBeforeCheckboxes = renderHiddenMarkersBeforeCheckboxes; 222 } 223 224 public Reactive getReactive() { 225 return this.reactive; 226 } 227 228 public Servlet getServlet() { 229 return this.servlet; 230 } 231 232 public static class Servlet { 233 234 /** 235 * Content-Type value written to HTTP responses. 236 */ 237 private MimeType contentType = MimeType.valueOf("text/html"); 238 239 /** 240 * Whether Thymeleaf should start writing partial output as soon as possible or 241 * buffer until template processing is finished. 242 */ 243 private boolean producePartialOutputWhileProcessing = true; 244 245 public MimeType getContentType() { 246 return this.contentType; 247 } 248 249 public void setContentType(MimeType contentType) { 250 this.contentType = contentType; 251 } 252 253 public boolean isProducePartialOutputWhileProcessing() { 254 return this.producePartialOutputWhileProcessing; 255 } 256 257 public void setProducePartialOutputWhileProcessing( 258 boolean producePartialOutputWhileProcessing) { 259 this.producePartialOutputWhileProcessing = producePartialOutputWhileProcessing; 260 } 261 262 } 263 264 public static class Reactive { 265 266 /** 267 * Maximum size of data buffers used for writing to the response. Templates will 268 * execute in CHUNKED mode by default if this is set. 269 */ 270 private DataSize maxChunkSize = DataSize.ofBytes(0); 271 272 /** 273 * Media types supported by the view technology. 274 */ 275 private List<MediaType> mediaTypes; 276 277 /** 278 * Comma-separated list of view names (patterns allowed) that should be executed 279 * in FULL mode even if a max chunk size is set. 280 */ 281 private String[] fullModeViewNames; 282 283 /** 284 * Comma-separated list of view names (patterns allowed) that should be the only 285 * ones executed in CHUNKED mode when a max chunk size is set. 286 */ 287 private String[] chunkedModeViewNames; 288 289 public List<MediaType> getMediaTypes() { 290 return this.mediaTypes; 291 } 292 293 public void setMediaTypes(List<MediaType> mediaTypes) { 294 this.mediaTypes = mediaTypes; 295 } 296 297 public DataSize getMaxChunkSize() { 298 return this.maxChunkSize; 299 } 300 301 public void setMaxChunkSize(DataSize maxChunkSize) { 302 this.maxChunkSize = maxChunkSize; 303 } 304 305 public String[] getFullModeViewNames() { 306 return this.fullModeViewNames; 307 } 308 309 public void setFullModeViewNames(String[] fullModeViewNames) { 310 this.fullModeViewNames = fullModeViewNames; 311 } 312 313 public String[] getChunkedModeViewNames() { 314 return this.chunkedModeViewNames; 315 } 316 317 public void setChunkedModeViewNames(String[] chunkedModeViewNames) { 318 this.chunkedModeViewNames = chunkedModeViewNames; 319 } 320 321 } 322 323}