Java Doc for PropertiesConfiguration.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons configuration 1.4 src » org.apache.commons.configuration 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.commons.configuration.AbstractConfiguration
   org.apache.commons.configuration.BaseConfiguration
      org.apache.commons.configuration.AbstractFileConfiguration
         org.apache.commons.configuration.PropertiesConfiguration

All known Subclasses:   org.apache.commons.configuration.XMLPropertiesConfiguration,
PropertiesConfiguration
public class PropertiesConfiguration extends AbstractFileConfiguration (Code)
This is the "classic" Properties loader which loads the values from a single or multiple files (which can be chained with "include =". All given path references are either absolute or relative to the file name supplied in the constructor.

In this class, empty PropertyConfigurations can be built, properties added and later saved. include statements are (obviously) not supported if you don't construct a PropertyConfiguration from a file.

The properties file syntax is explained here, basically it follows the syntax of the stream parsed by java.util.Properties.load and adds several useful extensions:

  • Each property has the syntax key <separator> value. The separators accepted are '=', ':' and any white space character. Examples:
     key1 = value1
     key2 : value2
     key3   value3
  • The key may use any character, separators must be escaped:
     key\:foo = bar
  • value may be separated on different lines if a backslash is placed at the end of the line that continues below.
  • value can contain value delimiters and will then be interpreted as a list of tokens. Default value delimiter is the comma ','. So the following property definition
     key = This property, has multiple, values
     
    will result in a property with three values. You can change the value delimiter using the AbstractConfiguration.setListDelimiter(char) method. Setting the delimiter to 0 will disable value splitting completely.
  • Commas in each token are escaped placing a backslash right before the comma.
  • If a key is used more than once, the values are appended like if they were on the same line separated with commas.
  • Blank lines and lines starting with character '#' or '!' are skipped.
  • If a property is named "include" (or whatever is defined by setInclude() and getInclude() and the value of that property is the full path to a file on disk, that file will be included into the configuration. You can also pull in files relative to the parent configuration file. So if you have something like the following: include = additional.properties Then "additional.properties" is expected to be in the same directory as the parent configuration file. The properties in the included file are added to the parent configuration, they do not replace existing properties with the same key.

Here is an example of a valid extended properties file:

 # lines starting with # are comments
 # This is the simplest property
 key = value
 # A long property may be separated on multiple lines
 longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 # This is a property with many tokens
 tokens_on_a_line = first token, second token
 # This sequence generates exactly the same result
 tokens_on_multiple_lines = first token
 tokens_on_multiple_lines = second token
 # commas may be escaped in tokens
 commas.escaped = Hi\, what'up?
 # properties can reference other properties
 base.prop = /base
 first.prop = ${base.prop}/first
 second.prop = ${first.prop}/second
 

A PropertiesConfiguration object is associated with an instance of the PropertiesConfigurationLayout class, which is responsible for storing the layout of the parsed properties file (i.e. empty lines, comments, and such things). The getLayout() method can be used to obtain this layout object. With setLayout() a new layout object can be set. This should be done before a properties file was loaded.
See Also:   java.util.Properties.load
author:
   Stefano Mazzocchi
author:
   Jon S. Stevens
author:
   Dave Bryson
author:
   Geir Magnusson Jr.
author:
   Leon Messerschmidt
author:
   Kent Johnson
author:
   Daniel Rall
author:
   Ilkka Priha
author:
   Jason van Zyl
author:
   Martin Poeschl
author:
   Henning P. Schmiedehausen
author:
   Eric Pugh
author:
   Oliver Heger
author:
   Emmanuel Bourg
version:
   $Id: PropertiesConfiguration.java 439648 2006-09-02 20:42:10Z oheger $


Inner Class :public static class PropertiesReader extends LineNumberReader
Inner Class :public static class PropertiesWriter extends FilterWriter

Field Summary
final static  StringCOMMENT_CHARS
     Constant for the supported comment characters.

Constructor Summary
public  PropertiesConfiguration()
     Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().
public  PropertiesConfiguration(String fileName)
     Creates and loads the extended properties from the specified file.
public  PropertiesConfiguration(File file)
     Creates and loads the extended properties from the specified file.
public  PropertiesConfiguration(URL url)
     Creates and loads the extended properties from the specified URL.

Method Summary
public  Objectclone()
     Creates a copy of this object.
protected  PropertiesConfigurationLayoutcreateLayout()
     Creates the associated layout object.
public  StringgetHeader()
     Return the comment header.
public static  StringgetInclude()
     Gets the property value for including other properties files.
public  booleangetIncludesAllowed()
     Reports the status of file inclusion.
public synchronized  PropertiesConfigurationLayoutgetLayout()
     Returns the associated layout object.
static  booleanisCommentLine(String line)
     Tests whether a line is a comment, i.e.
public synchronized  voidload(Reader in)
     Load the properties from the given reader.
 booleanpropertyLoaded(String key, String value)
     This method is invoked by the associated PropertiesConfigurationLayout object for each property definition detected in the parsed properties file.
public  voidsave(Writer writer)
     Save the configuration to the specified stream.
public  voidsetBasePath(String basePath)
     Extend the setBasePath method to turn includes on and off based on the existence of a base path.
public  voidsetHeader(String header)
     Set the comment header.
public static  voidsetInclude(String inc)
     Sets the property value for including other properties files.
protected  voidsetIncludesAllowed(boolean includesAllowed)
     Controls whether additional files can be loaded by the include = statement or not.
public synchronized  voidsetLayout(PropertiesConfigurationLayout layout)
     Sets the associated layout object.
protected static  StringunescapeJava(String str, char delimiter)
    

Unescapes any Java literals found in the String to a Writer.

This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').

Field Detail
COMMENT_CHARS
final static String COMMENT_CHARS(Code)
Constant for the supported comment characters.




Constructor Detail
PropertiesConfiguration
public PropertiesConfiguration()(Code)
Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().



PropertiesConfiguration
public PropertiesConfiguration(String fileName) throws ConfigurationException(Code)
Creates and loads the extended properties from the specified file. The specified file can contain "include = " properties which then are loaded and merged into the properties.
Parameters:
  fileName - The name of the properties file to load.
throws:
  ConfigurationException - Error while loading the properties file



PropertiesConfiguration
public PropertiesConfiguration(File file) throws ConfigurationException(Code)
Creates and loads the extended properties from the specified file. The specified file can contain "include = " properties which then are loaded and merged into the properties.
Parameters:
  file - The properties file to load.
throws:
  ConfigurationException - Error while loading the properties file



PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException(Code)
Creates and loads the extended properties from the specified URL. The specified file can contain "include = " properties which then are loaded and merged into the properties.
Parameters:
  url - The location of the properties file to load.
throws:
  ConfigurationException - Error while loading the properties file




Method Detail
clone
public Object clone()(Code)
Creates a copy of this object. the copy



createLayout
protected PropertiesConfigurationLayout createLayout()(Code)
Creates the associated layout object. This method is invoked when the layout object is accessed and has not been created yet. Derived classes can override this method to hook in a different layout implementation. the layout object to use
since:
   1.3



getHeader
public String getHeader()(Code)
Return the comment header. the comment header
since:
   1.1



getInclude
public static String getInclude()(Code)
Gets the property value for including other properties files. By default it is "include". A String.



getIncludesAllowed
public boolean getIncludesAllowed()(Code)
Reports the status of file inclusion. True if include files are loaded.



getLayout
public synchronized PropertiesConfigurationLayout getLayout()(Code)
Returns the associated layout object. the associated layout object
since:
   1.3



isCommentLine
static boolean isCommentLine(String line)(Code)
Tests whether a line is a comment, i.e. whether it starts with a comment character.
Parameters:
  line - the line a flag if this is a comment line
since:
   1.3



load
public synchronized void load(Reader in) throws ConfigurationException(Code)
Load the properties from the given reader. Note that the clear() method is not called, so the properties contained in the loaded file will be added to the actual set of properties.
Parameters:
  in - An InputStream.
throws:
  ConfigurationException - if an error occurs



propertyLoaded
boolean propertyLoaded(String key, String value) throws ConfigurationException(Code)
This method is invoked by the associated PropertiesConfigurationLayout object for each property definition detected in the parsed properties file. Its task is to check whether this is a special property definition (e.g. the include property). If not, the property must be added to this configuration. The return value indicates whether the property should be treated as a normal property. If it is false, the layout object will ignore this property.
Parameters:
  key - the property key
Parameters:
  value - the property value a flag whether this is a normal property
throws:
  ConfigurationException - if an error occurs
since:
   1.3



save
public void save(Writer writer) throws ConfigurationException(Code)
Save the configuration to the specified stream.
Parameters:
  writer - the output stream used to save the configuration
throws:
  ConfigurationException - if an error occurs



setBasePath
public void setBasePath(String basePath)(Code)
Extend the setBasePath method to turn includes on and off based on the existence of a base path.
Parameters:
  basePath - The new basePath to set.



setHeader
public void setHeader(String header)(Code)
Set the comment header.
Parameters:
  header - the header to use
since:
   1.1



setInclude
public static void setInclude(String inc)(Code)
Sets the property value for including other properties files. By default it is "include".
Parameters:
  inc - A String.



setIncludesAllowed
protected void setIncludesAllowed(boolean includesAllowed)(Code)
Controls whether additional files can be loaded by the include = statement or not. Base rule is, that objects created by the empty C'tor can not have included files.
Parameters:
  includesAllowed - includesAllowed True if Includes are allowed.



setLayout
public synchronized void setLayout(PropertiesConfigurationLayout layout)(Code)
Sets the associated layout object.
Parameters:
  layout - the new layout object; can be null, then a newlayout object will be created
since:
   1.3



unescapeJava
protected static String unescapeJava(String str, char delimiter)(Code)

Unescapes any Java literals found in the String to a Writer.

This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').
Parameters:
  str - the String to unescape, may be null
Parameters:
  delimiter - the delimiter for multi-valued properties the processed string
throws:
  IllegalArgumentException - if the Writer is null



Fields inherited from org.apache.commons.configuration.AbstractFileConfiguration
final public static int EVENT_RELOAD(Code)(Java Doc)
protected boolean autoSave(Code)(Java Doc)
protected String basePath(Code)(Java Doc)
protected String fileName(Code)(Java Doc)
protected ReloadingStrategy strategy(Code)(Java Doc)

Methods inherited from org.apache.commons.configuration.AbstractFileConfiguration
public void addProperty(String key, Object value)(Code)(Java Doc)
public void clearProperty(String key)(Code)(Java Doc)
public Object clone()(Code)(Java Doc)
public boolean containsKey(String key)(Code)(Java Doc)
protected void enterNoReload()(Code)(Java Doc)
protected void exitNoReload()(Code)(Java Doc)
protected void fireEvent(int type, String propName, Object propValue, boolean before)(Code)(Java Doc)
public String getBasePath()(Code)(Java Doc)
public String getEncoding()(Code)(Java Doc)
public File getFile()(Code)(Java Doc)
public String getFileName()(Code)(Java Doc)
public Iterator getKeys()(Code)(Java Doc)
public String getPath()(Code)(Java Doc)
public Object getProperty(String key)(Code)(Java Doc)
public ReloadingStrategy getReloadingStrategy()(Code)(Java Doc)
public URL getURL()(Code)(Java Doc)
public boolean isAutoSave()(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
public void load() throws ConfigurationException(Code)(Java Doc)
public void load(String fileName) throws ConfigurationException(Code)(Java Doc)
public void load(File file) throws ConfigurationException(Code)(Java Doc)
public void load(URL url) throws ConfigurationException(Code)(Java Doc)
public void load(InputStream in) throws ConfigurationException(Code)(Java Doc)
public void load(InputStream in, String encoding) throws ConfigurationException(Code)(Java Doc)
protected void possiblySave()(Code)(Java Doc)
public void reload()(Code)(Java Doc)
public void save() throws ConfigurationException(Code)(Java Doc)
public void save(String fileName) throws ConfigurationException(Code)(Java Doc)
public void save(URL url) throws ConfigurationException(Code)(Java Doc)
public void save(File file) throws ConfigurationException(Code)(Java Doc)
public void save(OutputStream out) throws ConfigurationException(Code)(Java Doc)
public void save(OutputStream out, String encoding) throws ConfigurationException(Code)(Java Doc)
public void setAutoSave(boolean autoSave)(Code)(Java Doc)
public void setBasePath(String basePath)(Code)(Java Doc)
public void setEncoding(String encoding)(Code)(Java Doc)
public void setFile(File file)(Code)(Java Doc)
public void setFileName(String fileName)(Code)(Java Doc)
public void setPath(String path)(Code)(Java Doc)
public void setProperty(String key, Object value)(Code)(Java Doc)
public void setReloadingStrategy(ReloadingStrategy strategy)(Code)(Java Doc)
public void setURL(URL url)(Code)(Java Doc)

Methods inherited from org.apache.commons.configuration.BaseConfiguration
protected void addPropertyDirect(String key, Object value)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
protected void clearPropertyDirect(String key)(Code)(Java Doc)
public Object clone()(Code)(Java Doc)
public boolean containsKey(String key)(Code)(Java Doc)
public Iterator getKeys()(Code)(Java Doc)
public Object getProperty(String key)(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)

Fields inherited from org.apache.commons.configuration.AbstractConfiguration
final protected static String END_TOKEN(Code)(Java Doc)
final public static int EVENT_ADD_PROPERTY(Code)(Java Doc)
final public static int EVENT_CLEAR(Code)(Java Doc)
final public static int EVENT_CLEAR_PROPERTY(Code)(Java Doc)
final public static int EVENT_READ_PROPERTY(Code)(Java Doc)
final public static int EVENT_SET_PROPERTY(Code)(Java Doc)
final protected static String START_TOKEN(Code)(Java Doc)

Methods inherited from org.apache.commons.configuration.AbstractConfiguration
public void addErrorLogListener()(Code)(Java Doc)
public void addProperty(String key, Object value)(Code)(Java Doc)
abstract protected void addPropertyDirect(String key, Object value)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
public void clearProperty(String key)(Code)(Java Doc)
protected void clearPropertyDirect(String key)(Code)(Java Doc)
abstract public boolean containsKey(String key)(Code)(Java Doc)
protected ConfigurationInterpolator createInterpolator()(Code)(Java Doc)
public BigDecimal getBigDecimal(String key)(Code)(Java Doc)
public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)(Code)(Java Doc)
public BigInteger getBigInteger(String key)(Code)(Java Doc)
public BigInteger getBigInteger(String key, BigInteger defaultValue)(Code)(Java Doc)
public boolean getBoolean(String key)(Code)(Java Doc)
public boolean getBoolean(String key, boolean defaultValue)(Code)(Java Doc)
public Boolean getBoolean(String key, Boolean defaultValue)(Code)(Java Doc)
public byte getByte(String key)(Code)(Java Doc)
public byte getByte(String key, byte defaultValue)(Code)(Java Doc)
public Byte getByte(String key, Byte defaultValue)(Code)(Java Doc)
public static char getDefaultListDelimiter()(Code)(Java Doc)
public static char getDelimiter()(Code)(Java Doc)
public double getDouble(String key)(Code)(Java Doc)
public double getDouble(String key, double defaultValue)(Code)(Java Doc)
public Double getDouble(String key, Double defaultValue)(Code)(Java Doc)
public float getFloat(String key)(Code)(Java Doc)
public float getFloat(String key, float defaultValue)(Code)(Java Doc)
public Float getFloat(String key, Float defaultValue)(Code)(Java Doc)
public int getInt(String key)(Code)(Java Doc)
public int getInt(String key, int defaultValue)(Code)(Java Doc)
public Integer getInteger(String key, Integer defaultValue)(Code)(Java Doc)
public ConfigurationInterpolator getInterpolator()(Code)(Java Doc)
abstract public Iterator getKeys()(Code)(Java Doc)
public Iterator getKeys(String prefix)(Code)(Java Doc)
public List getList(String key)(Code)(Java Doc)
public List getList(String key, List defaultValue)(Code)(Java Doc)
public char getListDelimiter()(Code)(Java Doc)
public Log getLogger()(Code)(Java Doc)
public long getLong(String key)(Code)(Java Doc)
public long getLong(String key, long defaultValue)(Code)(Java Doc)
public Long getLong(String key, Long defaultValue)(Code)(Java Doc)
public Properties getProperties(String key)(Code)(Java Doc)
public Properties getProperties(String key, Properties defaults)(Code)(Java Doc)
public short getShort(String key)(Code)(Java Doc)
public short getShort(String key, short defaultValue)(Code)(Java Doc)
public Short getShort(String key, Short defaultValue)(Code)(Java Doc)
public String getString(String key)(Code)(Java Doc)
public String getString(String key, String defaultValue)(Code)(Java Doc)
public String[] getStringArray(String key)(Code)(Java Doc)
public synchronized StrSubstitutor getSubstitutor()(Code)(Java Doc)
protected String interpolate(String base)(Code)(Java Doc)
protected Object interpolate(Object value)(Code)(Java Doc)
protected String interpolateHelper(String base, List priorVariables)(Code)(Java Doc)
public boolean isDelimiterParsingDisabled()(Code)(Java Doc)
abstract public boolean isEmpty()(Code)(Java Doc)
public boolean isThrowExceptionOnMissing()(Code)(Java Doc)
protected Object resolveContainerStore(String key)(Code)(Java Doc)
public static void setDefaultListDelimiter(char delimiter)(Code)(Java Doc)
public static void setDelimiter(char delimiter)(Code)(Java Doc)
public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)(Code)(Java Doc)
public void setListDelimiter(char listDelimiter)(Code)(Java Doc)
public void setLogger(Log log)(Code)(Java Doc)
public void setProperty(String key, Object value)(Code)(Java Doc)
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)(Code)(Java Doc)
public Configuration subset(String prefix)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.