Accessibility

Table of Contents

Managing Adobe AIR updates with ColdFusion 8

Leveraging ColdFusion in the update process

By utilizing ColdFusion 8 and an Apache Derby–embedded database, you can minimize the size of each update check to a single HTTPRequest. This creates two big advantages. First, this method can be used with both Flex/ActionScript and HTML/JavaScript applications. Second, by using the Derby-embedded database you are not relying on any services outside of ColdFusion 8. This also makes the application extremely easy to package and move to any other ColdFusion 8 server. By following this method it will also leave a detailed record of the releases of your application.

The embedded database is not the only new ColdFusion 8 feature that you will use in serving the Adobe AIR application files. You also will be taking advantage of the new CFZIP tag. With this tag, ColdFusion can look into an Adobe AIR application file and extract any information contained within its application descriptor file. Also, to take advantage of a lightweight data transfer format, you will be using the new ability in ColdFusion 8 where a ColdFusion component can return JavaScript Object Notation (JSON).

For the ColdFusion side of this application you will be using four files:

  • Application.cfc: This file verifies that the database table is created. If it is not, it creates it. The file also sets a few application scope variables.
  • UpdateManager.cfc: This file serves as your web service. The Adobe AIR applications call this file to get all of the update information.
  • serve.cfm: This file sends out the Adobe AIR application downloads.
  • index.cfm: This file allows the developer to add applications to the database and add release notes.

Installing the sample files

The sample files for this project can be found in the ColdFusion folder of the exercise files. Simply place these files in a directory on a ColdFusion 8 server, create the datasource (as outlined below), and update the Application.cfc file with the right path information.

Creating a database to store application information

The Derby database that will be used in the application can be created inside of the Data Sources section of the ColdFusion Administrator. To create the database:

  1. Create a new datasource with Apache Derby Embedded as the driver type.
  2. Provide the pathname where the database will reside on the server. If the database doesn't exist, select the Create Database check box (see Figure 1).

Creating the Derby Embedded database

Figure 1. Creating the Derby-embedded database

It only takes a simple database to store all of the application information. Table 1 displays the columns that will be used in the single table of the database.

Table 1. Columns for applications table

Column Data Type Description
uuid VARCHAR(36) The primary key for the database
dateTimeAdded TIMESTAMP The Date and Time the application was added to the database
applicationID VARCHAR(255) The appID from the Application Descriptor file
applicationName VARCHAR(255) The application name from the Application Descriptor file
applicationVersion VARCHAR(50) The application version from the Application Descriptor file
updateType INT The type of update: Critical, Major, or Minor
updateFile VARCHAR(255) The filename of the AIR file
releaseNotes LONG VARCHAR The release notes for this version of the AIR Application

The database creation process is handled in the Application.cfc file. This happens behind the scenes the first time you launch the application. Several application variables are also defined in the Application.cfc file. You will need to change these values to match your server.

Adding applications to the database

You will need to develop a simple front-end interface where you can add new versions of your Adobe AIR applications. By using this code, you can develop a simple form that will allow you to upload an AIR file as well as enter the additional information on each application update (see Figure 2); here is the code:

<form method="post" name="uploadForm" enctype="multipart/form-data"> AIR File<br />
 <input name="FileContents" type="file">
 <br /><br />
 Update Type:<br />
 <select name="updateType">
   <option value="0">Critical</option>
   <option value="1">Major</option>
   <option value="2">Minor</option>
 </select>
 <br />
 <br />
 Release Notes:<br />
 <textarea name="releaseNotes"></textarea>
 <br />
 <br />
 <input name="submit" type="submit" value="Upload File"><br />
</form>

Form for adding applications to the database

Figure 2. Form for adding applications to the database

You might notice that there are a few pieces of information missing from this form. It would be easy to create a form that would allow a developer to enter all of the information about an AIR application and upload the application file. However, the appID, version information, and name of the application are all contained within the Adobe AIR application's application descriptor file. Because an AIR application file is essentially a ZIP file, the CFZIP tag in ColdFusion 8 can be used to extract the application's information. The application descriptor file is always in the same place in the Adobe AIR package: META-INF/AIR/application.xml.

When the form is submitted, ColdFusion will perform the following actions:

  1. Move the uploaded Adobe AIR file to the directory that is defined in Application.cfc:

    <cffile action = "upload" fileField = "FileContents"
     destination = "#APPLICATION.airApplicationDirectory#" 
     nameConflict = "MakeUnique">
    <cfset airFile= APPLICATION.airApplicationDirectory &
        APPLICATION.fileSeparator & cffile.serverFile />
  2. Read the Adobe AIR file with CFZIP to get the application information:

    <cfzip action="read" file="#airFile#" entrypath="META-INF#fileSeparator#AIR#fileSeparator#application.xml"
     variable="applicationDescriptor" />
    <cfset appDescriptor = XmlParse(applicationDescriptor,true) />
    <cfset appID = appDescriptor['application']['id'].XMLText />
    <cfset appVersion = appDescriptor['application']['version'].XMLText />
    <cfset appName = appDescriptor['application']['name'].XMLText />
  3. Verify whether the same version of the application is already in the database; if so, display an error:

    <cfquery name="ifDuplicate" datasource="#APPLICATION.dsn#">
     SELECT * FROM versions WHERE applicationID = <cfqueryparam
        cfsqltype="cf_sql_varchar" value="#VARIABLES.appID#">
        AND version = <cfqueryparam cfsqltype="cf_sql_varchar"
        value="#VARIABLES.appVersion#">
    </cfquery>
    <cfif ifDuplicate.RecordCount NEQ 0>
    <cfset variables.message="Application Version Already in Database" />
  4. Add the application to the database with the information entered from the form:

    <cfquery name="addApplicationUpdate" datasource="#APPLICATION.dsn#">
     INSERT INTO versions uuid,dateTimeCreated,applicationID,version,name,updateType,updateFile,releaseNotes)
       VALUES (
         '#CreateUUID()#',
         <cfqueryparam cfsqltype="cf_sql_timestamp" value="#DateFormat(now())# #TimeFormat(now())#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#VARIABLES.appID#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#VARIABLES.appVersion#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#VARIABLES.appName#">,
         <cfqueryparam cfsqltype="cf_sql_integer" value="#FORM.updateType#">,
         <cfqueryparam cfsqltype="cf_sql_varchar" value="#cffile.serverFile#">,
         <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#FORM.releaseNotes#">
       )
    </cfquery>
    <cfset variables.message="Application Added" />