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 fb_.nAttrs = 0;
20 // there are five different forms of the <loop> verb:
21 // 1. condition - string - required
22 // 2. query - string - required
23 // 3. from - string - required
24 // to - string - required
25 // index - string - required
26 // step - string - optional
27 // 4. collection - string - required
28 // item - string - required
29 // 5. list - string - required
30 // index - index - required
31 // the last two are new in Fusebox 5
32 if (structKeyExists(fb_.verbInfo.attributes,"condition")) {
33 34 fb_.nAttrs = 1;
35 36 fb_appendLine('<cfloop condition="#fb_.verbInfo.attributes.condition#">');
37 38 } else if (structKeyExists(fb_.verbInfo.attributes,"query")) {
39 40 fb_.nAttrs = 1;
41 42 fb_appendLine('<cfloop query="#fb_.verbInfo.attributes.query#">');
43 44 } else if (structKeyExists(fb_.verbInfo.attributes,"from") or structKeyExists(fb_.verbInfo.attributes,"to")) {
45 46 fb_.nAttrs = 3; // from/to/index required
47 48 if (not structKeyExists(fb_.verbInfo.attributes,"from") or
49 not structKeyExists(fb_.verbInfo.attributes,"to") or
50 not structKeyExists(fb_.verbInfo.attributes,"index")) {
51 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
52 "Required attribute is missing",
53 "The attributes 'from', 'to' and 'index' are both required, for a 'loop' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
54 } else {
55 fb_appendSegment('<' & 'cfloop from="#fb_.verbInfo.attributes.from#"' &
56 ' to="#fb_.verbInfo.attributes.to#"' &
57 ' index="#fb_.verbInfo.attributes.index#"');
58 if (structKeyExists(fb_.verbInfo.attributes,"step")) {
59 60 fb_.nAttrs = fb_.nAttrs + 1; // step optional
61 62 fb_appendSegment(' step="#fb_.verbInfo.attributes.step#"');
63 }
64 fb_appendLine('>');
65 }
66 67 } else if (structKeyExists(fb_.verbInfo.attributes,"collection")) {
68 69 fb_.nAttrs = 2; // collection/item required
70 71 if (not structKeyExists(fb_.verbInfo.attributes,"item")) {
72 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
73 "Required attribute is missing",
74 "The attribute 'item' is required, for a 'loop' verb with a 'collection' attribute in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
75 } else {
76 fb_appendLine('<cfloop collection="#fb_.verbInfo.attributes.collection#" item="#fb_.verbInfo.attributes.item#">');
77 }
78 79 } else if (structKeyExists(fb_.verbInfo.attributes,"list")) {
80 81 fb_.nAttrs = 2; // list/index required
82 83 if (not structKeyExists(fb_.verbInfo.attributes,"index")) {
84 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
85 "Required attribute is missing",
86 "The attribute 'index' is required, for a 'loop' verb with a 'list' attribute in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
87 } else {
88 fb_appendLine('<cfloop list="#fb_.verbInfo.attributes.list#" index="#fb_.verbInfo.attributes.index#">');
89 }
90 91 } else {
92 // illegal attributes
93 fb_throw("fusebox.badGrammar.requiredAttributeMissing",
94 "Required attribute is missing",
95 "One of 'condition', 'query', 'from'/'to', 'collection' or 'list' is required, for a 'loop' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
96 }
97 // strict mode - check attribute count:
98 if (fb_.verbInfo.action.getCircuit().getApplication().strictMode) {
99 if (structCount(fb_.verbInfo.attributes) neq fb_.nAttrs) {
100 fb_throw("fusebox.badGrammar.unexpectedAttributes",
101 "Unexpected attributes",
102 "Unexpected attributes were found in a 'loop' verb in fuseaction #fb_.verbInfo.circuit#.#fb_.verbInfo.fuseaction#.");
103 }
104 }
105 }
106 107 // compile </loop>
108 if (fb_.verbInfo.executionMode is "end") {
109 fb_appendLine("</cfloop>");
110 }
111</cfscript>