public class PropertiesLoader extends Object
xml
properties file (.xml) format;
"*" is supported as widecard to match
the file name name of all of the two formats; Inclusion of files via ".include="
syntax is also supported.xml
格式(.xml),
也支持用“*”作为通配符同时匹配这两种格式的文件后缀,以及支持在文件中用“.include=”包含引用别的文件。Modifier and Type | Field and Description |
---|---|
protected Class<?> |
baseClass |
static String |
DEFAULT_INCLUDE_PROPERTY_NAME
The default inclusion keyword, which is ".include".
缺省的包含属性关键字。为".include" |
static String |
DELIMITERS
If more than one file need to be included, the delimiters that can
be used among file names, which is "[ ,;\t]+include".
如果需要包含多个文件,文件名之间所采用的分隔符,为"[ ,;\t]+include"。 |
protected boolean |
replacePlaceHolders |
Constructor and Description |
---|
PropertiesLoader()
Create a new instance that locates properties files via absolute path.
创建一个新的实例,寻找properties文件的时候用绝对位置。 |
PropertiesLoader(boolean replacePlaceHolders)
Create a new instance that locates properties files via absolute path.
创建一个新的实例,寻找properties文件的时候用绝对位置。 |
PropertiesLoader(Class<?> baseClass)
Create a new instance that locates properties files via relative path.
创建一个新的实例,寻找properties文件的时候用相对位置。 |
PropertiesLoader(Class<?> baseClass,
boolean replacePlaceHolders)
Create a new instance that locates properties files via relative path.
创建一个新的实例,寻找properties文件的时候用相对位置。 |
Modifier and Type | Method and Description |
---|---|
Properties |
load(String name)
Load properties from resource, with handling of the inclusion.
从指定的资源中载入properties,处理包含关系。 |
Properties |
load(String name,
String includePropertyName)
Load properties from resource, with handling of the inclusion.
从指定的资源中载入properties,处理包含关系。 |
protected Properties |
load(String name,
String includePropertyName,
Set<String> history)
(Internal usage only) Load properties from resource, with handling of the inclusion.
(内部使用)从指定的资源中载入properties,处理包含关系。 |
Properties |
loadWithoutInclude(String name)
Load properties from resource, without handling of the inclusion.
从指定的资源中载入properties,不处理包含关系。 |
protected Properties |
replacePlaceHolders(Properties props)
Replace place holders in both keys and values with values defined in system properties.
|
public static final String DEFAULT_INCLUDE_PROPERTY_NAME
public static final String DELIMITERS
protected Class<?> baseClass
protected boolean replacePlaceHolders
public PropertiesLoader(Class<?> baseClass, boolean replacePlaceHolders)
baseClass.Class.getResourceAsStream(String)
will be used to read properties files.
读取properties文件的时候将使用baseClass.Class.getResourceAsStream(String)
。
baseClass
- the Class that its location will be used as the base when locating properties files.replacePlaceHolders
- if true, place holders will be replaced by system properties.public PropertiesLoader(Class<?> baseClass)
baseClass.Class.getResourceAsStream(String)
will be used to read properties files.
读取properties文件的时候将使用baseClass.Class.getResourceAsStream(String)
。
baseClass
- the Class that its location will be used as the base when locating properties files.public PropertiesLoader(boolean replacePlaceHolders)
Thread Context ClassLoader will be used to read properties files.
读取properties文件的时候将使用Thread Context ClassLoaderg。
replacePlaceHolders
- if true, place holders will be replaced by system properties.public PropertiesLoader()
ClassLoader.ClassLoader.getSystemResourceAsStream(String)
will be used to read properties files.
读取properties文件的时候将使用ClassLoader.ClassLoader.getSystemResourceAsStream(String)
。
protected Properties replacePlaceHolders(Properties props)
props
- the input (before processing) which will not be altered during the processing.public Properties loadWithoutInclude(String name) throws InvalidPropertiesFormatException, IOException
name
- location of the properties file, which can ends with ".*".IOException
- resource found, but error when readingInvalidPropertiesFormatException
- resource found, but with wrong formatprotected Properties load(String name, String includePropertyName, Set<String> history) throws InvalidPropertiesFormatException, IOException
name
- location of the properties file, which can ends with ".*".includePropertyName
- To override the default inclusion keyword.history
- names of the files that have been loaded before.IOException
- resource found, but error when readingInvalidPropertiesFormatException
- resource found, but with wrong formatpublic Properties load(String name, String includePropertyName) throws InvalidPropertiesFormatException, IOException
name
- location of the properties file, which can ends with ".*".includePropertyName
- To override the default inclusion keyword.IOException
- resource found, but error when readingInvalidPropertiesFormatException
- resource found, but with wrong formatpublic Properties load(String name) throws InvalidPropertiesFormatException, IOException
name
- location of the properties file, which can ends with ".*".IOException
- resource found, but error when readingInvalidPropertiesFormatException
- resource found, but with wrong formatCopyright © 2014. All Rights Reserved.