The site I use in this example is very simple but should be sufficient to demonstrate the main principles of using Contribute Publishing Services. Before I go too far, let me review the directory structure of the sample files (linked to on the previous page) so you have some idea of what you are getting into.
I like to keep all my ColdFusion components (CFCs) under one directory, separate from other files. Apart from simply making things easier to find, it gives me greater flexibility because I can easily move this directory outside of the web root and access it using a ColdFusion mapping, or share functionality across multiple sites. In this example, I use a directory called "cfcs" (see Figure 1).

Figure 1. Directory structure of the sample files
When you create a site that will be administered through Contribute, it is a good idea to use of Dreamweaver templates. I like to keep all of them in one location as well. In this example, I use the "Templates" directory.
I set up a "ws" directory to store files that can be called for web services. Because web services are being accessed remotely, it is usually a good idea to keep them separate from other ColdFusion components. This allows more granular control over access to your web services.
The root directory contains the files: Application.cfm, index.cfm, OnRequestEnd.cfm, scribble.cfm, and search.cfm.
It's always a good idea to create the Application.cfm file in the root of your site even if the file is empty. If Application.cfm is missing, ColdFusion keeps looking up the directory tree until it either finds one or reaches the root of the drive. Because this happens for every request, it can cause a significant and unnecessary performance hit. It is also worth remembering that the name of this file is case-sensitive, so if you are on a Unix system, ColdFusion will only look for Application.cfm, not application.cfm. Personally, I always use an uppercase A regardless of which operating system I use.
The Application.cfm file in this site sets a variable called request.execTime to
the value returned from the getTickCount() function.
This variable becomes very handy when you want to look at the performance of
various pages or specific blocks of code. I also have a cfapplication tag,
which specifies the application name and I use to create application
scoped variables and a reference my VerityGateway.cfc, which I'll discuss
in more detail a little later.
Here is the code in my Application.cfm file:
<cfset request.execTime = getTickCount()>
<cfapplication name="desvdev-SVN.cletus.gruden.int">
<cfparam
name="application.VerityGateway"
default="#createObject('component','cfcs.VerityGateway').init(application.applicationName)#">
The index.cfm file is simply the site's landing page. I based it on the Basic.dwt template and it contains some sample text and the search form.
Here is the code in my index.cfm file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/Basic.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="Title" -->
<title>Lorem ipsum</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<!-- InstanceBeginEditable name="Content" -->
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque in pede in leo egestas mattis. Sed sit amet ante vel nibh interdum fermentum. Vestibulum tincidunt vestibulum ante. Vestibulum vitae sapien eget diam condimentum egestas. Nulla consequat nisl. Duis sed lacus. Donec non elit. In est. Aenean molestie massa quis mauris. Vivamus sit amet wisi quis mauris dignissim suscipit. Aliquam erat volutpat. Nullam semper lacinia wisi. Etiam dignissim sodales enim. Pellentesque cursus augue ut odio. Proin fermentum ornare urna.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque in pede in leo egestas mattis. Sed sit amet ante vel nibh interdum fermentum. Vestibulum tincidunt vestibulum ante. Vestibulum vitae sapien eget diam condimentum egestas. Nulla consequat nisl. Duis sed lacus. Donec non elit. In est. Aenean molestie massa quis mauris. Vivamus sit amet wisi quis mauris dignissim suscipit. Aliquam erat volutpat. Nullam semper lacinia wisi. Etiam dignissim sodales enim. Pellentesque cursus augue ut odio. Proin fermentum ornare urna.</p>
<!-- InstanceEndEditable -->
<form action="search.cfm" id="searchForm" method="get" enctype="multipart/form-data">
Search: <input type="text" id="q" name="q">
<input type="submit" name="submit" value="go" class="submit">
</form>
</body>
<!-- InstanceEnd --></html>
The OnRequestEnd.cfm file is similar to the Application.cfm file in that it has a special meaning to ColdFusion. Just as the Application.cfm is the first block of code that is processed on each request, the OnRequestEnd.cfm file is the last block of code. I often like to use this file as a generic place to put debugging code. One of my favorite tricks is to output the execution time for the entire page in the HTTP headers, as Sean Corfield describes in one of his blog entries.
Here is the code in my OnRequestEnd.cfm file:
<cftry> <cfheader name="X-ExecTime" value="#evaluate(getTickCount() - request.execTime)#"> <cfcatch><!--- headers sent ---></cfcatch> </cftry> <cfparam name="url.debug" default="false"> <cfif url.debug> <!--- insert debugging stuff here if required. ---> </cfif>
One useful trick I picked up comes from Spike is to have a scribble.cfm file. I use this file as a generic scribble pad. Anytime I need to test something quickly or thrash out an idea, I use this file. I'll describe later a little more about how I use this file to debug my web services.
Finally, the simple search.cfm file searches the Verity collection for a given keyword and lists the results.
Here is the code for the search.cfm file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Search Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Search Results</h1>
<cfset results = application.VerityGateway.search(url.q)>
<cfif NOT results.recordCount>
<p>No matches found.</p>
<cfelse>
<ol>
<cfoutput query="results">
<li>#numberFormat(results.score*100,'99')#% <a href="#results.URL#">#results.title#</a><br />#results.summary#</li>
</cfoutput>
</ol>
</cfif>
</body>
</html>