<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>devbox@COMPUTEC &#187; Java</title>
	<atom:link href="http://devbox.computec.de/category/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://devbox.computec.de</link>
	<description>The Computec development blog</description>
	<lastBuildDate>Tue, 24 Aug 2010 08:45:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='devbox.computec.de' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Coldfusion UDF to create &amp; CHMOD a full directory path</title>
		<link>http://devbox.computec.de/2010/07/coldfusion-udf-to-create-chmod-a-full-directory-path/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=coldfusion-udf-to-create-chmod-a-full-directory-path</link>
		<comments>http://devbox.computec.de/2010/07/coldfusion-udf-to-create-chmod-a-full-directory-path/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 09:10:28 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[udf]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=544</guid>
		<description><![CDATA[The following problem has come up during a file caching implementation: We've got a directory /var/www/MYCACHE; our filecaching mechanism uses a key-based directory structure to store files there. So let's suppose our key would be 123456789, we'd like to store the file 123456789.cache under /var/www/MYCACHE/123/123456/123456789.cache. This would make sure that no directory needs to hold [...]]]></description>
			<content:encoded><![CDATA[<p>The following problem has come up during a file caching implementation: We've got a directory <code>/var/www/MYCACHE</code>; our filecaching mechanism uses a key-based directory structure to store files there. So let's suppose our key would be <code>123456789</code>, we'd like to store the file <code>123456789.cache</code> under <code>/var/www/MYCACHE/123/123456/123456789.cache</code>. This would make sure that no directory needs to hold more than 1,000 nodes.</p>
<p>All would be well if we could be sure that the user jrun (i.e. the user that owns our ColdFusion process) was indeed the only user ever to access this directory structure. In our case we want to be able to access this structure with PHP, too, which runs as mod_php on the webserver, thus as user www-data. To avoid permission problems, we want to assign a permission of 0777 to all directories in the structure upon creation.</p>
<p><span id="more-544"></span>You'll need at least JDK 1.6 for this to work:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;createWRXPath&quot;</span> </span>
<span style="color: #333333;">	<span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> </span>
<span style="color: #333333;">	returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> </span>
<span style="color: #333333;">	output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;strPath&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;an absolute physical path </span>
<span style="color: #333333;">		to a directory, not a file&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;iMinDepth&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;numeric&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;4&quot;</span> </span>
<span style="color: #333333;">		<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;minimum depth to set permissions&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		var local = structNew();
&nbsp;
		local.strPath = GetDirectoryFromPath(
			JavaCast('string',arguments.strPath));
&nbsp;
		local.objFile = CreateObject('java'
			,'java.io.File').init(local.strPath);
&nbsp;
		if (arguments.iMinDepth gt 4) {
			local.iMinDepth = arguments.iMinDepth;
			} else {
			local.iMinDepth = 4;			
		} // end if (arguments.iMinDepth gt 4)
&nbsp;
		// create the path
		local.objFile.mkdirs();
&nbsp;
		// if that hasn't succeeded, return false
		if (not DirectoryExists(local.strPath)) return false;
&nbsp;
		local.l = ListLen(local.strPath,'/');
&nbsp;
		local.strPartPath = '/';
&nbsp;
		// now descend into the path from top down, 
		//   set permissions for every directory lower 
		//  than level iMinDepth
&nbsp;
		for (local.i=1; local.i lte local.l; local.i++) {
&nbsp;
			local.strPartPath &amp;= 
				ListGetAt(local.strPath,local.i,'/') &amp; '/';
&nbsp;
			if (local.i gte local.iMinDepth) {				
				local.objFile = CreateObject('java'
					,'java.io.File').init(
					    local.strPartPath);
&nbsp;
				local.objFile.setReadable(TRUE,FALSE);				
				local.objFile.setWritable(TRUE,FALSE);
				local.objFile.setExecutable(TRUE,FALSE);
&nbsp;
			} // end if (local.i gte local.iMinDepth)
&nbsp;
		} // end for (local.i=1; local.i lte local.l; local.i++)
&nbsp;
		return TRUE;
&nbsp;
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Example for usage:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>	
	variables.strFile  = '/var/www/MYCACHE/123/123456/123456789.cache';
	variables.strPath  = GetDirectoryFromPath(variables.strFile);
	variables.bSuccess = createWRXPath(variables.strPath,4);	
	writeOutput(variables.bSuccess);
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>




Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;bodytext=The%20following%20problem%20has%20come%20up%20during%20a%20file%20caching%20implementation%3A%20We%27ve%20got%20a%20directory%20%2Fvar%2Fwww%2FMYCACHE%3B%20our%20filecaching%20mechanism%20uses%20a%20key-based%20directory%20structure%20to%20store%20files%20there.%20So%20let%27s%20suppose%20our%20key%20would%20be%20123456789%2C%20we%27d%20lik" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;notes=The%20following%20problem%20has%20come%20up%20during%20a%20file%20caching%20implementation%3A%20We%27ve%20got%20a%20directory%20%2Fvar%2Fwww%2FMYCACHE%3B%20our%20filecaching%20mechanism%20uses%20a%20key-based%20directory%20structure%20to%20store%20files%20there.%20So%20let%27s%20suppose%20our%20key%20would%20be%20123456789%2C%20we%27d%20lik" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;t=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;annotation=The%20following%20problem%20has%20come%20up%20during%20a%20file%20caching%20implementation%3A%20We%27ve%20got%20a%20directory%20%2Fvar%2Fwww%2FMYCACHE%3B%20our%20filecaching%20mechanism%20uses%20a%20key-based%20directory%20structure%20to%20store%20files%20there.%20So%20let%27s%20suppose%20our%20key%20would%20be%20123456789%2C%20we%27d%20lik" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=The%20following%20problem%20has%20come%20up%20during%20a%20file%20caching%20implementation%3A%20We%27ve%20got%20a%20directory%20%2Fvar%2Fwww%2FMYCACHE%3B%20our%20filecaching%20mechanism%20uses%20a%20key-based%20directory%20structure%20to%20store%20files%20there.%20So%20let%27s%20suppose%20our%20key%20would%20be%20123456789%2C%20we%27d%20lik" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;bm_description=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;t=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&opener=bm&amp;ei=UTF-8&amp;d=The%20following%20problem%20has%20come%20up%20during%20a%20file%20caching%20implementation%3A%20We%27ve%20got%20a%20directory%20%2Fvar%2Fwww%2FMYCACHE%3B%20our%20filecaching%20mechanism%20uses%20a%20key-based%20directory%20structure%20to%20store%20files%20there.%20So%20let%27s%20suppose%20our%20key%20would%20be%20123456789%2C%20we%27d%20lik" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;t=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;submitHeadline=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;submitSummary=The%20following%20problem%20has%20come%20up%20during%20a%20file%20caching%20implementation%3A%20We%27ve%20got%20a%20directory%20%2Fvar%2Fwww%2FMYCACHE%3B%20our%20filecaching%20mechanism%20uses%20a%20key-based%20directory%20structure%20to%20store%20files%20there.%20So%20let%27s%20suppose%20our%20key%20would%20be%20123456789%2C%20we%27d%20lik&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;exttitle=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-udf-to-create-chmod-a-full-directory-path%2F&amp;bm_description=Coldfusion%20UDF%20to%20create%20%26%20CHMOD%20a%20full%20directory%20path&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/07/coldfusion-udf-to-create-chmod-a-full-directory-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion: Get date from Unix timestamp</title>
		<link>http://devbox.computec.de/2010/07/coldfusion-oneliner-to-get-a-date-from-a-unix-timestamp/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=coldfusion-oneliner-to-get-a-date-from-a-unix-timestamp</link>
		<comments>http://devbox.computec.de/2010/07/coldfusion-oneliner-to-get-a-date-from-a-unix-timestamp/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:45:12 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[unix timestamp]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=521</guid>
		<description><![CDATA[A quick followup on a previous post ColdFusion UDF to get Unix timestamp from date: Here's a oneliner that provides you with the complimentary function to get a date from a Unix timestamp - as I've discovered that the dateAdd() route mostly recommended on the net not only suffers from being quite clumsy, the result [...]]]></description>
			<content:encoded><![CDATA[<p>A quick followup on a previous post <a href="http://devbox.computec.de/2010/05/coldfusion-udf-to-get-unix-timestamp-from-date/">ColdFusion UDF to get Unix timestamp from date</a>: Here's a oneliner that provides you with the complimentary function to get a date from a Unix timestamp - as I've discovered that the <code>dateAdd()</code> route mostly recommended on the net not only suffers from being quite clumsy, the result is off by one hour, too - at least when DST is on.</p>
<p>So to get a date from a Unix timestamp in ColdFusion, you can use this oneliner:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dtMyDate <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">'java'</span>,<span style="color: #009900;">'java.util.Date'</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">javaCast</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">'long'</span>,iUnixTS*<span style="color: #FF0000;">1000</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>




Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;bodytext=A%20quick%20followup%20on%20a%20previous%20post%20ColdFusion%20UDF%20to%20get%20Unix%20timestamp%20from%20date%3A%20Here%27s%20a%20oneliner%20that%20provides%20you%20with%20the%20complimentary%20function%20to%20get%20a%20date%20from%20a%20Unix%20timestamp%20-%20as%20I%27ve%20discovered%20that%20the%20dateAdd%28%29%20route%20mostly%20recommend" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;notes=A%20quick%20followup%20on%20a%20previous%20post%20ColdFusion%20UDF%20to%20get%20Unix%20timestamp%20from%20date%3A%20Here%27s%20a%20oneliner%20that%20provides%20you%20with%20the%20complimentary%20function%20to%20get%20a%20date%20from%20a%20Unix%20timestamp%20-%20as%20I%27ve%20discovered%20that%20the%20dateAdd%28%29%20route%20mostly%20recommend" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;t=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;annotation=A%20quick%20followup%20on%20a%20previous%20post%20ColdFusion%20UDF%20to%20get%20Unix%20timestamp%20from%20date%3A%20Here%27s%20a%20oneliner%20that%20provides%20you%20with%20the%20complimentary%20function%20to%20get%20a%20date%20from%20a%20Unix%20timestamp%20-%20as%20I%27ve%20discovered%20that%20the%20dateAdd%28%29%20route%20mostly%20recommend" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=A%20quick%20followup%20on%20a%20previous%20post%20ColdFusion%20UDF%20to%20get%20Unix%20timestamp%20from%20date%3A%20Here%27s%20a%20oneliner%20that%20provides%20you%20with%20the%20complimentary%20function%20to%20get%20a%20date%20from%20a%20Unix%20timestamp%20-%20as%20I%27ve%20discovered%20that%20the%20dateAdd%28%29%20route%20mostly%20recommend" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;bm_description=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;t=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&opener=bm&amp;ei=UTF-8&amp;d=A%20quick%20followup%20on%20a%20previous%20post%20ColdFusion%20UDF%20to%20get%20Unix%20timestamp%20from%20date%3A%20Here%27s%20a%20oneliner%20that%20provides%20you%20with%20the%20complimentary%20function%20to%20get%20a%20date%20from%20a%20Unix%20timestamp%20-%20as%20I%27ve%20discovered%20that%20the%20dateAdd%28%29%20route%20mostly%20recommend" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;t=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;submitHeadline=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;submitSummary=A%20quick%20followup%20on%20a%20previous%20post%20ColdFusion%20UDF%20to%20get%20Unix%20timestamp%20from%20date%3A%20Here%27s%20a%20oneliner%20that%20provides%20you%20with%20the%20complimentary%20function%20to%20get%20a%20date%20from%20a%20Unix%20timestamp%20-%20as%20I%27ve%20discovered%20that%20the%20dateAdd%28%29%20route%20mostly%20recommend&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;exttitle=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fcoldfusion-oneliner-to-get-a-date-from-a-unix-timestamp%2F&amp;bm_description=ColdFusion%3A%20Get%20date%20from%20Unix%20timestamp&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/07/coldfusion-oneliner-to-get-a-date-from-a-unix-timestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String methods: ColdFusion vs. Java</title>
		<link>http://devbox.computec.de/2010/07/string-methods-coldfusion-vs-java/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=string-methods-coldfusion-vs-java</link>
		<comments>http://devbox.computec.de/2010/07/string-methods-coldfusion-vs-java/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 08:50:57 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=507</guid>
		<description><![CDATA[You may know from previous blog posts that I strongly advise every ColdFusion developer to familiarize himself/herself with the thing that actually makes ColdFusion tick, i.e. with Java. Everybody who writes a single line of CFML should know about the possibilities of extending ColdFusion by directly accessing the underlying Java methods of certain objects. One [...]]]></description>
			<content:encoded><![CDATA[<p>You may know from previous blog posts that I strongly advise every ColdFusion developer to familiarize himself/herself with the thing that actually makes ColdFusion tick, i.e. with Java. Everybody who writes a single line of CFML should know about the possibilities of extending ColdFusion by directly accessing the underlying Java methods of certain objects. One of the datatypes where actually using Java may make a lot of sense is the string object. </p>
<p>ColdFusion string literals are just plain old <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html" target="_blank">Java strings</a>. If you grab a string from e.g. a query object like <code>variables.qMyQuery.myTextColumn</code>, you need to be careful though - even if you think you just have one tuple returned, you've got something other than a string object on your hands. In such a case you need to either specifically target a certain row (like <code>variables.qMyQuery.myTextColumn[1]</code>) or you wrap it up in a JavaCast like <code>Javacast('string',variables.qMyQuery.myTextColumn)</code>.</p>
<p>I finally found a moment to actually do some benchmarking on some of the built-in ColdFusion functions against their Java counterparts. This is not a benchmark of Java vs. ColdFusion performance, mind you, it's about deciding whether to use Java-methods inside of ColdFusion vs. ColdFusion's built-in string functions.<br />
<span id="more-507"></span><br />
The test subject here is a string of 2848 characters length, pulled from our live article database, which should provide a realistic use case. The JavaCast has already been done, so if we're working with string data that may not be represented by actual Java string objects at the time of access, we may need to account for some additional processing cycles to do the JavaCast in order to be able to use Java methods on it. I ran the tests several times on the same machine, making sure the results where actually reproducable on each run. The tests have been performed on ColdFusion 8 Enterprise running in a 64-bit multi-instance configuration. If you're running CF9, your mileage may vary, though I wouldn't expect the results to point in a very much different direction.</p>
<p>On to the tests.</p>
<h2>len() vs. length()</h2>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;coldfusion len&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.iCfLen <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">len</span><span style="color: #0000FF;">&#40;</span>variables.strText<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#variables.iCfLen#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;java length&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.iJLength <span style="color: #0000FF;">=</span> variables.strText.length<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#variables.iJLength#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Results: ColdFusion 76ms vs. Java 104ms.</p>
<h2>Find() vs. indexOf()</h2>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;coldfusion find&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.iCfFind <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">Find</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">'Singularity'</span>,variables.strText<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#variables.iCfFind#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;java indexOf&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.iJindexOf <span style="color: #0000FF;">=</span> variables.strText.indexOf<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">'Singularity'</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>#variables.iJindexOf+1#<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Results: ColdFusion 67ms vs. Java 115ms.</p>
<h2>&#038; vs. concat()</h2>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;coldfusion &amp;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.strCFconcat <span style="color: #0000FF;">=</span>  variables.strText <span style="color: #0000FF;">&amp;</span> variables.strText<span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;java concat()&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.strJconcat <span style="color: #0000FF;">=</span> variables.strText.concat<span style="color: #0000FF;">&#40;</span>variables.strText<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Results: ColdFusion 120ms vs. Java 172ms.</p>
<h2>ReReplace() vs. replaceFirst()</h2>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;coldfusion ReReplace&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.strCfReReplace <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ReReplace</span><span style="color: #0000FF;">&#40;</span>variables.strText,<span style="color: #009900;">'Singularity'</span>,<span style="color: #009900;">'Singularity 2'</span>, <span style="color: #009900;">'ONE'</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;java replaceFirst&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.strJreplaceFirst <span style="color: #0000FF;">=</span> variables.strText.replaceFirst<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">'Singularity'</span>,<span style="color: #009900;">'Singularity 2'</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Results: ColdFusion 331ms vs. Java 228ms.</p>
<h2>ReReplace() vs. replaceAll()</h2>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;coldfusion ReReplace&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.strCfReReplace <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ReReplace</span><span style="color: #0000FF;">&#40;</span>variables.strText,<span style="color: #009900;">'Singularity'</span>,<span style="color: #009900;">'Singularity 2'</span>, <span style="color: #009900;">'ALL'</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cftimer</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;outline&quot;</span> <span style="color: #0000FF;">label</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;java replaceAll&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;10000&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;variables.i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.strJreplaceFirst <span style="color: #0000FF;">=</span> variables.strText.replaceAll<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">'Singularity'</span>,<span style="color: #009900;">'Singularity 2'</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cftimer</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Results: ColdFusion 543ms vs. Java 629ms.</p>
<h2>Conclusion</h2>
<p>There seems to be a certain overhead involved in using the underlying Java methods instead of the build-in ColdFusion functions (or operators in case of the &#038;). The difference is actually not that much, and depending on the data you work on, the Java approach might actually gain the upper hand in some cases.</p>
<p>However, based on these findings I would suggest you stick with ColdFusion for such simple cases; your CFML code will be more independent of the underlying VM (which may even be .NET) and easier to write, too, as most ColdFusion IDEs will not support mixed code completion for both CFML and Java.</p>
<p>This is no reason not to take a look behind the curtain, though. Where Java really shines from a ColdFusion developers view is in solving problems that couldn't be as elegantly solved in plain CFML. For example, you'll be able to implement a buffered stream writer instead of <code>&lt;cffile action="append" /&gt;</code>, you'll have <code>java.util.Calendar</code> to do your bidding working with date/time-data, and you'll be able to use a wide range of external Java libraries from within ColdFusion, solving both trivial and most complex problems without you doing all the legwork coding the solutions.</p>
<p>On the other hand, when you actually have discovered some of the gems that are hidden in the Java foundation of ColdFusion, don't just blindly adopt everything you find there. You still need to do some testing to find the tool that fits your needs best.</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;bodytext=You%20may%20know%20from%20previous%20blog%20posts%20that%20I%20strongly%20advise%20every%20ColdFusion%20developer%20to%20familiarize%20himself%2Fherself%20with%20the%20thing%20that%20actually%20makes%20ColdFusion%20tick%2C%20i.e.%20with%20Java.%20Everybody%20who%20writes%20a%20single%20line%20of%20CFML%20should%20know%20about%20th" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;notes=You%20may%20know%20from%20previous%20blog%20posts%20that%20I%20strongly%20advise%20every%20ColdFusion%20developer%20to%20familiarize%20himself%2Fherself%20with%20the%20thing%20that%20actually%20makes%20ColdFusion%20tick%2C%20i.e.%20with%20Java.%20Everybody%20who%20writes%20a%20single%20line%20of%20CFML%20should%20know%20about%20th" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;t=String%20methods%3A%20ColdFusion%20vs.%20Java" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;annotation=You%20may%20know%20from%20previous%20blog%20posts%20that%20I%20strongly%20advise%20every%20ColdFusion%20developer%20to%20familiarize%20himself%2Fherself%20with%20the%20thing%20that%20actually%20makes%20ColdFusion%20tick%2C%20i.e.%20with%20Java.%20Everybody%20who%20writes%20a%20single%20line%20of%20CFML%20should%20know%20about%20th" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=You%20may%20know%20from%20previous%20blog%20posts%20that%20I%20strongly%20advise%20every%20ColdFusion%20developer%20to%20familiarize%20himself%2Fherself%20with%20the%20thing%20that%20actually%20makes%20ColdFusion%20tick%2C%20i.e.%20with%20Java.%20Everybody%20who%20writes%20a%20single%20line%20of%20CFML%20should%20know%20about%20th" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;bm_description=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=String%20methods%3A%20ColdFusion%20vs.%20Java%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;t=String%20methods%3A%20ColdFusion%20vs.%20Java&opener=bm&amp;ei=UTF-8&amp;d=You%20may%20know%20from%20previous%20blog%20posts%20that%20I%20strongly%20advise%20every%20ColdFusion%20developer%20to%20familiarize%20himself%2Fherself%20with%20the%20thing%20that%20actually%20makes%20ColdFusion%20tick%2C%20i.e.%20with%20Java.%20Everybody%20who%20writes%20a%20single%20line%20of%20CFML%20should%20know%20about%20th" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;t=String%20methods%3A%20ColdFusion%20vs.%20Java" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;submitHeadline=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;submitSummary=You%20may%20know%20from%20previous%20blog%20posts%20that%20I%20strongly%20advise%20every%20ColdFusion%20developer%20to%20familiarize%20himself%2Fherself%20with%20the%20thing%20that%20actually%20makes%20ColdFusion%20tick%2C%20i.e.%20with%20Java.%20Everybody%20who%20writes%20a%20single%20line%20of%20CFML%20should%20know%20about%20th&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;exttitle=String%20methods%3A%20ColdFusion%20vs.%20Java" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;title=String%20methods%3A%20ColdFusion%20vs.%20Java" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F07%2Fstring-methods-coldfusion-vs-java%2F&amp;bm_description=String%20methods%3A%20ColdFusion%20vs.%20Java&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/07/string-methods-coldfusion-vs-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion UDF to get Unix Timestamp from Date</title>
		<link>http://devbox.computec.de/2010/05/coldfusion-udf-to-get-unix-timestamp-from-date/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=coldfusion-udf-to-get-unix-timestamp-from-date</link>
		<comments>http://devbox.computec.de/2010/05/coldfusion-udf-to-get-unix-timestamp-from-date/#comments</comments>
		<pubDate>Fri, 28 May 2010 13:44:16 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[datediff]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[unix timestamp]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=474</guid>
		<description><![CDATA[For some legacy MySQL database application I really need Unix timestamps - and I need them in ColdFusion, so MySQL's UNIX_TIMESTAMP just wasn't sufficient for the job. At first I though I could get away with a simple DateDiff - and the result did look plausible. A closer look revealed however that there is probably [...]]]></description>
			<content:encoded><![CDATA[<p>For some legacy MySQL database application I really need Unix timestamps - and I need them in ColdFusion, so MySQL's UNIX_TIMESTAMP just wasn't sufficient for the job. At first I though I could get away with a simple DateDiff - and the result did look plausible. A closer look revealed however that there is probably something fishy going on with DateDiff in ColdFusion. I strongly suspect Daylight Saving Time, though I can't really say at this moment.<br />
<span id="more-474"></span><br />
So as always when I get stuck with ColdFusion, I give Java a chance at solving the problem. Here's what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;CF2UnixTS&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;numeric&quot;</span></span>
<span style="color: #333333;">	<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;calculates a Unix Timestamp from a DateTime value&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;tsTheDate&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;date&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
	var local=structNew();
	local.objCalendar = createObject('java'
				,'java.util.Calendar').getInstance();
	local.objCalendar.clear();
	local.objCalendar.set(year(arguments.tsTheDate)
			,month(arguments.tsTheDate)-1
			,day(arguments.tsTheDate)
			,hour(arguments.tsTheDate)
			,minute(arguments.tsTheDate)
			,second(arguments.tsTheDate));
	local.iUnixTS = int(local.objCalendar.getTimeInMillis()/1000);
	return local.iUnixTS;	
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
	dtLocal = DateAdd('M',7,now());
	iUnixTS = CF2UnixTS(dtLocal);
	iDateDiff = DateDiff('s',CreateDate(1970,1,1),dtLocal);
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfquery</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getTS&quot;</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#APPLICATION.strSomeDS#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	SELECT UNIX_TIMESTAMP(<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfqueryparam</span> cfsqltype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span> </span>
<span style="color: #333333;">			<span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#DateFormat(dtLocal, 'yyyy-MM-dd' ) </span>
<span style="color: #333333;">			&amp; ' ' &amp; TimeFormat(dtLocal, 'HH:mm:ss' )#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
			) AS uxts;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfquery</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>
	dtLocal : <span style="color: #0000FF;">#dtLocal#</span> <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">br</span> <span style="color: #0000FF;">/&gt;</span></span>
	iUnixTS : <span style="color: #0000FF;">#iUnixTS#</span> <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">br</span> <span style="color: #0000FF;">/&gt;</span></span>
	getTS.uxts: <span style="color: #0000FF;">#getTS.uxts#</span> <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">br</span> <span style="color: #0000FF;">/&gt;</span></span>
	DateDiff: <span style="color: #0000FF;">#iDateDiff#</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>This gives me
<pre>
dtLocal : {ts '2010-12-28 15:33:14'}
iUnixTS : 1293546794
getTS.uxts: 1293546794
DateDiff: 1293550394
</pre>
<p></p>
<p>The values from the UDF and the one generated by MySQL are the same. The DateDiff-value is off by minus one hour exactly.</p>
<p>Maybe I am doing something overly complicated here. Is there some easier way to get at the Unix timestamp of a date in ColdFusion?</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;bodytext=For%20some%20legacy%20MySQL%20database%20application%20I%20really%20need%20Unix%20timestamps%20-%20and%20I%20need%20them%20in%20ColdFusion%2C%20so%20MySQL%27s%20UNIX_TIMESTAMP%20just%20wasn%27t%20sufficient%20for%20the%20job.%20At%20first%20I%20though%20I%20could%20get%20away%20with%20a%20simple%20DateDiff%20-%20and%20the%20result%20did%20loo" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;notes=For%20some%20legacy%20MySQL%20database%20application%20I%20really%20need%20Unix%20timestamps%20-%20and%20I%20need%20them%20in%20ColdFusion%2C%20so%20MySQL%27s%20UNIX_TIMESTAMP%20just%20wasn%27t%20sufficient%20for%20the%20job.%20At%20first%20I%20though%20I%20could%20get%20away%20with%20a%20simple%20DateDiff%20-%20and%20the%20result%20did%20loo" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;t=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;annotation=For%20some%20legacy%20MySQL%20database%20application%20I%20really%20need%20Unix%20timestamps%20-%20and%20I%20need%20them%20in%20ColdFusion%2C%20so%20MySQL%27s%20UNIX_TIMESTAMP%20just%20wasn%27t%20sufficient%20for%20the%20job.%20At%20first%20I%20though%20I%20could%20get%20away%20with%20a%20simple%20DateDiff%20-%20and%20the%20result%20did%20loo" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=For%20some%20legacy%20MySQL%20database%20application%20I%20really%20need%20Unix%20timestamps%20-%20and%20I%20need%20them%20in%20ColdFusion%2C%20so%20MySQL%27s%20UNIX_TIMESTAMP%20just%20wasn%27t%20sufficient%20for%20the%20job.%20At%20first%20I%20though%20I%20could%20get%20away%20with%20a%20simple%20DateDiff%20-%20and%20the%20result%20did%20loo" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;bm_description=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;t=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&opener=bm&amp;ei=UTF-8&amp;d=For%20some%20legacy%20MySQL%20database%20application%20I%20really%20need%20Unix%20timestamps%20-%20and%20I%20need%20them%20in%20ColdFusion%2C%20so%20MySQL%27s%20UNIX_TIMESTAMP%20just%20wasn%27t%20sufficient%20for%20the%20job.%20At%20first%20I%20though%20I%20could%20get%20away%20with%20a%20simple%20DateDiff%20-%20and%20the%20result%20did%20loo" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;t=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;submitHeadline=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;submitSummary=For%20some%20legacy%20MySQL%20database%20application%20I%20really%20need%20Unix%20timestamps%20-%20and%20I%20need%20them%20in%20ColdFusion%2C%20so%20MySQL%27s%20UNIX_TIMESTAMP%20just%20wasn%27t%20sufficient%20for%20the%20job.%20At%20first%20I%20though%20I%20could%20get%20away%20with%20a%20simple%20DateDiff%20-%20and%20the%20result%20did%20loo&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;exttitle=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Fcoldfusion-udf-to-get-unix-timestamp-from-date%2F&amp;bm_description=ColdFusion%20UDF%20to%20get%20Unix%20Timestamp%20from%20Date&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/05/coldfusion-udf-to-get-unix-timestamp-from-date/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Full-text search with ColdFusion using Sphinx</title>
		<link>http://devbox.computec.de/2010/05/full-text-search-with-coldfusion-using-sphinx/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=full-text-search-with-coldfusion-using-sphinx</link>
		<comments>http://devbox.computec.de/2010/05/full-text-search-with-coldfusion-using-sphinx/#comments</comments>
		<pubDate>Wed, 05 May 2010 11:18:30 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[cfc]]></category>
		<category><![CDATA[fulltext]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=392</guid>
		<description><![CDATA[A thorough tutorial on using the Sphinx search engine for ColdFusion developers, from compilation and setup to using the Java Sphinx API in a CFC.]]></description>
			<content:encoded><![CDATA[<p>Full text searching is and probably will be for a long time an interesting challenge for any database driven application. Of course ColdFusion already offers a couple of options, though I found most of them somewhat lacking in features or quite complicated to set up.<br />
<!--pagetitle:Introduction--><br />
As we're running mostly on <a href="http://www.postgresql.org/">PostgreSQL</a> as database backend, we used to rely solely on the built-in <a href="http://www.postgresql.org/docs/current/static/tsearch2.html">TSearch2</a> full text search methods of that database. But over the years we have accumulated so much data, some of which is nicely distributed over several tables (the dark side of normalization), that we were really yearning for a less table based and more document focused indexing mechanism - and more speed than TSearch2 could deliver.</p>
<p>Verity never really quite met all of our needs and was a real pain to set up and maintain. CF 9's <a href="http://lucene.apache.org/solr/">Solr</a>, which is based on <a href="http://lucene.apache.org/java/docs/index.html">Lucene</a>, might be a mighty step forward, but we're still running on ColdFusion 8, so I really cannot say a lot about handling and performance of the new indexing beast.</p>
<p>For our use cases (i.e. indexing of articles, products in our CMS as well as our forums), <a href="http://sphinxsearch.com/">Sphinx</a> (for <b>S</b>QL <b>Ph</b>rase <b>In</b>de<b>x</b>) has shown some amazing results - and we're using it for a couple of months now. In this article I'll show you how to compile, set up and use Sphinx in your ColdFusion application to retrieve search results from documents stored in a PostgreSQL or MySQL database.<br />
<span id="more-392"></span><br />
At the time of writing this article, the current version of Sphinx is 0.9.9-release. I assume you intend to deploy the Sphinx server on a Linux box (I'm using Debian Lenny) and are familiar with compiling code - if you're on Windows, you should get the binary distribution and see docs for installation.</p>
<p>The server you'll want to run Sphinx may or may not be the same as your ColdFusion box, though I'd recommend you set up a separate machine with a generous amount of RAM - Sphinx will store indexes completely in memory which explains the amazing search speed, so the more data you wish to index, the more RAM you should provide.</p>
<p><a href="http://devbox.computec.de/2010/05/full-text-search-with-coldfusion-using-sphinx/2/">Next page: Compiling Sphinx</a></p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;bodytext=A%20thorough%20tutorial%20on%20using%20the%20Sphinx%20search%20engine%20for%20ColdFusion%20developers%2C%20from%20compilation%20and%20setup%20to%20using%20the%20Java%20Sphinx%20API%20in%20a%20CFC." title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;notes=A%20thorough%20tutorial%20on%20using%20the%20Sphinx%20search%20engine%20for%20ColdFusion%20developers%2C%20from%20compilation%20and%20setup%20to%20using%20the%20Java%20Sphinx%20API%20in%20a%20CFC." title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;t=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;annotation=A%20thorough%20tutorial%20on%20using%20the%20Sphinx%20search%20engine%20for%20ColdFusion%20developers%2C%20from%20compilation%20and%20setup%20to%20using%20the%20Java%20Sphinx%20API%20in%20a%20CFC." title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=A%20thorough%20tutorial%20on%20using%20the%20Sphinx%20search%20engine%20for%20ColdFusion%20developers%2C%20from%20compilation%20and%20setup%20to%20using%20the%20Java%20Sphinx%20API%20in%20a%20CFC." title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;bm_description=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=Full-text%20search%20with%20ColdFusion%20using%20Sphinx%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;t=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&opener=bm&amp;ei=UTF-8&amp;d=A%20thorough%20tutorial%20on%20using%20the%20Sphinx%20search%20engine%20for%20ColdFusion%20developers%2C%20from%20compilation%20and%20setup%20to%20using%20the%20Java%20Sphinx%20API%20in%20a%20CFC." title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;t=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;submitHeadline=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;submitSummary=A%20thorough%20tutorial%20on%20using%20the%20Sphinx%20search%20engine%20for%20ColdFusion%20developers%2C%20from%20compilation%20and%20setup%20to%20using%20the%20Java%20Sphinx%20API%20in%20a%20CFC.&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;exttitle=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F05%2Ffull-text-search-with-coldfusion-using-sphinx%2F&amp;bm_description=Full-text%20search%20with%20ColdFusion%20using%20Sphinx&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/05/full-text-search-with-coldfusion-using-sphinx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ColdFusion UDF to intersect two lists</title>
		<link>http://devbox.computec.de/2010/04/coldfusion-udf-to-intersect-two-lists/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=coldfusion-udf-to-intersect-two-lists</link>
		<comments>http://devbox.computec.de/2010/04/coldfusion-udf-to-intersect-two-lists/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 08:28:51 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[intersection]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[udf]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=369</guid>
		<description><![CDATA[Just a quick one: I have a method that takes a list argument; there is a discrete list of legal values for this list. I want to filter the passed argument list by throwing out all the values which are not contained in the list of legal values.
Of course I could use a nested loop [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick one: I have a method that takes a list argument; there is a discrete list of legal values for this list. I want to filter the passed argument list by throwing out all the values which are not contained in the list of legal values.</p>
<p>Of course I could use a nested loop to do this - but for longer lists this is neither fast nor elegant. Again I'll turn to Java for this. ColdFusion's arrays are in fact <em>java.util.List</em>s, so after converting our ColdFusion lists to ColdFusion arrays, we can make use of the Java-API for lists.</p>
<p>Here's a quick UDF that does what I want:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;listIntersect&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> </span>
<span style="color: #333333;">	<span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;returns values from list 1 which are contained in list 2&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lstSand&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lstSieve&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;chDelimiter&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span></span>
<span style="color: #333333;">		    <span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;,&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
	var aLstSand  = listToArray(arguments.lstSand,arguments.chDelimiter);
	var aLstSieve = listToArray(arguments.lstSieve,arguments.chDelimiter);
	aLstSand.retainAll(aLstSieve);
	return arrayToList(aLstSand,arguments.chDelimiter);
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> lstSand   <span style="color: #0000FF;">=</span> <span style="color: #009900;">'foo,bar,illegalparam,whatever'</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> lstSieve  <span style="color: #0000FF;">=</span> <span style="color: #009900;">'bar,foo,someotherval,whatever'</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> lstSieved <span style="color: #0000FF;">=</span> listIntersect<span style="color: #0000FF;">&#40;</span>lstSand,lstSieve<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#lstSieved#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>This will output <em>foo,bar,whatever</em>.</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;bodytext=Just%20a%20quick%20one%3A%20I%20have%20a%20method%20that%20takes%20a%20list%20argument%3B%20there%20is%20a%20discrete%20list%20of%20legal%20values%20for%20this%20list.%20I%20want%20to%20filter%20the%20passed%20argument%20list%20by%20throwing%20out%20all%20the%20values%20which%20are%20not%20contained%20in%20the%20list%20of%20legal%20values.%0D%0A%0D%0AOf%20" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;notes=Just%20a%20quick%20one%3A%20I%20have%20a%20method%20that%20takes%20a%20list%20argument%3B%20there%20is%20a%20discrete%20list%20of%20legal%20values%20for%20this%20list.%20I%20want%20to%20filter%20the%20passed%20argument%20list%20by%20throwing%20out%20all%20the%20values%20which%20are%20not%20contained%20in%20the%20list%20of%20legal%20values.%0D%0A%0D%0AOf%20" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;t=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;annotation=Just%20a%20quick%20one%3A%20I%20have%20a%20method%20that%20takes%20a%20list%20argument%3B%20there%20is%20a%20discrete%20list%20of%20legal%20values%20for%20this%20list.%20I%20want%20to%20filter%20the%20passed%20argument%20list%20by%20throwing%20out%20all%20the%20values%20which%20are%20not%20contained%20in%20the%20list%20of%20legal%20values.%0D%0A%0D%0AOf%20" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=Just%20a%20quick%20one%3A%20I%20have%20a%20method%20that%20takes%20a%20list%20argument%3B%20there%20is%20a%20discrete%20list%20of%20legal%20values%20for%20this%20list.%20I%20want%20to%20filter%20the%20passed%20argument%20list%20by%20throwing%20out%20all%20the%20values%20which%20are%20not%20contained%20in%20the%20list%20of%20legal%20values.%0D%0A%0D%0AOf%20" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;bm_description=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=ColdFusion%20UDF%20to%20intersect%20two%20lists%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;t=ColdFusion%20UDF%20to%20intersect%20two%20lists&opener=bm&amp;ei=UTF-8&amp;d=Just%20a%20quick%20one%3A%20I%20have%20a%20method%20that%20takes%20a%20list%20argument%3B%20there%20is%20a%20discrete%20list%20of%20legal%20values%20for%20this%20list.%20I%20want%20to%20filter%20the%20passed%20argument%20list%20by%20throwing%20out%20all%20the%20values%20which%20are%20not%20contained%20in%20the%20list%20of%20legal%20values.%0D%0A%0D%0AOf%20" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;t=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;submitHeadline=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;submitSummary=Just%20a%20quick%20one%3A%20I%20have%20a%20method%20that%20takes%20a%20list%20argument%3B%20there%20is%20a%20discrete%20list%20of%20legal%20values%20for%20this%20list.%20I%20want%20to%20filter%20the%20passed%20argument%20list%20by%20throwing%20out%20all%20the%20values%20which%20are%20not%20contained%20in%20the%20list%20of%20legal%20values.%0D%0A%0D%0AOf%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;exttitle=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;title=ColdFusion%20UDF%20to%20intersect%20two%20lists" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F04%2Fcoldfusion-udf-to-intersect-two-lists%2F&amp;bm_description=ColdFusion%20UDF%20to%20intersect%20two%20lists&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/04/coldfusion-udf-to-intersect-two-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The real Y2K problem: LongInt Unix-Timestamps</title>
		<link>http://devbox.computec.de/2010/02/the-real-y2k-problem-longint-unix-timestamps/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-real-y2k-problem-longint-unix-timestamps</link>
		<comments>http://devbox.computec.de/2010/02/the-real-y2k-problem-longint-unix-timestamps/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 11:26:36 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[bigint]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[dateadd]]></category>
		<category><![CDATA[in8]]></category>
		<category><![CDATA[longint]]></category>
		<category><![CDATA[timestamp]]></category>
		<category><![CDATA[unix timestamp]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=353</guid>
		<description><![CDATA[On January 19th 2038 I'll be 63 years, 9 months and 23 days old. So unfortunately there are still a couple of days until I can think about retirement. What's wrong with this date?
The Unix timestamp of 2038-01-19 03:14:07 is 2147483647. This is the maximum number that fits into the int4 data type. One second [...]]]></description>
			<content:encoded><![CDATA[<p>On January 19th 2038 I'll be 63 years, 9 months and 23 days old. So unfortunately there are still a couple of days until I can think about retirement. What's wrong with this date?</p>
<p>The Unix timestamp of 2038-01-19 03:14:07 is 2147483647. This is the maximum number that fits into the int4 data type. One second later we'll be getting integer overflow for any operations on Unix timestamps. Like getting the actual date from that Unix timestamp via <em>dateAdd()</em> in ColdFusion.</p>
<p><span id="more-353"></span><br />
In our case, some user had entered a date somewhere in the 2040ies into our PostgreSQL database - which is working fine, as PostgreSQL actually has not only some sophisticated timestamp datatypes but also a couple of handy functions and operators to go with it.</p>
<p>For searching however we're using Sphinx, a very nice full text search engine. The results returned by Sphinx will use Unix Timestamps for date values - so here we get hit by the next Y2K problem. To convert such Unix Timestamps in ColdFusion, we'd usually do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dtMyDate <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">dateAdd</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;s&quot;</span>, iUnixTS, <span style="color: #009900;">&quot;01/01/1970&quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>If iUnixTS has a value of more than the maximum allowed value for int4, which is 2147483647, you get an exception like</p>
<blockquote><p>
Cannot convert the value 2.147607103E9 to an integer because it cannot fit inside an integer.
</p></blockquote>
<p>You'll have a hard time dealing with int8-values in ColdFusion. Java to the rescue:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;unixTStoDate&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;date&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;iUnixTs&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;numeric&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
var iMaxLongInt = 2147483647;
var objBigint = createObject('java', 'java.math.BigInteger').init(1);
var longUnixTs = objBigint.valueOf(javaCast('long',arguments.iUnixTs));
var longMaxLongInt = objBigint.valueOf(javaCast('long',iMaxLongInt));
var iUnixTsLongIntFactor = int(arguments.iUnixTs / iMaxLongInt);
var iUnixTsLongIntMod = longUnixTs.mod(longMaxLongInt);
var i=0;
var tsReturn = '01/01/1970';
// we'll just DateAdd the maximum allowed value for
// as often as needed...
for (i=1; i lte iUnixTsLongIntFactor; i++) {
tsReturn = DateAdd('s',iMaxLongInt,tsReturn);
} // end for (i=1; i lte iUnixTsLongIntFactor; i++)
// ... and then dateAdd the rest
tsReturn = DateAdd('s',iUnixTsLongIntMod,tsReturn);
return tsReturn;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Let's try this:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> longUnixTS <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">2147483647</span> + <span style="color: #FF0000;">123456</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dtMyDate <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">dateAdd</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;s&quot;</span>, longUnixTS, <span style="color: #009900;">&quot;01/01/1970&quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#unixTStoDate(longUnixTS)#&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Result:</p>
<blockquote><p>
{ts '2038-01-20 13:31:43'} .
</p></blockquote>
<p>Hooray!</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;bodytext=On%20January%2019th%202038%20I%27ll%20be%2063%20years%2C%209%20months%20and%2023%20days%20old.%20So%20unfortunately%20there%20are%20still%20a%20couple%20of%20days%20until%20I%20can%20think%20about%20retirement.%20What%27s%20wrong%20with%20this%20date%3F%0A%0AThe%20Unix%20timestamp%20of%202038-01-19%2003%3A14%3A07%20is%202147483647.%20This%20is%20the%20" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;notes=On%20January%2019th%202038%20I%27ll%20be%2063%20years%2C%209%20months%20and%2023%20days%20old.%20So%20unfortunately%20there%20are%20still%20a%20couple%20of%20days%20until%20I%20can%20think%20about%20retirement.%20What%27s%20wrong%20with%20this%20date%3F%0A%0AThe%20Unix%20timestamp%20of%202038-01-19%2003%3A14%3A07%20is%202147483647.%20This%20is%20the%20" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;t=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;annotation=On%20January%2019th%202038%20I%27ll%20be%2063%20years%2C%209%20months%20and%2023%20days%20old.%20So%20unfortunately%20there%20are%20still%20a%20couple%20of%20days%20until%20I%20can%20think%20about%20retirement.%20What%27s%20wrong%20with%20this%20date%3F%0A%0AThe%20Unix%20timestamp%20of%202038-01-19%2003%3A14%3A07%20is%202147483647.%20This%20is%20the%20" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=On%20January%2019th%202038%20I%27ll%20be%2063%20years%2C%209%20months%20and%2023%20days%20old.%20So%20unfortunately%20there%20are%20still%20a%20couple%20of%20days%20until%20I%20can%20think%20about%20retirement.%20What%27s%20wrong%20with%20this%20date%3F%0A%0AThe%20Unix%20timestamp%20of%202038-01-19%2003%3A14%3A07%20is%202147483647.%20This%20is%20the%20" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;bm_description=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps%20-%20http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;t=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&opener=bm&amp;ei=UTF-8&amp;d=On%20January%2019th%202038%20I%27ll%20be%2063%20years%2C%209%20months%20and%2023%20days%20old.%20So%20unfortunately%20there%20are%20still%20a%20couple%20of%20days%20until%20I%20can%20think%20about%20retirement.%20What%27s%20wrong%20with%20this%20date%3F%0A%0AThe%20Unix%20timestamp%20of%202038-01-19%2003%3A14%3A07%20is%202147483647.%20This%20is%20the%20" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;t=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;submitHeadline=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;submitSummary=On%20January%2019th%202038%20I%27ll%20be%2063%20years%2C%209%20months%20and%2023%20days%20old.%20So%20unfortunately%20there%20are%20still%20a%20couple%20of%20days%20until%20I%20can%20think%20about%20retirement.%20What%27s%20wrong%20with%20this%20date%3F%0A%0AThe%20Unix%20timestamp%20of%202038-01-19%2003%3A14%3A07%20is%202147483647.%20This%20is%20the%20&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;exttitle=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2010%2F02%2Fthe-real-y2k-problem-longint-unix-timestamps%2F&amp;bm_description=The%20real%20Y2K%20problem%3A%20LongInt%20Unix-Timestamps&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2010/02/the-real-y2k-problem-longint-unix-timestamps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion UDF to test if a Java Class implements a method</title>
		<link>http://devbox.computec.de/2009/09/coldfusion-udf-to-test-if-a-java-class-implements-a-method/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=coldfusion-udf-to-test-if-a-java-class-implements-a-method</link>
		<comments>http://devbox.computec.de/2009/09/coldfusion-udf-to-test-if-a-java-class-implements-a-method/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 15:13:48 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[udf]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=275</guid>
		<description><![CDATA[I recently started implementing a couple of our full text search requirements using Sphinx. I am extremely happy with this search engine, as it's lightning fast and provides some quite easy integration with the data we store in our PostgreSQL databases, is highly scalable and fairly easy to implement in ColdFusion via the Sphinx Client [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started implementing a couple of our full text search requirements using <a title="Sphinx search engine" href="http://www.sphinxsearch.com">Sphinx</a>. I am extremely happy with this search engine, as it's lightning fast and provides some quite easy integration with the data we store in our PostgreSQL databases, is highly scalable and fairly easy to implement in ColdFusion via the Sphinx Client API. <span id="more-275"></span></p>
<p>As I started writing the search component for our articles, I decided that it would be an extremely valuable feature to use the weighting functionality Sphinx provides. This would allow to set different weights to the indexed fields on a per-query basis, which is extremely cool as you don't have to decide on a general per-field weighting setting during indexing.</p>
<p>The Sphinx API documentation does mention a <em>SetFieldWeights</em>-method which takes a HashMap (i.e. an associative array for those of the PHP persuasion) as argument. I constructed the Hashmap like this (excerpt from a function):</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">var jHashMap = createobject(&quot;java&quot;, &quot;java.util.HashMap&quot;);
jHashMap.put('keywords',JavaCast('int',arguments.iWeightType));
jHashMap.put('text',JavaCast('int',arguments.iWeightText));</pre></div></div>

<p>So far, so good. Now I tried calling</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">variables.sphinx.SetFieldWeights(jHashMap);</pre></div></div>

<p>- and received an error that this function does not exist. One dump of the Sphinx-API later, I saw the error was a mere typo: In <em>org.sphx.api.SphinxClient</em> the method was actually spelled <em>SetFieldeights</em>. Being a responsible user, I did report this bug in the forums, but what to do for the time being? Two options: Correct the spelling mistake in the API-source, recompile and redeploy - and risk that a subsequent update might have to be patched as well (and one tends to forget something like that) or just accept the typo in my own code. I sort of opted for the latter, but I wanted to be equally safe from a later correction of this typo in an updated API.</p>
<p>So I wanted to make my code work with both <em>SetFieldeights</em> or <em>SetFieldWeights</em>. This could be done either by <em>CFTRY/CFCATCHING</em> an error on calling the method (something I try to avoid at all costs), or simply checking if the method is implemented by the class.</p>
<p>Now my first try with <em>structKeyExists()</em> failed. Apparently I cannot test a java object as if it were a structure, or probably more like I cannot test a method of such an object as if it were a member of a conventional structure. <em>isDefined()</em> failed, probably for similar reasons. Okay, on to the good Java stuff. Java provides reflection for such cases, in fact this is what ColdFusion uses when you <em>cfdump</em> such an object.</p>
<p>To make this reusable, decided to write this as as more generic function I could use in another CFC:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;methodExists&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;checks if a java class implements a method&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;strClassName&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;strMethodName&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
		var a = arrayNew(1);
		var myClass = a.getClass().forName(arguments.strClassName);
		var arrMethods = myClass.getDeclaredMethods();
		var i = 1;
		var arrMethodNames = arrayNew(1);
		for (i=1; i lte ArrayLen(arrMethods); i++) {
			arrMethodNames[i] = arrMethods[i].getName();
		}
		if (arrMethodNames.indexOf(arguments.strMethodName) eq -1) {
			return false;
			} else {
			return true;
		}			
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now to check if the Sphinx-API implements <em>SetFieldWeights</em>, I just need to test the boolean return value like</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
if (methodExists(strClassName='org.sphx.api.SphinxClient',strMethodName='SetFieldWeights')) {
  variables.sphinx.SetFieldWeights(jHashMap);
  } else {
  variables.sphinx.SetFieldeights(jHashMap);
}
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Mission accomplished! For those curious to know, the affected Sphinx version was <em>sphinx-0.9.9-rc2</em>.</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;bodytext=I%20recently%20started%20implementing%20a%20couple%20of%20our%20full%20text%20search%20requirements%20using%20Sphinx.%20I%20am%20extremely%20happy%20with%20this%20search%20engine%2C%20as%20it%27s%20lightning%20fast%20and%20provides%20some%20quite%20easy%20integration%20with%20the%20data%20we%20store%20in%20our%20PostgreSQL%20databas" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;notes=I%20recently%20started%20implementing%20a%20couple%20of%20our%20full%20text%20search%20requirements%20using%20Sphinx.%20I%20am%20extremely%20happy%20with%20this%20search%20engine%2C%20as%20it%27s%20lightning%20fast%20and%20provides%20some%20quite%20easy%20integration%20with%20the%20data%20we%20store%20in%20our%20PostgreSQL%20databas" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;t=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;annotation=I%20recently%20started%20implementing%20a%20couple%20of%20our%20full%20text%20search%20requirements%20using%20Sphinx.%20I%20am%20extremely%20happy%20with%20this%20search%20engine%2C%20as%20it%27s%20lightning%20fast%20and%20provides%20some%20quite%20easy%20integration%20with%20the%20data%20we%20store%20in%20our%20PostgreSQL%20databas" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=I%20recently%20started%20implementing%20a%20couple%20of%20our%20full%20text%20search%20requirements%20using%20Sphinx.%20I%20am%20extremely%20happy%20with%20this%20search%20engine%2C%20as%20it%27s%20lightning%20fast%20and%20provides%20some%20quite%20easy%20integration%20with%20the%20data%20we%20store%20in%20our%20PostgreSQL%20databas" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;bm_description=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method%20-%20http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;t=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&opener=bm&amp;ei=UTF-8&amp;d=I%20recently%20started%20implementing%20a%20couple%20of%20our%20full%20text%20search%20requirements%20using%20Sphinx.%20I%20am%20extremely%20happy%20with%20this%20search%20engine%2C%20as%20it%27s%20lightning%20fast%20and%20provides%20some%20quite%20easy%20integration%20with%20the%20data%20we%20store%20in%20our%20PostgreSQL%20databas" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;t=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;submitHeadline=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;submitSummary=I%20recently%20started%20implementing%20a%20couple%20of%20our%20full%20text%20search%20requirements%20using%20Sphinx.%20I%20am%20extremely%20happy%20with%20this%20search%20engine%2C%20as%20it%27s%20lightning%20fast%20and%20provides%20some%20quite%20easy%20integration%20with%20the%20data%20we%20store%20in%20our%20PostgreSQL%20databas&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;exttitle=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F09%2Fcoldfusion-udf-to-test-if-a-java-class-implements-a-method%2F&amp;bm_description=ColdFusion%20UDF%20to%20test%20if%20a%20Java%20Class%20implements%20a%20method&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2009/09/coldfusion-udf-to-test-if-a-java-class-implements-a-method/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>What if HTMLEditFormat() don&#8217;t cut it?</title>
		<link>http://devbox.computec.de/2009/06/what-if-htmleditformat-dont-cut-it/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=what-if-htmleditformat-dont-cut-it</link>
		<comments>http://devbox.computec.de/2009/06/what-if-htmleditformat-dont-cut-it/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 10:05:13 +0000</pubDate>
		<dc:creator>Markus Wollny</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[HTML et al.]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[antisamy]]></category>
		<category><![CDATA[cfc]]></category>
		<category><![CDATA[content management]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://devbox.computec.de/?p=162</guid>
		<description><![CDATA[You know of course that you need to HTMLEditFormat() any user input that you intend to display somewhere on your page to avoid racing down the road to XSS hell; to save on processing resources the best time to do this would obviously be before the data goes to your persistance layer (be it some [...]]]></description>
			<content:encoded><![CDATA[<p>You know of course that you need to <code>HTMLEditFormat()</code> any user input that you intend to display somewhere on your page to avoid racing down the road to XSS hell; to save on processing resources the best time to do this would obviously be before the data goes to your persistance layer (be it some physical file or most likely a database).</p>
<p>If all you want to do is allow your users to store some plain old text, maybe seasoned with some kind of BB-code markup to allow for some limited text formatting, this method is just fine. If that is not enough and you actually need to allow a limited amount of good old HTML, you'll need some more sophisticated sanitizing mechanism to parse out any potentially harmful code elements like JavaScript actions and the like.</p>
<p><span id="more-162"></span>Users' HTML input may be harmful in more than one way - if it is not well formed, it may mess up the rest of your page; take a look at my earlier post on this issue "<a title="ColdFusion UDF-Wrapper for JTidy to clean up HTML" href="http://devbox.computec.de/2009/06/coldfusion-udf-wrapper-for-jtidy-to-clean-up-html/">Coldfusion UDF-wrapper for JTidy to clean up HTML</a>". In this post I promised to also write about the other evil that lurks in user input and how to fight it if <code>HTMLEditFormat()</code> is doing too much collateral damage in your use case.</p>
<p>A little while ago, a guy named Samy Kamkar rocked the blogosphere with his spectacular yet simple XSS-worm which gathered myriads of "friends" for him, because <em><a title="Samy XSS worm explained on Wikipedia" href="http://en.wikipedia.org/wiki/Samy_(XSS)">Samy was their hero</a></em>. In honour of Samy, the <a title="Open Web Application Security Project (OWASP)" href="http://www.owasp.org/">Open Web Application Security Project (OWASP)</a> gave birth to an extremely useful API to combat Samy copycats, along with implementations for .NET and - hooray! - Java, named the offspring <a title="The AntiSamy Project at OWASP" href="http://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project">AntiSamy</a>, and generously put everything under a <a title="BSD licenses explained on Wikipedia" href="http://en.wikipedia.org/wiki/BSD_licenses">BSD license</a>.</p>
<p>AntiSamy is not just a simple RegEx-Replacer that silently drops a certain set of potentially malicious code elements. You can define your own ruleset inside a policy file - or rulesets (i.e. policy files) for that matter - maybe you've got some group of privileged users whose input should be treated not quite as strict as that of your average Joe WannabeH4XX0r. And AntiSamy won't just do the sanitizing, it will also allow you to tell the user what has been rejected and why, as there's quite some potential for frustration if he designs some beautifully CSSed code and your policy chucks out all the good stuff.</p>
<p>Speaking of good stuff, let's get onto it.</p>
<p>First you'll need to head to the <a title="The AntiSamy download page" href="http://code.google.com/p/owaspantisamy/downloads/list">AntiSamy download page</a> on <a title="Google Code" href="http://code.google.com/">Google Code</a>. Grab the latest <em>antisamy-bin.jar</em> (<a title="Download antisamy-bin.1.3.jar from Google Code" href="http://owaspantisamy.googlecode.com/files/antisamy-bin.1.3.jar">antisamy-bin.1.3.jar</a> at the time of this post) and drop it in your ColdFusion class path (e.g. <code>/opt/coldfusion/lib</code> in a standalone-server install). Restart ColdFusion.</p>
<p>On the download page you'll also find a couple of pre-made policy files. The <a title="Example &quot;Slashdot&quot; policy file" href="http://owaspantisamy.googlecode.com/files/antisamy-slashdot-1.3.xml"><em>slashdot</em> policy file</a> is the most resttrictive one, followed by the <a title="Example &quot;eBay&quot; policy file" href="http://owaspantisamy.googlecode.com/files/antisamy-ebay-1.3.xml"><em>ebay</em></a>- and <a title="Example &quot;MySpace&quot; policy file" href="http://owaspantisamy.googlecode.com/files/antisamy-myspace-1.3.xml"><em>myspace</em></a>- files. The <a title="Example &quot;anythinggoes&quot; policy file" href="http://owaspantisamy.googlecode.com/files/antisamy-anythinggoes-1.3.xml"><em>anythinggoes</em>-file</a> is too permissive for any serious application, so you may as well ignore that one. Put those policy files in a new AntiSamy-policy folder somewhere on your server - the files need not be web-accessible, so you may well use something like <code>/var/local/lib/AntiSamyPolicies/</code>. You may of course build your own policy file based on one of the existing examples and drop it in that same folder.</p>
<p>Now to use this from ColdFusion, you may grab my <code>sanitizer.cfc</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> displayname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sanitizer&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sanitize user generated HTML from malicious elements&quot;</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!--- call init() automatically when the CFC is instantiated ---&gt;</span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> init<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;init&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sanitizer&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;policy&quot;</span> <span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;myspace&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span><span style="color: #0000FF;">&gt;</span></span>
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
                        variables.policyVersion = '1.1.1';
                        variables.listPolicyDefaults = 'anythinggoes,ebay,slashdot,myspace';
                        variables.defaultPolicy = 'myspace';
                        variables.policyFilePath = '/var/local/lib/AntiSamyPolicies/';
                        variables.policyFile = variables.policyFilePath &amp; setPolicy(arguments.policy);
                        this.sanitizer = createObject(&quot;java&quot;, &quot;org.owasp.validator.html.AntiSamy&quot;);
                        return this;
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setPolicy&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;private&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sPolicy&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span><span style="color: #0000FF;">&gt;</span></span>
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
                        var sFullPolicyPath = variables.policyFilePath &amp; 'antisamy-';
                        arguments.sPolicy = lCase(arguments.sPolicy);
                        if (ListFind(variables.listPolicyDefaults,arguments.sPolicy,',')) {
                                return 'antisamy-' &amp; arguments.sPolicy &amp; '-' &amp; variables.policyVersion &amp; '.xml';
                        } else {
                                // in this case we might need to load a custom policy file
                                sFullPolicyPath = sFullPolicyPath &amp; arguments.sPolicy &amp; '-' &amp; variables.policyVersion &amp; '.xml';
                                if (FileExists(sFullPolicyPath)) {
                                        return 'antisamy-' &amp; arguments.sPolicy &amp; '-' &amp; variables.policyVersion &amp; '.xml';
                                } else {
                                        return 'antisamy-' &amp; variables.defaultPolicy &amp; '-' &amp; variables.policyVersion &amp; '.xml';
                                }
                        }
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sanitize&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;s</span>
<span style="color: #333333;">                &lt;cfargument name=&quot;</span>sTaintedHTML<span style="color: #009900;">&quot; default=&quot;</span><span style="color: #009900;">&quot; required=&quot;</span>yes<span style="color: #009900;">&quot; type=&quot;</span></span>
<span style="color: #333333;">                <span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;sPolicy&quot;</span> <span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string</span>
<span style="color: #333333;">                &lt;cfscript&gt;</span></span>
                        var objResults = 0;
                        if (arguments.sPolicy neq '') {variables.policyFile = va
                        objResults = this.sanitizer.scan(arguments.sTaintedHTML,
                        this.arrayErrorMessages = objResults.getErrorMessages();
                        return objResults.getCleanHTML();
                <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>To use this component, you would instantiate an AntiSamy instance for each required policy in your <code>request</code> scope for each request where you need this component:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
	request.objSanitizer=CreateObject('component','antisamy.sanitizer').init('slashdot');
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now you can process your user's input:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span>
	variables.sSanitizedHTML=request.objSanitizer.sanitize(variables.sSomeTaintedHTML);
	if (arrayLen(request.objSanitizer.arrayErrorMessages) gt 0) {
		// do some error handling like displaying the errors to the user
	} // end if (arrayLen(request.objSanitizer.arrayErrorMessages) gt 0)
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfscript</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>You may now store and output the processed HTML and also display information about what sanitizing changed in the original HTML to the user - these messages are available in the <code>request.objSanitizer.arrayErrorMessages</code>-array.</p>
<p>I hope some of you might find this useful!</p>
<p>BTW - for those who need functionality like this in PHP, maybe <a title="HTML Purifier" href="http://htmlpurifier.org/">HTML Purifier</a> will suit your needs.</p>



Share and Enjoy:


	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;partner=sociable" title="Print"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;bodytext=You%20know%20of%20course%20that%20you%20need%20to%20HTMLEditFormat%28%29%20any%20user%20input%20that%20you%20intend%20to%20display%20somewhere%20on%20your%20page%20to%20avoid%20racing%20down%20the%20road%20to%20XSS%20hell%3B%20to%20save%20on%20processing%20resources%20the%20best%20time%20to%20do%20this%20would%20obviously%20be%20before%20the%20da" title="Digg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;notes=You%20know%20of%20course%20that%20you%20need%20to%20HTMLEditFormat%28%29%20any%20user%20input%20that%20you%20intend%20to%20display%20somewhere%20on%20your%20page%20to%20avoid%20racing%20down%20the%20road%20to%20XSS%20hell%3B%20to%20save%20on%20processing%20resources%20the%20best%20time%20to%20do%20this%20would%20obviously%20be%20before%20the%20da" title="del.icio.us"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;t=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="Facebook"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;annotation=You%20know%20of%20course%20that%20you%20need%20to%20HTMLEditFormat%28%29%20any%20user%20input%20that%20you%20intend%20to%20display%20somewhere%20on%20your%20page%20to%20avoid%20racing%20down%20the%20road%20to%20XSS%20hell%3B%20to%20save%20on%20processing%20resources%20the%20best%20time%20to%20do%20this%20would%20obviously%20be%20before%20the%20da" title="Google Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;source=devbox%40COMPUTEC+The+Computec+development+blog&amp;summary=You%20know%20of%20course%20that%20you%20need%20to%20HTMLEditFormat%28%29%20any%20user%20input%20that%20you%20intend%20to%20display%20somewhere%20on%20your%20page%20to%20avoid%20racing%20down%20the%20road%20to%20XSS%20hell%3B%20to%20save%20on%20processing%20resources%20the%20best%20time%20to%20do%20this%20would%20obviously%20be%20before%20the%20da" title="LinkedIn"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.de/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;bm_description=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;plugin=soc" title="MisterWong.DE"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong.DE" alt="MisterWong.DE" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.netvibes.com/share?title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F" title="Netvibes"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="Reddit"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://slashdot.org/bookmark.pl?title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F" title="Slashdot"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="StumbleUpon"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F" title="Technorati"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://twitter.com/home?status=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F%20-%20http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F" title="Twitter"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://bookmarks.yahoo.com/toolbar/savebm?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;t=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&opener=bm&amp;ei=UTF-8&amp;d=You%20know%20of%20course%20that%20you%20need%20to%20HTMLEditFormat%28%29%20any%20user%20input%20that%20you%20intend%20to%20display%20somewhere%20on%20your%20page%20to%20avoid%20racing%20down%20the%20road%20to%20XSS%20hell%3B%20to%20save%20on%20processing%20resources%20the%20best%20time%20to%20do%20this%20would%20obviously%20be%20before%20the%20da" title="Yahoo! Bookmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://linkarena.com/bookmarks/addlink/?url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="LinkArena"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/linkarena.png" title="LinkArena" alt="LinkArena" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="Live"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;t=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="MySpace"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://buzz.yahoo.com/submit/?submitUrl=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;submitHeadline=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;submitSummary=You%20know%20of%20course%20that%20you%20need%20to%20HTMLEditFormat%28%29%20any%20user%20input%20that%20you%20intend%20to%20display%20somewhere%20on%20your%20page%20to%20avoid%20racing%20down%20the%20road%20to%20XSS%20hell%3B%20to%20save%20on%20processing%20resources%20the%20best%20time%20to%20do%20this%20would%20obviously%20be%20before%20the%20da&amp;submitCategory=science&amp;submitAssetType=text" title="Yahoo! Buzz"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yahoobuzz.png" title="Yahoo! Buzz" alt="Yahoo! Buzz" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://yigg.de/neu?exturl=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;exttitle=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="Yigg"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/yiggit.png" title="Yigg" alt="Yigg" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="blogmarks"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://faves.com/Authoring.aspx?u=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F" title="Faves"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/bluedot.png" title="Faves" alt="Faves" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.friendfeed.com/share?title=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;link=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F" title="FriendFeed"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<a rel="nofollow"  href="http://www.mister-wong.com/addurl/?bm_url=http%3A%2F%2Fdevbox.computec.de%2F2009%2F06%2Fwhat-if-htmleditformat-dont-cut-it%2F&amp;bm_description=What%20if%20HTMLEditFormat%28%29%20don%27t%20cut%20it%3F&amp;plugin=soc" title="MisterWong"><img src="http://devbox.computec.de/wp-content/plugins/sociable/images/misterwong.png" title="MisterWong" alt="MisterWong" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://devbox.computec.de/2009/06/what-if-htmleditformat-dont-cut-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
