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


java.lang.Object
   org.apache.commons.configuration.PropertiesConfigurationLayout

PropertiesConfigurationLayout
public class PropertiesConfigurationLayout implements ConfigurationListener(Code)

A helper class used by PropertiesConfiguration to keep the layout of a properties file.

Instances of this class are associated with a PropertiesConfiguration object. They are responsible for analyzing properties files and for extracting as much information about the file layout (e.g. empty lines, comments) as possible. When the properties file is written back again it should be close to the original.

The PropertiesConfigurationLayout object associated with a PropertiesConfiguration object can be obtained using the getLayout() method of the configuration. Then the methods provided by this class can be used to alter the properties file's layout.

Implementation note: This is a very simple implementation, which is far away from being perfect, i.e. the original layout of a properties file won't be reproduced in all cases. One limitation is that comments for multi-valued property keys are concatenated. Maybe this implementation can later be improved.

To get an impression how this class works consider the following properties file:

 # A demo configuration file
 # for Demo App 1.42
 # Application name
 AppName=Demo App
 # Application vendor
 AppVendor=DemoSoft
 # GUI properties
 # Window Color
 windowColors=0xFFFFFF,0x000000
 # Include some setting
 include=settings.properties
 # Another vendor
 AppVendor=TestSoft
 

For this example the following points are relevant:

  • The first two lines are set as header comment. The header comment is determined by the last blanc line before the first property definition.
  • For the property AppName one comment line and one leading blanc line is stored.
  • For the property windowColors two comment lines and two leading blanc lines are stored.
  • Include files is something this class cannot deal with well. When saving the properties configuration back, the included properties are simply contained in the original file. The comment before the include property is skipped.
  • For all properties except for AppVendor the "single line" flag is set. This is relevant only for windowColors, which has multiple values defined in one line using the separator character.
  • The AppVendor property appears twice. The comment lines are concatenated, so that layout.getComment("AppVendor"); will result in Application vendor<CR>Another vendor, whith <CR> meaning the line separator. In addition the "single line" flag is set to false for this property. When the file is saved, two property definitions will be written (in series).


author:
   author:
   href="http://jakarta.apache.org/commons/configuration/team-list.html">Commons
author:
   Configuration team
version:
   $Id: PropertiesConfigurationLayout.java 439648 2006-09-02 20:42:10Z oheger $
since:
   1.3

Inner Class :static class PropertyLayoutData implements Cloneable


Constructor Summary
public  PropertiesConfigurationLayout(PropertiesConfiguration config)
     Creates a new instance of PropertiesConfigurationLayout and initializes it with the associated configuration object.
public  PropertiesConfigurationLayout(PropertiesConfiguration config, PropertiesConfigurationLayout c)
     Creates a new instance of PropertiesConfigurationLayout and initializes it with the given configuration object.

Method Summary
public  voidconfigurationChanged(ConfigurationEvent event)
     The event listener callback.
public  intgetBlancLinesBefore(String key)
     Returns the number of blanc lines before this property key.
public  StringgetCanonicalComment(String key, boolean commentChar)
     Returns the comment for the specified property key in a cononical form. "Canonical" means that either all lines start with a comment character or none.
public  StringgetCanonicalHeaderComment(boolean commentChar)
     Returns the header comment of the represented properties file in a canonical form.
public  StringgetComment(String key)
     Returns the comment for the specified property key.
public  PropertiesConfigurationgetConfiguration()
     Returns the associated configuration object.
public  StringgetHeaderComment()
     Returns the header comment of the represented properties file.
public  SetgetKeys()
     Returns a set with all property keys managed by this object.
static  booleanisCommentLine(String line)
     Tests whether a line is a comment, i.e.
public  booleanisForceSingleLine()
     Returns the "force single line" flag.
public  booleanisSingleLine(String key)
     Returns a flag whether the specified property is defined on a single line.
public  voidload(Reader in)
     Reads a properties file and stores its internal structure.
public  voidsave(Writer out)
     Writes the properties file to the given writer, preserving as much of its structure as possible.
public  voidsetBlancLinesBefore(String key, int number)
     Sets the number of blanc lines before the given property key.
public  voidsetComment(String key, String comment)
     Sets the comment for the specified property key.
public  voidsetForceSingleLine(boolean f)
     Sets the "force single line" flag.
public  voidsetHeaderComment(String comment)
     Sets the header comment for the represented properties file.
public  voidsetSingleLine(String key, boolean f)
     Sets the "single line flag" for the specified property key. This flag is evaluated if the property has multiple values (i.e.
static  StringstripCommentChar(String s, boolean comment)
     Either removes the comment character from the given comment line or ensures that the line starts with a comment character.
static  StringtrimComment(String s, boolean comment)
     Trims a comment.


Constructor Detail
PropertiesConfigurationLayout
public PropertiesConfigurationLayout(PropertiesConfiguration config)(Code)
Creates a new instance of PropertiesConfigurationLayout and initializes it with the associated configuration object.
Parameters:
  config - the configuration (must not be null)



PropertiesConfigurationLayout
public PropertiesConfigurationLayout(PropertiesConfiguration config, PropertiesConfigurationLayout c)(Code)
Creates a new instance of PropertiesConfigurationLayout and initializes it with the given configuration object. The data of the specified layout object is copied.
Parameters:
  config - the configuration (must not be null)
Parameters:
  c - the layout object to be copied




Method Detail
configurationChanged
public void configurationChanged(ConfigurationEvent event)(Code)
The event listener callback. Here event notifications of the configuration object are processed to update the layout object properly.
Parameters:
  event - the event object



getBlancLinesBefore
public int getBlancLinesBefore(String key)(Code)
Returns the number of blanc lines before this property key. If this key does not exist, 0 will be returned.
Parameters:
  key - the property key the number of blanc lines before the property definition for thiskey



getCanonicalComment
public String getCanonicalComment(String key, boolean commentChar)(Code)
Returns the comment for the specified property key in a cononical form. "Canonical" means that either all lines start with a comment character or none. The commentChar parameter is false, all comment characters are removed, so that the result is only the plain text of the comment. Otherwise it is ensured that each line of the comment starts with a comment character.
Parameters:
  key - the key of the property
Parameters:
  commentChar - determines whether all lines should start with commentcharacters or not the canonical comment for this key (can be null)



getCanonicalHeaderComment
public String getCanonicalHeaderComment(boolean commentChar)(Code)
Returns the header comment of the represented properties file in a canonical form. With the commentChar parameter it can be specified whether comment characters should be stripped or be always present.
Parameters:
  commentChar - determines the presence of comment characters the header comment (can be null)



getComment
public String getComment(String key)(Code)
Returns the comment for the specified property key. The comment is returned as it was set (either manually by calling setComment() or when it was loaded from a properties file). No modifications are performed.
Parameters:
  key - the key of the property the comment for this key (can be null)



getConfiguration
public PropertiesConfiguration getConfiguration()(Code)
Returns the associated configuration object. the associated configuration



getHeaderComment
public String getHeaderComment()(Code)
Returns the header comment of the represented properties file. This method returns the header comment exactly as it was set using setHeaderComment() or extracted from the loaded properties file. the header comment (can be null)



getKeys
public Set getKeys()(Code)
Returns a set with all property keys managed by this object. a set with all contained property keys



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



isForceSingleLine
public boolean isForceSingleLine()(Code)
Returns the "force single line" flag. the force single line flag
See Also:   PropertiesConfigurationLayout.setForceSingleLine(boolean)



isSingleLine
public boolean isSingleLine(String key)(Code)
Returns a flag whether the specified property is defined on a single line. This is meaningful only if this property has multiple values.
Parameters:
  key - the property key a flag if this property is defined on a single line



load
public void load(Reader in) throws ConfigurationException(Code)
Reads a properties file and stores its internal structure. The found properties will be added to the associated configuration object.
Parameters:
  in - the reader to the properties file
throws:
  ConfigurationException - if an error occurs



save
public void save(Writer out) throws ConfigurationException(Code)
Writes the properties file to the given writer, preserving as much of its structure as possible.
Parameters:
  out - the writer
throws:
  ConfigurationException - if an error occurs



setBlancLinesBefore
public void setBlancLinesBefore(String key, int number)(Code)
Sets the number of blanc lines before the given property key. This can be used for a logical grouping of properties.
Parameters:
  key - the property key
Parameters:
  number - the number of blanc lines to add before this propertydefinition



setComment
public void setComment(String key, String comment)(Code)
Sets the comment for the specified property key. The comment (or its single lines if it is a multi-line comment) can start with a comment character. If this is the case, it will be written without changes. Otherwise a default comment character is added automatically.
Parameters:
  key - the key of the property
Parameters:
  comment - the comment for this key (can be null, then thecomment will be removed)



setForceSingleLine
public void setForceSingleLine(boolean f)(Code)
Sets the "force single line" flag. If this flag is set, all properties with multiple values are written on single lines. This mode provides more compatibility with java.lang.Properties, which cannot deal with multiple definitions of a single property.
Parameters:
  f - the force single line flag



setHeaderComment
public void setHeaderComment(String comment)(Code)
Sets the header comment for the represented properties file. This comment will be output on top of the file.
Parameters:
  comment - the comment



setSingleLine
public void setSingleLine(String key, boolean f)(Code)
Sets the "single line flag" for the specified property key. This flag is evaluated if the property has multiple values (i.e. if it is a list property). In this case, if the flag is set, all values will be written in a single property definition using the list delimiter as separator. Otherwise multiple lines will be written for this property, each line containing one property value.
Parameters:
  key - the property key
Parameters:
  f - the single line flag



stripCommentChar
static String stripCommentChar(String s, boolean comment)(Code)
Either removes the comment character from the given comment line or ensures that the line starts with a comment character.
Parameters:
  s - the comment line
Parameters:
  comment - if true, a comment character will always beenforced; if false, it will be removed the line without comment character



trimComment
static String trimComment(String s, boolean comment)(Code)
Trims a comment. This method either removes all comment characters from the given string, leaving only the plain comment text or ensures that every line starts with a valid comment character.
Parameters:
  s - the string to be processed
Parameters:
  comment - if true, a comment character will always beenforced; if false, it will be removed the trimmed comment



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(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.