root / website / trunk / fusebox4.parser.cfmx.cfm

Revision 217, 28.1 kB (checked in by scorfield, 3 years ago)

Initial import of partial fusebox.org site just to kick off the repository.

Line 
1<cfsilent>
2<!---
3Fusebox Software License
4Version 1.0
5
6Copyright (c) 2003, 2004, 2005 The Fusebox Corporation. All rights reserved.
7
8Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9
101. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
13
143. The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
15
16"This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)."
17
18Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear.
19
204. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products derived from this software without prior written (non-electronic) permission. For written permission, please contact fusebox@fusebox.org.
21
225. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in their name, without prior written (non-electronic) permission of the Fusebox Corporation. For written permission, please contact fusebox@fusebox.org.
23
24If one or more of the above conditions are violated, then this license is immediately revoked and can be re-instated only upon prior written authorization of the Fusebox Corporation.
25
26THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28-------------------------------------------------------------------------------
29
30This software consists of voluntary contributions made by many individuals on behalf of the Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>.
31
32--->
33
34<!--- which version of the parser is this? --->
35<cfset myFusebox.version.parser = "4.1.0" />
36
37<cfif myFusebox.version.runtime NEQ myFusebox.version.parser>
38        <cfthrow type="fusebox.versionMismatchException"
39                message="The parser is not the same version as the runtime" />
40</cfif>
41
42<cffunction name="fb_appendLine" output="false" returntype="void">
43        <cfargument name="lineContent" type="string" required="true" />
44        <cfset fb_appendIndent() />
45        <cfset fb_appendSegment(lineContent) />
46        <cfset fb_appendNewline() />
47</cffunction>
48
49<cffunction name="fb_appendIndent" output="false" returntype="void">
50        <cfset fb_appendSegment(repeatString(fb_.indentBlock, min(fb_.maxIndentLevel, fb_.indentLevel))) />
51</cffunction>
52
53<cffunction name="fb_appendSegment" output="false" returntype="void">
54        <cfargument name="segmentContent" type="string" required="true" />
55        <cfset fb_.parsedFile = fb_.parsedFile & segmentContent />
56</cffunction>
57
58<cffunction name="fb_appendNewline" output="false" returntype="void">
59        <cfset fb_appendSegment(fb_.CRLF) />
60</cffunction>
61
62<cffunction name="fb_increaseIndent" output="false" returntype="void">
63        <cfset fb_.indentLevel = fb_.indentLevel + 1 />
64</cffunction>
65
66<cffunction name="fb_decreaseIndent" output="false" returntype="void">
67        <cfset fb_.indentLevel = max(fb_.indentLevel - 1, 0) />
68</cffunction>
69
70<cffunction name="fb_throw" output="false" returntype="void">
71        <cfargument name="type" type="string" required="true" />
72        <cfargument name="message" type="string" required="false" default="" />
73        <cfargument name="detail" type="string" required="false" default="" />
74        <cfif left(type, len("fusebox.badGrammar")) NEQ "fusebox.badGrammar" OR NOT application.fusebox.ignoreBadGrammar>
75                <cfthrow type="#type#" message="#message#" detail="#detail#" />
76        <cfelse>
77                <cfthrow type="fusebox.continueException" />
78        </cfif>
79</cffunction>
80
81<cfscript>
82        // prepare to create the fuseaction file
83        fb_.parsedfile = "";
84        fb_.CRLF = chr(10);     
85       
86        // this variable tracks the current level of indentation
87        fb_.indentLevel = 0;
88        fb_.indentBlock = chr(9);
89        // we'll just assume that no one is going to look at a parse file with
90        // more than 1000 levels of indentation.
91        fb_.maxIndentLevel = iif(application.fusebox.parseWithIndentation, 1000, 0);
92       
93        // cut down on white space a bit
94        fb_appendLine('<cfsetting enablecfoutputonly="Yes">');
95       
96        // set the character encoding for this file
97        fb_appendLine('<cfprocessingdirective pageencoding="' & application.fusebox.characterEncoding & '">');
98       
99        // if any plugins were defined for the processError phase then insert an opening tag for <cftry> here
100        if (arrayLen(application.fusebox.pluginphases['processError']) GT 0) {
101                fb_appendLine("<cftry>");
102        }
103</cfscript>
104
105<!--- now parse the Fusebox XML grammar --->
106<cfloop from="1" to="#arrayLen(fb_.fuseQ)#" index="fb_.i">
107<cftry><!--- the first part of the hack to let us have a CFCONTINUE tag --->
108        <cfscript>
109                if (listLen(fb_.fuseQ[fb_.i].xmlName, '.') GT 1) {
110                        fb_.lexicon = listFirst(fb_.fuseQ[fb_.i].xmlName, '.');
111                        fb_.lexiconVerb = listRest(fb_.fuseQ[fb_.i].xmlName, '.');
112                } else {
113                        fb_.lexiconVerb = fb_.fuseQ[fb_.i].xmlName;
114                        fb_.lexicon = 'fusebox';
115                }
116               
117                if (application.fusebox.parseWithComments) {
118                        fb_.parsedComment = '';
119                        fb_.parsedComment = fb_.parsedComment & '#fb_.fuseQ[fb_.i].circuit#.#fb_.fuseQ[fb_.i].fuseaction#: ';
120                        fb_.parsedComment = fb_.parsedComment & '<#lcase(fb_.lexicon)#:#lcase(fb_.lexiconVerb)#';
121                        for (fb_.attr in fb_.fuseQ[fb_.i].xmlAttributes) {
122                                if (fb_.attr NEQ "circuit")
123                                        fb_.parsedComment = fb_.parsedComment & ' #fb_.attr#="#fb_.fuseQ[fb_.i].xmlAttributes[fb_.attr]#"';
124                                }
125                        fb_.parsedComment = fb_.parsedComment & '>';
126                        fb_appendLine(fb_.COMMENT_CF_BEGIN & ljustify(fb_.parsedComment, 75) & fb_.COMMENT_CF_END);
127                }
128        </cfscript>
129       
130        <cfswitch expression="#fb_.fuseQ[fb_.i].xmlName#">
131
132                <cfcase value="set,xfa">
133                <cfscript>
134                        // throw an error if we have an overwrite attribute, but no name attribute
135                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "name")) {
136                                fb_throw("fusebox.badGrammar.invalidAttributeSet",
137                                        "If you specify the OVERWRITE attribute to a SET or XFA verb, you must also specify the NAME attribute",
138                                        "The error occurred in the #fb_.fuseQ[fb_.i].circuit#.#fb_.fuseQ[fb_.i].fuseaction# fuseaction"
139                                );
140                        }
141                        // bit of massaging if this is the <xfa> verb
142                        if (fb_.fuseQ[fb_.i].xmlName EQ "xfa") {
143                                // throw an error if we don't have a name
144                                if ( NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "name") OR NOT Len( fb_.fuseQ[fb_.i].xmlAttributes.name) ) {
145                                        fb_throw("fusebox.badGrammar.requiredAttributeMissing",
146                                                "The XFA verb requires a NAME attribute",
147                                                "The error occurred in the #fb_.fuseQ[fb_.i].circuit#.#fb_.fuseQ[fb_.i].fuseaction# fuseaction"
148                                        );
149                                }
150                                //prepend "xfa." to the value of the "name" attribute
151                                fb_.fuseQ[fb_.i].xmlAttributes.name = "xfa." & fb_.fuseQ[fb_.i].xmlAttributes.name;
152                                //assume no circuit specified means the current circuit
153                                if (ListLen(fb_.fuseQ[fb_.i].xmlAttributes.value, '.') LTE 1) {
154                                        fb_.fuseQ[fb_.i].xmlAttributes.value = fb_.fuseQ[fb_.i].circuit & '.' & fb_.fuseQ[fb_.i].xmlAttributes.value;
155                                }
156                        }
157                        // if the attribute 'overwrite' is FALSE then treat this like a CFPARAM
158                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
159                                fb_appendLine('<cfif NOT IsDefined("' & fb_.fuseQ[fb_.i].xmlAttributes.name & '")>');
160                                fb_increaseIndent();
161                        }
162                        fb_appendIndent();
163                        // if the 'name' attribute has any pound ( that is, chr(35) ) signs in it, we'll need double quotes to evaluate the dynamic variable name
164                        fb_appendSegment('<cfset ');
165                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "name") AND Len( fb_.fuseQ[fb_.i].xmlAttributes.name)) {
166                                if ( FindNoCase( chr(35) , fb_.fuseQ[fb_.i].xmlAttributes.name ) ) {
167                                        fb_appendSegment('"#fb_.fuseQ[fb_.i].xmlAttributes.name#"');
168                                }
169                                else {
170                                        fb_appendSegment('#fb_.fuseQ[fb_.i].xmlAttributes.name#');
171                                }
172                                fb_appendSegment(' = ');
173                        }
174                        // if the attributes 'evaluate' is TRUE the use the evaluate function
175                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "evaluate") AND fb_.fuseQ[fb_.i].xmlAttributes.evaluate) {
176                                fb_appendSegment('Evaluate("' &  fb_.fuseQ[fb_.i].xmlAttributes.value & '")>');
177                        }
178                        else {
179                                fb_appendSegment('"' &  fb_.fuseQ[fb_.i].xmlAttributes.value & '">');
180                        }
181                        fb_appendNewline();
182                        // if the attribute 'overwrite' is FALSE then treat this like a CFPARAM
183                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
184                                fb_decreaseIndent();
185                                fb_appendLine('</cfif>');
186                        }
187                </cfscript>
188                </cfcase>
189
190                <cfcase value="invoke">
191                <cfscript>
192                        // if returning a value and the attribute 'overwrite' is FALSE then treat this like a CFPARAM
193                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "returnVariable") AND LEN(fb_.fuseQ[fb_.i].xmlAttributes.returnVariable) AND StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
194                                fb_appendLine('<cfif NOT IsDefined("' & fb_.fuseQ[fb_.i].xmlAttributes.returnVariable & '")>');
195                                fb_increaseIndent();
196                        }
197                        // if the 'returnVariable' attribute has any pound ( that is, chr(35) )signs in it, we'll need double quotes to evaluate the dynamic variable name
198                        fb_appendIndent();
199                        fb_appendSegment('<cfset ');
200                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "returnVariable") AND LEN(fb_.fuseQ[fb_.i].xmlAttributes.returnVariable) ) {
201                                if ( FindNoCase( chr(35) , fb_.fuseQ[fb_.i].xmlAttributes.returnVariable ) ) {
202                                        fb_appendSegment('"#fb_.fuseQ[fb_.i].xmlAttributes.returnVariable#"');
203                                }
204                                else {
205                                        fb_appendSegment('#fb_.fuseQ[fb_.i].xmlAttributes.returnVariable#');
206                                }
207                                fb_appendSegment(' = ');
208                        }   
209                       
210                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "object")) {
211                                fb_appendSegment(fb_.fuseQ[fb_.i].xmlAttributes.object & '.' & fb_.fuseQ[fb_.i].xmlAttributes.methodcall & ' />');
212                        }
213                        else if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "class")) {
214                                fb_appendSegment("createObject('" & application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].type & "', '" & application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].classpath  & "')");
215                                fb_appendSegment("." & fb_.fuseQ[fb_.i].xmlAttributes.methodcall & ' />');
216                        }
217                        else if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "webservice")) {
218                                fb_appendSegment(fb_.fuseQ[fb_.i].xmlAttributes.webservice & '.' & fb_.fuseQ[fb_.i].xmlAttributes.methodcall & ' />');
219                        }
220                        else {
221                                fb_throw("fusebox.badGrammar.noInvokeeException",
222                                        "Bad Grammar verb in circuit file",
223                                        "A bad grammar construct was encountered in the circuit '#fb_.fuseQ[fb_.i].circuit#' caused by not providing a object, class, or webservice attribute to the INVOKE verb."
224                                );
225                        }
226                        fb_appendNewline();
227                        // if returning a value and the attribute 'overwrite' is FALSE then treat this like a CFPARAM
228                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "returnVariable") AND StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
229                                fb_decreaseIndent();
230                                fb_appendLine('</cfif>');
231                        }
232                </cfscript>
233                </cfcase>               
234               
235                <cfcase value="instantiate">
236                <cfscript>
237                        // give empty value for arguments if not specified
238                        if (NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "arguments")) {
239                                fb_.fuseQ[fb_.i].xmlAttributes.arguments = "";
240                        }
241                        // if returning a value and the attribute 'overwrite' is FALSE then treat this like a CFPARAM
242                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
243                                fb_appendIndent();
244                                fb_appendSegment('<cfif NOT IsDefined("' & fb_.fuseQ[fb_.i].xmlAttributes.object & '")>');
245                                fb_increaseIndent();
246                        }
247                        // if the 'object' attribute has any pound ( that is, chr(35) )signs in it, we'll need double quotes to evaluate the dynamic variable name
248                        fb_appendIndent();
249                        fb_appendSegment('<cfset ');
250                        if ( FindNoCase( chr(35) , fb_.fuseQ[fb_.i].xmlAttributes.object ) ) {
251                                fb_appendSegment('"#fb_.fuseQ[fb_.i].xmlAttributes.object#"');
252                        }
253                        else {
254                                fb_appendSegment('#fb_.fuseQ[fb_.i].xmlAttributes.object#');
255                        }
256                        fb_appendSegment(' = ');
257                       
258                        if ( StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes,"class") AND Len(fb_.fuseQ[fb_.i].xmlAttributes.class) ) {
259                                //creating a reference to a class
260                                fb_appendSegment("createObject('" & application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].type & "', '" & application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].classpath & "') />");
261                                if (application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].type EQ "component" AND StructKeyExists(application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class],"constructor") AND Len(application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].constructor) ) {
262                                        // if CFML, call a constructor if specified (in Java constructor is called automatically)
263                                        fb_appendSegment('<cfset ' & fb_.fuseQ[fb_.i].xmlAttributes.object & '.' & application.fusebox.classes[fb_.fuseQ[fb_.i].xmlAttributes.class].constructor & '(' & fb_.fuseQ[fb_.i].xmlAttributes.arguments & ')');
264                                }
265                        } else if ( StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "webservice") AND Len(fb_.fuseQ[fb_.i].xmlAttributes.webservice) ) {
266                                // else creating a webservice
267                                fb_appendSegment("createObject('webservice', '" & fb_.fuseQ[fb_.i].xmlAttributes.webservice & "')");
268                        }
269                       
270                        fb_appendSegment(' />');
271                        // if returning a value and the attribute 'overwrite' is FALSE then treat this like a CFPARAM
272                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite") AND NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
273                                fb_decreaseIndent();
274                                fb_appendLine('</cfif>');
275                        }
276                </cfscript>
277                </cfcase>
278
279                <cfcase value="include">
280                <cfscript>
281                        fb_.template = fb_.fuseQ[fb_.i].xmlAttributes.template;
282                        fb_.templateDelimiter = ListLast(fb_.template, '.');
283                        if (NOT ( ListFindNoCase(application.fusebox.maskedFileDelimiters, fb_.templateDelimiter, ',') OR ListFindNoCase(application.fusebox.maskedFileDelimiters, '*', ',') )) {
284                                fb_.template = fb_.template & '.' & application.fusebox.scriptFileDelimiter;
285                        }
286                        if ( NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "required")) {
287                                StructInsert(fb_.fuseQ[fb_.i].xmlAttributes, "required", "true");
288                        }
289                        if ( NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "contentvariable")) {
290                                fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"] = "";
291                        }
292                        if ( (NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "overwrite")) OR fb_.fuseQ[fb_.i].xmlAttributes.overwrite NEQ "false" ) {
293                                fb_.fuseQ[fb_.i].xmlAttributes["overwrite"] = "true";
294                        }
295                        if ( (NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "append")) OR fb_.fuseQ[fb_.i].xmlAttributes.overwrite NEQ "true" ) {
296                                fb_.fuseQ[fb_.i].xmlAttributes["append"] = "false";
297                        }
298                        if ( (NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "prepend")) OR fb_.fuseQ[fb_.i].xmlAttributes.overwrite NEQ "true" ) {
299                                fb_.fuseQ[fb_.i].xmlAttributes["prepend"] = "false";
300                        }
301                                               
302                        if ( len(fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]) AND fb_.fuseQ[fb_.i].xmlAttributes["overwrite"] IS FALSE ) {
303                                fb_appendLine('<cfif NOT IsDefined("#fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]#")>');
304                                fb_increaseIndent();
305                        }
306
307                fb_appendLine('<cftry>');
308                        fb_increaseIndent();
309                       
310                                if ( len(fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]) ) {
311                                        if ( fb_.fuseQ[fb_.i].xmlAttributes["append"] IS TRUE OR fb_.fuseQ[fb_.i].xmlAttributes["prepend"] IS TRUE ) {
312                                                fb_appendLine('<cfparam name="#fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]#" default="">');
313                                        }
314                                        fb_appendIndent();
315                                        fb_appendSegment('<cfsavecontent variable="#fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]#">');
316                                        fb_increaseIndent();
317                                        if ( fb_.fuseQ[fb_.i].xmlAttributes["append"] IS TRUE ) {
318                                                fb_appendSegment('<cfoutput>###fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]###</cfoutput>');
319                                        }
320                                } else {
321                                        fb_appendIndent();
322                                }
323                                fb_appendSegment('<cfoutput><cfinclude template="' & REreplace(application.fusebox.parseRootPath & application.fusebox.circuits[fb_.fuseQ[fb_.i].xmlAttributes.circuit].path & fb_.template, "\\/", application.fusebox.osdelimiter, "all") & '"></cfoutput>');
324                               
325                                if ( len(fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]) ) {
326                                        if ( fb_.fuseQ[fb_.i].xmlAttributes["prepend"] IS TRUE ) {
327                                                fb_appendSegment('<cfoutput>###fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]###</cfoutput>');
328                                        }
329                                        fb_decreaseIndent();
330                                        fb_appendSegment('</cfsavecontent>');
331                                        if ( fb_.fuseQ[fb_.i].xmlAttributes["prepend"] IS TRUE ) {
332                                                fb_appendLine('<cfparam name="#fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]#" default="">');
333                                        }
334
335                                }
336                                fb_appendNewline();
337                 
338                       
339                                fb_appendLine('<cfcatch type="missingInclude">');
340                                fb_increaseIndent();
341                                        fb_appendLine('<cfif Right(cfcatch.missingFilename, len("#application.fusebox.circuits[fb_.fuseQ[fb_.i].xmlAttributes.circuit].path##fb_.template#") ) EQ "#application.fusebox.circuits[fb_.fuseQ[fb_.i].xmlAttributes.circuit].path##fb_.template#">');
342                                        fb_increaseIndent();
343                                                if ( fb_.fuseQ[fb_.i].xmlAttributes['required'] IS TRUE) {
344                                                        fb_appendLine('<cfthrow type="fusebox.missingFuse" message="missing Fuse" detail="You tried to include a fuse #fb_.fuseQ[fb_.i].xmlAttributes.template# in circuit #fb_.fuseQ[fb_.i].xmlAttributes.circuit# which does not exist.">');
345                                                } else {
346                                                        fb_appendLine(fb_.COMMENT_CF_BEGIN & 'do nothing' & fb_.COMMENT_CF_END);
347                                                }
348                                        fb_decreaseIndent();
349                                        fb_appendLine('<cfelse>');
350                                        fb_increaseIndent();
351                                                fb_appendLine('<cfrethrow>');
352                                        fb_decreaseIndent();
353                                        fb_appendLine('</cfif>');
354                                fb_decreaseIndent();
355                                fb_appendLine('</cfcatch>');
356                        fb_decreaseIndent();
357                        fb_appendLine('</cftry>');
358                       
359                        if ( len(fb_.fuseQ[fb_.i].xmlAttributes["contentvariable"]) AND fb_.fuseQ[fb_.i].xmlAttributes["overwrite"] IS FALSE ) {
360                                fb_decreaseIndent();
361                                fb_appendLine('</cfif>');
362                        }
363                </cfscript>
364                </cfcase>
365
366                <cfcase value="plugin">
367                <cfscript>
368                        fb_.template = fb_.fuseQ[fb_.i].plugin.template;
369                        fb_.templateDelimiter = ListLast(fb_.template, '.');
370                        if (NOT ( ListFindNoCase(application.fusebox.maskedFileDelimiters, fb_.templateDelimiter, ',')
371                                OR ListFindNoCase(application.fusebox.maskedFileDelimiters, '*', ',') )) {
372                                        fb_.template = fb_.template & '.' & application.fusebox.scriptFileDelimiter;
373                        }
374                        fb_appendLine('<cfset myFusebox.thisPlugin  = "' & fb_.fuseQ[fb_.i].plugin.name & '">');
375                        fb_appendLine('<cfset myFusebox.thisPhase  = "' & fb_.fuseQ[fb_.i].phase & '">');
376                        fb_appendLine('<cfoutput><cfinclude template="' & application.fusebox.parseRootPath & REreplace(fb_.fuseQ[fb_.i].plugin.path, "\\/", application.fusebox.osdelimiter, "all") & REreplace(fb_.template, "\\/", application.fusebox.osdelimiter, "all") & '"></cfoutput>');
377                </cfscript>
378                </cfcase>
379               
380                <cfcase value="errorHandler,exceptionHandler">
381                        <cfset fb_.handlerfile = application.fusebox.approotdirectory & REreplace(fb_.fuseQ[fb_.i].plugin.path, "\\/", application.fusebox.osdelimiter, "all") & REreplace(fb_.fuseQ[fb_.i].plugin.template, "\\/", application.fusebox.osdelimiter, "all")>
382                        <cffile action="read" file="#fb_.handlerfile#" variable="fb_.handlerfile" charset="#application.fusebox.characterEncoding#">
383                        <cfset fb_.handlerfile = repeatString(fb_.indentBlock, min(fb_.maxIndentLevel, fb_.indentLevel)) & REreplace(fb_.handlerfile, "([#chr(10)##chr(13)#])", "\1" & repeatString(fb_.indentBlock, min(fb_.maxIndentLevel, fb_.indentLevel)), "all") />
384                        <cfset fb_appendNewline() />
385                        <cfset fb_appendSegment(fb_.handlerfile) />
386                        <cfset fb_appendNewline() />
387                </cfcase>
388
389                <cfcase value="beginExceptionHandler">
390                        <cfset fb_appendLine("<cftry>") />
391                        <cfset fb_increaseIndent() />
392                </cfcase>
393
394                <cfcase value="endExceptionHandler">
395                        <cfset fb_decreaseIndent() />
396                        <cfset fb_appendLine("</cftry>") />
397                </cfcase>
398
399                <cfcase value="conditional">
400                <cfscript>
401                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "mode")) {
402                                if (fb_.fuseQ[fb_.i].xmlAttributes['mode'] EQ "begin") {
403                                        fb_appendLine("<cfif " & fb_.fuseQ[fb_.i].xmlAttributes['condition'] & ">");
404                                        fb_increaseIndent();
405                                }
406                                else if (fb_.fuseQ[fb_.i].xmlAttributes['mode'] EQ "else") {
407                                        fb_decreaseIndent();
408                                        fb_appendLine("<cfelse>");
409                                        fb_increaseIndent();
410                                }
411                                else if (fb_.fuseQ[fb_.i].xmlAttributes['mode'] EQ "end") {
412                                        fb_decreaseIndent();
413                                        fb_appendLine("</cfif>");
414                                }
415                        }
416                </cfscript>
417                </cfcase>
418
419                <cfcase value="loop">
420                <cfscript>
421                        // mode=begin
422                        if (fb_.fuseQ[fb_.i].xmlAttributes['mode'] EQ "begin") {
423                                if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, 'condition')) {
424                                        fb_appendLine('<cfloop condition="' & fb_.fuseQ[fb_.i].xmlAttributes['condition'] & '">');
425                                }
426                                else if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, 'query')) {
427                                        fb_appendLine('<cfloop query="' & fb_.fuseQ[fb_.i].xmlAttributes['query'] & '">');
428                                }
429                                else if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, 'from')
430                                        AND StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, 'to')
431                                        AND StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, 'index')) {
432                                                if (NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, 'step')) {
433                                                        fb_.fuseQ[fb_.i].xmlAttributes.step = 1;
434                                                }
435                                                fb_appendLine('<cfloop from="' & fb_.fuseQ[fb_.i].xmlAttributes['from'] & '"'
436                                                        & ' to="' & fb_.fuseQ[fb_.i].xmlAttributes['to'] & '"'
437                                                        & ' index="' & fb_.fuseQ[fb_.i].xmlAttributes['index'] & '"'
438                                                        & ' step="' & fb_.fuseQ[fb_.i].xmlAttributes['step'] & '"'
439                                                        & '>');
440                                }
441                                fb_increaseIndent();
442                        } else { // mode=end
443                                fb_decreaseIndent();
444                                fb_appendline("</cfloop>");
445                        }
446                </cfscript>
447                </cfcase>
448               
449                <cfcase value="contentvariable">
450                <cfscript>
451                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "mode")) {
452                                if (fb_.fuseQ[fb_.i].xmlAttributes['mode'] EQ "begin") {
453                                        if (fb_.fuseQ[fb_.i].xmlAttributes.overwrite EQ "false") {
454                                                fb_appendLine('<cfif NOT isDefined("' & fb_.fuseQ[fb_.i].xmlAttributes['contentvariable'] & '")>');
455                                                fb_increaseIndent();
456                                        }
457                                        fb_appendLine('<cfsavecontent variable="' & fb_.fuseQ[fb_.i].xmlAttributes['contentvariable'] & '">');
458                                        fb_increaseIndent();
459                                        if (fb_.fuseQ[fb_.i].xmlAttributes.append EQ "true") {
460                                                fb_appendLine('<cfparam name="'& fb_.fuseQ[fb_.i].xmlAttributes['contentvariable'] & '" default="">');
461                                                fb_appendLine('<cfoutput>##' & fb_.fuseQ[fb_.i].xmlAttributes['contentvariable'] & '##</cfoutput>');
462                                        }
463                                }
464                                else { // mode=end
465                                        if (fb_.fuseQ[fb_.i].xmlAttributes.prepend EQ "true") {
466                                                fb_appendLine('<cfparam name="'& fb_.fuseQ[fb_.i].xmlAttributes['contentvariable'] & '" default="">');
467                                                fb_appendLine('<cfoutput>##' & fb_.fuseQ[fb_.i].xmlAttributes['contentvariable'] & '##</cfoutput>');
468                                        }
469                                        fb_decreaseIndent();   
470                                        fb_appendLine('</cfsavecontent>');
471                                        if (NOT fb_.fuseQ[fb_.i].xmlAttributes.overwrite) {
472                                                fb_decreaseIndent();
473                                                fb_appendLine('</cfif>');
474                                        }
475                                }
476                        }
477                </cfscript>
478                </cfcase>
479
480                <cfcase value="relocate">
481                <cfscript>
482                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "addtoken") AND fb_.fuseQ[fb_.i].xmlAttributes['addtoken'] IS TRUE) {
483                                fb_.addtoken = 'addtoken="yes"';
484                        }
485                        else {
486                                fb_.addtoken = 'addtoken="no"';
487                        }
488                        if (StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "type") AND fb_.fuseQ[fb_.i].xmlAttributes['type'] EQ "server") {
489                                fb_appendLine('<cfset getPageContext().forward("' & fb_.fuseQ[fb_.i].xmlAttributes.url & '")>');
490                        }
491                        else {
492                                fb_appendLine('<cflocation url="' & fb_.fuseQ[fb_.i].xmlAttributes.url & '" ' & fb_.addtoken & '>');
493                        }
494                        // add a cfabort after each relocate (server or client)
495                        fb_appendLine('<cfabort>');
496                </cfscript>
497                </cfcase>
498
499                <cfcase value="assert">
500                <cfscript>
501                        if ( NOT StructKeyExists(fb_.fuseQ[fb_.i].xmlAttributes, "message"))   {
502                                StructInsert(fb_.fuseQ[fb_.i].xmlAttributes, 'message', 'The assertion failed.');
503                        }
504                        fb_appendLine(fb_.COMMENT_CF_BEGIN & '<assertion>');
505                        fb_increaseIndent();
506                       
507                                fb_appendLine('<cfif NOT (' & fb_.fuseQ[fb_.i].xmlAttributes.expression & ')>');
508                                /* John QvT's former code
509                                fb_.indentLevel = fb_.indentLevel + 1;
510                                fb_.parsedfile = fb_.parsedfile & fb_.CRLF & repeatString(fb_.indentBlock, min(fb_.maxIndentLevel, fb_.indentLevel)) & '<!-'&'-- assertion is TRUE; do nothing --'&'->';
511                                fb_.indentLevel = fb_.indentLevel - 1;
512                                fb_.parsedfile = fb_.parsedfile & fb_.CRLF & repeatString(fb_.indentBlock, min(fb_.maxIndentLevel, fb_.indentLevel)) & '<cfelse>';
513                                fb_.indentLevel = fb_.indentLevel + 1;
514                                */
515                                fb_appendLine('<cfthrow type="fusebox.failedAssertion" message="#fb_.fuseQ[fb_.i].xmlAttributes.message#" detail="The assertion, #fb_.fuseQ[fb_.i].xmlAttributes.expression#, failed at run-time in fuseaction #fb_.fuseQ[fb_.i].circuit#.#fb_.fuseQ[fb_.i].fuseaction#.">');
516                                /* John QvT's former code
517                                fb_.indentLevel = fb_.indentLevel - 1;
518                                */
519                                fb_appendLine('</cfif>');
520                               
521                        fb_decreaseIndent();
522                        fb_appendLine('</assertion>' & fb_.COMMENT_CF_END);
523                        fb_.hasAssertions = TRUE;
524                </cfscript>
525                </cfcase>
526
527                <cfdefaultcase>
528                        <cfif (application.fusebox.allowLexicon AND ListLen(fb_.fuseQ[fb_.i].xmlName, '.') GT 1)>
529                                <cftry>
530                                        <cfset fb_.lexicon = listFirst(fb_.fuseQ[fb_.i].xmlName, '.')>
531                                        <cfset fb_.lexiconVerb = listRest(fb_.fuseQ[fb_.i].xmlName, '.')>
532                                       
533                                        <cfset fb_.verbInfo = structNew() />
534                                        <cfset fb_.verbInfo.lexicon = fb_.lexicon />
535                                        <cfset fb_.verbInfo.verb = fb_.lexiconVerb />
536                                        <cfset fb_.verbInfo.attributes = fb_.fuseQ[fb_.i].xmlAttributes />
537                                        <cfif StructKeyExists(application.fusebox.lexicons, fb_.lexicon)>
538                                                <cfinclude template="#application.fusebox.CoreToAppRootPath##application.fusebox.lexiconPath##application.fusebox.lexicons[fb_.lexicon].path##fb_.lexiconVerb#.#application.fusebox.scriptFileDelimiter#">
539                                        <cfelse>
540                                                <cfset fb_throw("fusebox.badGrammar.unregisteredLexiconException",
541                                                        "Bad Grammar verb in circuit file",
542                                                        "The '#fb_.lexicon#' lexicon is not registered in fusebox.xml, but is used in the '#fb_.fuseQ[fb_.i].circuit#' circuit."
543                                                ) />
544                                        </cfif>
545                                        <cfcatch type="missingInclude">
546                                                <cfset fb_throw("fusebox.badGrammar.missingImplementationException",
547                                                        "Bad Grammar verb in circuit file",
548                                                        "The implementation file for the '#fb_.lexiconVerb#' verb from the '#fb_.lexicon#' custom lexicon could not be found.  It is used in the '#fb_.fuseQ[fb_.i].circuit#' circuit."
549                                                ) />
550                                        </cfcatch>
551                                </cftry>
552                        <cfelse>
553                                <cfscript>
554                                        if (application.fusebox.parseWithComments) {
555                                                fb_appendLine(fb_.COMMENT_CF_BEGIN & 'generated by fuseQ[#fb_.i#]  UNKNOWN VERB: #fb_.fuseQ[fb_.i].xmlName#' & fb_.COMMENT_CF_END);
556                                        }
557                                </cfscript>
558                                <cfset fb_throw("fusebox.badGrammar.unknownVerbException",
559                                        "Bad Grammar verb in circuit file",
560                                        "A bad grammar construct was encountered in the circuit '#fb_.fuseQ[fb_.i].circuit#' caused by the unknown or misspelled Fusebox grammar verb '#fb_.fuseQ[fb_.i].xmlName#'."
561                                ) />
562                        </cfif>
563                </cfdefaultcase>
564
565        </cfswitch>
566       
567        <!--- the rest of the CFCONTINUE hack --->
568        <cfcatch type="fusebox.continueException">
569                <!--- just let 'er continue --->
570        </cfcatch>
571</cftry>
572</cfloop>
573
574<cfscript>
575        // if any plugins were defined for the processError phase then insert a closing tag for </cftry> here
576        if (arrayLen(application.fusebox.pluginphases['processError']) GT 0) {
577                fb_decreaseIndent();
578                fb_appendLine("</cftry>");
579        }
580        fb_appendLine('<cfsetting enablecfoutputonly="No">');
581</cfscript>
582
583<!--- finished --->
584</cfsilent>
Note: See TracBrowser for help on using the browser.