mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Polishing
This commit is contained in:
+1
-1
@@ -55,7 +55,7 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage
|
||||
* Set a single basename, following the basic ResourceBundle convention
|
||||
* of not specifying file extension or language codes. The resource location
|
||||
* format is up to the specific {@code MessageSource} implementation.
|
||||
* <p>Regular and XMl properties files are supported: for example, "messages" will find
|
||||
* <p>Regular and XML properties files are supported: for example, "messages" will find
|
||||
* a "messages.properties", "messages_en.properties" etc arrangement as well
|
||||
* as "messages.xml", "messages_en.xml" etc.
|
||||
* @param basename the single basename
|
||||
|
||||
+10
-8
@@ -95,10 +95,12 @@ import org.springframework.util.StringUtils;
|
||||
public class ReloadableResourceBundleMessageSource extends AbstractResourceBasedMessageSource
|
||||
implements ResourceLoaderAware {
|
||||
|
||||
private static final String PROPERTIES_EXTENSION = ".properties";
|
||||
|
||||
private static final String XML_EXTENSION = ".xml";
|
||||
|
||||
|
||||
private List<String> fileExtensions = List.of(".properties", XML_EXTENSION);
|
||||
private List<String> fileExtensions = List.of(PROPERTIES_EXTENSION, XML_EXTENSION);
|
||||
|
||||
private @Nullable Properties fileEncodings;
|
||||
|
||||
@@ -380,18 +382,18 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
||||
StringBuilder temp = new StringBuilder(basename);
|
||||
|
||||
temp.append('_');
|
||||
if (language.length() > 0) {
|
||||
if (!language.isEmpty()) {
|
||||
temp.append(language);
|
||||
result.add(0, temp.toString());
|
||||
}
|
||||
|
||||
temp.append('_');
|
||||
if (country.length() > 0) {
|
||||
if (!country.isEmpty()) {
|
||||
temp.append(country);
|
||||
result.add(0, temp.toString());
|
||||
}
|
||||
|
||||
if (variant.length() > 0 && (language.length() > 0 || country.length() > 0)) {
|
||||
if (!variant.isEmpty() && (!language.isEmpty() || !country.isEmpty())) {
|
||||
temp.append('_').append(variant);
|
||||
result.add(0, temp.toString());
|
||||
}
|
||||
@@ -560,13 +562,13 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
||||
*/
|
||||
protected Properties loadProperties(Resource resource, String filename) throws IOException {
|
||||
Properties props = newProperties();
|
||||
try (InputStream is = resource.getInputStream()) {
|
||||
try (InputStream inputStream = resource.getInputStream()) {
|
||||
String resourceFilename = resource.getFilename();
|
||||
if (resourceFilename != null && resourceFilename.endsWith(XML_EXTENSION)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Loading properties [" + resource.getFilename() + "]");
|
||||
}
|
||||
this.propertiesPersister.loadFromXml(props, is);
|
||||
this.propertiesPersister.loadFromXml(props, inputStream);
|
||||
}
|
||||
else {
|
||||
Charset charset = null;
|
||||
@@ -583,13 +585,13 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Loading properties [" + resource.getFilename() + "] with encoding '" + charset + "'");
|
||||
}
|
||||
this.propertiesPersister.load(props, new InputStreamReader(is, charset));
|
||||
this.propertiesPersister.load(props, new InputStreamReader(inputStream, charset));
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Loading properties [" + resource.getFilename() + "]");
|
||||
}
|
||||
this.propertiesPersister.load(props, is);
|
||||
this.propertiesPersister.load(props, inputStream);
|
||||
}
|
||||
}
|
||||
return props;
|
||||
|
||||
Reference in New Issue
Block a user