File |
Line |
net\sf\prefixedproperties\spring\PrefixedPropertiesPlaceholderConfigurer.java |
252 |
net\sf\prefixedproperties\spring\PrefixedPropertyOverrideConfigurer.java |
197 |
}
/**
* 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.
*
* @param properties
* the new properties
*/
@Override
public void setProperties(final Properties properties) {
localProperties = new Properties[] { properties };
}
/**
* Set local properties, e.g. via the "props" tag in XML bean definitions, allowing for merging multiple properties sets into one.
*
* @param propertiesArray
* the new properties array
*/
@Override
public void setPropertiesArray(final Properties[] propertiesArray) {
localProperties = propertiesArray;
}
/**
* Creates the properties.
*
* @return the prefixed properties
*/
protected synchronized PrefixedProperties createProperties() {
if (myProperties == null) {
PrefixedProperties resultProperties = null;
String environment = defaultPrefix;
if (environmentFactory != null) {
environment = environmentFactory.getEnvironment();
} else if (defaultPrefixSystemPropertyKey != null) {
environment = System.getProperty(defaultPrefixSystemPropertyKey);
if (environment == null) {
if (logger.isWarnEnabled()) {
logger.warn(String.format("Didn't found system property key to set default prefix: %1s", defaultPrefixSystemPropertyKey));
}
}
}
if (prefixConfigList != null) {
resultProperties = PrefixedProperties.createCascadingPrefixProperties(prefixConfigList);
} else {
if (environment != null) {
resultProperties = PrefixedProperties.createCascadingPrefixProperties(environment);
} else {
resultProperties = new PrefixedProperties();
}
}
resultProperties.setDefaultPrefix(environment);
if (logger.isInfoEnabled()) {
logger.info(String.format("Setting default prefix to: %1s", environment));
}
myProperties = resultProperties;
}
return myProperties;
}
/**
* Load properties.
*
* @param props
* the props
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Override
protected void loadProperties(final Properties props) throws IOException {
if (locations != null) {
for (int i = 0; i < locations.length; i++) {
final Resource location = locations[i];
if (logger.isInfoEnabled()) {
logger.info("Loading properties file from " + location);
}
File file = null;
InputStream is = null;
try {
try {
file = location.getFile();
is = new BufferedInputStream(new FileInputStream(file));
} catch (final IOException ie) {//ignore
} finally {
if (file == null) {
is = location.getInputStream();
}
}
if (location.getFilename().toLowerCase().endsWith(XML_FILE_EXTENSION)) {
persister.loadFromXml(props, is);
} else if (location.getFilename().toLowerCase().endsWith(JSON_FILE_EXTENSION)) {
if (fileEncoding != null) {
persister.loadFromJson(props, new InputStreamReader(is, Charset.forName(fileEncoding)));
} else {
persister.loadFromJson(props, is);
}
} else {
if (fileEncoding != null) {
persister.load(props, new InputStreamReader(is, Charset.forName(fileEncoding)));
} else {
persister.load(props, is);
}
}
} catch (final IOException ex) {
if (ignoreResourceNotFound) {
if (logger.isWarnEnabled()) {
logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
}
} else {
throw ex;
}
} finally {
if (is != null) {
is.close();
}
}
}
}
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#mergeProperties()
*/
@Override
protected Properties mergeProperties() throws IOException {
final PrefixedProperties myProperties = createProperties();
if (localOverride) {
loadProperties(myProperties);
}
if (localProperties != null) {
for (int i = 0; i < localProperties.length; i++) {
|
File |
Line |
net\sf\prefixedproperties\spring\PrefixedPropertiesFactoryBean.java |
202 |
net\sf\prefixedproperties\spring\PrefixedPropertyOverrideConfigurer.java |
238 |
}
}
if (prefixConfigList != null) {
resultProperties = PrefixedProperties.createCascadingPrefixProperties(prefixConfigList);
} else {
if (environment != null) {
resultProperties = PrefixedProperties.createCascadingPrefixProperties(environment);
} else {
resultProperties = new PrefixedProperties();
}
}
resultProperties.setDefaultPrefix(environment);
if (logger.isInfoEnabled()) {
logger.info(String.format("Setting default prefix to: %1s", environment));
}
myProperties = resultProperties;
}
return myProperties;
}
@Override
protected void loadProperties(final Properties props) throws IOException {
if (locations != null) {
for (int i = 0; i < locations.length; i++) {
final Resource location = locations[i];
if (logger.isInfoEnabled()) {
logger.info("Loading properties file from " + location);
}
File file = null;
InputStream is = null;
try {
try {
file = location.getFile();
is = new BufferedInputStream(new FileInputStream(file));
} catch (final IOException ie) {//ignore
} finally {
if (file == null) {
is = location.getInputStream();
}
}
if (location.getFilename().toLowerCase().endsWith(XML_FILE_EXTENSION)) {
persister.loadFromXml(props, is);
} else if (location.getFilename().toLowerCase().endsWith(JSON_FILE_EXTENSION)) {
if (fileEncoding != null) {
persister.loadFromJson(props, new InputStreamReader(is, Charset.forName(fileEncoding)));
} else {
persister.loadFromJson(props, is);
}
} else {
if (fileEncoding != null) {
persister.load(props, new InputStreamReader(is, Charset.forName(fileEncoding)));
} else {
persister.load(props, is);
}
}
} catch (final IOException ex) {
if (ignoreResourceNotFound) {
if (logger.isWarnEnabled()) {
logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
|
File |
Line |
net\sf\prefixedproperties\spring\PrefixedPropertiesFactoryBean.java |
269 |
net\sf\prefixedproperties\spring\PrefixedPropertiesPlaceholderConfigurer.java |
346 |
logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
}
} else {
throw ex;
}
} finally {
if (is != null) {
is.close();
}
}
}
}
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#mergeProperties()
*/
@Override
protected Properties mergeProperties() throws IOException {
final PrefixedProperties myProperties = createProperties();
if (localOverride) {
// Load properties from file upfront, to let local properties override.
loadProperties(myProperties);
}
if (localProperties != null) {
for (int i = 0; i < localProperties.length; i++) {
final Properties props = localProperties[i];
if (props != null) {
for (final Enumeration<Object> en = props.keys(); en.hasMoreElements();) {
final Object key = en.nextElement();
myProperties.put(key, props.get(key));
}
}
}
}
if (!localOverride) {
// Load properties from file afterwards, to let those properties override.
loadProperties(myProperties);
}
return myProperties;
}
}
|
File |
Line |
net\sf\prefixedproperties\spring\PrefixedPropertiesFactoryBean.java |
83 |
net\sf\prefixedproperties\spring\PrefixedPropertiesPlaceholderConfigurer.java |
151 |
}
/**
* Sets the default prefix.
*
* @param defaultPrefix
* the new default prefix
*/
public void setDefaultPrefix(final String defaultPrefix) {
this.defaultPrefix = defaultPrefix;
}
/**
* Sets this method to specify a system property to be used as an environment. The value of the property will be used for setting the default prefix.
* {@link PrefixedProperties#setDefaultPrefix(String)}
*
* @param defaultPrefixSystemPropertyKey
* the new ddefault prefix system property key
*/
public void setDefaultPrefixSystemPropertyKey(final String defaultPrefixSystemPropertyKey) {
this.defaultPrefixSystemPropertyKey = defaultPrefixSystemPropertyKey;
}
/**
* Sets the environment factory.
*
* @param environmentFactory
* the new environment factory
*/
public void setEnvironmentFactory(final EnvironmentFactory environmentFactory) {
this.environmentFactory = environmentFactory;
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#setFileEncoding(java.lang.String)
*/
@Override
public void setFileEncoding(final String encoding) {
fileEncoding = encoding;
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#setIgnoreResourceNotFound(boolean)
*/
@Override
public void setIgnoreResourceNotFound(final boolean ignoreResourceNotFound) {
this.ignoreResourceNotFound = ignoreResourceNotFound;
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#setLocalOverride(boolean)
*/
@Override
public void setLocalOverride(final boolean localOverride) {
this.localOverride = localOverride;
}
/**
* Set a location of a properties file to be loaded.
* <p>
* Can point to a classic properties, json or XML file that follows JDK 1.5's properties XML format.
*
* @param location
* the new location
*/
@Override
public void setLocation(final Resource location) {
locations = new Resource[] { location };
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#setLocations(org.springframework.core.io.Resource[])
*/
@Override
public void setLocations(final Resource[] locations) {
this.locations = locations;
}
/**
* Sets the prefix configs to build up a {@link PrefixedProperties}-Structure.
*
* @param configList
* the new prefix configs
*/
public void setPrefixConfigs(final List<PrefixConfig> configList) {
prefixConfigList = configList;
}
|
File |
Line |
net\sf\prefixedproperties\spring\PrefixedPropertiesFactoryBean.java |
83 |
net\sf\prefixedproperties\spring\PrefixedPropertyOverrideConfigurer.java |
106 |
}
/**
* Sets the default prefix.
*
* @param defaultPrefix
* the new default prefix
*/
public void setDefaultPrefix(final String defaultPrefix) {
this.defaultPrefix = defaultPrefix;
}
/**
* Sets this method to specify a system property to be used as an environment. The value of the property will be used for setting the default prefix.
* {@link PrefixedProperties#setDefaultPrefix(String)}
*
* @param defaultPrefixSystemPropertyKey
* the new ddefault prefix system property key
*/
public void setDefaultPrefixSystemPropertyKey(final String defaultPrefixSystemPropertyKey) {
this.defaultPrefixSystemPropertyKey = defaultPrefixSystemPropertyKey;
}
/**
* Sets the environment factory.
*
* @param environmentFactory
* the new environment factory
*/
public void setEnvironmentFactory(final EnvironmentFactory environmentFactory) {
this.environmentFactory = environmentFactory;
}
/**
* Set the encoding to use for parsing properties files.
* <p>
* Default is none, using the <code>java.util.Properties</code> default encoding.
* <p>
* Only applies to classic properties files, not to XML files.
*
* @param encoding
* the new file encoding
* @see org.springframework.util.PropertiesPersister#load
*/
@Override
public void setFileEncoding(final String encoding) {
fileEncoding = encoding;
}
/**
* Set if failure to find the property resource should be ignored.
* <p>
* "true" is appropriate if the properties file is completely optional. Default is "false".
*
* @param ignoreResourceNotFound
* the new ignore resource not found
*/
@Override
public void setIgnoreResourceNotFound(final boolean ignoreResourceNotFound) {
this.ignoreResourceNotFound = ignoreResourceNotFound;
}
/* (non-Javadoc)
* @see org.springframework.core.io.support.PropertiesLoaderSupport#setLocalOverride(boolean)
*/
@Override
public void setLocalOverride(final boolean localOverride) {
this.localOverride = localOverride;
}
/**
* Set a location of a properties file to be loaded.
* <p>
* Can point to a classic properties file or to an XML file that follows JDK 1.5's properties XML format.
*
* @param location
* the new location
*/
@Override
public void setLocation(final Resource location) {
locations = new Resource[] { location };
}
|