Adobe COLDFUSION 9 Manual page 234

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
ZipBrowser example
The following example shows the use of the
package to implement a Java CFX tag called
Note: The Java source file that implements cfx_ZipBrowser, ZipBrowser.java, is included in the
cf_root/cfx/java/distrib/examples (server configuration) or cf_webapp_root/WEB-
INF/cfusion/cfx/java/distrib/examples (J2EE configuration) directory. Compile ZipBrowser.java to implement the tag.
The tag
attribute specifies the fully qualified path of the ZIP archive to browse. The tag
archive
specify the query to return to the calling page. The returned query contains three columns: Name, Size, and
Compressed.
For example, to query an archive at the path C:\logfiles.zip for its contents and output the results, you use the following
CFML code:
<cfx_ZipBrowser
archive="C:\logfiles.zip"
name="LogFiles">
<cfoutput query="LogFiles">
#Name#,#Size#, #Compressed# <BR>
</cfoutput>
The Java implementation of ZipBrowser is as follows:
import com.allaire.cfx.* ;
import java.util.Hashtable ;
import java.io.FileInputStream ;
import java.util.zip.* ;
public class ZipBrowser implements CustomTag {
public void processRequest( Request request, Response response )
throws Exception {
// Validate that required attributes were passed.
if (!request.attributeExists( "ARCHIVE" ) || !request.attributeExists( "NAME" ) ) {
throw new Exception(
"Missing attribute (ARCHIVE and NAME are both " +
"required attributes for this tag)" ) ;
}
// get attribute values
String strArchive = request.getAttribute( "ARCHIVE" ) ;
String strName = request.getAttribute( "NAME" ) ;
// create a query to use for returning the list of files
String[] columns = { "Name", "Size", "Compressed" } ;
int iName = 1, iSize = 2, iCompressed = 3 ;
Query files = response.addQuery( strName, columns ) ;
// read the ZIP file and build a query from its contents
,
, and
Request
Response
Query
, which is a ZIP file browsing tag.
cfx_ZipBrowser
Last updated 8/5/2010
objects. The example uses the java.util.zip
attribute must
name
229

Advertisement

Table of Contents
loading

Table of Contents