Jump to content

ColdFusion Markup Language

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Masondixon (talk | contribs) at 04:58, 23 March 2010 (the history section on this page is a joke.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Cold Fusion Markup Language (CFML)
Paradigmimperative, object-oriented
Designed byJeremy Allaire
DeveloperAdobe Systems, Railo, New Atlanta
First appeared1995
OSWindows, Linux, UNIX, Macintosh
LicenseDepends on the implementation
WebsiteCFML Advisory Committee, Adobe ColdFusion, Railo, BlueDragon
Major implementations
Adobe ColdFusion, Railo, BlueDragon

ColdFusion Markup Language, more commonly known as CFML, is the scripting language used by Adobe ColdFusion, BlueDragon and Railo, as well as other CFML server engines. The CFML language is guided by the CFML Advisory Committee.

Synopsis

CFML generally augments standard HTML files with database commands, conditional operators, high-level formatting functions, and other elements to produce web applications.[1]

The pages in a ColdFusion application include the server-side CFML tags in addition to HTML tags. When a web browser requests a page in a ColdFusion application, it is automatically pre-processed by the ColdFusion Application Server.[2]

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.

ColdFusion tags tell the ColdFusion server that it must process the tagged information. The ColdFusion server only processes ColdFusion tag contents; it returns text outside of ColdFusion tags to the web server unchanged.[3]

History

The program was originally made by Allaire systems, based in Cambridge, Mass. The server-side technology was bought by Macromedia and became Macromedia Cold Fusion.

On June 18 2009, Adobe announced at the CFUnited conference that it had formed a CFML Advisory Committee[4] that would be responsible for guiding and reviewing changes to the CFML language.

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, as in the example below. If it is legal for tags not to have a body, it is syntactically acceptable to leave them unclosed.

 
<cfset value = "Hello">
<cfset value = "Hello" />

Sometimes, although the tag can have a body, you find that you do not need to put anything in it because the attributes specify all the required information. In these cases (as with all HTML), you can choose to omit the end tag (and hence, the body) and just put a forward slash character before the closing (>) character, as in the following example:[5]

<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.

Built-in tags

Over 80 built-in tags make up the heart of ColdFusion. The following lists CFML tags by their function or purpose.[6]

Custom tags

CFML allows language extensions in the form of custom tags. In other words, CFML allows tags that are not built-in ColdFusion tags. Custom tags are normal 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 written in CFML may be prefixed with cf_, although there are other ways to invoke them.

If a template is invoked as a custom tag, the attributes used to invoke that tag are available in a special structure attributes and the variables on the calling page are accessible via the caller struct. 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 language or C++, and are prefixed with cfx_ just like cf_. Tags are added to the ColdFusion runtime environment using the ColdFusion administrator, where JAR or DLL files are registered as custom tags.

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 [7] (ArraySort, ArrayAppend, ArrayDeleteAt...)
Conversion [8] (URLEncodedFormat, ToString...)
Date and time [9] (LsTimeFormat, DateAdd, DateDiff...)
Decision [10] (IsDefined, IIF...)
Display and formatting [11] (CJustify, NumberFormat...)
Dynamic evaluation [12] (DE, Evaluate...)
Extensibility [13] (CreateObject, ToScript...)
Image [14] (ImageRotate, ImageAddBorder...)
International functions [15] (SetLocale, GetTimeZoneInfo...)
List [16] (FindOneOf, ListSetAt...)
Mathematical [17] (Randomize, Sqr...)
Other functions [18] (WriteOutput, GetBaseTemplatePath...)
Query [19] (QueryAddColumn, QuerySetCell...)
Security [20] (Encrypt, Decrypt...)
String [21] (Reverse, HTMLCodeFormat...)
Structure [22] (StructKeyExists, StructDelete...)
System [23] (GetTickCount, GetTempFile...)
XML [24] (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 you can use any tag, function, custom tag, component, and more. After creating your CFC, save it with.cfc extension.

To use your CFC, use <cfinvoke> tag to call your component methods from a.cfm file. <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.[25]

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#&deg;F = #result#&deg;C</cfoutput> <br />

References

  1. ^ ColdFusion Markup Language[1]
  2. ^ Michael Smith. "What is ColdFusion?" [2]
  3. ^ Tags. [3]
  4. ^ http://corfield.org/entry/CFML_Advisory_Committee
  5. ^ Tag syntax[4]
  6. ^ Tags by function. [5]
  7. ^ Array functions[6]
  8. ^ Conversion functions[7]
  9. ^ Date and time functions[8]
  10. ^ Decision functions[9]
  11. ^ Display and formmatting functions[10]
  12. ^ Dynamic evaluation functions[11]
  13. ^ Extensibility [12]
  14. ^ Image functions[13]
  15. ^ International functions[14]
  16. ^ List functions[15]
  17. ^ Mathematical functions[16]
  18. ^ Other functions[17]
  19. ^ Query functions[18]
  20. ^ Security functions[19]
  21. ^ String functions[20]
  22. ^ Structure functions[21]
  23. ^ System functions[22]
  24. ^ XML functions[23]
  25. ^ Ben Forta, "Using ColdFusion components"[24]