ColdFusion Blackstone Coolness

So I’ve been testing Macromedia’s next version of Cold Fusion, named: Blackstone.
I was writing a component, and used the self-doccumenting feature of cfc’s to create a little documentation. However when I went to print it, it came out all crappy. For some reason these things never print right.

So I got to thinking wouldn’t it be cool if you could output this documentation in flashpaper, since that’s one of the features of Blackstone. Then I took a look at the url for the documentation, I noticed that the renderer for the cfc documentation was a cfc named “cfcexplorer.cfc,” and the documentation was created using the “getcfcinhtml” mehtod. Since the cfc was installed on myserver I opend it up and saw this:

<cffunction name=”getcfcinhtml” access=”remote”
hint=”Generates html descriptor of a component with the specified name or URI path as the http response.”>
<cfargument name=”name” type=”string” required=”yes” />
<cfargument name=”path” type=”string” required=”no” />

<cftry>
<cfscript>
if ( IsDefined(‘arguments.path’) and arguments.path neq ” ) {
proxy = CreateObject( “java”, “coldfusion.runtime.TemplateProxyFactory” ) ;
comp = proxy.ResolvePath( arguments.path, getPageContext() ) ;
} else {
comp = CreateObject( “component”, name ) ;
}

utils = CreateObject( “component”, “utils” ) ;
WriteOutput( utils.cfcToHTML(comp) ) ;
</cfscript>
<cfcatch type=”coldfusion.runtime.CfJspPage$NoSuchTemplateException”>
<cfoutput><h4>Component not found</h4>
The component definition file for component ‘#name#’ cannot be found on this server.</cfoutput>
</cfcatch>
</cftry>
</cffunction>

So I got to thinking, couldn’t I just wrap the whole thing in a <cfdocument> tag. I tried it, and it worked.

<cffunction name=”getcfcinfp” access=”remote”
hint=”Generates flashpaper descriptor of a component with the specified name or URI path as the http response.”>
<cfargument name=”name” type=”string” required=”yes” />
<cfargument name=”path” type=”string” required=”no” />

<cftry>
<cfdocument format=”flashpaper”>

<cfscript> if ( IsDefined(‘arguments.path’) and arguments.path neq ” ) {
proxy = CreateObject( “java”, “coldfusion.runtime.TemplateProxyFactory” ) ;
comp = proxy.ResolvePath( arguments.path, getPageContext() ) ;
} else {
comp = CreateObject( “component”, name ) ;
}

utils = CreateObject( “component”, “utils” ) ;
WriteOutput( utils.cfcToHTML(comp) ) ;
</cfscript>

</cfdocument>
<cfcatch type=”coldfusion.runtime.CfJspPage$NoSuchTemplateException”>
<cfoutput><h4>Component not found</h4>
The component definition file for component ‘#name#’ cannot be found on this server.</cfoutput>
</cfcatch>

</cftry>
</cffunction>

Once that’s done, all you have to do is change the method called in the URL when you browse your cfc from “cfcexplorer.cfc?method=getcfcinhtml” to “cfcexplorer.cfc?method=getcfcinfp”

Cool huh? From the flashpaper, it prints beautifully.

2 thoughts on “ColdFusion Blackstone Coolness

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s