PageRenderTime 46ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 17ms app.codeStats 0ms

/wheels/global/cfml.cfm

http://cfwheels.googlecode.com/
ColdFusion | 242 lines | 214 code | 24 blank | 4 comment | 0 complexity | 650a9e51ca779e0d73a56878b5c0045a MD5 | raw file
  1<cffunction name="$namedReadLock" returntype="any" access="public" output="false">
  2	<cfargument name="name" type="string" required="true">
  3	<cfargument name="object" type="any" required="true">
  4	<cfargument name="method" type="string" required="true">
  5	<cfargument name="args" type="struct" required="false" default="#StructNew()#">
  6	<cfargument name="timeout" type="numeric" required="false" default="30">
  7	<cfset var loc = {}>
  8	<cflock name="#arguments.name#" type="readonly" timeout="#arguments.timeout#">
  9		<cfset loc.returnValue = $invoke(componentReference=arguments.object, method=arguments.method, invokeArgs=arguments.args)>
 10	</cflock>
 11	<cfreturn loc.returnValue>
 12</cffunction>
 13
 14<cffunction name="$doubleCheckedLock" returntype="any" access="public" output="false">
 15	<cfargument name="name" type="string" required="true">
 16	<cfargument name="condition" type="string" required="true">
 17	<cfargument name="execute" type="string" required="true">
 18	<cfargument name="conditionArgs" type="struct" required="false" default="#StructNew()#">
 19	<cfargument name="executeArgs" type="struct" required="false" default="#StructNew()#">
 20	<cfargument name="timeout" type="numeric" required="false" default="30">
 21	<cfset var loc = {}>
 22	<cfset loc.returnValue = $invoke(method=arguments.condition, invokeArgs=arguments.conditionArgs)>
 23	<cfif IsBoolean(loc.returnValue) AND NOT loc.returnValue>
 24		<cflock name="#arguments.name#" timeout="#arguments.timeout#">
 25			<cfset loc.returnValue = $invoke(method=arguments.condition, invokeArgs=arguments.conditionArgs)>
 26			<cfif IsBoolean(loc.returnValue) AND NOT loc.returnValue>
 27				<cfset loc.returnValue = $invoke(method=arguments.execute, invokeArgs=arguments.executeArgs)>
 28			</cfif>
 29		</cflock>
 30	</cfif>
 31	<cfreturn loc.returnValue>
 32</cffunction>
 33
 34<cffunction name="$simpleLock" returntype="any" access="public" output="false">
 35	<cfargument name="execute" type="string" required="true">
 36	<cfargument name="executeArgs" type="struct" required="false" default="#StructNew()#">
 37	<cfargument name="timeout" type="numeric" required="false" default="30">
 38	<cfset var loc = {}>
 39	<cfset loc.lockArgs = Duplicate(arguments)>
 40	<cfset StructDelete(loc.lockArgs, "execute")>
 41	<cfset StructDelete(loc.lockArgs, "executeArgs")>
 42	<cfset arguments.executeArgs.$locked = true>
 43	<cflock attributeCollection="#loc.lockArgs#">
 44		<cfinvoke method="#arguments.execute#" argumentCollection="#arguments.executeArgs#" returnvariable="loc.returnValue">
 45	</cflock>
 46	<cfif StructKeyExists(loc, "returnValue")>
 47		<cfreturn loc.returnValue>
 48	</cfif>
 49</cffunction>
 50
 51<cffunction name="$setting" returntype="void" access="public" output="false">
 52	<cfsetting attributeCollection="#arguments#">
 53</cffunction>
 54
 55<cffunction name="$image" returntype="struct" access="public" output="false">
 56	<cfset var returnValue = {}>
 57	<cfset arguments.structName = "returnValue">
 58	<cfimage attributeCollection="#arguments#">
 59	<cfreturn returnValue>
 60</cffunction>
 61
 62<cffunction name="$mail" returntype="void" access="public" output="false">
 63	<cfset var loc = {}>
 64	<cfif StructKeyExists(arguments, "mailparts")>
 65		<cfset loc.mailparts = arguments.mailparts>
 66		<cfset StructDelete(arguments, "mailparts")>
 67	</cfif>
 68	<cfif StructKeyExists(arguments, "mailparams")>
 69		<cfset loc.mailparams = arguments.mailparams>
 70		<cfset StructDelete(arguments, "mailparams")>
 71	</cfif>
 72	<cfif StructKeyExists(arguments, "tagContent")>
 73		<cfset loc.tagContent = arguments.tagContent>
 74		<cfset StructDelete(arguments, "tagContent")>
 75	</cfif>
 76	<cfmail attributeCollection="#arguments#">
 77		<cfif StructKeyExists(loc, "mailparams")>
 78			<cfloop array="#loc.mailparams#" index="loc.i">
 79				<cfmailparam attributeCollection="#loc.i#">
 80			</cfloop>
 81		</cfif>
 82		<cfif StructKeyExists(loc, "mailparts")>
 83			<cfloop array="#loc.mailparts#" index="loc.i">
 84				<cfset loc.innerTagContent = loc.i.tagContent>
 85				<cfset StructDelete(loc.i, "tagContent")>
 86				<cfmailpart attributeCollection="#loc.i#">
 87					#loc.innerTagContent#
 88				</cfmailpart>
 89			</cfloop>
 90		</cfif>
 91		<cfif StructKeyExists(loc, "tagContent")>
 92			#loc.tagContent#
 93		</cfif>
 94	</cfmail>
 95</cffunction>
 96
 97<cffunction name="$zip" returntype="any" access="public" output="false">
 98	<cfzip attributeCollection="#arguments#">
 99	</cfzip>
100</cffunction>
101
102<cffunction name="$cache" returntype="any" access="public" output="false">
103	<cfcache attributeCollection="#arguments#">
104</cffunction>
105
106<cffunction name="$content" returntype="any" access="public" output="false">
107	<cfcontent attributeCollection="#arguments#">
108</cffunction>
109
110<cffunction name="$header" returntype="void" access="public" output="false">
111	<cfheader attributeCollection="#arguments#">
112</cffunction>
113
114<cffunction name="$abort" returntype="void" access="public" output="false">
115	<cfabort attributeCollection="#arguments#">
116</cffunction>
117
118<cffunction name="$include" returntype="void" access="public" output="false">
119	<cfargument name="template" type="string" required="true">
120	<cfset var loc = {}>
121	<cfinclude template="../../#LCase(arguments.template)#">
122</cffunction>
123
124<cffunction name="$includeAndOutput" returntype="void" access="public" output="true">
125	<cfargument name="template" type="string" required="true">
126	<cfset var loc = {}>
127	<cfinclude template="../../#LCase(arguments.template)#">
128</cffunction>
129
130<cffunction name="$includeAndReturnOutput" returntype="string" access="public" output="false">
131	<cfargument name="$template" type="string" required="true">
132	<cfset var loc = {}>
133	<cfif StructKeyExists(arguments, "$type") AND arguments.$type IS "partial">
134		<!--- make it so the developer can reference passed in arguments in the loc scope if they prefer --->
135		<cfset loc = arguments>
136	</cfif>
137	<!--- we prefix returnValue with "wheels" here to make sure the variable does not get overwritten in the included template --->
138	<cfsavecontent variable="loc.wheelsReturnValue"><cfinclude template="../../#LCase(arguments.$template)#"></cfsavecontent>
139	<cfreturn loc.wheelsReturnValue>
140</cffunction>
141
142<cffunction name="$directory" returntype="any" access="public" output="false">
143	<cfset var returnValue = "">
144	<cfset arguments.name = "returnValue">
145	<cfdirectory attributeCollection="#arguments#">
146	<cfreturn returnValue>
147</cffunction>
148
149<cffunction name="$file" returntype="any" access="public" output="false">
150	<cfset var returnValue = "">
151	<cfset arguments.variable = "returnValue">
152	<cffile attributeCollection="#arguments#">
153	<cfreturn returnValue>
154</cffunction>
155
156<cffunction name="$throw" returntype="void" access="public" output="false">
157	<cfthrow attributeCollection="#arguments#">
158</cffunction>
159
160<cffunction name="$invoke" returntype="any" access="public" output="false">
161	<cfset var loc = {}>
162	<cfset arguments.returnVariable = "loc.returnValue">
163	<cfif StructKeyExists(arguments, "componentReference")>
164		<cfset arguments.component = arguments.componentReference>
165		<cfset StructDelete(arguments, "componentReference")>
166	<cfelseif NOT StructKeyExists(variables, arguments.method)>
167		<!--- this is done so that we can call dynamic methods via "onMissingMethod" on the object (we need to pass in the object for this so it can call methods on the "this" scope instead) --->
168		<cfset arguments.component = this>
169	</cfif>
170	<cfif StructKeyExists(arguments, "invokeArgs")>
171		<cfset arguments.argumentCollection = arguments.invokeArgs>
172		<cfset StructDelete(arguments, "invokeArgs")>
173	</cfif>
174	<cfinvoke attributeCollection="#arguments#">
175	<cfif StructKeyExists(loc, "returnValue")>
176		<cfreturn loc.returnValue>
177	</cfif>
178</cffunction>
179
180<cffunction name="$location" returntype="void" access="public" output="false">
181	<cfargument name="delay" type="boolean" required="false" default="false">
182	<cfset StructDelete(arguments, "$args", false)>
183	<cfif NOT arguments.delay>
184		<cfset StructDelete(arguments, "delay", false)>
185		<cfif arguments.url Contains "?" AND arguments.url Contains "##">
186			<!--- fix for cflocation anchor bug --->
187			<cfset arguments.url = Replace(arguments.url, "##", "&##")>
188		</cfif>
189		<cflocation attributeCollection="#arguments#">
190	</cfif>
191</cffunction>
192
193<cffunction name="$htmlhead" returntype="void" access="public" output="false">
194	<cfhtmlhead attributeCollection="#arguments#">
195</cffunction>
196
197<cffunction name="$dbinfo" returntype="any" access="public" output="false">
198	<cfset var loc = {}>
199	<cfset arguments.name = "loc.returnValue">
200	<cfif NOT Len(arguments.username)>
201		<cfset StructDelete(arguments, "username")>
202	</cfif>
203	<cfif NOT Len(arguments.password)>
204		<cfset StructDelete(arguments, "password")>
205	</cfif>
206	<cfdbinfo attributeCollection="#arguments#">
207	<cfreturn loc.returnValue>
208</cffunction>
209
210<cffunction name="$dump" returntype="void" access="public" output="true">
211	<cfargument name="var" type="any" required="true">
212	<cfargument name="abort" type="boolean" required="false" default="true">
213	<cfdump var="#arguments.var#">
214	<cfif arguments.abort>
215		<cfabort>
216	</cfif>
217</cffunction>
218
219<cffunction name="$objectcache" returntype="void" access="public" output="false">
220	<cfobjectcache attributeCollection="#arguments#">
221</cffunction>
222
223<cffunction name="$wddx" returntype="any" access="public" output="false">
224	<cfargument name="input" type="any" required="true">
225	<cfargument name="action" type="string" required="false" default="cfml2wddx">
226	<cfargument name="useTimeZoneInfo" type="boolean" required="false" default="true">
227	<cfset var loc = {}>
228	<cfset arguments.output = "loc.output">
229	<cfwddx attributeCollection="#arguments#">
230	<cfif StructKeyExists(loc, "output")>
231		<cfreturn loc.output>
232	</cfif>
233</cffunction>
234
235<cffunction name="$structDelete" returntype="void" access="public" output="false">
236	<cfargument name="myStruct" type="struct" required="true">
237	<cfargument name="keys" type="string" required="true">
238	<cfset var loc = {}>
239	<cfloop list="#arguments.keys#" index="loc.i">
240		<cfset StructDelete(arguments.myStruct, loc.i, false)>
241	</cfloop>
242</cffunction>