FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

PropertyFile Util

v1.2.0 Public

PropertyFile Utility for CFML

ProperyFile is a library to make it is easy to load, modify, and store Java property files from CFML without needing to touch any Java. This library is a single CFC that encapsulates the data and behaviors of a Java properties file in a fluent API.

getInstance( 'propertyFile' )
    .load( myPath )
    .set( 'myProp', 'myValue' )
    .store();

Read files

To use, create an instance of PropertyFile and call the load() method with the full path to the file you wish to load.

var propertyFile = getInstance( 'propertyFile' ).load( expandPath( 'myFile.properties' ) );

Manipulate properties

We support two ways of interacting with the file. You can call methods to get/set/remove properties like so:

propertyFile.set( 'myProp', 'myValue' );
propertyFile.get( 'myProp' );
propertyFile.get( 'anotherProp', 'defaultValue' );
propertyFile.exists( 'questionableProp' );

Or you can just use the object directly as a struct and we'll treat the public properties with a dab of fairy dust to keep track of them. This code block does the same as above.

propertyFile.myProp = 'myValue';
propertyFile.myProp;
propertyFile.anotherProp ?: 'defaultValue';
structKeyExists( propertyFile, 'questionableProp' );

Note, this method will give you some issues if you happen to have any property names that conflict with built-in method names since they live in the this scope too. Also, make sure property names with periods in them are set like propertyFile[ 'this.is.my.prop' ] and NOT like propertyFile.this.is.my.prop. The latter will create nested structs instead of a single property which isn't what you want.

Iterate properties

If you want to get the properties in an iterable form, use this method:

var myStruct = propertyFile.getAsStruct();
for( var prop in myStruct ) {
	writeDump( myStruct[ prop ] );
}

Store properties

To write a properties file back to the same file you read it from use this store() method with no arguments.

propertyFile.store();

To save what's in memory to a new file (or to save a new properties object that you didn't read in the first place), pass the path you want into the store() method.

propertyFile.store( expandPath( 'myNewFile.properties' ) );

Method Chaining

All methods in the PropertyFile object that don't return an explicit value will return this so you can chain calls like so:

getInstance( 'propertyFile' )
	.load( myPath )
	.set( 'myProp', 'myValue' )
	.set( 'myOtherProp', 'myOtherValue' )
	.store();

Here are all the versions for this package. Please note that you can leverage CommandBox package versioning to install any package you like. Please refer to our managing package version guide for more information.

Version Created Last Update Published By Stable Actions
Current
1.2.0 Dec 27 2018 03:07 PM Dec 27 2018 03:07 PM
Version History
1.1.0 May 17 2017 11:49 PM May 17 2017 11:49 PM
1.0.9 Feb 10 2017 07:42 PM Feb 10 2017 07:42 PM
1.0.8 Feb 10 2017 07:40 PM Feb 10 2017 07:40 PM
1.0.7 Feb 06 2017 10:19 PM Feb 06 2017 10:19 PM
1.0.6 Feb 06 2017 10:06 PM Feb 06 2017 10:06 PM
1.0.4 Feb 06 2017 10:04 PM Feb 06 2017 10:04 PM
1.0.3 Feb 06 2017 10:02 PM Feb 06 2017 10:02 PM
1.0.2 Feb 06 2017 09:59 PM Feb 06 2017 09:59 PM
1.0.1 Feb 06 2017 03:48 PM Feb 06 2017 03:48 PM
1.0.0 Jan 28 2017 11:14 PM Jan 28 2017 11:14 PM

 

No collaborators yet.
     
  • Jan 28 2017 11:14 PM
  • Dec 27 2018 03:07 PM
  • 1117
  • 0
  • 41958