commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [commons-configuration] Variable Syntax Conflict
Date Sat, 23 Jun 2007 15:03:59 GMT
Hi Dave,

Dave Westerman wrote:
> I am using the commons-configuration for my property files. However, 
> unfortunately, I have a need to have a value in some of my properties 
> that look exactly like the variables that commons-config uses.
> 
> myproperty=${myNonCommonsConfigVariable}
> 
> I've tried to escape it thus:
> 
> myproperty=\${myNonCommonsConfigVariable}
> myproperty=\\${myNonCommonsConfigVariable}
> myproperty=$${myNonCommonsConfigVariable}
> 
> but all to no avail.
> 
> Is there any way for me to get around this conflict? Can I change the 
> delimiter that commons-config uses (I've looked at all the classes, 
> there doesn't seem to be a way)?
> 
> The error I'm getting is this:
> 
> java.lang.IllegalStateException: infinite loop in property interpolation 
> of 
> ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar:

> DB2UNIVERSAL_JDBC_DRIVER_PATH->DB2UNIVERSAL_JDBC_DRIVER_PATH
> 

which version of Commons Configuration do you use? Since the 1.3 release 
substituation of variables is handled by the StrSubstitutor class of 
Commons Lang [1]. Here the '$' sign is used for escaping variables, so 
your 3rd example

myproperty=$${myNonCommonsConfigVariable}

should work. There is also a unit test that checks this behavior:

     public void testInterpolationEscaped()
     {
         config.addProperty("var", "x");
         config.addProperty("escVar", "Use the variable $${${var}}.");
         assertEquals("Wrong escaped variable", "Use the variable 
${x}.", config
                 .getString("escVar"));
     }

IIRC in earlier versions of Configuration escaping variables was not 
supported.

Oliver

[1] 
http://jakarta.apache.org/commons/lang/api-release/org/apache/commons/lang/text/StrSubstitutor.html

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message