public class PropertyFileConnector extends AbstractPropertyConnector
Properties
-File implementation of an Connector
.
Example usage read property File from Classpath or Filepath:
In this case a prefix "file:" or "classpath:" is required.
<settings4j:configuration xmlns:settings4j='http://settings4j.org/'> <connector name="PropertyFileConnector" class="org.settings4j.connector.PropertyFileConnector"> <param name="propertyFromPath" value="classpath:org/settings4j/config/propertyFile.properties" /> </connector> </settings4j:configuration>
In this Example you can configure the path to your Property-File via System-Properties or per Server-JNDI-Context.
E.g.: Start your application with: "-DmyAppConfig=file:/somePath/myConfig.properties"
<settings4j:configuration xmlns:settings4j='http://settings4j.org/'> <connector name="PropertyFileConnector" class="org.settings4j.connector.PropertyFileConnector"> <param name="propertyFromPath" value="${connectors.string['myAppConfig']}" /> <connector-ref ref="SystemPropertyConnector" /> <connector-ref ref="JNDIConnector" /> </connector> <connector name="SystemPropertyConnector" class="org.settings4j.connector.SystemPropertyConnector"/> <connector name="JNDIConnector" class="org.settings4j.connector.JNDIConnector"/> </settings4j:configuration>
In many application it is required to configure some paths.
Some Examples are:
The chance are good, that you want place this folders somewhere relative to the property file.
You must only set the parameter "resolveRelativePaths" on the PropertyFileConnector to "true", and all values from the Property-File which starts with
"file:." will be resolved relative to the Property-File.
<settings4j:configuration xmlns:settings4j='http://settings4j.org/'> <connector name="SystemPropertyConnector" class="org.settings4j.connector.SystemPropertyConnector"/> <connector name="PropertyFileConnector" class="org.settings4j.connector.PropertyFileConnector"> <param name="propertyFromPath" value="${connectors.string['myAppConfig']}" /> <param name="resolveRelativePaths" value="true /> <connector-ref ref="SystemPropertyConnector" /> </connector> </settings4j:configuration>
With this config, you can start your app with "-DmyAppConfig=file:/somePath/myConfig.properties"
.
In "myConfig.properties" you have somewhere configured the property:
xyz=file:./test.xml
The Settings4j.getString("xyz") will return the URL
-Qualified path: "file:/somePath/test.xml"
Constructor and Description |
---|
PropertyFileConnector() |
Modifier and Type | Method and Description |
---|---|
(package private) URL |
getPropertyFileFolderUrl() |
String |
getString(String key)
return a String-Value for the given key.
|
void |
setProperty(Properties property) |
void |
setPropertyFromPath(String propertyPath) |
void |
setResolveRelativePaths(boolean resolveRelativePaths) |
getContent, getObject
addConnector, getConnectors, getContentResolver, getName, getObjectResolver, init, setContentResolver, setName, setObjectResolver
public String getString(String key)
Connector
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public void setProperty(Properties property)
URL getPropertyFileFolderUrl()
public void setResolveRelativePaths(boolean resolveRelativePaths)
resolveRelativePaths
- set to true if Property Values wit a relative path (starting with "file:.") should be replace with a full qualified URL Path relative to the
Property-Filepublic void setPropertyFromPath(String propertyPath)
propertyPath
- The filepath to a Property-File. Supported prefixes: "file:" and "classpath:".Copyright © 2008–2016 Brabenetz Harald, Austria. All rights reserved.