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	fb_.fbApp = fb_.verbInfo.action.getCircuit().getApplication();
    18	if (fb_.verbInfo.executionMode is "start") {
    19		// validate attributes
    20		// evaluate - boolean default false
    21		if (structKeyExists(fb_.verbInfo.attributes,"evaluate")) {
    22			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.evaluate) eq 0) {
    23				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    24							"Attribute has invalid value",
    25							"The attribute 'evaluate' must either be ""true"" or ""false"", for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    26			}
    27		} else {
    28			fb_.verbInfo.attributes.evaluate = false;
    29		}
    30		// name - string - required
    31		if (not structKeyExists(fb_.verbInfo.attributes,"name") or trim(fb_.verbInfo.attributes.name) is "") {
    32			fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    33						"Required attribute is missing",
    34						"The attribute 'name' is required when 'overwrite' is present, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    35		}
    36		// overwrite - boolean - default true
    37		if (structKeyExists(fb_.verbInfo.attributes,"overwrite")) {
    38			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.overwrite) eq 0) {
    39				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    40							"Attribute has invalid value",
    41							"The attribute 'overwrite' must either be ""true"" or ""false"", for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    42			}
    43		} else {
    44			fb_.verbInfo.attributes.overwrite = true;
    45		}
    46		// value - string - required
    47		if (not structKeyExists(fb_.verbInfo.attributes,"value")) {
    48			fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    49						"Required attribute is missing",
    50						"The attribute 'value' is required, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    51		}
    52		// strict mode - check attribute count and that there are no URL parameters:
    53		if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
    54			if (structCount(fb_.verbInfo.attributes) neq 4) {
    55				fb_throw("fusebox.badGrammar.unexpectedAttributes",
    56							"Unexpected attributes",
    57							"Unexpected attributes were found in a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    58			}
    59			// do not allow URL parameters in the XFA value:
    60			if (find(fb_.fbApp.queryStringSeparator,fb_.verbInfo.attributes.value) neq 0) {
    61				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    62							"Attribute has invalid value",
    63							"The attribute 'value' contains URL parameters, which is not allowed in 'strict' mode, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    64			}
    65		}
    66		
    67		// if there are children, set up a parameter block:
    68		if (fb_.verbInfo.hasChildren) {
    69			// do not allow URL parameters in the XFA value:
    70			if (find(fb_.fbApp.queryStringSeparator,fb_.verbInfo.attributes.value) neq 0) {
    71				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    72							"Attribute has invalid value",
    73							"The attribute 'value' contains URL parameters, which is not allowed when 'parameter' is present, for a 'xfa' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    74			}
    75			// this is where the child <parameter> verbs will store the parameter details:
    76			fb_.verbInfo.parameters = arrayNew(1);
    77		}
    78		
    79	} else {
    80	
    81		// compile <xfa>
    82		name = "xfa." & fb_.verbInfo.attributes.name;
    83		value = fb_.verbInfo.attributes.value;
    84
    85		if (fb_.verbInfo.attributes.evaluate) {
    86			value = "evaluate(" & value & ")";
    87		} else if (listLen(value,".") lt 2) {
    88			// adjust xfa value if it is local to this circuit:
    89			// <xfa name="foo" value="bar" /> becomes
    90			// <xfa name="foo" value="thiscircuit.bar" />
    91			value = fb_.verbInfo.circuit & "." & value;
    92		}
    93		// append any parameters to the URL value:
    94		if (fb_.verbInfo.hasChildren) {
    95			fb_.n = arrayLen(fb_.verbInfo.parameters);
    96			for (fb_.i = 1; fb_.i lte fb_.n; fb_.i = fb_.i + 1) {
    97				value = value & fb_.fbApp.queryStringSeparator & fb_.verbInfo.parameters[fb_.i].name &
    98								fb_.fbApp.queryStringEqual & fb_.verbInfo.parameters[fb_.i].value;
    99			}
   100		}
   101		value = '"' & value & '"';
   102		
   103		if (find("##",name) gt 0) {
   104			name = '"' & name & '"';
   105		}
   106		if (fb_.verbInfo.attributes.overwrite) {
   107			fb_appendLine("<cfset #name# = #value# />");		
   108		} else {
   109			fb_appendLine("<cfif not isDefined(""#name#"")><cfset #name# = #value# /></cfif>");
   110		}
   111	}
   112</cfscript>