root / framework / tags / fusebox51B1 / fuseboxVerb.cfc

Revision 292, 5.4 kB (checked in by scorfield, 2 years ago)

Fixes #169 by changing copyright to TeraTech and adopting Apache Source License 2.0
(awaiting final confirmation from Michael Smith that ASL2.0 is acceptable).

Line 
1<!---
2Copyright 2006 TeraTech, Inc. http://teratech.com/
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15--->
16<cfcomponent output="false" hint="I represent a verb that is implemented as part of a lexicon.">
17       
18        <cffunction name="init" returntype="any" access="public" output="false"
19                                hint="I am the constructor.">
20                <cfargument name="action" type="any" required="true"
21                                        hint="I am the enclosing fuseaction object." />
22                <cfargument name="customVerb" type="string" required="true"
23                                        hint="I am the name of this (custom) verb." />
24                <cfargument name="attributes" type="struct" required="true"
25                                        hint="I am the attributes for this verb." />
26                <cfargument name="children" type="any" required="true"
27                                        hint="I am the XML representation of any children this verb has." />
28               
29                <cfset var ns = listFirst(arguments.customVerb,".:") />
30                <cfset var i = 0 />
31                <cfset var verb = "" />
32                <cfset var factory = arguments.action.getCircuit().getApplication().getFuseactionFactory() />
33               
34                <cfset variables.action = arguments.action />
35                <cfset variables.attributes = arguments.attributes />
36                <!--- we will create our children below --->
37                <cfset variables.verb = listLast(arguments.customVerb,".:") />
38                <cfset variables.children = structNew() />
39               
40                <cfset variables.factory = factory />
41                <cfset variables.nChildren = arrayLen(arguments.children) />
42               
43                <cfloop from="1" to="#variables.nChildren#" index="i">
44                        <cfset verb = arguments.children[i].xmlName />
45                        <cfset variables.children[i] = factory.create(verb,
46                                                variables.action,
47                                                        arguments.children[i].xmlAttributes,
48                                                                arguments.children[i].xmlChildren) />
49                </cfloop>
50
51                <cfset variables.fb41style = listLen(arguments.customVerb,".") eq 2 />
52                <cfif variables.fb41style>
53                        <cfset variables.lexicon = variables.action.getCircuit().getApplication().getLexiconDefinition(ns) />
54                <cfelse>
55                        <cfset variables.lexicon = variables.action.getCircuit().getLexiconDefinition(ns) />
56                </cfif>
57               
58                <cfreturn this />
59               
60        </cffunction>
61       
62        <cffunction name="compile" returntype="void" access="public" output="false"
63                                hint="I compile a custom lexicon verb. I create the thread-safe context and perform the start and end execution, as well as compiling any children.">
64                <cfargument name="writer" type="any" required="false"
65                                        hint="I am the parsed file writer object. I am required but it's faster to specify that I am not required." />
66                <cfargument name="context" type="any" required="false"
67                                        hint="I am the context in which this verb is compiled. I can be omitted if the verb has no enclosing parent." />
68
69                <!---
70                        the following is purely a device to allow nested custom verbs:
71                        we pass the struct reference into the lexicon compiler but then we
72                        fill in the fields here *afterwards* - relies on pass by reference!
73                        because we are recursive, we need to create a new lexicon compiler
74                        on each 'call' of the (static) compiler (i.e., this method)
75                        trust me! -- sean corfield
76                --->
77                <cfset var verbInfo = structNew() />
78                <cfset var compiler = variables.factory.createLexiconCompiler()
79                                .init(arguments.writer,verbInfo,variables) />
80                <cfset var i = 0 />
81
82                <cfset verbInfo.lexicon = variables.lexicon.namespace />
83                <cfset verbInfo.lexiconVerb = variables.verb />
84                <cfset verbInfo.attributes = variables.attributes />
85                <!---
86                        change to FB41 lexicons (but needed for FB5):
87                                circuit - alias of current circuit
88                                fuseaction - name of current fuseaction
89                                action - fuseaction object for more complex usage
90                --->
91                <cfset verbInfo.circuit = variables.action.getCircuit().getAlias() />
92                <cfset verbInfo.fuseaction = variables.action.getName() />
93                <cfset verbInfo.action = variables.action />
94               
95                <cfif variables.fb41style>
96
97                        <!--- FB41: just compile the lexicon once with no executionMode --->
98                        <cfset compiler.compile() />
99
100                <cfelse>
101
102                        <!---
103                                FB5 has new fields in verbInfo:
104                                skipBody - false, can be set to true by start tag to skip compilation of child tags
105                                hasChildren - true if there are nested tags, else false
106                                parent - present if we are nested (the verbInfo of the parent tag)
107                                executionMode - start|inactive|end, just like custom tags
108                        --->
109                        <cfset verbInfo.skipBody = false />
110                        <cfset verbInfo.hasChildren = variables.nChildren neq 0 />
111
112                        <cfif structKeyExists(arguments,"context")>
113                                <cfset verbInfo.parent = arguments.context />
114                        </cfif>
115
116                        <cfset verbInfo.executionMode = "start" />
117                        <cfset compiler.compile() />
118
119                        <cfif structKeyExists(verbInfo,"skipBody") and isBoolean(verbInfo.skipBody) and verbInfo.skipBody>
120                                <!--- the verb decided not to compile its children --->
121                        <cfelse>
122                                <cfif variables.nChildren gt 0>
123                                        <cfset verbInfo.executionMode = "inactive" />
124                                        <cfloop from="1" to="#variables.nChildren#" index="i">
125                                                <cfset variables.children[i].compile(arguments.writer,verbInfo) />
126                                        </cfloop>               
127                                </cfif>
128                        </cfif>
129
130                        <cfset verbInfo.executionMode = "end" />
131                        <cfset compiler.compile() />
132
133                </cfif>
134               
135                <cfset variables.factory.freeLexiconCompiler(compiler) />
136
137        </cffunction>
138       
139</cfcomponent>
Note: See TracBrowser for help on using the browser.