<cfcomponent
output="false"
hint="This is a crude ColdFusion-based decorator for the java.lang.String object.">
<cfset VARIABLES.Target = JavaCast( "string", "" ) />
<cffunction
name="Init"
access="public"
returntype="any"
output="false"
hint="Initializes the string wrapper.">
<cfargument
name="Value"
type="string"
required="false"
default=""
/>
<cfset VARIABLES.Target = ARGUMENTS.Value />
<cfreturn THIS />
</cffunction>
<cffunction
name="Contains"
access="public"
returntype="numeric"
output="false"
hint="Tests to see if the given regular experssion exists somewhere in the target string.">
<cfargument
name="RegEx"
type="string"
required="true"
/>
<cfreturn REFind( ARGUMENTS.RegEx, VARIABLES.Target ) />
</cffunction>
<cffunction
name="Get"
access="public"
returntype="string"
output="false"
hint="Gets the internal string value.">
<cfreturn VARIABLES.Target />
</cffunction>
<cffunction
name="OnMissingMethod"
access="public"
returntype="any"
output="false"
hint="Handles missing method exceptions.">
<cfargument
name="MissingMethodName"
type="string"
required="true"
hint="The name of the missing method."
/>
<cfargument
name="MissingMethodArguments"
type="struct"
required="true"
hint="The arguments that were passed to the missing method. This might be a named argument set or a numerically indexed set."
/>
<cfset var LOCAL = {} />
<cfset LOCAL.Keys = StructKeyArray(
ARGUMENTS.MissingMethodArguments
) />
<cfif NOT ArrayLen( LOCAL.Keys )>
<cfreturn Evaluate(
"VARIABLES.Target.#ARGUMENTS.MissingMethodName#()"
) />
<cfelseif IsNumeric( LOCAL.Keys[ 1 ] )>
<cfset LOCAL.Args = "" />
<cfloop
index="LOCAL.KeyIndex"
from="1"
to="#ArrayLen( LOCAL.Keys )#"
step="1">
<cfset LOCAL.Args &= (
IIF(
(LOCAL.KeyIndex GT 1),
DE( "," ),
DE( "" )
) &
"ARGUMENTS.MissingMethodArguments[ #LOCAL.KeyIndex# ]"
) />
</cfloop>
<cfreturn Evaluate(
"VARIABLES.Target.#ARGUMENTS.MissingMethodName#(" &
LOCAL.Args &
")"
) />
<cfelse>
<cfset LOCAL.Args = "" />
<cfloop
index="LOCAL.KeyIndex"
from="1"
to="#ArrayLen( LOCAL.Keys )#"
step="1">
<cfset LOCAL.Args &= (
IIF(
(LOCAL.KeyIndex GT 1),
DE( "," ),
DE( "" )
) &
"#LOCAL.Keys[ LOCAL.KeyIndex ]#=" &
"ARGUMENTS.MissingMethodArguments[ #LOCAL.KeyIndex# ]"
) />
</cfloop>
<cfreturn Evaluate(
"VARIABLES.Target.#ARGUMENTS.MissingMethodName#(" &
LOCAL.Args &
")"
) />
</cfif>
<cfreturn ARGUMENTS.MissingMethodName />
</cffunction>
<cffunction
name="Set"
access="public"
returntype="any"
output="false"
hint="Sets the internal string value and return a pointer to the wrapper.">
<cfargument
name="Value"
type="string"
required="false"
default=""
/>
<cfset VARIABLES.Target = ARGUMENTS.Value />
<cfreturn THIS />
</cffunction>
</cfcomponent>