root / framework / tags / fusebox5A2 / fuseboxVerbBasedo.cfc

Revision 91, 9.7 kB (checked in by scorfield, 3 years ago)

Bug fix. getAlias() needed circuit :)

Line 
1<!---
2Fusebox Software License
3Version 1.0
4
5Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved.
6
7Redistribution and use in source and binary forms, with or without modification, are permitted
8provided that the following conditions are met:
9
101. Redistributions of source code must retain the above copyright notice, this list of conditions
11   and the following disclaimer.
12
132. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright
14   notice, this list of conditions and the following disclaimer in the documentation and/or other
15   materials provided with the distribution.
16
173. The end-user documentation included with the redistribution, if any, must include the following
18   acknowledgment:
19
20   "This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)."
21
22   Alternately, this acknowledgment may appear in the software itself, if and wherever such
23   third-party acknowledgments normally appear.
24
254. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products
26   derived from this software without prior written (non-electronic) permission. For written
27   permission, please contact fusebox@fusebox.org.
28
295. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in
30   their name, without prior written (non-electronic) permission of the Fusebox Corporation. For
31   written permission, please contact fusebox@fusebox.org.
32
33If one or more of the above conditions are violated, then this license is immediately revoked and
34can be re-instated only upon prior written authorization of the Fusebox Corporation.
35
36THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY
39DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
45-------------------------------------------------------------------------------
46
47This software consists of voluntary contributions made by many individuals on behalf of the
48Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>.
49
50--->
51<cfcomponent extends="fuseboxVerb" output="false">
52       
53        <cffunction name="init" returntype="any" access="public" output="false">
54                <cfargument name="action" type="fuseboxBaseAction" required="true" />
55                <cfargument name="attributes" type="struct" required="true" />
56                <cfargument name="children" type="any" required="true" />
57                <cfargument name="verb" type="string" required="true" />
58               
59                <cfset super.init(arguments.action,arguments.attributes,arguments.children,arguments.verb) />
60               
61                <cfif not structKeyExists(variables.attributes,"action")>
62                        <cfthrow type="fusebox.badGrammar.requiredAttributeMissing"
63                                        message="Required attribute is missing"
64                                        detail="The attribute 'action' is required, for a '#variables.verb#' verb in fuseaction #variables.action.getCircuit().getAlias()#.#variables.action.getName()#." />
65                </cfif>
66                <cfif structKeyExists(variables.attributes,"append")>
67                        <cfif listFind("true,false",variables.attributes.append) eq 0>
68                                <cfthrow type="fusebox.badGrammar.invalidAttributeValue"
69                                                message="Attribute has invalid value"
70                                                detail="The attribute 'append' must either be ""true"" or ""false"", for a 'variables.verb' verb in fuseaction #variables.action.getCircuit().getAlias()#.#variables.action.getName()#." />
71                        </cfif>
72                <cfelse>
73                        <cfset variables.attributes.append = false />
74                </cfif>
75                <cfif structKeyExists(variables.attributes,"prepend")>
76                        <cfif listFind("true,false",variables.attributes.prepend) eq 0>
77                                <cfthrow type="fusebox.badGrammar.invalidAttributeValue"
78                                                message="Attribute has invalid value"
79                                                detail="The attribute 'prepend' must either be ""true"" or ""false"", for a 'variables.verb' verb in fuseaction #variables.action.getCircuit().getAlias()#.#variables.action.getName()#." />
80                        </cfif>
81                <cfelse>
82                        <cfset variables.attributes.prepend = false />
83                </cfif>
84                <cfif structKeyExists(variables.attributes,"overwrite")>
85                        <cfif listFind("true,false",variables.attributes.overwrite) eq 0>
86                                <cfthrow type="fusebox.badGrammar.invalidAttributeValue"
87                                                message="Attribute has invalid value"
88                                                detail="The attribute 'overwrite' must either be ""true"" or ""false"", for a 'variables.verb' verb in fuseaction #variables.action.getCircuit().getAlias()#.#variables.action.getName()#." />
89                        </cfif>
90                <cfelse>
91                        <cfset variables.attributes.overwrite = true />
92                </cfif>
93               
94                <cfreturn this />
95               
96        </cffunction>
97       
98        <cffunction name="compile" returntype="void" access="public" output="false">
99                <cfargument name="writer" type="fuseboxWriter" required="true" />
100
101                <cfset var i = 0 />
102                <cfset var n = 0 />
103                <cfset var plugins = variables.action.getCircuit().getApplication().pluginPhases />
104                <cfset var c = "" />
105                <cfset var f = "" />
106                <cfset var old_c = "" />
107                <cfset var old_p = "" />
108                <cfset var circuits = variables.action.getCircuit().getApplication().circuits />
109                <cfset var needTryOnFuseaction = false />
110               
111                <cfif listLen(variables.attributes.action,".") eq 2>
112                        <!--- action is a circuit.fuseaction pair somewhere --->
113                        <cfset c = listFirst(variables.attributes.action,".") />
114                        <cfset f = listLast(variables.attributes.action,".") />
115                <cfelse>
116                        <cfset c = variables.action.getCircuit().getAlias() />
117                        <cfset f = variables.attributes.action />
118                </cfif>
119                <cfset arguments.writer.rawPrintln('<!--- #variables.verb# action="#variables.attributes.action#" --->') />
120                <cfset old_c = arguments.writer.setCircuit(c) />
121                <cfset old_f = arguments.writer.setFuseaction(f) />
122                <cfif structKeyExists(plugins,"fuseactionException") and
123                                arrayLen(plugins["fuseactionException"]) gt 0>
124                        <cfset needTryOnFuseaction = true />
125                        <cfset arguments.writer.rawPrintln("<cftry>") />
126                </cfif>
127                <cfif structKeyExists(plugins,"preFuseaction")>
128                        <cfset n = arrayLen(plugins["preFuseaction"]) />
129                        <cfloop from="1" to="#n#" index="i">
130                                <cfset plugins["preFuseaction"][i].compile(arguments.writer) />
131                        </cfloop>
132                </cfif>
133                <cfif structKeyExists(variables.attributes,"contentvariable")>
134                        <cfif not variables.attributes.overwrite>
135                                <cfset arguments.writer.println('<cfif not isDefined("#variables.attributes.contentvariable#")>') />
136                        </cfif>
137                        <cfif variables.attributes.append or variables.attributes.prepend>
138                                <cfset arguments.writer.println('<cfparam name="#variables.attributes.contentvariable#" default="">') />
139                        </cfif>
140                        <cfset arguments.writer.println('<cfsavecontent variable="#variables.attributes.contentvariable#">') />
141                        <cfif variables.attributes.append>
142                                <cfset arguments.writer.println('<' & 'cfoutput>###variables.attributes.contentvariable###</' & 'cfoutput>') />
143                        </cfif>
144                </cfif>
145                <!--- TODO: make do/fuseaction appear in verb parent tree --->
146                <cfif listLen(variables.attributes.action,".") eq 2>
147                        <cfif not structKeyExists(circuits,c)>
148                                <cfthrow type="fusebox.undefinedCircuit"
149                                                message="undefined Circuit"
150                                                detail="You specified a Circuit of #c# which is not defined." />
151                        </cfif>
152                        <cfif not structKeyExists(circuits[c].fuseactions,f)>
153                                <cfthrow type="fusebox.undefinedFuseaction"
154                                                message="undefined Fuseaction"
155                                                detail="You specified a Fuseaction of #f# which is not defined in Circuit #c#." />
156                        </cfif>
157                        <!--- if not in the same circuit, check access is not private --->
158                        <cfif c is not variables.action.getCircuit().getAlias()>
159                                <cfif circuits[c].fuseactions[f].getAccess() is "private">
160                                        <cfthrow type="fusebox.invalidAccessModifier"
161                                                        message="invalid access modifier"
162                                                        detail="The fuseaction '#c#.#f#' has an access modifier of private and can only be called from within its own circuit. Use an access modifier of internal or public to make it available outside its immediate circuit.">
163                                </cfif>
164                        </cfif>
165                        <cfset variables.action.getCircuit().getApplication().compile(c,f) />
166                <cfelse>
167                        <!--- action is a fuseaction in this same circuit --->
168                        <cfif not structKeyExists(variables.action.getCircuit().fuseactions,f)>
169                                <cfthrow type="fusebox.undefinedFuseaction"
170                                                message="undefined Fuseaction"
171                                                detail="You specified a Fuseaction of #f# which is not defined in Circuit #c#." />
172                        </cfif>
173                        <cfset variables.action.getCircuit().compile(arguments.writer,f) />
174                </cfif>
175                <cfif structKeyExists(variables.attributes,"contentvariable")>
176                        <cfif variables.attributes.prepend>
177                                <cfset arguments.writer.println('<' & 'cfoutput>###variables.attributes.contentvariable###</' & 'cfoutput>') />
178                        </cfif>
179                        <cfset arguments.writer.println('</cfsavecontent>') />
180                        <cfif not variables.attributes.overwrite>
181                                <cfset arguments.writer.println('</cfif>') />
182                        </cfif>
183                </cfif>
184                <cfif structKeyExists(plugins,"postFuseaction")>
185                        <cfset n = arrayLen(plugins["postFuseaction"]) />
186                        <cfloop from="1" to="#n#" index="i">
187                                <cfset plugins["postFuseaction"][i].compile(arguments.writer) />
188                        </cfloop>
189                </cfif>
190                <cfif needTryOnFuseaction>
191                        <cfset n = arrayLen(plugins["fuseactionException"]) />
192                        <cfloop from="1" to="#n#" index="i">
193                                <cfset plugins["fuseactionException"][i].compile(arguments.writer) />
194                        </cfloop>
195                        <cfset arguments.writer.rawPrintln("</cftry>") />
196                </cfif>
197                <cfset arguments.writer.setFuseaction(old_f) />
198                <cfset arguments.writer.setCircuit(old_c) />
199               
200        </cffunction>
201       
202</cfcomponent>
Note: See TracBrowser for help on using the browser.