A look at Macromedia's new ColdFusion MX 7 Server for Linux

Cold New Tool


Macromedia's new ColdFusion MX 7 Server creates highly available and high performance web applications. We'll show you what is new and what is changed with the latest ColdFusion release.

By Larkin Cunningham

The release of ColdFusion MX 7 [1] marks the tenth anniversary of the ColdFusion web development platform. Originally a C++ Windows application, ColdFusion is now a J2EE-based development environment that runs on Linux, AIX, Mac OS X, and Solaris, as well as Windows.

The ColdFusion platform was created and developed by Allaire Corporation. Macromedia acquired ColdFusion in 2001 and released what would have been ColdFusion version 6.0, calling the product ColdFusion MX to promote a connection with other products in Macromedia's MX line, such as Dreamweaver and Flash.

Macromedia has continued to develop ColdFusion and has added major enhancements. This latest release has further added to ColdFusion's arsenal of rich content generation with improved charting capabilities, report generation using FlashPaper and PDF, and Flash-based input forms, allowing for complex form layouts such as tabbing.

The Administrator

ColdFusion comes with a web-based administrator application (Figure 1) to help you manage your ColdFusion environment. The admin application allows you to adjust settings for client variable caching, Java / JVM memory, and other run-time variables that you can tweak to improve overall performance. This feature gives you an easy-to-use interface to manage settings that would require a text file (php.ini) in PHP.

Figure 1: The ColdFusion Administrator keeps you away from the command line and configuration files.

The Administrator also allows you to manage data sources, web services, scheduled tasks, tag extensions (more on this later), sandbox security, and more. With ColdFusion, you are discouraged from going near any configuration files; the configuration options available through the Administrator mean you'll probably never have to.

Rich Content

Macromedia is without a doubt the master of rich content on the Internet. The Flash format [3] for web-based animations, games, and user friendly interfaces is almost the de facto standard. Java Applets and ActiveX controls seem clumsy in comparison.

It is no surprise, then, that Macromedia have taken advantage of their own popular Flash technology to enhance the content output options in ColdFusion. Flash format is an option when rendering charts and input forms, and Macromedia's new FlashPaper [4] format (Figure 2) is an option when outputting documents such as reports. Adobe's PDF (Portable Document Format) is also supported. The choice of PDF and FlashPaper means you can output content that is guaranteed to be printable exactly as it appears in the web browser.

Support for Flash and PDF on Linux has improved in recent months, meaning it should not be a major problem to deploy a ColdFusion intranet application on a Linux desktop environment while offering all the rich content features you want.

Figure 2: An example of a FlashPaper document embedded in a web page.
The Tag-Based Approach

CFML is a tag based language with your CFML and HTML store in .cfm web pages. Rather than the traditional scripting approach used by PHP and ASP, CFML uses tags similar to HTML, with opening and closing tags. Not all CFML has to be tag based, however, because many tags have script equivalents. Listing 1 shows a simple SQL query followed by the output of the query results.

Notice how the CFML tags take parameters like standard HTML. In the example above, the CFQUERY tag was used to populate a result set from the database connection created using the MyDSN connection string defined in the Cold-Fusion Administrator (more on this later). Outputting the result set data is easily achieved using the CFOUTPUT tag. Variables and function calls enclosed between hashes (#) and included between CFML tags or as parameters to a CFML tag are interpreted by ColdFusion. Including the query as a parameter to the CFOUTPUT tag causes the tag contents to be repeated for each row in the query's result set.

Let's compare this with the PHP5 / mysqli [2] equivalent in Listing 2. Exception catching code has been omitted for simplicity.

As you can see from the code snippets, CFML can have the advantage of being easier to write and easier to read than equivalent PHP code. For a web designer with little or no background in programming, CFML is easier and quicker to learn than PHP. CFML lets a relative novice create quite powerful code with just a few tags.

Listing 1: empquery.cfm
01 <CFQUERY NAME= qryGetREmps  DATASOURCE= #MyDSN# >
02         SELECT * FROM employees
03 </CFQUERY>
04
05 <CFOUTPUT QUERY= qryGetEmps >
06         Name: #qryGetEmps.FirstName# #qryGetEmps.LastName#<br>
07         Address: #qryGetEmps.Address1#, #qryGetEmps.Address2#
08 </CFOUTPUT>
Listing 2: empquery.php
01 $dbconn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
02
03 $result = $dbconn->query('SELECT * FROM employees');
04
05 while ($row = $result->fetch_assoc())
06 {
07         printf( Name: %s %s<br> , $row['FirstName'], $row['LastName']);
08         printf( Address: %s, %s , $row['Address1'], $row['Address2']);
09 }

The CFCHART Tag

ColdFusion's CFCHART tag allows you to output smoothly rendered charts in PNG, JPEG, or Flash format. The Flash format charts provide a number of additional charting options. such as lines or bars rising from the x-axis to the correct data point on the graph or pie charts fading into view. Each chart format allows for clickable area maps, which gives the user the power to assign URL values to chart segments. This feature gives you the possibility of creating drill down charts for Management Information Systems (MIS) or Decision Support Systems (DSS). ColdFusion offers many other chart type options. For instance, you can choose to include line, bar, pie, and scatter charts.

PHP offers some third party options for creating graphs. Possibly the most popular graph option available with PHP is JpGraph, which offers a more comprehensive array of chart types than ColdFusion. JpGraph is available free for non-commercial use. ColdFusion's graphing, it has to be said, is more polished, with anti-aliased smooth edges, and the native ColdFusion graphing system is easier to configure.

In Figure 3, you can see an example chart showing levels of spam and viruses in the past 30 days. In Listing 3, you will find the CFCHART tags used to create the chart depicted in Figure 3.

Figure 3: The CFCHART tags allow you to easily create stunning graphs

The CFCHARTSERIES tag is used to specify each line or bar in a line or bar chart and each segment in a pie chart. In the example described previously, we loop through some queries, creating many data points with the CFCHARTDATA tag. As you can see in Listing 3, you can use quite a number of parameters to configure your charts in ColdFusion.

Listing 3: chart.cfm
01 <cfchart scalefrom="0" scaleto="1" showlegend="yes" markersize="4" labelformat="percent"
02 title="Percentage Spam and Viruses - Last 30 days" backgroundcolor="##eeeeee" showborder="yes" format="FLASH" xAxisTitle="Date"
03 yAxisTitle="Percentage of Overall" chartHeight="400" chartWidth="540" show3D="no" showXGridlines="yes" seriesPlacement="cluster">
04
05 <cfchartseries type="line" seriescolor="blue" serieslabel="Spam" markerstyle="circle">
06         <cfloop query="qry30days">
07                <cfchartdata item="#DateFormat(scan_date,"dd-mmm-yy")# value="#(pspam_sum + bspam_sum) / total_sum#">
08         </cfloop>
09 </cfchartseries>
10 <cfchartseries type="line" seriescolor="red" serieslabel="Viruses" markerstyle="circle">
11         <cfloop query="qry30days">
12                 <cfchartdata item="#DateFormat(scan_date,"dd-mmm-yy")#" value="#virus_sum / total_sum#">
13         </cfloop>
14 </cfchartseries>
15
16 </cfchart>

Flash Forms, ActionScript, and Remoting

Flash-based input forms allow for client side processing, validation, and form rendering. Flash-based input forms exceed the capabilities of standard HTML and JavaScript and are easier to implement and deploy than Java Applet-based input forms. Not only do Flash forms give you more control over how data is entered to enforce business rules, Flash also makes the user experience much richer. Figure 4 shows an example of a Flash form that uses tabbing, a calendar control, headings, and additional layout features.

Figure 4: Flash Forms give you greater control over how users input their data.

ActionScript is the scripting language used to interact with Flash MX. You can use ActionScript in your ColdFusion code to interact with a Flash Remoting server to allow your ColdFusion application to interact with advanced Flash MX applications and animations. A Flash MX developer who doesn't know CFML can still build a server-side ActionScript that interacts with ColdFusion resources. This allows a separation of business logic from Flash presentation logic.

Object-Oriented Programming

While both CFML and PHP are historically structured programming languages, both implement object-oriented features. Neither can be called true object-oriented languages, however, as they do not implement all of the features of true object-oriented languages such as C++ or Java. CFML provides what are called ColdFusion Components or CFCs. CFCs support encapsulation, inheritance, and introspection. CFCs are stored in .cfc files rather than .cfm files.

Listing 4 shows a sample CFC file that defines a component called ConvertTemp, which converts from Celcius to Fahrenheit and vice versa. Listing 5 shows some sample CFML code that invokes the methods in the component.

ColdFusion's object-oriented features are not quite as elegant as PHP 5's implementation of object-oriented functionality, but ColdFusion gives you what you need to create easily maintainable component-based applications.

Listing 4: convertTemp.cfc
01 <cfcomponent>
02    <!--- Celsius to Fahrenheit conversion method. --->
03    <cffunction name="ctof" output="false">
04       <cfargument name="temp" required="yes" type="numeric">
05       <cfreturn ((temp*9)/5)+32>
06    </cffunction>
07
08    <!--- Fahrenheit to Celsius conversion method. --->
09    <cffunction name="ftoc" output="false">
10       <cfargument name="temp" required="yes" type="numeric">
11       <cfreturn ((temp-32)*5/9)>
12    </cffunction>
13 </cfcomponent>
Listing 5: convTempForm.cfm
01 <cfinvoke component="convertTemp" method="ctof"
02         returnvariable="newtemp" temp=30>
03 <cfoutput>30 degrees Celsius is #newtemp# degrees Farenheit.</cfoutput>
04 <cfinvoke component="convertTemp" method="ftoc"
05         returnvariable="newtemp" temp=64>
06 <cfoutput>64 degrees Fahrenheit is #newtemp# degrees Celsius.</cfoutput>

Extending ColdFusion

You can extend the functionality of ColdFusion through the use of Custom Tags written using CFML, Java, or C++. In the case of CFML custom tags, you can simply create a file containing your custom tag CFML code and place it in a directory in ColdFusion's custom tag path (similar to a classpath). Java and C++ custom tags (referred to as CFX tags), however, must be explicitly declared using the ColdFusion Administrator. Custom tags can then be used like any other CFML tag, as if they were a part of the core language. This is possible in PHP also, but it usually involves either including other PHP source into your page or recompiling PHP with a new module.

Because ColdFusion runs in a J2EE application server, you also have access to Java classes in the JVM's classpath and in the WEB-INF/lib and WEB-INF/classes directories (as you would also expect with Tomcat, for example). Using the CFOBJECT tag, you can create objects, allowing access to functions and methods. Access to JavaBeans is also possible.

Interoperation between CFML, JSP, and Servlet pages is also possible. This allows you to maintain legacy JSP / Servlet applications while converting to CFML. You can incorporate CFML functionality into your existing JSP applications, for example, to take advantage of ColdFusion's charting or business reporting features. Conversely, if there are certain operations best performed by a JSP or a Servlet page, you can incorporate that functionality into CFML applications.

Search Engine

ColdFusion comes with a powerful search engine called Verity. The Verity engine can run independently of the ColdFusion server and can be accessed by multiple ColdFusion instances (by installing ColdFusion in multiserver mode - more on this below). Using the ColdFusion Administrator, you can create a Collection. A Collection is a store on disk for Verity searchable content.

A number of CFML tags are available to index content (for example Plain text, PDF document, and HTML documents) and to search the content. You can also index content returned from a query. This feature of ColdFusion allows you to quickly search through large amounts of text much faster than using a SQL SELECT query, where large text fields (for example the TEXT datatype in MySQL) cannot be indexed. One area this technology can be deployed in is a knowledge base.

New in ColdFusion MX 7 is the Verity Spider. The Verity Spider allows you to index whole directories or websites dynamically. Unlike the CFINDEX CFML tag, which allows you create specific indexes for searching, the Verity Spider creates the searchable content dynamically. The Verity Spider supports a wide range of document types, including HTML, PDF, Microsoft Office, WordPerfect, XML, and others. Verity Spider behaves just like other website spiders, obeying the instructions provided in robots.txt and following links specified in HTML HREF, FRAME, and META Refresh / Redirect tags. The capabilities provided by the Verity Spider allow you to create an intelligent search facility on your website.

Database Abstraction

CFML includes, by default, a database abstraction layer that allows you to write database-independent applications. The CFQUERY tag, as an example, only requires the DATASOURCE parameter to be able to connect to a database and perform a SQL query. Like ODBC, ColdFusion offers a database abstraction layer. ColdFusion's database abstraction layer can support ODBC connections and native database connections using JDBC. Included are drivers for MySQL (before 4.1), DB2, Informix, SQL Server, Sybase, Oracle, and J2EE Datasources (using JNDI). Oracle and Sybase drivers are only included with the Enterprise edition of ColdFusion, however, you can create data sources using your own JDBC drivers (typically by copying a JAR file to an appropriate library directory) and specifying the JDBC url and class name for your driver. You can achieve something similar using a JNDI resource.

There are ways of incorporating database abstraction into PHP using ADODB and Pear DB, however, these techniques require the installation of additional files and can require you to include additional files into your PHP scripts.

Editions

ColdFusion comes in three different editions. The Developer edition can be accessed from the local machine running ColdFusion and two remote clients. This makes it possible for a small team of developers to work on application development using the same ColdFusion instance. The Developer edition contains all of the functionality in ColdFusion and is free to download.

The Standard edition contains just about all of the functionality of ColdFusion, except for some features concerned primarily with performance and availability. Rather than explaining the features that the professional edition contains, it is easier to talk about the features only available in the third and final edition of ColdFusion, the Enterprise edition. The retail price for Standard Edition is US$ 1,299 / EUR 1,299. For a bit more money (Enterprise Edition costs US$ 5,999 / EUR 5,999), you get additional enterprise level features. The next section describes the Enterprise edition.

Enterprise Edition Features

The Enterprise Manager allows you to manage multiple instances of ColdFusion on a single server. The configuration is similar to other J2EE application servers like Tomcat, where an application server binary base is shared among multiple private JVMs (Java Virtual Machines). This means that multiple applications can enjoy isolation from each other, providing better security and stability without the requirement of separate dedicated servers. You can also cluster these applications to improve performance and availability.

JRun [5] is included with the Enterprise edition, giving you a commercial alternative to Tomcat. You can combine your ColdFusion application code with JSP or Servlet code in JRun.

You can deploy your ColdFusion applications using your preferred J2EE application server. JRun, Weblogic, and Websphere are supported by Macromedia.

Security is enhanced for virtual hosting environments using sandbox security. Sandbox security allows you to set security policies, such as tag, function, datasource, and IP address restrictions, on directories. Applications running within the directories have no access to the settings or files of any other applications.

You can create custom event gateways to interact with mobile devices and instant messaging servers, for example, or any other server application via any networking protocol (using Java sockets). You can also use the included gateways to SMS, XMPP (Extensible Messaging and Presence Protocol), Sun's JMS (Java Messaging Service) and Lotus Sametime. XMPP [6] is an open source instant messaging solution and protocol from the Jabber [7] Software Foundation. Lotus Sametime [8] is a product offered by IBM for instant messaging and web conferencing.

The Enterprise edition also lets you take advantage of a high performance, multithreaded business reporting engine. This is ideal for Management Information Systems, which can also use the charting features to create drill down statistics.

You can deploy your applications as Java bytecode, avoiding the exposure of your source code. This is important if you want to protect your intellectual property.

Supported Platforms

ColdFusion is supported on a number of platforms, including Linux, Windows, Solaris, AIX, and Mac OS X (development only). Red Hat Enterprise Linux 2.1 and 3.0, SUSE Linux Enterprise Server 8, and TurboLinux 8 (Japanese only) are supported by Macromedia, though there should be no issues running on CentOS 3, White Box Linux 3, and many other Linux distributions. In theory, it should be possible to deploy ColdFusion on any Java platform. JRun, BEA Weblogic, and IBM Websphere are supported by Macromedia, but instructions are provided for Tomcat, and there should be few issues deploying on JBoss or Resin.

ColdFusion can run either as a standalone web server or in conjunction with Apache (1.3.27 or higher, 2.0.43 or higher), iPlanet 6.x, or Sun ONE 6.x.

Is ColdFusion For You?

There is no simple answer to the question of why or when you might benefit from using ColdFusion. For some applications, PHP or Perl or JSP will be the better choice, and for others, ColdFusion is best. There is little you cannot do with ColdFusion that you can do with any other scripting language. And what ColdFusion cannot do, you can do by extending ColdFusion with Java, JSP, or Servlets.

The choice of whether you use ColdFusion will depend on the nature of the application. For rich content sites using charts, Flash forms, FlashPaper or PDF, ColdFusion is a good choice. For general purpose content management systems, ColdFusion is also an excellent choice. For rapid development, ColdFusion offers an easy-to-learn, tag-based scripting language that allows you to create powerful applications with the minimum of coding effort. For many, this is enough to justify even the price of the Enterprise edition of ColdFusion, which allows you to construct the kind of highly available and high-performing environment that mission critical applications demand.

For many developers on the Linux platform, it will come down to a choice of PHP, JSP / Servlets, or ColdFusion. ColdFusion is the only choice requiring the purchase of a license for deployment in a production environment, though all are free to download and develop on. And with an ever growing number of hosting companies offering support for ColdFusion at reasonable prices, you may never need to pay for a license. In short, if you're thinking about exploring the benefits of a commercial product, before you commit to anything else, you should at least investigate Cold-Fusion MX 7.

INFO
[1] Macromedia ColdFusion MX 7: http://www.macromedia.com/software/coldfusion/
[2] PHP 5 and the mysqli module: http://www.php.net/manual/en/ref.mysqli.php
[3] Macromedia Flash: http://www.macromedia.com/software/flash/
[4] Macromedia FlashPaper: http://www.macromedia.com/software/flashpaper/
[5] Macromedia JRun: http://www.macromedia.com/software/jrun/
[6] XMPP Protocol: http://www.xmpp.org
[7] Jabber Software Foundation: http://www.jabber.org
[8] Lotus Sametime: http://www.lotus.com/products/product3.nsf/wdocs/homepage/