| Method from org.springframework.core.io.support.PropertiesLoaderSupport Detail: |
protected void loadProperties(Properties props) throws IOException {
if (this.locations != null) {
for (int i = 0; i < this.locations.length; i++) {
Resource location = this.locations[i];
if (logger.isInfoEnabled()) {
logger.info("Loading properties file from " + location);
}
InputStream is = null;
try {
is = location.getInputStream();
if (location.getFilename().endsWith(XML_FILE_EXTENSION)) {
this.propertiesPersister.loadFromXml(props, is);
}
else {
if (this.fileEncoding != null) {
this.propertiesPersister.load(props, new InputStreamReader(is, this.fileEncoding));
}
else {
this.propertiesPersister.load(props, is);
}
}
}
catch (IOException ex) {
if (this.ignoreResourceNotFound) {
if (logger.isWarnEnabled()) {
logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
}
}
else {
throw ex;
}
}
finally {
if (is != null) {
is.close();
}
}
}
}
}
Load properties into the given instance. |
protected Properties mergeProperties() throws IOException {
Properties result = new Properties();
if (this.localOverride) {
// Load properties from file upfront, to let local properties override.
loadProperties(result);
}
if (this.localProperties != null) {
for (int i = 0; i < this.localProperties.length; i++) {
CollectionUtils.mergePropertiesIntoMap(this.localProperties[i], result);
}
}
if (!this.localOverride) {
// Load properties from file afterwards, to let those properties override.
loadProperties(result);
}
return result;
}
Return a merged Properties instance containing both the
loaded properties and properties set on this FactoryBean. |
public void setFileEncoding(String encoding) {
this.fileEncoding = encoding;
}
Set the encoding to use for parsing properties files.
Default is none, using the java.util.Properties
default encoding.
Only applies to classic properties files, not to XML files. |
public void setIgnoreResourceNotFound(boolean ignoreResourceNotFound) {
this.ignoreResourceNotFound = ignoreResourceNotFound;
}
|
public void setLocalOverride(boolean localOverride) {
this.localOverride = localOverride;
}
Set whether local properties override properties from files.
Default is "false": Properties from files override local defaults.
Can be switched to "true" to let local properties override defaults
from files. |
public void setLocation(Resource location) {
this.locations = new Resource[] {location};
}
Set a location of a properties file to be loaded.
Can point to a classic properties file or to an XML file
that follows JDK 1.5's properties XML format. |
public void setLocations(Resource[] locations) {
this.locations = locations;
}
Set locations of properties files to be loaded.
Can point to classic properties files or to XML files
that follow JDK 1.5's properties XML format.
Note: Properties defined in later files will override
properties defined earlier files, in case of overlapping keys.
Hence, make sure that the most specific files are the last
ones in the given list of locations. |
public void setProperties(Properties properties) {
this.localProperties = new Properties[] {properties};
}
Set local properties, e.g. via the "props" tag in XML bean definitions.
These can be considered defaults, to be overridden by properties
loaded from files. |
public void setPropertiesArray(Properties[] propertiesArray) {
this.localProperties = propertiesArray;
}
Set local properties, e.g. via the "props" tag in XML bean definitions,
allowing for merging multiple properties sets into one. |
public void setPropertiesPersister(PropertiesPersister propertiesPersister) {
this.propertiesPersister =
(propertiesPersister != null ? propertiesPersister : new DefaultPropertiesPersister());
}
Set the PropertiesPersister to use for parsing properties files.
The default is DefaultPropertiesPersister. |