Properties Objects |
Active Web |
A Properties object allows the manipulation of a properties file.
A properties file is a standard Windows ini file with name/value pairs, one per line, separated by an equals sign. Any line staring with a # character is considered a comment line. Leading and trailing spaces will be removed from the value.
An example of a properties file is shown below:
# Properties file for Active Web
webalias = /concerto
scriptalias = /concertox
This example would set two properties in the Properties object webalias and scriptalias.
All the properties created from the properties file are primitive strings.
Properties objects are of class Properties.
Property |
Description |
error |
An error message If an error has occurred. If no error has occurred then it will be null. The error messages are explained below: No file name - The read or write function was called when there was no properties file name set. While accessing the properties file the operating system can generate various other error messages. |
fileName |
The name of the properties file. |
prototype |
A reference to the Properties Prototype. This property does not enumerate and can not be deleted but can be changed. |
The Properties object has no predefined functions.
The Properties constructor is used to create new Properties objects.
var myProperties = new Properties([name]);
A new Properties object for the file identified by the name is created. The name uses the script file reference to identify the file. The file can be anywhere on the host filing system. If the name argument is not present then a Properties object withe no fileName property is created.
If a properties file name was supplied then the constructor will automatically call the read function to load the properties into the Properties object.
Shown below is the Properties object prototype chain.
When the constructor is run as a function without the new operator it has exactly the same behaviour as using the new operator.
Constructor properties are read only (they can not be changed or deleted) and it is not possible to add new properties to the Constructor.
Property |
Description |
prototype |
A reference to the Properties Prototype. This property does not enumerate and can not be changed or deleted. |
The Properties constructor has no predefined functions.
This prototype can be used by any object. It requires the properties file name to be a property in the object called fileName. If this is not present then the read and write functions will cause the error property to be set in the object.
Property |
Description |
prototype |
A reference to the Object Prototype. This property does not enumerate and can not be deleted, but it can be changed. |
The this reference used here always refers to the object that was used to run the function.
Function |
Description |
getFileName() |
Returns the name of the properties file. This returns the value of the fileName property from this object. |
read() |
Reads the properties from the properties file and adds them to this object as properties. If an error is detected this function will return false and the error property will be set. If the properties were read successfully then this function will return true. Note: All properties created are primitive strings. |
remove(name) |
Remove the named property from the this object. Note that name is a string. |
setFileName(name) |
Sets the name of the properties file. This sets the fileName property of this object. |
write([comment]) |
Writes all the properties from this object to the properties file. This will overwrite any existing properties file. The comment argument is an optional comment string that will be put at the top of the properties file. If an error is detected this function will return false and the error property will be set. If the properties were written successfully then this function will return true. Note: This function only writes the immediate properties of this object and does not do recursive properties. The string value of the properties is what is written. |
Topic ID: 150089