Utility Functions: CreateMapping() and RemoveMapping()

Some more "stolen" code for today's pair of utility functions. Thanks to FusionGrokker's post on controlling mappings in CF7. As FusionGrokker points out, these functions work in CF7, but its actually hacking global mapping values, so you could have problems.

<cffunction name="CreateMapping" output="false" returntype="void">
    <cfargument name="mapping" type="string" required="true" />
    <cfargument name="path" type="string" required="true" />
    
    <cfset var factory = CreateObject("java", "coldfusion.server.ServiceFactory") />
    <cfset var mappings = factory.runtimeService.getMappings() />
    
    <cfset mappings[arguments.mapping] = arguments.path />
    
    <cfreturn />
</cffunction>

<cffunction name="RemoveMapping" output="false" returntype="void">
    <cfargument name="mapping" type="string" required="true" />
    
    <cfset var factory = CreateObject("java", "coldfusion.server.ServiceFactory") />
    <cfset var mappings = factory.runtimeService.getMappings() />
    
    <cfset StructDelete(mappings, arguments.mapping) />
    
    <cfreturn />
</cffunction>

 
Comments are not allowed for this entry.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.