Java Doc for UberProperties.java in  » Template-Engine » ostermillerutils » com » Ostermiller » util » 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 » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.Ostermiller.util.UberProperties

UberProperties
public class UberProperties (Code)
The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string. More information about this class is available from ostermiller.org.

A property list can contain another property list as its "defaults"; this second property list is searched if the property key is not found in the original property list.

When saving properties to a stream or loading them from a stream, the ISO 8859-1 character encoding is used. For characters that cannot be directly represented in this encoding, Unicode escapes are used; however, only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

Unlike the java.util.Properties, UberProperties does not inherit from java.util.Hashtable, so Objects other than strings cannot be stored in it. Also, comments from a files are preserved, and there can be several properties for a given name.

This class is not synchronized, so it should not be used in a multi-threaded environment without external synchronization.

The file format that UberProperties uses is as follows:

The file is assumed to be using the ISO 8859-1 character encoding. All of the comment lines (starting with a '#' or '!') at the beginning of the file before the first line that is not a comment, are the comment associated with the file. After that, each comment will be associated with the next property. If there is more than one property with the same name, the first comment will be the only one that is loaded.

Every property occupies one line of the input stream. Each line is terminated by a line terminator (\n or \r or \r\n).

A line that contains only whitespace or whose first non-whitespace character is an ASCII # or ! is ignored (thus, # or ! indicate comment lines).

Every line other than a blank line or a comment line describes one property to be added to the table (except that if a line ends with \, then the following line, if it exists, is treated as a continuation line, as described below). The key consists of all the characters in the line starting with the first non-whitespace character and up to, but not including, the first ASCII =, :, or whitespace character. All of the key termination characters may be included in the key by preceding them with a \. Any whitespace after the key is skipped; if the first non-whitespace character after the key is = or :, then it is ignored and any whitespace characters after it are also skipped. All remaining characters on the line become part of the associated element string. Within the element string, the ASCII escape sequences \t, \n, \r, \\, \", \', \ (a backslash and a space), and \\uxxxx are recognized and converted to single characters. Moreover, if the last character on the line is \, then the next line is treated as a continuation of the current line; the \ and line terminator are simply discarded, and any leading whitespace characters on the continuation line are also discarded and are not part of the element string.

As an example, each of the following four lines specifies the key "Truth" and the associated element value "Beauty":

Truth = Beauty
 Truth:Beauty
 Truth			:Beauty

As another example, the following three lines specify a single property:

fruits				apple, banana, pear, \
 cantaloupe, watermelon, \
 kiwi, mango

The key is "fruits" and the associated element is:
"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
Note that a space appears before each \ so that a space will appear after each comma in the final result; the \, line terminator, and leading whitespace on the continuation line are merely discarded and are not replaced by one or more other characters.

As a third example, the line:
cheeses
specifies that the key is "cheeses" and the associated element is the empty string.


author:
   Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
since:
   ostermillerutils 1.00.00



Constructor Summary
public  UberProperties()
     Creates an empty property list with no default values.
public  UberProperties(UberProperties defaults)
     Creates an empty property list with the specified defaults.

Method Summary
public  voidaddProperties(String name, String[] values, String comment)
     Adds the values to the list of properties with the given name.
public  voidaddProperties(String name, String[] values)
     Adds the values to the list of properties with the given name.
public  voidaddProperty(String name, String value, String comment)
     Adds a value to the list of properties with the given name.
public  voidaddProperty(String name, String value)
     Adds a value to the list of properties with the given name.
public  booleancontains(String name)
     Test to see if a property with the given name exists.
Parameters:
  name - the name of the property.
public  StringgetComment(String name)
     Get the comment associated with this property.

If the property is not specified in this UberProperties but it is in the default UberProperties, the default is used.

public  StringgetComment()
     Get the comment associated with this set of properties.
public  String[]getProperties(String name)
     Get the values for a property. Properties returned in the same order in which they were added.

If the property is not specified in this UberProperties but it is in the default UberProperties, the default is used.

public  String[]getProperties(String name, String[] defaultValues)
     Get the values for a property.
public  StringgetProperty(String name)
     Get the first property with the given name. If the property is not specified in this UberProperties but it is in the default UberProperties, the default is used.
public  StringgetProperty(String name, String defaultValue)
     Get the first property with the given name.
public  intgetPropertyNameCount()
     Get the number of unique names for properties stored in this UberProperties.
public  voidload(String[] userFile, String systemResource)
     Load these properties from a user file with default properties from a system resource.

Example:

load(
 new String(){".java","tld","company","package","component.properties"}
 "tld/company/package/component.properties",
 )
This will load the properties file relative to the classpath as the defaults and the file <%userhome%>/.java/tld/company/package/component.properties if the file exists.
public  voidload(InputStream in, boolean add)
     Add the properties from the input stream to this UberProperties.
public  voidload(InputStream in)
     Add the properties from the input stream to this UberProperties.
public  String[]propertyNames()
     Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.
public  booleanremove(String name)
     Remove any property with the given name.
Parameters:
  name - the name of the property.
public  voidsave(String[] userFile)
     Save these properties from a user file.
public  voidsave(OutputStream out)
     Save these properties to the given stream.
public  voidsetComment(String comment)
     Set the comment associated with this set of properties.
public  voidsetProperties(String name, String[] values)
     Replaces all properties of the given name with properties with the given values.
public  voidsetProperties(String name, String[] values, String comment)
     Replaces all properties of the given name with properties with the given values.
public  voidsetProperty(String name, String value)
     Replaces all properties of the given name with a single property with the given value.
public  voidsetProperty(String name, String value, String comment)
     Replaces all properties of the given name with a single property with the given value.
public  StringtoString()
     Save these properties to a string.


Constructor Detail
UberProperties
public UberProperties()(Code)
Creates an empty property list with no default values.
since:
   ostermillerutils 1.00.00



UberProperties
public UberProperties(UberProperties defaults)(Code)
Creates an empty property list with the specified defaults.
Parameters:
  defaults - the defaults.
throws:
  NullPointerException - if defaults is null.
since:
   ostermillerutils 1.00.00




Method Detail
addProperties
public void addProperties(String name, String[] values, String comment)(Code)
Adds the values to the list of properties with the given name.
Parameters:
  name - the name of the property.
Parameters:
  values - the values for the property.
Parameters:
  comment - the comment for the property, or null to remove it.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if values is null.
since:
   ostermillerutils 1.00.00



addProperties
public void addProperties(String name, String[] values)(Code)
Adds the values to the list of properties with the given name.
Parameters:
  name - the name of the property.
Parameters:
  values - the values for the property.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if values is null.
since:
   ostermillerutils 1.00.00



addProperty
public void addProperty(String name, String value, String comment)(Code)
Adds a value to the list of properties with the given name.
Parameters:
  name - the name of the property.
Parameters:
  value - the values for the property, or null to remove.
Parameters:
  comment - the comment for the property, or null to remove it.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if value is null.
since:
   ostermillerutils 1.00.00



addProperty
public void addProperty(String name, String value)(Code)
Adds a value to the list of properties with the given name.
Parameters:
  name - the name of the property.
Parameters:
  value - the values for the property.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if value is null.
since:
   ostermillerutils 1.00.00



contains
public boolean contains(String name)(Code)
Test to see if a property with the given name exists.
Parameters:
  name - the name of the property. true if the property existed and was removed, false if it did not exist.
throws:
  NullPointerException - if name is null.
since:
   ostermillerutils 1.00.00



getComment
public String getComment(String name)(Code)
Get the comment associated with this property.

If the property is not specified in this UberProperties but it is in the default UberProperties, the default is used. If no default is found, null is returned.
Parameters:
  name - Parameter name the comment for this property, or null if there is no comment or the property does not exist.
since:
   ostermillerutils 1.00.00




getComment
public String getComment()(Code)
Get the comment associated with this set of properties. comment for entire set of properties, or null if there is no comment.
since:
   ostermillerutils 1.00.00



getProperties
public String[] getProperties(String name)(Code)
Get the values for a property. Properties returned in the same order in which they were added.

If the property is not specified in this UberProperties but it is in the default UberProperties, the default is used. If no default is found, null is returned.
Parameters:
  name - Parameter name all the values associated with the given key, or null if the property does not exist.
since:
   ostermillerutils 1.00.00




getProperties
public String[] getProperties(String name, String[] defaultValues)(Code)
Get the values for a property. Properties returned in the same order in which they were added.

If the property is not specified in this UberProperties but it is in the default UberProperties, the default UberProperties is consulted, otherwise, the supplied defaults are used.
Parameters:
  name - Parameter name
Parameters:
  defaultValues - Values to use when property not present all the values associated with the given key, or null if the property does not exist.
since:
   ostermillerutils 1.00.00




getProperty
public String getProperty(String name)(Code)
Get the first property with the given name. If the property is not specified in this UberProperties but it is in the default UberProperties, the default is used. If no default is found, null is returned.
Parameters:
  name - Parameter name the first value of this property, or null if the property does not exist.
since:
   ostermillerutils 1.00.00



getProperty
public String getProperty(String name, String defaultValue)(Code)
Get the first property with the given name. If the property is not specified in this UberProperties but it is in the default UberProperties, the default UberProperties is consulted, otherwise, the supplied default is used.
Parameters:
  name - Parameter name
Parameters:
  defaultValue - Value to use when property not present the first value of this property.
since:
   ostermillerutils 1.00.00



getPropertyNameCount
public int getPropertyNameCount()(Code)
Get the number of unique names for properties stored in this UberProperties. number of names.
since:
   ostermillerutils 1.00.00



load
public void load(String[] userFile, String systemResource) throws IOException(Code)
Load these properties from a user file with default properties from a system resource.

Example:

load(
 new String(){".java","tld","company","package","component.properties"}
 "tld/company/package/component.properties",
 )
This will load the properties file relative to the classpath as the defaults and the file <%userhome%>/.java/tld/company/package/component.properties if the file exists. The .java directory is recommended as it is a common, possibly hidden, directory in the users home directory commonly used by Java programs. This method is meant to be used with the save(String systemResource) method which will save modified properties back to the user directory.
Parameters:
  userFile - array of Strings representing a path and file name relative to the user home directory.
Parameters:
  systemResource - name relative to classpath of default properties, or null to ignore.
throws:
  IOException - if an error occurs when reading.
throws:
  NullPointerException - if userFile is null.
throws:
  IllegalArgumentException - if userFile is empty.
since:
   ostermillerutils 1.00.00



load
public void load(InputStream in, boolean add) throws IOException(Code)
Add the properties from the input stream to this UberProperties.
Parameters:
  in - InputStream containing properties.
Parameters:
  add - whether parameters should add to parameters with the same name or replace them.
throws:
  IOException - if an error occurs when reading.
since:
   ostermillerutils 1.00.00



load
public void load(InputStream in) throws IOException(Code)
Add the properties from the input stream to this UberProperties.

Properties that are found replace any properties that were there before.
Parameters:
  in - InputStream containing properties.
throws:
  IOException - if an error occurs when reading.
since:
   ostermillerutils 1.00.00




propertyNames
public String[] propertyNames()(Code)
Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list. an enumeration of all the keys in this property list, including the keys in the default property list.
since:
   ostermillerutils 1.00.00



remove
public boolean remove(String name)(Code)
Remove any property with the given name.
Parameters:
  name - the name of the property. true if the property existed and was removed, false if it did not exist.
throws:
  NullPointerException - if name is null.
since:
   ostermillerutils 1.00.00



save
public void save(String[] userFile) throws IOException(Code)
Save these properties from a user file.

Example:

save(
 new String(){"tld","company","package","component.properties"}
 )
This will save the properties file relative to the user directory: <%userhome%>/tld/company/package/component.properties Directories will be created as needed.
Parameters:
  userFile - array of Strings representing a path and file name relative to the user home directory.
throws:
  IOException - if an error occurs when reading.
throws:
  NullPointerException - if userFile is null.
throws:
  IllegalArgumentException - if userFile is empty.
since:
   ostermillerutils 1.00.00



save
public void save(OutputStream out) throws IOException(Code)
Save these properties to the given stream.
Parameters:
  out - OutputStream to which these properties should be written.
throws:
  IOException - if an error occurs when writing.
since:
   ostermillerutils 1.00.00



setComment
public void setComment(String comment)(Code)
Set the comment associated with this set of properties.
Parameters:
  comment - the comment for entire set of properties, or null to clear.
since:
   ostermillerutils 1.00.00



setProperties
public void setProperties(String name, String[] values)(Code)
Replaces all properties of the given name with properties with the given values.
Parameters:
  name - the name of the property.
Parameters:
  values - for the property.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if values is null.
throws:
  IllegalArgumentException - if values is empty.
since:
   ostermillerutils 1.00.00



setProperties
public void setProperties(String name, String[] values, String comment)(Code)
Replaces all properties of the given name with properties with the given values.
Parameters:
  name - the name of the property.
Parameters:
  values - value of the property.
Parameters:
  comment - the comment for the property, or null to remove it.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if values is null.
throws:
  IllegalArgumentException - if values is empty.
since:
   ostermillerutils 1.00.00



setProperty
public void setProperty(String name, String value)(Code)
Replaces all properties of the given name with a single property with the given value.
Parameters:
  name - the name of the property.
Parameters:
  value - the value of the property, or null to remove it.
throws:
  NullPointerException - if name is null.
since:
   ostermillerutils 1.00.00



setProperty
public void setProperty(String name, String value, String comment)(Code)
Replaces all properties of the given name with a single property with the given value.
Parameters:
  name - the name of the property.
Parameters:
  value - the value of the property or null to remove it.
Parameters:
  comment - the comment for the property, or null to remove it.
throws:
  NullPointerException - if name is null.
throws:
  NullPointerException - if comment is null.
since:
   ostermillerutils 1.00.00



toString
public String toString()(Code)
Save these properties to a string. Serialized String version of these properties.
since:
   ostermillerutils 1.02.23



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.