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 // condition - string - required
20 if (not structKeyExists(fb_.verbInfo.attributes,"condition")) {
21 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
22 "Required attribute is missing",
23 "The attribute 'condition' is required, for a 'if' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
24 }
25 // strict mode - check attribute count:
26 if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
27 if (structCount(fb_.verbInfo.attributes) neq 1) {
28 fb_throw("fusebox.badGrammar.unexpectedAttributes",
29 "Unexpected attributes",
30 "Unexpected attributes were found in a 'if' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
31 }
32 }
33 34 // validation of children:
35 // at most one <true>, at most one <false>, nothing else:
36 fb_.hasTrue = false;
37 fb_.hasFalse = false;
38 for (fb_.i = 1; fb_.i lte fb_.verbInfo.nChildren; fb_.i = fb_.i + 1) {
39 if (fb_.verbInfo.children[fb_.i].getNamespace() is not "") {
40 fb_throw("fusebox.badGrammar.illegalVerb",
41 "Illegal verb",
42 "An 'if' may contain only 'true' and 'false' verbs in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
43 }
44 switch (fb_.verbInfo.children[fb_.i].getVerb()) {
45 case "true":
46 if (fb_.hasTrue) {
47 fb_throw("fusebox.badGrammar.illegalVerb",
48 "Illegal verb",
49 "An 'if' may contain at most one 'true' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
50 } else {
51 fb_.hasTrue = true;
52 }
53 break;
54 case "false":
55 if (fb_.hasFalse) {
56 fb_throw("fusebox.badGrammar.illegalVerb",
57 "Illegal verb",
58 "An 'if' may contain at most one 'false' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
59 } else {
60 fb_.hasFalse = true;
61 }
62 break;
63 default:
64 fb_throw("fusebox.badGrammar.illegalVerb",
65 "Illegal verb",
66 "An 'if' may contain only 'true' and 'false' verbs in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
67 break;
68 }
69 }
70 71 // compile <if>
72 // <true> and <false> can occur in either order so we defer the conditional
73 // to the child tags...
74 fb_.verbInfo.condition = fb_.verbInfo.attributes.condition;
75 fb_.verbInfo.ifUsed = false;
76 } else {
77 // compile </if>
78 if (fb_.verbInfo.ifUsed) {
79 fb_appendLine("</cfif>");
80 }
81 }
82</cfscript>