Sorcerer's IsleCode QueryParam Scanner / files

     1<cfcomponent output="false" hint="I am a simple object wrapper for attributes scope.">
     2<!---
     3Copyright 2006-2007 TeraTech, Inc. http://teratech.com/
     4
     5Licensed under the Apache License, Version 2.0 (the "License");
     6you may not use this file except in compliance with the License.
     7You may obtain a copy of the License at
     8
     9http://www.apache.org/licenses/LICENSE-2.0
    10
    11Unless required by applicable law or agreed to in writing, software
    12distributed under the License is distributed on an "AS IS" BASIS,
    13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14See the License for the specific language governing permissions and
    15limitations under the License.
    16--->
    17
    18	<cffunction name="init" returntype="any" access="public" output="false" 
    19				hint="I am the constructor.">
    20		<cfargument name="attributes" type="struct" required="true" 
    21					hint="I am the attributes scope passed in." />
    22		<cfargument name="xfa" type="struct" required="true" 
    23					hint="I am the XFA scope passed in." />
    24		<cfargument name="myFusebox" type="any" required="true" 
    25					hint="I am the myFusebox object passed in." />
    26		
    27		<cfset variables.attributes = arguments.attributes />
    28		<cfset variables.xfa = arguments.xfa />
    29		<cfset variables.myFusebox = arguments.myFusebox />
    30		
    31		<cfreturn this />
    32	
    33	</cffunction>
    34
    35	<cffunction name="getValue" returntype="any" access="public" output="false" 
    36				hint="I return a given attribute value, or the default if it is not present.">
    37		<cfargument name="valueName" type="string" required="true" 
    38					hint="I am the name of the attribute to return." />
    39		<cfargument name="defaultValue" type="any" default="" 
    40					hint="I am the default value to return if the given attribute is missing." />
    41
    42		<cfif valueExists(arguments.valueName)>
    43			<cfreturn variables.attributes[arguments.valueName] />
    44		<cfelse>
    45			<cfreturn arguments.defaultValue />
    46		</cfif>
    47
    48	</cffunction>
    49
    50	<cffunction name="valueExists" returntype="boolean" access="public" output="false" 
    51				hint="I check with a given attribute value is present.">
    52		<cfargument name="valueName" type="string" required="true" 
    53					hint="I am the name of the attribute to check." />
    54
    55		<cfreturn structKeyExists(variables.attributes,arguments.valueName) />
    56
    57	</cffunction>
    58
    59	<cffunction name="setValue" returntype="void" access="public" output="false" 
    60				hint="I update the given attribute value.">
    61		<cfargument name="valueName" type="string" required="true" 
    62					hint="I am the name of the attribute to update." />
    63		<cfargument name="newValue" type="any" required="true" 
    64					hint="I am the new value for the given attribute." />
    65		
    66		<cfset variables.attributes[arguments.valueName] = arguments.newValue />
    67
    68	</cffunction>
    69
    70	<cffunction name="getAllValues" returntype="any" access="public" output="false" 
    71				hint="I return a struct containing all the attribute values - this is a reference to the actual attributes scope.">
    72		
    73		<cfreturn variables.attributes />
    74
    75	</cffunction>
    76
    77	<cffunction name="removeValue" returntype="void" access="public" output="false" 
    78				hint="I remove a given attribute's value.">
    79		<cfargument name="valueName" type="string" required="true" 
    80					hint="I am the name of the attribute to remove." />
    81
    82		<cfset structDelete(variables.attributes,arguments.valueName) />
    83
    84	</cffunction>
    85	
    86	<cffunction name="xfa" returntype="string" access="public" output="false" 
    87				hint="I set/get an eXit FuseAction.">
    88		<cfargument name="name" type="string" required="true" 
    89					hint="I am the XFA to get/set." />
    90		<cfargument name="value" type="string" required="false" 
    91					hint="I am the optional value to set." />
    92		
    93		<cfset var xfaValue = "" />
    94		<cfset var n = arrayLen(arguments) />
    95		<cfset var i = 3 />
    96		
    97		<cfif structKeyExists(arguments,"value")>
    98			<cfif listLen(arguments.value,".") gte 2>
    99				<cfset variables.xfa[arguments.name] = arguments.value />
   100			<cfelse>
   101				<cfset variables.xfa[arguments.name] = variables.myFusebox.thisCircuit & "." & arguments.value />
   102			</cfif>
   103			<cfif n mod 2 neq 0>
   104				<cfthrow type="fusebox.badGrammar,illegalArguments" 
   105						message="Odd arguments to event.xfa()" 
   106						detail="event.xfa() must be passed an even number of arguments as name-value pairs." />
   107			</cfif>
   108			<cfloop condition="i lt n">
   109				<cfset variables.xfa[arguments.name] = variables.xfa[arguments.name] &
   110						variables.myFusebox.getApplication().queryStringSeparator & arguments[i] &
   111								variables.myFusebox.getApplication().queryStringEqual & arguments[i+1] />
   112				<cfset i = i + 2 />
   113			</cfloop>
   114		</cfif>
   115		
   116		<cfif structKeyExists(variables.xfa,arguments.name)>
   117			<cfset xfaValue = variables.xfa[arguments.name] />
   118		</cfif>
   119		
   120		<cfreturn xfaValue />
   121		
   122	</cffunction>
   123
   124</cfcomponent>