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.context; 018 019import java.nio.charset.Charset; 020import java.nio.charset.StandardCharsets; 021import java.time.Duration; 022import java.time.temporal.ChronoUnit; 023 024import org.springframework.boot.convert.DurationUnit; 025 026/** 027 * Configuration properties for Message Source. 028 * 029 * @author Stephane Nicoll 030 * @author Kedar Joshi 031 * @since 2.0.0 032 */ 033public class MessageSourceProperties { 034 035 /** 036 * Comma-separated list of basenames (essentially a fully-qualified classpath 037 * location), each following the ResourceBundle convention with relaxed support for 038 * slash based locations. If it doesn't contain a package qualifier (such as 039 * "org.mypackage"), it will be resolved from the classpath root. 040 */ 041 private String basename = "messages"; 042 043 /** 044 * Message bundles encoding. 045 */ 046 private Charset encoding = StandardCharsets.UTF_8; 047 048 /** 049 * Loaded resource bundle files cache duration. When not set, bundles are cached 050 * forever. If a duration suffix is not specified, seconds will be used. 051 */ 052 @DurationUnit(ChronoUnit.SECONDS) 053 private Duration cacheDuration; 054 055 /** 056 * Whether to fall back to the system Locale if no files for a specific Locale have 057 * been found. if this is turned off, the only fallback will be the default file (e.g. 058 * "messages.properties" for basename "messages"). 059 */ 060 private boolean fallbackToSystemLocale = true; 061 062 /** 063 * Whether to always apply the MessageFormat rules, parsing even messages without 064 * arguments. 065 */ 066 private boolean alwaysUseMessageFormat = false; 067 068 /** 069 * Whether to use the message code as the default message instead of throwing a 070 * "NoSuchMessageException". Recommended during development only. 071 */ 072 private boolean useCodeAsDefaultMessage = false; 073 074 public String getBasename() { 075 return this.basename; 076 } 077 078 public void setBasename(String basename) { 079 this.basename = basename; 080 } 081 082 public Charset getEncoding() { 083 return this.encoding; 084 } 085 086 public void setEncoding(Charset encoding) { 087 this.encoding = encoding; 088 } 089 090 public Duration getCacheDuration() { 091 return this.cacheDuration; 092 } 093 094 public void setCacheDuration(Duration cacheDuration) { 095 this.cacheDuration = cacheDuration; 096 } 097 098 public boolean isFallbackToSystemLocale() { 099 return this.fallbackToSystemLocale; 100 } 101 102 public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) { 103 this.fallbackToSystemLocale = fallbackToSystemLocale; 104 } 105 106 public boolean isAlwaysUseMessageFormat() { 107 return this.alwaysUseMessageFormat; 108 } 109 110 public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) { 111 this.alwaysUseMessageFormat = alwaysUseMessageFormat; 112 } 113 114 public boolean isUseCodeAsDefaultMessage() { 115 return this.useCodeAsDefaultMessage; 116 } 117 118 public void setUseCodeAsDefaultMessage(boolean useCodeAsDefaultMessage) { 119 this.useCodeAsDefaultMessage = useCodeAsDefaultMessage; 120 } 121 122}