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 // evaluate - boolean default false
20 if (structKeyExists(fb_.verbInfo.attributes,"evaluate")) {
21 if (listFind("true,false,yes,no",fb_.verbInfo.attributes.evaluate) eq 0) {
22 fb_throw("fusebox.badGrammar.invalidAttributeValue",
23 "Attribute has invalid value",
24 "The attribute 'evaluate' must either be ""true"" or ""false"", for a 'set' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
25 }
26 } else {
27 fb_.verbInfo.attributes.evaluate = false;
28 }
29 // name - string - required if overwrite is present
30 if (not structKeyExists(fb_.verbInfo.attributes,"name")) {
31 if (structKeyExists(fb_.verbInfo.attributes,"overwrite")) {
32 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
33 "Required attribute is missing",
34 "The attribute 'name' is required when 'overwrite' is present, for a 'set' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
35 } else {
36 fb_.verbInfo.attributes.name = "";
37 }
38 }
39 // overwrite - boolean - default true
40 if (structKeyExists(fb_.verbInfo.attributes,"overwrite")) {
41 if (listFind("true,false,yes,no",fb_.verbInfo.attributes.overwrite) eq 0) {
42 fb_throw("fusebox.badGrammar.invalidAttributeValue",
43 "Attribute has invalid value",
44 "The attribute 'overwrite' must either be ""true"" or ""false"", for a 'set' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
45 }
46 } else {
47 fb_.verbInfo.attributes.overwrite = true;
48 }
49 // value - string - required
50 if (not structKeyExists(fb_.verbInfo.attributes,"value")) {
51 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
52 "Required attribute is missing",
53 "The attribute 'value' is required, for a 'set' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
54 }
55 // strict mode - check attribute count:
56 if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
57 if (structCount(fb_.verbInfo.attributes) neq 4) {
58 fb_throw("fusebox.badGrammar.unexpectedAttributes",
59 "Unexpected attributes",
60 "Unexpected attributes were found in a 'set' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
61 }
62 }
63 64 // compile <set>
65 name = fb_.verbInfo.attributes.name;
66 value = '"' & fb_.verbInfo.attributes.value & '"';
67 68 if (find("##",name) gt 0) {
69 name = '"' & name & '"';
70 }
71 if (fb_.verbInfo.attributes.evaluate) {
72 value = "evaluate(" & value & ")";
73 }
74 if (name is not "") {
75 if (fb_.verbInfo.attributes.overwrite) {
76 fb_appendLine("<cfset #name# = #value# />");
77 } else {
78 fb_appendLine("<cfif not isDefined(""#name#"")><cfset #name# = #value# /></cfif>");
79 }
80 } else {
81 fb_appendLine("<cfset #value# />");
82 }
83 }
84</cfscript>