Although this has been done a million times I took a little time (wasting time mostly) to cook up a simple ColdFusion component that implements a basic soundex algorithm (see http://www.creativyst.com/Doc/Articles/SoundEx1/SoundEx1.htm for more info on the reference I used). The component provides a simple interface to add “dictionary” items, and compare subject text against the dictionary items within a specific threshold for potential soundex matches.
Read the rest of this entry »
Posts Tagged ‘ColdFusion’
Coldfusion Soundex Algorithm Component
Tags: ColdFusion, Development
Posted in ColdFusion, Development | Comments (0)
ColdFusion Race Conditions?
One of the things I’ve been struggling with at work lately is related to bizzare ColdFusion errors. Essentially what I am seeing is a page that normally works just suddenly throw an error stating that a specific variable cannot be accessed as an object because it is of type java.lang.String. The problem with this is that it is in fact a CFC instance, and works great for the most part. Then suddenly it will stop working, and logging off the software, and back in, is the only solution. This, of course, is problematic.
Tags: ColdFusion, Development
Posted in ColdFusion, Development | Comments (0)
New article on file name and uploading to ColdFusion
Howdy peeps! New little article talking about cleaning up file names in ColdFusion, useful for when processing a file upload, for example. Check it out!
Tags: ColdFusion, Development, Tutorial
Posted in Development, General | Comments (0)
No Expand? Sweet!
It’s funny the little things you miss as you use a programming language. Although not considered the longest amount of time, I have been using ColdFusion for over 4 years now. I’ve worked with CFC’s, frameworks, performance tuning, reflection, advanced Java techniques, and more, but somehow seemed to missed one of the most simple, yet useful little attributes (at least useful to me now).
Very frequently I find myself dumping out debug data to evaluate how the results of a given set of code is coming along. Good old <CFDUMP> is my friend in plenty of cases. How in the world, then, did I miss the expand=”no” attribute? OMG! Whenever I’m dumping out large CFC structures, that puppy is my FRIEND! lol.
This, in my opinion, is one of the beauties of programming. Always learning something new.
Tags: attributes, ColdFusion, Development
Posted in ColdFusion, Development | Comments (0)
On ColdFusion 7 Arrays
At Ben Nadel’s Blog, which I enjoy reading simply because he has a similar passion to me (digging into how and why it works under the hood), he talked about calling Java functions in ColdFusion that require an actual value array instead of a vector, which is what ColdFusion’s arrays are based on. He has an example, and then goes to show how ColdFusion 8 made that task much easier.
Only one thing I saw about it that struck me as odd was that he was manually copying the values from the ColdFusion “array” (vector) to the Java array. Didn’t think that would be necessary, so I looked it up. Not much different than Mr. Nadel’s code, but a few lines shorter and if I had to guess, the Java method to copy the data to the new array is likely more efficient than a manual copy.
-
<!————————————————-
-
ColdFusion array, which is actually a Vector.
-
————————————————–>
-
<cfset<!– Traffic Statistics –> <!– End Traffic Statistics –> arrValue = ArrayNew(1)>
-
-
<cfset arrValue[1] = "What’s up hot stuff?" />
-
<cfset arrvalue[2] = "You come here a lot?" />
-
<cfset arrValue[3] = "You from out of town?" />
-
<cfset arrValue[4] = "Want a little of this?" />
-
<cfset arrValue[5] = "How ’bout a little of that?" />
-
-
<!—————————————————————–
-
Need to get the class of a string, and create our java array.
-
——————————————————————>
-
<cfset stringClass = createObject("java", "java.lang.String").getClass()>
-
<cfset arrJavaValue = createObject("java", "java.lang.reflect.Array").newInstance(stringClass, arrayLen(arrValue))>
-
-
<cfset arrValue.copyInto(arrJavaValue)>
-
-
<cfdump var="#arrValue#">
-
-
<cfoutput>
-
-
<p>
-
#arrValue.GetClass().GetName()#<br />
-
#arrValue.GetClass().GetSuperClass().GetName()#<br />
-
#arrValue.GetClass().GetSuperClass().GetSuperClass().GetName()#<br />
-
#arrValue.GetClass().GetSuperClass().GetSuperClass().GetSuperClass().GetName()#<br />
-
#arrValue.GetClass().GetSuperClass().GetSuperClass().GetSuperClass().GetSuperClass().GetName()#<br />
-
</p>
-
-
<h4>
-
</h4>
-
-
<p>
-
#arrJavaValue.GetClass().GetName()#<br />
-
</p>
-
-
</cfoutput>
Tags: ColdFusion, Development
Posted in ColdFusion, Development | Comments (0)
Barbecue revisited.
I made a post recently about using Barbecue barcode software in ColdFusion. In my example I instantiated the CFC object and called the getCode128 function as the source of an image tag. With a bit of experimentation you will find that although this produces an image… that’s ALL it produces. Why? Cause we essentially hijack the content type of ColdFusion’s output buffer and set it to image/jpeg. It removes all other content from the buffer, and only sends over the image. The fix?
The component
-
<cfcomponent>
-
-
<cffunction name="getCode128" returntype="any" access="remote" output="true">
-
<cfargument name="data" type="string" required="true" />
-
-
<cfsetting showdebugoutput="false">
-
-
<cfscript>
-
-
outStream = createObject("java", "java.io.ByteArrayOutputStream").init();
-
-
//———————————————————–
-
// Create the barcode, and draw it to a buffered image class.
-
//———————————————————–
-
barcode = createObject("java", "net.sourceforge.barbecue.BarcodeFactory").createCode128("#arguments.data#");
-
bufferedImage = createObject("java", "net.sourceforge.barbecue.BarcodeImageHandler").writeJPEG(barcode, outStream);
-
-
</cfscript>
-
-
<!— Return the information as streaming bytes of type image/jpeg —>
-
<cfset getPageContext().getOut().clearBuffer()><cfcontent type="image/jpeg" variable="#outStream.toByteArray()#"><cfreturn>
-
</cffunction>
-
-
</cfcomponent>
Usage:
-
<cfoutput>
-
-
<img src="barcode.cfc?method=getCode128&data=My First Barcode" />
-
-
</cfoutput>
So, as you can see in this case I am calling the CFC method remotely in the image source attribute forcing a separate HTTP request. This also required me to make the access to the getCode128 function to remote. Hope it helps! Cheers!
Tags: ColdFusion, Development
Posted in ColdFusion, Development | Comments (3)
Using Barbecue Barcode in ColdFusion
I was approached today by a coworker about integrating the open source Java-based barcode library, Barbecue, into ColdFusion. He wanted to use this library to prototype a project concept for adding barcode support to certain parts of our application. A little bit of play and here’s how it works.
The first thing you will need to do is extract the JAR file from the download ZIP file (the file I used was barbecue-1.5-beta1.jar). Put this file into your {ColdFusionRoot}\runtime\lib (for single server installs). You will need to restart the ColdFusion service for CF to pick that up.
Now lets do some code. First lets create a component called barcode.cfc. And in there we will have a function called getCode128, which will return a Code 128 barcode that dynamically switches between character sets to give the smallest possible encoding. It will look like so.
-
<cfcomponent>
-
-
<cffunction name="getCode128" returntype="any" access="public" output="true">
-
<cfargument name="data" type="string" required="true" />
-
-
<cfsetting showdebugoutput="false">
-
-
<cfscript>
-
-
outStream = createObject("java", "java.io.ByteArrayOutputStream").init();
-
-
//———————————————————–
-
// Create the barcode, and draw it to a buffered image class.
-
//———————————————————–
-
barcode = createObject("java", "net.sourceforge.barbecue.BarcodeFactory").createCode128("#arguments.data#");
-
bufferedImage = createObject("java", "net.sourceforge.barbecue.BarcodeImageHandler").writeJPEG(barcode, outStream);
-
-
</cfscript>
-
-
<!— Return the information as streaming bytes of type image/jpeg —>
-
<cfset getPageContext().getOut().clearBuffer()><cfcontent type="image/jpeg" variable="#outStream.toByteArray()#"><cfreturn>
-
</cffunction>
-
-
</cfcomponent>
The code is pretty well documented so it should be pretty clear what we are doing here. Now, to use it we will simply create an instance of our new component, and call the getCode128 function as the source to an image tag in HTML. Like so.
-
<cfoutput>
-
-
<cfset o = createObject("component", "barcode")>
-
<img src="#o.getCode128(’My First Barcode’)#" />
-
-
</cfoutput>
So there you have it. Give it a go! It was fun!
Tags: ColdFusion, Development
Posted in ColdFusion, Development | Comments (3)
Using TreeMap in ColdFusion
Have you ever found the need to maintain a structured list of items? Of course! Have you ever needed to make sure those items stay in natural order? Maybe. If you answered yes then you need the Java TreeMap class.
Let us say we are going to store a structure of employee names and their titles associated to them. In this example we will keep just such a list, insert them in random order, and you will see the output result comes out in alphabetical (natural) order. The order is maintained based on the KEY, by the way. So, without further ado, here is an example.
-
<script>
-
-
treeMap = createObject("java", "java.util.TreeMap").init();
-
-
writeOutput("<strong>Inserting the following employees in this order:</strong> Dave, Adam, Kyle, James.<br />");
-
-
treeMap.put("Donny", "President");
-
treeMap.put("Adam", "Engineer");
-
treeMap.put("Kujo", "Director");
-
treeMap.put("Johnny", "Support");
-
-
writeOutput("<strong>Now show the contents of this tree in key order.</strong><br />");
-
-
iter = treeMap.keySet().iterator();
-
while (iter.hasNext())
-
{
-
key = iter.next();
-
writeOutput("Key: #key# Value: #treeMap.get(key)#<br />");
-
}
-
-
</script>
In this example we instantiate the TreeMap class first. We then insert the employees Donny, Adam, Kujo, and Johnny, making the value of these keys their job titles. We then get an iterator for the keyset (an array of the TreeMap keys) and loop while we still have keys, displaying the key name, and its value. Here is what the output looks like.
Inserting the following employees in this order: Donny, Adam, Kujo, Johnny. Now show the contents of this tree in key order. Key: Adam Value: Engineer Key: Donny Value: President Key: Johnny Value: Support Key: Kujo Value: Director
Tags: ColdFusion, Development
Posted in ColdFusion, Development | Comments (0)