Entries Tagged as "Railo"

REEscape, new function for Railo

I happened to see a Railo JIRA ticket, suggesting to add a REEscape() function for Railo. It caught my attention, because I recently blogged about my RegExSafe() function, which does exactly the same. REEscape does sound more logical then RegExSafe, if you think about the already existent functions REFind, REReplace, and REMatch.

So, I took it upon me to create this new function for Railo, which was essentially nothing more then renaming the function, and (for now) creating an installer for it. I assume the function will become Railo core in the near future, presumably for version 3.3.

3 Comments

CFCSV, a new CFML tag for Lucee and Railo! - version 1.2, march 2015

Ever had to work with CSV files? It stands for Comma Separated Values, and although the file format looks incredibly simple, it can be a pain to work with. But not anymore!!!

Thanks to Ben Nadel's extensive research into CSV parsing, and a bit of extra coding and tweaking on my part, you can now start using <cfcsv> in Railo!

Now updated to version 1.2 (March 2015)

42 Comments

getParentTemplatePath() function for Railo

Railo has the cool ability to use relative file paths in all it's main directory and file functions. For example <cfset fileRead("myFile.txt") />.

Now, I am writing a new custom tag CFCSV for Railo, and also wanted to include this ability: <cfcsv action="parse" file="myFile.csv" />. Therefor, my custom tag needed to know the caller's template path, and calculate the full file path from there. Finding the caller's template path took me longer then expected. I thought I could easily get it from the reference to the "caller" within my custom tag. I didn't find it in that object unfortunately. So in the end, I chose to just get the current stack trace for the request, and loop through there:

<cffunction name="getParentTemplatePath" returntype="string" output="no">
<cfset var stackTraceArr = getPageContext().getThread().getStackTrace() />
<cfset var i = -1 />
<cfset var thisFncFound = false />
<cfset var currentFilePath = "" />
<cfloop collection="#stackTraceArr#" item="i">
<cfif right(stackTraceArr[i].getClassName(), 3) == "$cf">
<cfif not thisFncFound>
<cfset thisFncFound = true />
<cfelseif len(currentFilePath) and stackTraceArr[i].getFileName() neq currentFilePath>
<cfreturn stackTraceArr[i].getFileName() />
<cfelse>
<cfset currentFilePath = stackTraceArr[i].getFileName() />
</cfif>
</cfif>
</cfloop>
<cfreturn "" />
</cffunction>

You can use this function inline within your current template, and also called as an external cfc function.

In case it's not working, let me know. It's not really thoroughly investigated, so it might explode at a moment you least expect it ;-)

For Adobe Coldfusion, you might want to check out this blog post by Elliott Sprehn: http://www.elliottsprehn.com/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/

No Comments

Railo custom tag CFDNS

I was actually surprised it was not in Coldfusion yet: the ability to do dns lookups. Since I'm the official Railo Extension Manager®™, I saw it as an excellent chance to create a new custom tag: CFDNS.
But, as seems to happen a lot with good ideas, someone else already thought of it. Just check www.cfdns.org :-/

The thing I could still do, was create the code to use it as a custom tag in Railo. I used the existing cfdns code with a few changes, and made a custom tag wrapper for it, and here it is: <CFDNS> for Railo!

6 Comments

Railo tip: using conditional assignments!

I saw this type of code popping up in some Railo source code, but for some reason did not use it before.

In javascript, I was already using it a long time: var a = (b>100) ? 100 : b, but in Railo? Not yet.

Well, that has changed now! It is much simpler then using IIF(), and has great power:

<cfset testValue = 107 />
<cfset nothigherThen100 = testValue gt 100 ? 100 : testValue />

And you can also use it inline:

<cfset testValue = 107 />
<cfoutput>#testValue# is #(testValue gt 100 ? 'greater then' : 'smaller or equal to')# hundred</cfoutput>

Off course, you can nest these statements:

<cfoutput>#testValue# is #(testValue gt 100 ? 'greater then' : (testValue eq 100 ? 'exactly' : 'smaller then'))# hundred</cfoutput>

If you are new to this concept, the syntax is really simple, once you get the hang of it: (also see Wikipedia)

[statement, evaluated to true or false] ? [value if statement is true] : [value if statement is false]

Pretty nifty eeh? [edit] And it works in Adobe Coldfusion 9 too. [/edit]

6 Comments