Java Doc for INIConfiguration.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.INIConfiguration

INIConfiguration
public class INIConfiguration extends AbstractFileConfiguration (Code)

An initialization or ini file is a configuration file tpically found on Microsoft's Windows operating system and contains data for Windows based applications.

Although popularized by Windows, ini files can be used on any system or platform due to the fact that they are merely text files that can easily be parsed and modified by both humans and computers.

A typcial ini file could look something like:

[section1]
; this is a comment!
var1 = foo
var2 = bar

[section2]
var1 = doo

The format of ini files is fairly straight forward and is comosed of three components:

  • Sections: Ini files are split into sections, each section starting with a section declaration. A section declaration starts with a '[' and ends with a ']'. Sections occur on one line only.
  • Parameters: Items in a section are known as parameters. Parameters have a typical key = value format.
  • Comments: Lines starting with a ';' are assumed to be comments.

There are various implementations of the ini file format by various vendors which has caused a number of differences to appear. As far as possible this configuration tries to be lenient and support most of the differences.

Some of the differences supported are as follows:

  • Comments: The '#' character is also accepted as a comment signifier.
  • Key value separtor: The ':' character is also accepted in place of '=' to separate keys and values in parameters, for example var1 : foo.
  • Duplicate sections: Typically duplicate sections are not allowed , this configuration does however support it. In the event of a duplicate section, the two section's values are merged.
  • Duplicate parameters: Typically duplicate parameters are only allowed if they are in two different sections, thus they are local to sections; this configuration simply merges duplicates; if a section has a duplicate parameter the values are then added to the key as a list.

Global parameters are also allowed; any parameters declared before a section is declared are added to a global section. It is important to note that this global section does not have a name.

In all instances, a parameter's key is prepended with its section name and a '.' (period). Thus a parameter named "var1" in "section1" will have the key section1.var1 in this configuration. Thus, a section's parameters can easily be retrieved using the subset method using the section name as the prefix.

Implementation Details:

Consider the following ini file:
default = ok

[section1]
var1 = foo
var2 = doodle

[section2]
; a comment
var1 = baz
var2 = shoodle
bad =
= worse

[section3]
# another comment
var1 : foo
var2 : bar
var5 : test1

[section3]
var3 = foo
var4 = bar
var5 = test2

This ini file will be parsed without error. Note:

  • The parameter named "default" is added to the global section, it's value is accessed simply using getProperty("default").
  • Section 1's parameters can be accessed using getProperty("section1.var1").
  • The parameter named "bad" simply adds the parameter with an empty value.
  • The empty key with value "= worse" is added using an empty key. This key is still added to section 2 and the value can be accessed using getProperty("section2."), notice the period '.' following the section name.
  • Section three uses both '=' and ':' to separate keys and values.
  • Section 3 has a duplicate key named "var5". The value for this key is [test1, test2], and is represented as a List.

The set of sections in this configuration can be retrieved using the getSections method.


author:
   trevor.miller
version:
   $Id: INIConfiguration.java 492216 2007-01-03 16:51:24Z oheger $
since:
   1.4


Field Summary
final protected static  StringCOMMENT_CHARS
     The characters that signal the start of a comment line.
final protected static  StringSEPARATOR_CHARS
     The characters used to separate keys from values.

Constructor Summary
public  INIConfiguration()
     Create a new empty INI Configuration.
public  INIConfiguration(String filename)
     Create and load the ini configuration from the given file.
public  INIConfiguration(File file)
     Create and load the ini configuration from the given file.
public  INIConfiguration(URL url)
     Create and load the ini configuration from the given url.

Method Summary
public  SetgetSections()
     Return a set containing the sections in this ini configuration.
protected  booleanisCommentLine(String s)
     Determine if the given line is a comment line.
Parameters:
  s - The line to check.
protected  booleanisSectionLine(String s)
     Determine if the given line is a section.
Parameters:
  s - The line to check.
public  voidload(Reader reader)
     Load the configuration from the given reader.
public  voidsave(Writer writer)
     Save the configuration to the specified writer.

Field Detail
COMMENT_CHARS
final protected static String COMMENT_CHARS(Code)
The characters that signal the start of a comment line.



SEPARATOR_CHARS
final protected static String SEPARATOR_CHARS(Code)
The characters used to separate keys from values.




Constructor Detail
INIConfiguration
public INIConfiguration()(Code)
Create a new empty INI Configuration.



INIConfiguration
public INIConfiguration(String filename) throws ConfigurationException(Code)
Create and load the ini configuration from the given file.
Parameters:
  filename - The name pr path of the ini file to load.
throws:
  ConfigurationException - If an error occurs while loading the file



INIConfiguration
public INIConfiguration(File file) throws ConfigurationException(Code)
Create and load the ini configuration from the given file.
Parameters:
  file - The ini file to load.
throws:
  ConfigurationException - If an error occurs while loading the file



INIConfiguration
public INIConfiguration(URL url) throws ConfigurationException(Code)
Create and load the ini configuration from the given url.
Parameters:
  url - The url of the ini file to load.
throws:
  ConfigurationException - If an error occurs while loading the file




Method Detail
getSections
public Set getSections()(Code)
Return a set containing the sections in this ini configuration. Note that changes to this set do not affect the configuration. a set containing the sections.



isCommentLine
protected boolean isCommentLine(String s)(Code)
Determine if the given line is a comment line.
Parameters:
  s - The line to check. true if the line is empty or starts with one of the commentcharacters



isSectionLine
protected boolean isSectionLine(String s)(Code)
Determine if the given line is a section.
Parameters:
  s - The line to check. true if the line contains a secion



load
public void load(Reader reader) throws ConfigurationException(Code)
Load the configuration from the given reader. Note that the clear method is not called so the configuration read in will be merged with the current configuration.
Parameters:
  reader - The reader to read the configuration from.
throws:
  ConfigurationException - If an error occurs while reading theconfiguration



save
public void save(Writer writer) throws ConfigurationException(Code)
Save the configuration to the specified writer.
Parameters:
  writer - - The writer to save the configuration to.
throws:
  ConfigurationException - If an error occurs while writing theconfiguration



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.