An app I am working on needs to check the Java CLASSPATH (I am trying to return more useful errors if a call fails). The CLASSPATH is a Java property (kind of like environment variables) named java.class.path, and to obtain this value all you need to do is call getProperty() in java.lang.System. To make this simpler I through these two UDFs together, the first returns a structure of all Java properties and the second returns a specific property.
<!--- Return all Java properties --->
<cffunction name="GetJavaProperties" returntype="struct" output="no">
<cfreturn CreateObject("Java", "java.lang.System").getProperties()>
</cffunction>
<!--- Return a specific Java property --->
<cffunction name="GetJavaProperty" returntype="string" output="no">
<cfargument name="property" type="string" required="yes">
<cfreturn CreateObject("Java", "java.lang.System").getProperty(ARGUMENTS.property)>
</cffunction>
It is worth noting that to access a property with a . in its name you'll need to use struct["member"] syntax instead of struct.member. So this will work:
<cfset p=GetJavaProperties()>
<cfoutput>
#p["java.class.path"]#
</cfoutput>
But this won't:
<cfset p=GetJavaProperties()>
<cfoutput>
#p.java.class.path#
</cfoutput>
Actually, you are probably THE guy to ask... all the Java hooks that we have, are those officially supported by ColdFusion? I know the serviceFactory used to be secret, and now its sort of advertised... does that go for all underlying, accessible java stuffs?
--- Ben
--- Ben
I am pretty sure I know the answer to this one, but I just wanted to run it by you. I have discovered that if i have a String object (ex. strTest = "ben forta") then I can actually call the Java replace methods directly:
strTest.ReplaceAll( [regexp], [replacestring] )
This however is not documented (that I can find). However, it can be found via the GetMetaData() and then a few other methods calls. So, I assuming that this is NOT safe to do, but I was hoping maybe it was :)
--- Ben
That is very exciting... I love using the Java ReplaceAll() method :) Sweeet. And yeah, I have found some interesting stuff using thet GetClass().GetName() stuff. For instance, the underlying query object is coldfusion.sql.QueryTable and that has some cool methods like IsFirst(), IsLast(), and RemoveRows() which I would be excited to use. Do you think that is safe (and that's my final question)?
--- Ben
Red sea real estate
datamaster@mysharm-el-sheikh.com
www.mysharm-el-sheikh.com
Red sea real estate
info@redsearealestatesharm.com
http://www.redsearealestatesharm.com
post.