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		// name - string - optional
    20		// value - string - required
    21		if (not structKeyExists(fb_.verbInfo.attributes,"value")) {
    22			fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    23						"Required attribute is missing",
    24						"The attribute 'value' is required, for a 'argument' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    25		}
    26		// must be nested inside an <invoke> that uses the method attribute
    27		// or an <instantiate> that does not use the arguments attribute
    28		fb_.validParent = false;
    29		if (structKeyExists(fb_.verbInfo,"parent")) {
    30			if (fb_.verbInfo.parent.lexiconVerb is "invoke" and structKeyExists(fb_.verbInfo.parent.attributes,"method")) {
    31				fb_.validParent = true;
    32			} else if (fb_.verbInfo.parent.lexiconVerb is "instantiate" and not structKeyExists(fb_.verbInfo.parent.attributes,"arguments")) {
    33				fb_.validParent = true;
    34			}
    35		}
    36		if (not fb_.validParent) {
    37			fb_throw("fusebox.badGrammar.argumentInvalidParent",
    38						"Verb 'argument' has invalid parent verb",
    39						"Found 'argument' verb with no valid parent verb (either 'invoke' with 'method' attribute or 'instantiate' without 'arguments' attribute) in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    40		}
    41		// strict mode - check attribute count:
    42		if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
    43			if (structKeyExists(fb_.verbInfo.attributes,"name")) {
    44				if (structCount(fb_.verbInfo.attributes) neq 2) {
    45					fb_throw("fusebox.badGrammar.unexpectedAttributes",
    46								"Unexpected attributes",
    47								"Unexpected attributes were found in a 'argument' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    48				}
    49			} else {
    50				if (structCount(fb_.verbInfo.attributes) neq 1) {
    51					fb_throw("fusebox.badGrammar.unexpectedAttributes",
    52								"Unexpected attributes",
    53								"Unexpected attributes were found in a 'arguments' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    54				}
    55			}
    56		}
    57		// append this argument to the parent data:
    58		fb_.data = fb_.verbInfo.parent.data;
    59		if (structKeyExists(fb_.verbInfo.attributes,"name")) {
    60			// named argument:
    61			fb_.data.arguments = fb_.data.arguments & fb_.data.separator &
    62					fb_.verbInfo.attributes.name & '="#fb_.verbInfo.attributes.value#"';
    63		} else {
    64			// positional argument:
    65			fb_.data.arguments = fb_.data.arguments & fb_.data.separator &
    66					'"#fb_.verbInfo.attributes.value#"';
    67		}
    68		fb_.data.separator = ",";
    69	}
    70</cfscript>