Sorcerer's IsleCode QueryParam Scanner / files

     1<!---
     2Copyright 2006-2007 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<cfscript>
    17	if (fb_.verbInfo.executionMode is "start") {
    18		// validate attributes
    19		fb_.app = fb_.verbInfo.action.getCircuit().getApplication();
    20		fb_.nAttrs = 0;
    21		// required - boolean - default true
    22		if (structKeyExists(fb_.verbInfo.attributes,"required")) {
    23			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.required) eq 0) {
    24				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    25							"Attribute has invalid value",
    26							"The attribute 'required' must either be ""true"" or ""false"", for a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    27			}
    28		} else {
    29			fb_.verbInfo.attributes.required = true;
    30		}
    31		fb_.nAttrs = fb_.nAttrs + 1;	// for required - since we default it
    32		// template - string - required
    33		if (not structKeyExists(fb_.verbInfo.attributes,"template")) {
    34			fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    35						"Required attribute is missing",
    36						"The attribute 'template' is required, for a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    37		}
    38		fb_.nAttrs = fb_.nAttrs + 1;	// for template
    39		// contentvariable - string - default ""
    40		if (not structKeyExists(fb_.verbInfo.attributes,"contentvariable")) {
    41			fb_.verbInfo.attributes.contentvariable = "";
    42		}
    43		fb_.nAttrs = fb_.nAttrs + 1;	// for contentvariable - since we default it
    44		// overwrite - boolean - default true
    45		if (structKeyExists(fb_.verbInfo.attributes,"overwrite")) {
    46			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.overwrite) eq 0) {
    47				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    48							"Attribute has invalid value",
    49							"The attribute 'overwrite' must either be ""true"" or ""false"", for a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    50			}
    51		} else {
    52			fb_.verbInfo.attributes.overwrite = true;
    53		}
    54		fb_.nAttrs = fb_.nAttrs + 1;	// for overwrite - since we default it
    55		// append - boolean - default false
    56		if (structKeyExists(fb_.verbInfo.attributes,"append")) {
    57			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.append) eq 0) {
    58				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    59							"Attribute has invalid value",
    60							"The attribute 'append' must either be ""true"" or ""false"", for a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    61			}
    62		} else {
    63			fb_.verbInfo.attributes.append = false;
    64		}
    65		fb_.nAttrs = fb_.nAttrs + 1;	// for append - since we default it
    66		// prepend - boolean - default false
    67		if (structKeyExists(fb_.verbInfo.attributes,"prepend")) {
    68			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.prepend) eq 0) {
    69				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    70							"Attribute has invalid value",
    71							"The attribute 'prepend' must either be ""true"" or ""false"", for a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    72			}
    73		} else {
    74			fb_.verbInfo.attributes.prepend = false;
    75		}
    76		fb_.nAttrs = fb_.nAttrs + 1;	// for prepend - since we default it
    77		// circuit - string - default current circuit alias
    78		// FB5: official support for this undocumented feature of FB4.x
    79		if (structKeyExists(fb_.verbInfo.attributes,"circuit")) {
    80			fb_.nAttrs = fb_.nAttrs + 1;	// we don't default this into the attributes struct
    81			if (structKeyExists(fb_.app.circuits,fb_.verbInfo.attributes.circuit)) {
    82				fb_.targetCircuit = fb_.app.circuits[fb_.verbInfo.attributes.circuit];
    83			} else if (fb_.app.allowImplicitCircuits) {
    84				// FB55: attempt to create an implicit circuit
    85				fb_.app.circuits[fb_.verbInfo.attributes.circuit] = __makeImplicitCircuit();
    86				fb_.targetCircuit = fb_.app.circuits[fb_.verbInfo.attributes.circuit];
    87			} else {
    88				fb_throw("fusebox.undefinedCircuit",
    89							"undefined Circuit",
    90							"The attribute 'circuit' (which was '#fb_.verbInfo.attributes.circuit#') must specify an existing circuit alias, for a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    91			}
    92		} else {
    93			fb_.targetCircuit = fb_.verbInfo.action.getCircuit();
    94		}
    95		// strict mode - check attribute count:
    96		if (fb_.app.strictMode) {
    97			if (structCount(fb_.verbInfo.attributes) neq fb_.nAttrs) {
    98				fb_throw("fusebox.badGrammar.unexpectedAttributes",
    99							"Unexpected attributes",
   100							"Unexpected attributes were found in a 'include' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
   101			}
   102		}
   103				
   104		// auto-append script extension:
   105		fb_.standardExtension = fb_.app.scriptFileDelimiter;
   106		fb_.extension = listLast(fb_.verbInfo.attributes.template,".");
   107		if (listFindNoCase(fb_.app.maskedFileDelimiters,fb_.extension,',') eq 0 and 
   108				listFindNoCase(fb_.app.maskedFileDelimiters,'*',',') eq 0) {
   109			fb_.template = fb_.verbInfo.attributes.template & "." & fb_.standardExtension;
   110		} else {
   111			fb_.template = fb_.verbInfo.attributes.template;
   112		}
   113		if (find('##',fb_.template) gt 0) {
   114			fb_.templateLen = 'len("#fb_.template#")';
   115		} else {
   116			fb_.templateLen = len(fb_.template);
   117		}
   118		
   119		if (fb_.app.debug) {
   120			// trace inclusion of this fuse:
   121			fb_appendLine('<' & 'cfset myFusebox.trace("Runtime","&lt;include template=""#fb_.template#"" circuit=""#fb_.targetCircuit.getAlias()#""/&gt;") >');
   122		}
   123		
   124		// if there are children, assume we need a stack frame:
   125		if (fb_.verbInfo.hasChildren) {
   126			fb_appendLine('<' & 'cfset myFusebox.enterStackFrame() >');
   127			// this is where the child <parameter> verbs will store the variable names:
   128			fb_.verbInfo.parameters = arrayNew(1);
   129		}
   130		
   131	} else {
   132		
   133		// any child <parameter> verbs will have been compiled by now
   134		
   135		// compile <include>
   136		if (fb_.verbInfo.attributes.contentvariable is not "" and not fb_.verbInfo.attributes.overwrite) {
   137			fb_appendLine('<cfif not isDefined("#fb_.verbInfo.attributes.contentvariable#")>');
   138		}
   139		fb_appendLine("<cftry>");
   140		if (fb_.verbInfo.attributes.contentvariable is not "") {
   141			if (fb_.verbInfo.attributes.append) {
   142				fb_appendLine('<cfparam name="#fb_.verbInfo.attributes.contentvariable#" default=""><cfsavecontent variable="#fb_.verbInfo.attributes.contentvariable#"><cfoutput>###fb_.verbInfo.attributes.contentvariable###<cfinclude template="#fb_.verbInfo.action.getCircuit().getApplication().parseRootPath##fb_.targetCircuit.getRelativePath()##fb_.template#"></cfoutput></cfsavecontent>');
   143			} else if (fb_.verbInfo.attributes.prepend) {
   144				fb_appendLine('<cfparam name="#fb_.verbInfo.attributes.contentvariable#" default=""><cfsavecontent variable="#fb_.verbInfo.attributes.contentvariable#"><cfoutput><cfinclude template="#fb_.verbInfo.action.getCircuit().getApplication().parseRootPath##fb_.targetCircuit.getRelativePath()##fb_.template#">###fb_.verbInfo.attributes.contentvariable###</cfoutput></cfsavecontent>');
   145			} else {
   146				fb_appendLine('<cfsavecontent variable="#fb_.verbInfo.attributes.contentvariable#"><cfoutput><cfinclude template="#fb_.verbInfo.action.getCircuit().getApplication().parseRootPath##fb_.targetCircuit.getRelativePath()##fb_.template#"></cfoutput></cfsavecontent>');
   147			}
   148		} else {
   149			fb_appendLine('<cfoutput><cfinclude template="#fb_.verbInfo.action.getCircuit().getApplication().parseRootPath##fb_.targetCircuit.getRelativePath()##fb_.template#"></cfoutput>');
   150		}
   151		fb_appendLine('<cfcatch type="missingInclude"><cfif len(cfcatch.MissingFileName) gte #fb_.templateLen# and right(cfcatch.MissingFileName,#fb_.templateLen#) is "#fb_.template#">');
   152		if (fb_.verbInfo.attributes.required) {
   153			fb_appendLine('<cfthrow type="fusebox.missingFuse" message="missing Fuse" ' &
   154					'detail="You tried to include a fuse #fb_.template# in circuit ' &
   155						'#fb_.targetCircuit.getAlias()# which does not exist (from fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#).">');
   156		} else {
   157			fb_appendLine('<!--- do nothing --->');
   158		}
   159		fb_appendLine('<cfelse><cfrethrow></cfif></cfcatch></cftry>');
   160		if (fb_.verbInfo.attributes.contentvariable is not "" and not fb_.verbInfo.attributes.overwrite) {
   161			fb_appendLine('</cfif>');
   162		}
   163		
   164		// clean up any stack frame:
   165		if (fb_.verbInfo.hasChildren) {
   166			// unwind the stack:
   167			for (fb_.i = arrayLen(fb_.verbInfo.parameters); fb_.i gt 0; fb_.i = fb_.i - 1) {
   168				fb_.name = fb_.verbInfo.parameters[fb_.i];
   169				fb_.scope = listFirst(fb_.name,".");
   170				fb_.qName = listRest(fb_.name,".");
   171				fb_appendLine('<' & 'cfif structKeyExists(myFusebox.stack,"#fb_.name#")><' &
   172							'cfset #fb_.name# = myFusebox.stack["#fb_.name#"] ><' &
   173							'cfelse><' & 
   174							'cfset structDelete(#fb_.scope#,"#fb_.qName#")></' & 'cfif>');
   175			}
   176			fb_appendLine('<' & 'cfset myFusebox.leaveStackFrame() >');
   177		}
   178	}
   179</cfscript>