Reorganize methods in ReloadableResourceBundleMessageSource
See gh-30369
This commit is contained in:
@@ -398,45 +398,6 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the specified bundle {@code filename} into a concrete {@link Resource},
|
||||
* potentially checking multiple sources or file extensions.
|
||||
* <p>If no suitable concrete {@code Resource} can be resolved, this method
|
||||
* returns a {@code Resource} for which {@link Resource#exists()} returns
|
||||
* {@code false}, which gets subsequently ignored.
|
||||
* <p>This can be leveraged to check the last modification timestamp or to load
|
||||
* properties from alternative sources — for example, from an XML BLOB
|
||||
* in a database, or from properties serialized using a custom format such as
|
||||
* JSON.
|
||||
* <p>The default implementation delegates to the configured
|
||||
* {@link #setResourceLoader(ResourceLoader) ResourceLoader} to resolve
|
||||
* resources, first checking for an existing {@code Resource} with a
|
||||
* {@code .properties} extension, and otherwise returning a {@code Resource}
|
||||
* with a {@code .xml} extension.
|
||||
* <p>When overriding this method, {@link #loadProperties(Resource, String)}
|
||||
* <strong>must</strong> be capable of loading properties from any type of
|
||||
* {@code Resource} returned by this method. As a consequence, implementors
|
||||
* are strongly encouraged to also override {@code loadProperties()}.
|
||||
* <p>As an alternative to overriding this method, you can configure a
|
||||
* {@link #setPropertiesPersister(PropertiesPersister) PropertiesPersister}
|
||||
* that is capable of dealing with all resources returned by this method.
|
||||
* Please note, however, that the default {@code loadProperties()} implementation
|
||||
* uses {@link PropertiesPersister#loadFromXml(Properties, InputStream) loadFromXml}
|
||||
* for XML resources and otherwise uses the two
|
||||
* {@link PropertiesPersister#load(Properties, InputStream) load} methods
|
||||
* for other types of resources.
|
||||
* @param filename the bundle filename (basename + Locale)
|
||||
* @return the {@code Resource} to use
|
||||
* @since 6.1
|
||||
*/
|
||||
protected Resource determineResource(String filename) {
|
||||
Resource propertiesResource = this.resourceLoader.getResource(filename + PROPERTIES_SUFFIX);
|
||||
if (propertiesResource.exists()) {
|
||||
return propertiesResource;
|
||||
}
|
||||
return this.resourceLoader.getResource(filename + XML_SUFFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the PropertiesHolder for the given bundle filename.
|
||||
* <p>The holder can be {@code null} if not cached before, or a timed-out cache entry
|
||||
@@ -498,6 +459,45 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
|
||||
return propHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the specified bundle {@code filename} into a concrete {@link Resource},
|
||||
* potentially checking multiple sources or file extensions.
|
||||
* <p>If no suitable concrete {@code Resource} can be resolved, this method
|
||||
* returns a {@code Resource} for which {@link Resource#exists()} returns
|
||||
* {@code false}, which gets subsequently ignored.
|
||||
* <p>This can be leveraged to check the last modification timestamp or to load
|
||||
* properties from alternative sources — for example, from an XML BLOB
|
||||
* in a database, or from properties serialized using a custom format such as
|
||||
* JSON.
|
||||
* <p>The default implementation delegates to the configured
|
||||
* {@link #setResourceLoader(ResourceLoader) ResourceLoader} to resolve
|
||||
* resources, first checking for an existing {@code Resource} with a
|
||||
* {@code .properties} extension, and otherwise returning a {@code Resource}
|
||||
* with a {@code .xml} extension.
|
||||
* <p>When overriding this method, {@link #loadProperties(Resource, String)}
|
||||
* <strong>must</strong> be capable of loading properties from any type of
|
||||
* {@code Resource} returned by this method. As a consequence, implementors
|
||||
* are strongly encouraged to also override {@code loadProperties()}.
|
||||
* <p>As an alternative to overriding this method, you can configure a
|
||||
* {@link #setPropertiesPersister(PropertiesPersister) PropertiesPersister}
|
||||
* that is capable of dealing with all resources returned by this method.
|
||||
* Please note, however, that the default {@code loadProperties()} implementation
|
||||
* uses {@link PropertiesPersister#loadFromXml(Properties, InputStream) loadFromXml}
|
||||
* for XML resources and otherwise uses the two
|
||||
* {@link PropertiesPersister#load(Properties, InputStream) load} methods
|
||||
* for other types of resources.
|
||||
* @param filename the bundle filename (basename + Locale)
|
||||
* @return the {@code Resource} to use
|
||||
* @since 6.1
|
||||
*/
|
||||
protected Resource determineResource(String filename) {
|
||||
Resource propertiesResource = this.resourceLoader.getResource(filename + PROPERTIES_SUFFIX);
|
||||
if (propertiesResource.exists()) {
|
||||
return propertiesResource;
|
||||
}
|
||||
return this.resourceLoader.getResource(filename + XML_SUFFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the properties from the given resource.
|
||||
* @param resource the resource to load from
|
||||
|
||||
Reference in New Issue
Block a user