org.ceryle.xml
Class PropertyManager

java.lang.Object
  extended by org.ceryle.xml.PropertyManager
All Implemented Interfaces:
Constants

public class PropertyManager
extends Object
implements Constants

Uses an XMLProcessor to provide access to a simple XML properties file that can be queried for name/value pairs. Each <property> element contains a name and value attribute. For example:

     <property name="widget.color"  value="#80ffff"/>
     <property name="widget.height" value="60"/>
     <property name="widget.width"  value="200"/>
        ...
 

Note that the Ceryle properties file also contains a "type" and a "title" attribute for each property, designating (resp.) its datatype and a short description. Datatypes include: "int", "string", "color", "URL", "path", "boolean", "rect" and "struct". There is currently support for storage and retrieval of String, boolean, int, float, long and double values. Default values are required in the get methods, similar to the Java Preferences API.

Calling readProperty(String,String) on "struct" type properties will return an int value indicating the number of embedded <value> elements. A call to readProperties(String) will return a Hashtable of name-value (key-value) pairs corresponding to the stored attribute contents. The writeProperties(String,Set,String) method is the corresponding write-to-file method. An example is shown below:

    <property name="http://purl.org/ceryle/prop/#helperMap"
              type="struct"
              title="the map of MIME type to helper applications">
      <value mime="application/fu-manchu"
             ext="fuu"
             desc="Fu Manchu documents"
             action="1"
             path="/usr/bin/fumanchu" />
    </property>
 

Since:
JDK1.3
Version:
$Id: PropertyManager.java,v 3.12 2007-06-15 12:10:29 altheim Exp $
Author:
Murray Altheim
See Also:
XMLProcessor

Field Summary
static boolean valueAsColumn
          A boolean variable controlling whether current property values are included in the generated XHTML PSI/Property Set document as a separate column or simply appended to the description.
 
Fields inherited from interface org.ceryle.util.Constants
Amp, AMP, Apos, APOS, APP_NAME, APP_VERSION_NAME, APP_VERSION_NUMBER, AT, BANG, BAR, BIT_dev, BIT_http, BIT_ignoreCom, BIT_merge, BIT_none, BIT_noPreload, BIT_simple, BIT_ui, BIT_unused1, BIT_unused2, BIT_unused3, BIT_validating, BIT_verbose, BIT_xcatalog, BIT_xlink, BIT_xmlnsAware, BIT_xsd, BROKB, BSlash, BSLASH, CERYLE_CREDITS_FILE, CERYLE_DATA_DIR, CERYLE_HIST_FILE, CERYLE_LICENSE_FILE, CERYLE_PREF_FILE, CERYLE_PROP, CERYLE_PROP_BASE, CERYLE_PROP_FILE, CERYLE_RSRC_DIR, CERYLE_THANKS_FILE, CFLEX, Colon, COLON, Comma, COMMA, CR, CRet, Dash, DASH, DEFAULT_DIRECTORY, DEVELOPER, DOLR, Dot, DOT, EIGHT, Ellip, EOF, EqQuot, EQUAL, Equals, False, FALSE, FileProt, Filesep, FileURL, Five, FIVE, FONTSIZES, Four, FOUR, FSchar, GCOL_PROP, GRAPH_PROP, GRAVE, GT, Hash, HASH, HOME_DIRECTORY, HOME_DIRECTORY_PATH, HOME_DIRECTORY_URL, HTML, HttpProt, HttpURL, INDENT, INDENT_0, INDENT_1, INDENT_10, INDENT_2, INDENT_3, INDENT_4, INDENT_5, INDENT_6, INDENT_7, INDENT_8, INDENT_9, INIT, LCURL, LCurly, LF, LFS, Localhost, LPAR, LParen, LS, LSBrkt, LSBrkt2, LSQB, LT, MT, NBSP, NEL, NINE, NL, NL20x, NLchar, No, Null, NULL, NULL_STATE, NumParams, One, ONE, Pathsep, Percent, PERO, PLUS, Prcnt, PS, QMark, QMARK, Quot, QUOT, RCURL, RCurly, RESOURCE_BUNDLE, RPAR, RParen, RSBrkt, RSBrkt2, RSQB, Semi, SEMI, SEVEN, SIX, Slash, SLASH, SP, SPACE, Stago, Star, STAR, Tab, TAB, Tee, Three, THREE, Tilde, TILDE, TM_PROP, True, TRUE, Two, TWO, Under, UNDER, URI, URL, VBar, WIKI_PROP, XNodePfx, XNodeURL, XtmExt, Yes, Zero, ZERO
 
Constructor Summary
PropertyManager(MessageHandler messagehandler, XMLProcessor xp, String filename)
          Constructor provided a String filename containing the pathname of the preferences file.
 
Method Summary
 MessageHandler getMessageHandler()
          A convenience method returning the MessageHandler used with this PropertyManager.
 Properties getProperties()
          Returns the current properties as a Properties object.
 Vector getProperties(boolean fullNames)
          Returns a Vector of Vectors containing the entire list of properties.
 boolean isDirty()
          Returns true if any properties have been modified since import of the properties file.
 Set readProperties(String name)
          Returns a Set of Hashtables as the set of name-value pairs corresponding to the property name, null if unavailable or empty.
 boolean readProperty(String name, boolean def)
          Returns a boolean as the value corresponding to the property name, null if unavailable or empty.
 double readProperty(String name, double def)
          Returns a double as the value corresponding to the property name, null if unavailable or empty.
 float readProperty(String name, float def)
          Returns a float as the value corresponding to the property name, null if unavailable or empty.
 int readProperty(String name, int def)
          Returns an int as the value corresponding to the property name, null if unavailable or empty.
 long readProperty(String name, long def)
          Returns a long as the value corresponding to the property name, null if unavailable or empty.
 String readProperty(String name, String def)
          Returns a String as the value corresponding to the property name, null if unavailable or empty.
 void writeAsSystemProperty(String name, String systemName, boolean def)
          Obtains the value of the named property and writes it as a Java System property of the name systemName (or using the same name if the second parameter is null).
 void writeAsSystemProperty(String name, String systemName, int def)
          Obtains the value of the named property and writes it as a Java System property of the name systemName (or using the same name if the second parameter is null).
 boolean writeAsSystemProperty(String name, String systemName, String def)
          Obtains the value of the named property from the property file and writes it as a Java System property of the name systemName (or using the same name if the second parameter is null), returning true.
 boolean writePreferences()
          Writes the current properties document to the default preferences filename.
 boolean writePreferences(String filename)
          Writes the current properties document to a File named filename.
 boolean writeProperties(String name, Set set, String title)
          Writes to the properties Document the properties of String name with a Set of Hashtables each containing name-value pairs, returning true if the property replaced an existing value, false if the property did not exist prior.
 void writePropertiesAsXHTML(String filename)
          Writes the current properties document to a generated XHTML file named filename.
 boolean writeProperty(String name, String value, String title)
          Writes the property of String name with String value to the properties document, returning true if the property replaced an existing value, false if the property did not exist prior.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueAsColumn

public static boolean valueAsColumn
A boolean variable controlling whether current property values are included in the generated XHTML PSI/Property Set document as a separate column or simply appended to the description. Default is "false" (i.e., appended as description).

Constructor Detail

PropertyManager

public PropertyManager(MessageHandler messagehandler,
                       XMLProcessor xp,
                       String filename)
                throws FileNotFoundException,
                       ProcessException
Constructor provided a String filename containing the pathname of the preferences file. Each named preference shows up as PCDATA content in a like-named element. Following construction, the parse takes place, then the PropertyManager object can be queried for individual properties.

The preferences file is built from a canonical properties file that is not modified. If the preference file fails to load for any reason, an attempt is made to load the properties file. If the properties file cannot be read, a ProcessException is thrown and subsequent calls to readProperty(String,String) will return null.

Throws:
FileNotFoundException
ProcessException
Method Detail

readProperty

public int readProperty(String name,
                        int def)
Returns an int as the value corresponding to the property name, null if unavailable or empty.

Parameters:
name - the name or key of the property
def - the default value of the property should it not be set

readProperty

public long readProperty(String name,
                         long def)
Returns a long as the value corresponding to the property name, null if unavailable or empty.

Parameters:
name - the name or key of the property
def - the default value of the property should it not be set

readProperty

public float readProperty(String name,
                          float def)
Returns a float as the value corresponding to the property name, null if unavailable or empty.

Parameters:
name - the name or key of the property
def - the default value of the property should it not be set

readProperty

public double readProperty(String name,
                           double def)
Returns a double as the value corresponding to the property name, null if unavailable or empty.

Parameters:
name - the name or key of the property
def - the default value of the property should it not be set

readProperty

public boolean readProperty(String name,
                            boolean def)
Returns a boolean as the value corresponding to the property name, null if unavailable or empty.

Parameters:
name - the name or key of the property
def - the default value of the property should it not be set

readProperty

public String readProperty(String name,
                           String def)
Returns a String as the value corresponding to the property name, null if unavailable or empty. Note that this performs whitespace trimming on individual values.

Parameters:
name - the name or key of the property
def - the default value of the property should it not be set

readProperties

public Set readProperties(String name)
Returns a Set of Hashtables as the set of name-value pairs corresponding to the property name, null if unavailable or empty. Note that this performs whitespace trimming on individual values. If the property type is "struct" but there are no <value> child elements, this will return an empty Set. If the property type is not "struct" this will return null.


writeProperty

public boolean writeProperty(String name,
                             String value,
                             String title)
                      throws ProcessException
Writes the property of String name with String value to the properties document, returning true if the property replaced an existing value, false if the property did not exist prior. An optional title String may be added to describe the property (leave null if unused; any existing title will be preserved).

Note that this does not write to a file, just the internal property Document.

Throws:
ProcessException

writeProperties

public boolean writeProperties(String name,
                               Set set,
                               String title)
                        throws ProcessException
Writes to the properties Document the properties of String name with a Set of Hashtables each containing name-value pairs, returning true if the property replaced an existing value, false if the property did not exist prior. Note that this will completely replace any prior contents. An optional title String may be added to describe the property (leave null if unused, as any existing title will be preserved).

Note that this does not write to a file, just the internal property Document.

Throws:
ProcessException

writePreferences

public boolean writePreferences()
Writes the current properties document to the default preferences filename. See {#link #writePreferences(String)}.

Returns:
true if successful writing the file

writePreferences

public boolean writePreferences(String filename)
Writes the current properties document to a File named filename. If no properties file has been loaded, this method does nothing.

Returns:
true if successful writing the file

writePropertiesAsXHTML

public void writePropertiesAsXHTML(String filename)
Writes the current properties document to a generated XHTML file named filename.


getProperties

public Vector getProperties(boolean fullNames)
Returns a Vector of Vectors containing the entire list of properties. Each property (treated as a row) has four associated parts (treated as columns): the property name, type, value, and description. If a part is missing for any property, an empty string is used.

If the boolean fullNames is true, the full Ceryle property name is returned; if false, only the fragment identifier portion.

This returns null if no properties file has been read.


getProperties

public Properties getProperties()
Returns the current properties as a Properties object.

Note

This returns an empty Properties if no properties file has been read.


writeAsSystemProperty

public boolean writeAsSystemProperty(String name,
                                     String systemName,
                                     String def)
Obtains the value of the named property from the property file and writes it as a Java System property of the name systemName (or using the same name if the second parameter is null), returning true. If the PropertyManager property has not been set (i.e., a call to readProperty(String,String) returns null), no System property is set and the method returns false.

Parameters:
name - the name or key of the property
systemName - the name to be used for the system property
def - the default value of the property should it not be set
Returns:
true if the System property was set

writeAsSystemProperty

public void writeAsSystemProperty(String name,
                                  String systemName,
                                  boolean def)
Obtains the value of the named property and writes it as a Java System property of the name systemName (or using the same name if the second parameter is null). Because the prefs API does not provide a means of determining whether primitive value properties have already been set, no value is returned.

Parameters:
name - the name or key of the property
systemName - the name to be used for the system property
def - the default value of the property should it not be set

writeAsSystemProperty

public void writeAsSystemProperty(String name,
                                  String systemName,
                                  int def)
Obtains the value of the named property and writes it as a Java System property of the name systemName (or using the same name if the second parameter is null). Because the prefs API does not provide a means of determining whether primitive value properties have already been set, no value is returned.

Parameters:
name - the name or key of the property
systemName - the name to be used for the system property
def - the default value of the property should it not be set

isDirty

public boolean isDirty()
Returns true if any properties have been modified since import of the properties file.


getMessageHandler

public MessageHandler getMessageHandler()
A convenience method returning the MessageHandler used with this PropertyManager.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.