Aarrgghh!!

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.


November 19, 2004 Posted by Terrence Ryan at 2:28 PM

ColdFusion,



Comments

Just what I was looking for...

Thanks,

Steini


Posted by: Steini Jonsson at February 22, 2006 9:20 AM

Aarrgghh Guy! Glad I could help. Although even though I came up with the thing in the first place, what would you actually use it for?




Posted by: Terrence Ryan at February 23, 2006 1:57 AM

Posted by Who at July 24, 2008 8:35 PM

Post a comment











Remember personal info?