Utility Functions: CreateMapping() and RemoveMapping()
- February 26, 2009 5:30 AM
- ColdFusion, Utility Function
- Comments (0)
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>
<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>