| 1 | <!--- |
|---|
| 2 | Fusebox Software License |
|---|
| 3 | Version 1.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved. |
|---|
| 6 | |
|---|
| 7 | Redistribution and use in source and binary forms, with or without modification, are permitted |
|---|
| 8 | provided that the following conditions are met: |
|---|
| 9 | |
|---|
| 10 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
|---|
| 11 | and the following disclaimer. |
|---|
| 12 | |
|---|
| 13 | 2. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright |
|---|
| 14 | notice, this list of conditions and the following disclaimer in the documentation and/or other |
|---|
| 15 | materials provided with the distribution. |
|---|
| 16 | |
|---|
| 17 | 3. The end-user documentation included with the redistribution, if any, must include the following |
|---|
| 18 | acknowledgment: |
|---|
| 19 | |
|---|
| 20 | "This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)." |
|---|
| 21 | |
|---|
| 22 | Alternately, this acknowledgment may appear in the software itself, if and wherever such |
|---|
| 23 | third-party acknowledgments normally appear. |
|---|
| 24 | |
|---|
| 25 | 4. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products |
|---|
| 26 | derived from this software without prior written (non-electronic) permission. For written |
|---|
| 27 | permission, please contact fusebox@fusebox.org. |
|---|
| 28 | |
|---|
| 29 | 5. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in |
|---|
| 30 | their name, without prior written (non-electronic) permission of the Fusebox Corporation. For |
|---|
| 31 | written permission, please contact fusebox@fusebox.org. |
|---|
| 32 | |
|---|
| 33 | If one or more of the above conditions are violated, then this license is immediately revoked and |
|---|
| 34 | can be re-instated only upon prior written authorization of the Fusebox Corporation. |
|---|
| 35 | |
|---|
| 36 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 38 | DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|---|
| 39 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 40 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 41 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|---|
| 42 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 43 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 44 | |
|---|
| 45 | ------------------------------------------------------------------------------- |
|---|
| 46 | |
|---|
| 47 | This software consists of voluntary contributions made by many individuals on behalf of the |
|---|
| 48 | Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>. |
|---|
| 49 | |
|---|
| 50 | ---> |
|---|
| 51 | <cfcomponent output="false" hint="I represent a verb that is implemented as part of a lexicon."> |
|---|
| 52 | |
|---|
| 53 | <cffunction name="init" returntype="any" access="public" output="false" |
|---|
| 54 | hint="I am the constructor."> |
|---|
| 55 | <cfargument name="action" type="any" required="true" |
|---|
| 56 | hint="I am the enclosing fuseaction object." /> |
|---|
| 57 | <cfargument name="customVerb" type="string" required="true" |
|---|
| 58 | hint="I am the name of this (custom) verb." /> |
|---|
| 59 | <cfargument name="attributes" type="struct" required="true" |
|---|
| 60 | hint="I am the attributes for this verb." /> |
|---|
| 61 | <cfargument name="children" type="any" required="true" |
|---|
| 62 | hint="I am the XML representation of any children this verb has." /> |
|---|
| 63 | |
|---|
| 64 | <cfset var ns = listFirst(arguments.customVerb,".:") /> |
|---|
| 65 | <cfset var i = 0 /> |
|---|
| 66 | <cfset var verb = "" /> |
|---|
| 67 | <cfset var factory = arguments.action.getCircuit().getApplication().getFuseactionFactory() /> |
|---|
| 68 | |
|---|
| 69 | <cfset variables.action = arguments.action /> |
|---|
| 70 | <cfset variables.attributes = arguments.attributes /> |
|---|
| 71 | <!--- we will create our children below ---> |
|---|
| 72 | <cfset variables.verb = listLast(arguments.customVerb,".:") /> |
|---|
| 73 | <cfset variables.children = structNew() /> |
|---|
| 74 | |
|---|
| 75 | <cfset variables.factory = factory /> |
|---|
| 76 | <cfset variables.nChildren = arrayLen(arguments.children) /> |
|---|
| 77 | |
|---|
| 78 | <cfloop from="1" to="#variables.nChildren#" index="i"> |
|---|
| 79 | <cfset verb = arguments.children[i].xmlName /> |
|---|
| 80 | <cfset variables.children[i] = factory.create(verb, |
|---|
| 81 | variables.action, |
|---|
| 82 | arguments.children[i].xmlAttributes, |
|---|
| 83 | arguments.children[i].xmlChildren) /> |
|---|
| 84 | </cfloop> |
|---|
| 85 | |
|---|
| 86 | <cfset variables.fb41style = listLen(arguments.customVerb,".") eq 2 /> |
|---|
| 87 | <cfif variables.fb41style> |
|---|
| 88 | <cfset variables.lexicon = variables.action.getCircuit().getApplication().getLexiconDefinition(ns) /> |
|---|
| 89 | <cfelse> |
|---|
| 90 | <cfset variables.lexicon = variables.action.getCircuit().getLexiconDefinition(ns) /> |
|---|
| 91 | </cfif> |
|---|
| 92 | |
|---|
| 93 | <cfreturn this /> |
|---|
| 94 | |
|---|
| 95 | </cffunction> |
|---|
| 96 | |
|---|
| 97 | <cffunction name="compile" returntype="void" access="public" output="false" |
|---|
| 98 | hint="I compile a custom lexicon verb. I create the thread-safe context and perform the start and end execution, as well as compiling any children."> |
|---|
| 99 | <cfargument name="writer" type="any" required="false" |
|---|
| 100 | hint="I am the parsed file writer object. I am required but it's faster to specify that I am not required." /> |
|---|
| 101 | <cfargument name="context" type="any" required="false" |
|---|
| 102 | hint="I am the context in which this verb is compiled. I can be omitted if the verb has no enclosing parent." /> |
|---|
| 103 | |
|---|
| 104 | <!--- |
|---|
| 105 | the following is purely a device to allow nested custom verbs: |
|---|
| 106 | we pass the struct reference into the lexicon compiler but then we |
|---|
| 107 | fill in the fields here *afterwards* - relies on pass by reference! |
|---|
| 108 | because we are recursive, we need to create a new lexicon compiler |
|---|
| 109 | on each 'call' of the (static) compiler (i.e., this method) |
|---|
| 110 | trust me! -- sean corfield |
|---|
| 111 | ---> |
|---|
| 112 | <cfset var verbInfo = structNew() /> |
|---|
| 113 | <cfset var compiler = variables.factory.createLexiconCompiler() |
|---|
| 114 | .init(arguments.writer,verbInfo,variables) /> |
|---|
| 115 | <cfset var i = 0 /> |
|---|
| 116 | |
|---|
| 117 | <cfset verbInfo.lexicon = variables.lexicon.namespace /> |
|---|
| 118 | <cfset verbInfo.lexiconVerb = variables.verb /> |
|---|
| 119 | <cfset verbInfo.attributes = variables.attributes /> |
|---|
| 120 | <!--- |
|---|
| 121 | change to FB41 lexicons (but needed for FB5): |
|---|
| 122 | circuit - alias of current circuit |
|---|
| 123 | fuseaction - name of current fuseaction |
|---|
| 124 | action - fuseaction object for more complex usage |
|---|
| 125 | ---> |
|---|
| 126 | <cfset verbInfo.circuit = variables.action.getCircuit().getAlias() /> |
|---|
| 127 | <cfset verbInfo.fuseaction = variables.action.getName() /> |
|---|
| 128 | <cfset verbInfo.action = variables.action /> |
|---|
| 129 | |
|---|
| 130 | <cfif variables.fb41style> |
|---|
| 131 | |
|---|
| 132 | <!--- FB41: just compile the lexicon once with no executionMode ---> |
|---|
| 133 | <cfset compiler.compile() /> |
|---|
| 134 | |
|---|
| 135 | <cfelse> |
|---|
| 136 | |
|---|
| 137 | <!--- |
|---|
| 138 | FB5 has new fields in verbInfo: |
|---|
| 139 | skipBody - false, can be set to true by start tag to skip compilation of child tags |
|---|
| 140 | hasChildren - true if there are nested tags, else false |
|---|
| 141 | parent - present if we are nested (the verbInfo of the parent tag) |
|---|
| 142 | executionMode - start|inactive|end, just like custom tags |
|---|
| 143 | ---> |
|---|
| 144 | <cfset verbInfo.skipBody = false /> |
|---|
| 145 | <cfset verbInfo.hasChildren = variables.nChildren neq 0 /> |
|---|
| 146 | |
|---|
| 147 | <cfif structKeyExists(arguments,"context")> |
|---|
| 148 | <cfset verbInfo.parent = arguments.context /> |
|---|
| 149 | </cfif> |
|---|
| 150 | |
|---|
| 151 | <cfset verbInfo.executionMode = "start" /> |
|---|
| 152 | <cfset compiler.compile() /> |
|---|
| 153 | |
|---|
| 154 | <cfif structKeyExists(verbInfo,"skipBody") and isBoolean(verbInfo.skipBody) and verbInfo.skipBody> |
|---|
| 155 | <!--- the verb decided not to compile its children ---> |
|---|
| 156 | <cfelse> |
|---|
| 157 | <cfif variables.nChildren gt 0> |
|---|
| 158 | <cfset verbInfo.executionMode = "inactive" /> |
|---|
| 159 | <cfloop from="1" to="#variables.nChildren#" index="i"> |
|---|
| 160 | <cfset variables.children[i].compile(arguments.writer,verbInfo) /> |
|---|
| 161 | </cfloop> |
|---|
| 162 | </cfif> |
|---|
| 163 | </cfif> |
|---|
| 164 | |
|---|
| 165 | <cfset verbInfo.executionMode = "end" /> |
|---|
| 166 | <cfset compiler.compile() /> |
|---|
| 167 | |
|---|
| 168 | </cfif> |
|---|
| 169 | |
|---|
| 170 | <cfset variables.factory.freeLexiconCompiler(compiler) /> |
|---|
| 171 | |
|---|
| 172 | </cffunction> |
|---|
| 173 | |
|---|
| 174 | </cfcomponent> |
|---|