How to use org.apache.commons.configuration with Coldfusion

170 Views Asked by At

I am trying to utilize PropertiesConfiguration to manipulate property files in coldfusion. Using org.apache.commons.configuration version 1.10.

propertyFile = "usergui.properties";

config = createObject("java","org.apache.commons.configuration.PropertiesConfiguration").init(propertyFile);

I am getting to matching function init that takes a string. I have tried doing java.io.file.

1

There are 1 best solutions below

2
jonesk On

I figured it out problem was that I didn't include all the dependencies. DUH!

function updatePropFile(string propFile, struct propStruct, struct removeStruct){
    propertyFile = propFile;
    javaFile = createObject("java", "java.io.File").init(propertyFile);
    fileStream = createObject("java", "java.io.FileInputStream").init(javaFile);


    config = createObject("java","org.apache.commons.configuration.PropertiesConfiguration").init(javaFile);

    configLayout = config.getLayout();

    for(key in propStruct){
        if(config.containsKey(key)){
            config.setProperty(key, propStruct[key]);
        }else{
            config.addProperty(key, propStruct[key]);
        }
    }

    for(key in removeStruct){
        if(config.containsKey(key)){
            /* clear prop and add as comment */
            value = config.getProperty(key).toString();
            config.clearProperty(key);
            config.addProperty('##'&key, key & "=" & value);
        }
    }

    configLayout.save(createObject("java", "java.io.FileWriter").init(propFile, false));
}