net.sf.jabb.util.prop
Class PropertiesLoader

java.lang.Object
  extended by net.sf.jabb.util.prop.PropertiesLoader

public class PropertiesLoader
extends Object

Utility to load properties from file; It supports both classic text properties file (.properties) format and new 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.
载入Properties的工具类;它支持传统properties文件格式(.properties)和新的xml格式(.xml), 也支持用“*”作为通配符同时匹配这两种格式的文件后缀,以及支持在文件中用“.include=”包含引用别的文件。

Author:
Zhengmao HU (James)

Field Summary
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 Summary
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文件的时候用相对位置。
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INCLUDE_PROPERTY_NAME

public static final String DEFAULT_INCLUDE_PROPERTY_NAME
The default inclusion keyword, which is ".include".
缺省的包含属性关键字。为".include"

See Also:
Constant Field Values

DELIMITERS

public static final 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"。

See Also:
Constant Field Values

baseClass

protected Class<?> baseClass

replacePlaceHolders

protected boolean replacePlaceHolders
Constructor Detail

PropertiesLoader

public PropertiesLoader(Class<?> baseClass,
                        boolean replacePlaceHolders)
Create a new instance that locates properties files via relative path.
创建一个新的实例,寻找properties文件的时候用相对位置。

baseClass.Class.getResourceAsStream(String) will be used to read properties files.
读取properties文件的时候将使用baseClass.Class.getResourceAsStream(String)

Parameters:
baseClass - the Class that its location will be used as the base when locating properties files.
这个类的位置将会作为基准位置来寻找properties文件。
replacePlaceHolders - if true, place holders will be replaced by system properties.
如果为true,则其中的占位标志会被系统Properties所替代。 If running inside JBoss, it replace any occurrence of ${p} with the System.getProperty(p) value. If there is no such property p defined, then the ${p} reference will remain unchanged. If the property reference is of the form ${p:v} and there is no such property p, then the default value v will be returned. If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the primary and the secondary properties will be tried in turn, before returning either the unchanged input, or the default value. The property ${/} is replaced with System.getProperty("file.separator") value and the property ${:} is replaced with System.getProperty("path.separator").

PropertiesLoader

public PropertiesLoader(Class<?> baseClass)
Create a new instance that locates properties files via relative path.
创建一个新的实例,寻找properties文件的时候用相对位置。

baseClass.Class.getResourceAsStream(String) will be used to read properties files.
读取properties文件的时候将使用baseClass.Class.getResourceAsStream(String)

Parameters:
baseClass - the Class that its location will be used as the base when locating properties files.
这个类的位置将会作为基准位置来寻找properties文件。

PropertiesLoader

public PropertiesLoader(boolean replacePlaceHolders)
Create a new instance that locates properties files via absolute path.
创建一个新的实例,寻找properties文件的时候用绝对位置。

Thread Context ClassLoader will be used to read properties files.
读取properties文件的时候将使用Thread Context ClassLoaderg。

Parameters:
replacePlaceHolders - if true, place holders will be replaced by system properties.
如果为true,则其中的占位标志会被系统Properties所替代。 If running inside JBoss, it replace any occurrence of ${p} with the System.getProperty(p) value. If there is no such property p defined, then the ${p} reference will remain unchanged. If the property reference is of the form ${p:v} and there is no such property p, then the default value v will be returned. If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the primary and the secondary properties will be tried in turn, before returning either the unchanged input, or the default value. The property ${/} is replaced with System.getProperty("file.separator") value and the property ${:} is replaced with System.getProperty("path.separator").

PropertiesLoader

public PropertiesLoader()
Create a new instance that locates properties files via absolute path.
创建一个新的实例,寻找properties文件的时候用绝对位置。

ClassLoader.ClassLoader.getSystemResourceAsStream(String) will be used to read properties files.
读取properties文件的时候将使用ClassLoader.ClassLoader.getSystemResourceAsStream(String)

Method Detail

replacePlaceHolders

protected Properties replacePlaceHolders(Properties props)
Replace place holders in both keys and values with values defined in system properties.

Parameters:
props -
Returns:

loadWithoutInclude

public Properties loadWithoutInclude(String name)
                              throws InvalidPropertiesFormatException,
                                     IOException
Load properties from resource, without handling of the inclusion.
从指定的资源中载入properties,不处理包含关系。

Parameters:
name - location of the properties file, which can ends with ".*".
properties文件的位置,可以以".*"结尾。
Returns:
null if not found, otherwise return the loaded properties
Throws:
IOException - resource found, but error when reading
InvalidPropertiesFormatException - resource found, but with wrong format

load

protected Properties load(String name,
                          String includePropertyName,
                          Set<String> history)
                   throws InvalidPropertiesFormatException,
                          IOException
(Internal usage only) Load properties from resource, with handling of the inclusion.
(内部使用)从指定的资源中载入properties,处理包含关系。

Parameters:
name - location of the properties file, which can ends with ".*".
properties文件的位置,可以以".*"结尾。
includePropertyName - To override the default inclusion keyword.
如果不想使用缺省的包含属性关键字,可以在这里指定。
history - names of the files that have been loaded before.
Returns:
null if not found, otherwise return the loaded properties
Throws:
IOException - resource found, but error when reading
InvalidPropertiesFormatException - resource found, but with wrong format

load

public Properties load(String name,
                       String includePropertyName)
                throws InvalidPropertiesFormatException,
                       IOException
Load properties from resource, with handling of the inclusion.
从指定的资源中载入properties,处理包含关系。

Parameters:
name - location of the properties file, which can ends with ".*".
properties文件的位置,可以以".*"结尾。
includePropertyName - To override the default inclusion keyword.
如果不想使用缺省的包含属性关键字,可以在这里指定。
Returns:
null if not found, otherwise return the loaded properties
Throws:
IOException - resource found, but error when reading
InvalidPropertiesFormatException - resource found, but with wrong format

load

public Properties load(String name)
                throws InvalidPropertiesFormatException,
                       IOException
Load properties from resource, with handling of the inclusion.
从指定的资源中载入properties,处理包含关系。

Parameters:
name - location of the properties file, which can ends with ".*".
properties文件的位置,可以以".*"结尾。
Returns:
null if not found, otherwise return the loaded properties
Throws:
IOException - resource found, but error when reading
InvalidPropertiesFormatException - resource found, but with wrong format


Copyright © 2012. All Rights Reserved.