- ColdFusion Markup Language
-
"CFML" redirects here. For the radio station, see CFML-FM.
Cold Fusion Markup Language (CFML) Paradigm(s) imperative, object-oriented Appeared in 1995 Designed by Jeremy Allaire Developer Adobe Systems, Railo, New Atlanta, aw2.0 Major implementations Adobe ColdFusion, Railo, BlueDragon, Open BlueDragon OS Windows, Linux, UNIX, Macintosh License Depends on the implementation. Proprietary, LGPL, and GPL-licensed engines are all available. Website CFML Advisory Committee (this committee is now defunct), Adobe ColdFusion, Railo, BlueDragon, Open BlueDragon, CFML Conventional Wisdom Google Group ColdFusion Markup Language, more commonly known as CFML, is a scripting language for web development that runs on the JVM, the .NET framework, and Google App Engine. Multiple commercial and open source implementations of CFML engines are available, including Adobe ColdFusion, New Atlanta BlueDragon (who makes both a Java-based and a .NET-based version), Railo, and Open BlueDragon as well as other CFML server engines.
The CFML language was guided by the CFML Advisory Committee beginning in 2009. This committee included representatives from Adobe, Railo, and Open BlueDragon, but the committee was disbanded in 2010. General language discussions and feature suggestions now tend to happen on the CFML Conventional Wisdom Google Group or on various other CFML mailing lists.
Contents
Synopsis
In its simplest form, like many other web scripting languages CFML augments standard HTML files with database commands, conditional operators, high-level formatting functions, and other elements to produce web applications.[1][2] CFML also includes numerous other constructs including ColdFusion Components (CFCs), CFML's version of objects, that allow for separation of business logic from presentation.
CFML can be written using either tags or CFSCript, which is an ECMA script style language.
The pages in a CFML application include the server-side CFML tags and functions in addition to HTML tags, and modern CFML applications also tend to have CFCs that are accessed by the CFML pages for executing business logic. When a web browser requests a page in a ColdFusion application, it is automatically pre-processed by the ColdFusion Application Server.[3]
CFML can also be used to generate other languages, aside from HTML, such as XML, JavaScript, CSS, and so on.
Despite the name, CFML is not a markup language. It is also not SGML, since certain core CFML features prevent it from complying.
The CFML engine is configured in such a way that certain file extensions on the server (.cfm, .cfc) are handed off to the CFML engine for processing. In the case of the Java-based engines this is accomplished via Java servlets. The CFML engine only processes CFML tags and functions; it returns text outside of CFML tags and functions to the web server unchanged.[4]
History
ColdFusion was originally created by the Allaire Corporation, originally located in Minnesota but later moving to Cambridge, MA and finally Newton, MA. Allaire was acquired by Macromedia in 2001, thus Allaire Cold Fusion became Macromedia Cold Fusion (the space was removed from the product name with the release of ColdFusion version 4). Adobe acquired Macromedia in 2005 and is still actively developing ColdFusion.
In 1998 Alan Williamson and his Scottish company n-ary began creating a templating engine for Java to simplify common programming tasks.[5] Williamson was using curly-brace notation instead of tags, but when he saw an example of CFML and how it was solving similar problems (although not in Java) using a tag syntax, he started developing what would eventually become BlueDragon, which was the first Java implementation of the CFML language. (ColdFusion was written in C and C++ until version 6.0--the first Java-based version of ColdFusion--was released in 2002.) New Atlanta licensed BlueDragon around 2001 and made it available as a commercial product, eventually creating a .NET implementation of CFML. Open BlueDragon is a fork of the commerical BlueDragon product and was first released in 2008.
The Railo CFML engine began as a student project in 2002 and was first launched as a commercial project in 2005.[6] Railo announced they were making the engine open source in 2008, and the first open source version was released in 2009.
On June 18 2009, Adobe announced at the CFUnited conference that it had formed a CFML Advisory Committee[7] that would be responsible for guiding and reviewing changes to the CFML language. This effort was disbanded in 2010. The Google Group CFML Conventional Wisdom was created as a forum for open, public discussions about language and engine features.
Syntax
CFML tags have a similar format to HTML tags. They are enclosed in angle brackets (< and >) and generally have zero or more named attributes, though some tags (e.g. cfset, cfif) contain an expression rather than attributes. Many CFML tags have bodies; that is, they have beginning and end tags with text to be processed between them. For example:
<cfoutput> #value# Bob! </cfoutput>
Other tags, such as cfset and cfftp, never have bodies; all the required information goes between the beginning (<) character and the ending (>) character in the form of tag attributes (name/value pairs), as in the example below. If it is legal for tags not to have a body, it is syntactically acceptable to leave them unclosed as in the first example, though many CFML developers choose to self-close tags as in the second example to (arguably) make the code more legible.
<cfset value = "Hello"> <cfset value = "Hello" />
Even if the tag can have a body, including a body may not be necessary in some instances because the attributes specify all the required information. In these cases, as with the second example above, the end tag (and hence, the tag body) may be ommitted and the tag may be self-closing as in the following example:[8]
<cfexecute name="C:\\winNT\\System32\\netstat.exe" arguments="-e" outputfile="C:\\Temp\\out.txt" timeout="1" />
Various tags offer the ability to type-check input parameters (e.g. cffunction, cfparam, cfqueryparam) if the programmer declares their type specifically. This functionality is used with cfqueryparam to secure web applications and databases from hackers and malicious web requests such as SQL injection.
Built-in tags
Nearly 100 tags and many more functions make up the heart of the CFML language. The following lists CFML tags by their function or purpose.[9]
- Application framework
- Communications
- Control
- Flow-control
- Database manipulation
- Exception handling
- Data output
- Debugging
- Display management
- Extensibility
- File management
- form
- Internet protocol
- Page processing
- Security
- Variable manipulation
- Other tags (cfimage, cfregistry etc)
Custom tags
CFML allows language extensions in the form of custom tags, which are tags created by the developer that are not part of the CFML language itself. Custom tags are regular CFML files which are intended to be invoked as tags, although it is possible to treat a template as both a custom tag and a regular template. Custom tags are written in CFML and are typically invoked by prefixing the custom tag's file name with cf_, although there are other ways to invoke custom tags.
If a template is invoked as a custom tag, the attributes used to invoke that tag are available within the tag in a special attributes structure and the variables contained in the calling page are accessible via the caller structure.
For example, if writing an add tag which takes two attributes and adds them together, the sum.cfm page would look like this:
<cfset caller.sum = attributes.first + attributes.second />
Assuming the template and tag are in the same directory, the tag can be invoked thus:
<cf_sum first="1" second="2">
CFX tags are custom tags which are developed using Java or C++, and are prefixed with cfx_ just like cf_. Java and C++ tags are added to the CFML runtime environment using the CFML engine's administrator or by editing configuration files.
On some CFML engines JSP tags can also be included in CFML pages using the <cfimport> tag.
Functions
ColdFusion Markup Language includes a set of functions that you use to perform logical and arithmetic operations and manipulate data.
function code Array [10] (ArraySort, ArrayAppend, ArrayDeleteAt...) Conversion [11] (URLEncodedFormat, ToString...) Date and time [12] (LsTimeFormat, DateAdd, DateDiff...) Decision [13] (IsDefined, IIF...) Display and formatting [14] (CJustify, NumberFormat...) Dynamic evaluation [15] (DE, Evaluate...) Extensibility [16] (CreateObject, ToScript...) Image [17] (ImageRotate, ImageAddBorder...) International functions [18] (SetLocale, GetTimeZoneInfo...) List [19] (FindOneOf, ListSetAt...) Mathematical [20] (Randomize, Sqr...) Other functions [21] (WriteOutput, GetBaseTemplatePath...) Query [22] (QueryAddColumn, QuerySetCell...) Security [23] (Encrypt, Decrypt...) String [24] (Reverse, HTMLCodeFormat...) Structure [25] (StructKeyExists, StructDelete...) System [26] (GetTickCount, GetTempFile...) XML [27] (XMLParse, GetSOAPResponse...) ColdFusion Components (CFCs)
CFCs provide some (not all) of the typical features and functionality that are provided by object-oriented (OOP) languages. To create a CFC:
- Create a file with a.CFC extension (this distinguishes CFCs from ColdFusion templates, which have a.CFM extension).
- Use four tags to create the components, define their functions and arguments, and return a value.
- <cfcomponent>: Defines a CFC
- <cffunction>: Defines the functions (methods) within a CFC
- <cfargument>: Defines the arguments (parameters) that a function accepts
- <cfreturn>: Returns a value or result from a function
CFCs are plain CFML. Within a CFC any CFML tag, function, custom tag, other components, etc. may be used.
CFCs can be used in various ways. If a method contained in a CFC simply needs to be invoked, the <cfinvoke> tag will create an instance of the CFC, invoke the desired method, and then destroy the instance of the CFC. <cfinvoke> takes the name of the component (minus the.cfc extension) and the method to execute. To access any returned data, the RETURNVARIABLE attribute provides the name of a variable to contain whatever the function returns. CFCs are created using four tags, saved as.CFC files, and invoked using the <cfinvoke> tag.[28]
In the example below, component temperature.cfc has a method FtoC which converts temperature from Fahrenheit to Celsius. The test.cfm template invokes the method and converts 212 degrees Fahrenheit and outputs the result.
<!--- temperature.cfc ---> <cfcomponent> <cffunction name="FtoC" access="public" returntype="numeric"> <cfargument name="fahrenheit" required="yes" type="numeric" /> <cfset answer= (fahrenheit - 32)*100/180 /> <cfreturn answer /> </cffunction> </cfcomponent> <!--- test.cfm ---> <cfset fDegrees = 212 /> <cfinvoke component="temperature" method="FtoC" returnvariable="result"> <cfinvokeargument name="fahrenheit" value="#fDegrees#" /> </cfinvoke> <cfoutput>#fDegrees#°F = #result#°C</cfoutput> <br />
CFCs may also be instantiated as objects. Assuming a CFC file called Person.cfc, an instance of this CFC would be instantiated as follows:
<cfset person = CreateObject("component", "Person") />
CFCs also form the basis of the ability to create web services in CFML. A CFC is created in the usual way, and the attribute access="remote" added to any function within the CFC will make that function available to be called as a SOAP-based web service. The CFML engine auto-generates a WSDL and creates all the necessary stubs for the web service to function.
References
- ^ ColdFusion Markup Language[1]
- ^ Open BlueDragon Manual[2]
- ^ Michael Smith. "What is ColdFusion?" [3]
- ^ Tags. [4]
- ^ Interview with Alan Williamson[5]
- ^ About Railo[6]
- ^ http://corfield.org/entry/CFML_Advisory_Committee
- ^ Tag syntax[7]
- ^ Tags by function. [8]
- ^ Array functions[9]
- ^ Conversion functions[10]
- ^ Date and time functions[11]
- ^ Decision functions[12]
- ^ Display and formatting functions[13]
- ^ Dynamic evaluation functions[14]
- ^ Extensibility [15]
- ^ Image functions[16]
- ^ International functions[17]
- ^ List functions[18]
- ^ Mathematical functions[19]
- ^ Other functions[20]
- ^ Query functions[21]
- ^ Security functions[22]
- ^ String functions[23]
- ^ Structure functions[24]
- ^ System functions[25]
- ^ XML functions[26]
- ^ Ben Forta, "Using ColdFusion components"[27]
External links
- CFML in 100 minutes — introduction to the basics of the CFML language.
- CFQuickDocs — ColdFusion tags and functions reference.
- EasyCFM — ColdFusion Reference, Tutorials and Community Outreach site.
- LearnCF — Learn ColdFusion with ColdFusion tutorials.
- ColdFusion.TV — Free ColdFusion Video Tutorials.
Implementations Applications Frameworks Full-Stack and Application FrameworksTask-specific FrameworksDevelopment Resources IDEs / EditorsDebugging and MonitoringcfTracker · ColdFire · FusionDebug · FusionReactor · SeeFusionWebsitesCategory:CFML programming languageCategories:- CFML programming language
Wikimedia Foundation. 2010.