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		// url/xfa - string - one of these is required
    20		if (structKeyExists(fb_.verbInfo.attributes,"url")) {
    21			if (structKeyExists(fb_.verbInfo.attributes,"xfa")) {
    22				fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    23							"Required attribute is missing",
    24							"Either the attribute 'url' or 'xfa' is required, for a 'relocate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    25			} else {
    26				fb_.theUrl = fb_.verbInfo.attributes.url;
    27			}
    28		} else {
    29			if (structKeyExists(fb_.verbInfo.attributes,"xfa")) {
    30				// url = myself + the xfa value
    31				fb_.theUrl = "##myFusebox.getMyself()####xfa." & fb_.verbInfo.attributes.xfa & "##";
    32			} else {
    33				fb_throw("fusebox.badGrammar.requiredAttributeMissing",
    34							"Required attribute is missing",
    35							"Either the attribute 'url' or 'xfa' is required, for a 'relocate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    36			}
    37		}
    38		// addtoken - boolean - default false
    39		if (structKeyExists(fb_.verbInfo.attributes,"addtoken")) {
    40			if (listFind("true,false,yes,no",fb_.verbInfo.attributes.addtoken) eq 0) {
    41				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    42							"Attribute has invalid value",
    43							"The attribute 'addtoken' must either be ""true"" or ""false"", for a 'relocate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    44			}
    45		} else {
    46			fb_.verbInfo.attributes.addtoken = false;
    47		}
    48		// type - server|client - default client
    49		if (structKeyExists(fb_.verbInfo.attributes,"type")) {
    50			// FB51: adds moved and javascript types:
    51			if (listFind("server,client,moved,javascript",fb_.verbInfo.attributes.type) eq 0) {
    52				fb_throw("fusebox.badGrammar.invalidAttributeValue",
    53							"Attribute has invalid value",
    54							"The attribute 'type' must either be ""server"", ""client"", ""moved"" or ""javascript"", for a 'relocate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    55			}
    56		} else {
    57			fb_.verbInfo.attributes.type = "client";
    58		}
    59		// strict mode - check attribute count:
    60		if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
    61			if (structCount(fb_.verbInfo.attributes) neq 3) {
    62				fb_throw("fusebox.badGrammar.unexpectedAttributes",
    63							"Unexpected attributes",
    64							"Unexpected attributes were found in a 'relocate' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
    65			}
    66		}
    67		
    68		// compile <relocate>
    69		switch (fb_.verbInfo.attributes.type) {
    70
    71		case "server":
    72			fb_appendLine('<cfset getPageContext().forward("#fb_.theUrl#")>');
    73			break;
    74
    75		case "client":
    76			fb_appendLine('<cflocation url="#fb_.theUrl#" addtoken="#fb_.verbInfo.attributes.addtoken#">');
    77			break;
    78
    79		case "moved":
    80			fb_appendLine('<cfheader statuscode="301" statustext="Moved Permanently">');
    81			fb_appendLine('<cfheader name="Location" value="#fb_.theUrl#">');
    82			break;
    83
    84		case "javascript":
    85			fb_appendLine('<cfoutput><script type="text/javascript">( document.location.replace ) ? ' &
    86							'document.location.replace("#fb_.theUrl#") : ' &
    87							'document.location.href = "#fb_.theUrl#";</script></cfoutput>');
    88			break;
    89
    90		}
    91		fb_appendLine('<cfabort>');
    92	}
    93</cfscript>