Browse Source

Polishing

pull/36422/head
Juergen Hoeller 2 weeks ago
parent
commit
4734c15d81
  1. 2
      spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java
  2. 18
      spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java
  3. 11
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java

2
spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java

@ -55,7 +55,7 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage @@ -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

18
spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java

@ -95,10 +95,12 @@ import org.springframework.util.StringUtils; @@ -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 @@ -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 @@ -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 @@ -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;

11
spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java

@ -114,21 +114,12 @@ final class PersistenceUnitReader { @@ -114,21 +114,12 @@ final class PersistenceUnitReader {
}
/**
* Parse and build all persistence unit infos defined in the specified XML file(s).
* @param persistenceXmlLocation the resource location (can be a pattern)
* @return the resulting PersistenceUnitInfo instances
*/
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String persistenceXmlLocation) {
return readPersistenceUnitInfos(new String[] {persistenceXmlLocation});
}
/**
* Parse and build all persistence unit infos defined in the given XML files.
* @param persistenceXmlLocations the resource locations (can be patterns)
* @return the resulting PersistenceUnitInfo instances
*/
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) {
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String... persistenceXmlLocations) {
ErrorHandler handler = new SimpleSaxErrorHandler(logger);
List<SpringPersistenceUnitInfo> infos = new ArrayList<>(1);
String resourceLocation = null;

Loading…
Cancel
Save