| 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 circuit."> |
|---|
| 52 | |
|---|
| 53 | <cffunction name="init" returntype="fuseboxCircuit" access="public" output="false" |
|---|
| 54 | hint="I am the constructor."> |
|---|
| 55 | <cfargument name="fbApp" type="fuseboxApplication" required="true" |
|---|
| 56 | hint="I am the fusebox application object." /> |
|---|
| 57 | <cfargument name="alias" type="string" required="true" |
|---|
| 58 | hint="I am the circuit alias." /> |
|---|
| 59 | <cfargument name="path" type="string" required="true" |
|---|
| 60 | hint="I am the path from the application root to the circuit directory." /> |
|---|
| 61 | <cfargument name="parent" type="string" required="true" |
|---|
| 62 | hint="I am the alias of the parent circuit." /> |
|---|
| 63 | <cfargument name="myFusebox" type="myFusebox" required="true" |
|---|
| 64 | hint="I am the myFusebox data structure." /> |
|---|
| 65 | |
|---|
| 66 | <cfset variables.fuseboxApplication = arguments.fbApp /> |
|---|
| 67 | <cfset variables.alias = arguments.alias /> |
|---|
| 68 | |
|---|
| 69 | <cfset variables.fuseboxLexicon = variables.fuseboxApplication.getFuseactionFactory().getBuiltinLexicon() /> |
|---|
| 70 | |
|---|
| 71 | <cfset variables.customAttributes = structNew() /> |
|---|
| 72 | |
|---|
| 73 | <cfset variables.originalPath = arguments.path /> |
|---|
| 74 | <cfset this.parent = arguments.parent /> |
|---|
| 75 | <cfset variables.appPath = variables.fuseboxApplication.getApplicationRoot() /> |
|---|
| 76 | <cfset variables.lexicons = structNew() /> |
|---|
| 77 | |
|---|
| 78 | <cfset variables.relativePath = replace(arguments.path,"\","/","all") /> |
|---|
| 79 | <cfif len(variables.relativePath) and right(variables.relativePath,1) is not "/"> |
|---|
| 80 | <cfset variables.relativePath = variables.relativePath & "/" /> |
|---|
| 81 | </cfif> |
|---|
| 82 | <cfset this.path = variables.relativePath /> |
|---|
| 83 | <cfset variables.fullPath = variables.appPath & variables.relativePath /> |
|---|
| 84 | <!--- remove pairs of directory/../ to form canonical path: ---> |
|---|
| 85 | <cfloop condition="find('/../',variables.fullPath) gt 0"> |
|---|
| 86 | <cfset variables.fullPath = REreplace(variables.fullPath,"[^\.:/]*/\.\./","") /> |
|---|
| 87 | </cfloop> |
|---|
| 88 | <cfset this.rootPath = variables.fuseboxApplication.relativePath(variables.fullPath,variables.appPath) /> |
|---|
| 89 | |
|---|
| 90 | <cfset reload(arguments.myFusebox) /> |
|---|
| 91 | |
|---|
| 92 | <cfreturn this /> |
|---|
| 93 | |
|---|
| 94 | </cffunction> |
|---|
| 95 | |
|---|
| 96 | <cffunction name="reload" returntype="fuseboxCircuit" access="public" output="false" |
|---|
| 97 | hint="I reload the circuit file and build the in-memory structures from it."> |
|---|
| 98 | <cfargument name="myFusebox" type="myFusebox" required="true" |
|---|
| 99 | hint="I am the myFusebox data structure." /> |
|---|
| 100 | |
|---|
| 101 | <cfset var circuitFile = "circuit.xml.cfm" /> |
|---|
| 102 | <cfset var circuitXML = "" /> |
|---|
| 103 | <cfset var circuitCode = "" /> |
|---|
| 104 | <cfset var needToLoad = true /> |
|---|
| 105 | <cfset var circuitFiles = 0 /> |
|---|
| 106 | |
|---|
| 107 | <cfif structKeyExists(variables,"timestamp")> |
|---|
| 108 | <cfdirectory action="list" directory="#variables.fullPath#" filter="circuit.xml*" name="circuitFiles" /> |
|---|
| 109 | <cfif circuitFiles.recordCount eq 1> |
|---|
| 110 | <cfset needToLoad = parseDateTime(circuitFiles.dateLastModified) gt parseDateTime(variables.timestamp) /> |
|---|
| 111 | <!--- else ignore the ambiguity ---> |
|---|
| 112 | </cfif> |
|---|
| 113 | </cfif> |
|---|
| 114 | |
|---|
| 115 | <cfif needToLoad> |
|---|
| 116 | <cfif variables.fuseboxApplication.debug> |
|---|
| 117 | <cfset arguments.myFusebox.trace("Compiler","Loading #getAlias()# circuit.xml file") /> |
|---|
| 118 | </cfif> |
|---|
| 119 | <!--- attempt to load circuit.xml(.cfm): ---> |
|---|
| 120 | <cfif not fileExists(variables.fullPath & circuitFile)> |
|---|
| 121 | <cfset circuitFile = "circuit.xml" /> |
|---|
| 122 | </cfif> |
|---|
| 123 | <cftry> |
|---|
| 124 | |
|---|
| 125 | <cffile action="read" file="#variables.fullPath##circuitFile#" |
|---|
| 126 | variable="circuitXML" |
|---|
| 127 | charset="#variables.fuseboxApplication.characterEncoding#" /> |
|---|
| 128 | <cfset variables.circuitPath = variables.fullPath & circuitFile /> |
|---|
| 129 | |
|---|
| 130 | <cfcatch type="any"> |
|---|
| 131 | <cfif variables.fuseboxApplication.allowImplicitCircuits> |
|---|
| 132 | <cfset circuitXML = "<circuit/>" /> |
|---|
| 133 | <cfelse> |
|---|
| 134 | <cfthrow type="fusebox.missingCircuitXML" |
|---|
| 135 | message="missing circuit.xml" |
|---|
| 136 | detail="The circuit xml file, #circuitFile#, for circuit #getAlias()# could not be found." |
|---|
| 137 | extendedinfo="#cfcatch.detail#" /> |
|---|
| 138 | </cfif> |
|---|
| 139 | </cfcatch> |
|---|
| 140 | |
|---|
| 141 | </cftry> |
|---|
| 142 | |
|---|
| 143 | <cftry> |
|---|
| 144 | |
|---|
| 145 | <cfset circuitCode = xmlParse(circuitXML) /> |
|---|
| 146 | |
|---|
| 147 | <cfcatch type="any"> |
|---|
| 148 | <cfthrow type="fusebox.circuitXMLError" |
|---|
| 149 | message="Error reading circuit.xml" |
|---|
| 150 | detail="A problem was encountered while reading the circuit file #circuitFile# for circuit #getAlias()#. This is usually caused by unmatched XML tag-pairs. Close all XML tags explicitly or use the / (slash) short-cut." |
|---|
| 151 | extendedinfo="#cfcatch.detail#" /> |
|---|
| 152 | </cfcatch> |
|---|
| 153 | |
|---|
| 154 | </cftry> |
|---|
| 155 | |
|---|
| 156 | <cfif circuitCode.xmlRoot.xmlName is not "circuit"> |
|---|
| 157 | <cfthrow type="fusebox.badGrammar.badCircuitFile" |
|---|
| 158 | detail="Circuit file does contain 'circuit' XML" |
|---|
| 159 | message="Circuit file #variables.circuitPath# does not contain 'circuit' as the root XML node." /> |
|---|
| 160 | </cfif> |
|---|
| 161 | <cfif structKeyExists(circuitCode.xmlRoot.xmlAttributes,"access")> |
|---|
| 162 | <cfif listFind("private,internal,public",circuitCode.xmlRoot.xmlAttributes.access) eq 0> |
|---|
| 163 | <cfthrow type="fusebox.badGrammar.illegalAccess" |
|---|
| 164 | message="Circuit access illegal" |
|---|
| 165 | detail="The 'access' value '#circuitCode.xmlRoot.xmlAttributes.access#' is illegal in Circuit #getAlias()#. 'private', 'internal' or 'public' are the only legal values." /> |
|---|
| 166 | </cfif> |
|---|
| 167 | <cfset this.access = circuitCode.xmlRoot.xmlAttributes.access /> |
|---|
| 168 | <cfelse> |
|---|
| 169 | <cfset this.access = "internal" /> |
|---|
| 170 | </cfif> |
|---|
| 171 | <cfif structKeyExists(circuitCode.xmlRoot.xmlAttributes,"permissions")> |
|---|
| 172 | <cfset this.permissions = circuitCode.xmlRoot.xmlAttributes.permissions /> |
|---|
| 173 | <cfelse> |
|---|
| 174 | <cfset this.permissions = "" /> |
|---|
| 175 | </cfif> |
|---|
| 176 | |
|---|
| 177 | <cfset loadLexicons(circuitCode) /> |
|---|
| 178 | <cfset loadPreAndPostFuseactions(circuitCode) /> |
|---|
| 179 | <cfset loadFuseactions(circuitCode) /> |
|---|
| 180 | <cfset variables.circuitFile = circuitFile /> |
|---|
| 181 | </cfif> |
|---|
| 182 | |
|---|
| 183 | <cfset variables.timestamp = now() /> |
|---|
| 184 | |
|---|
| 185 | <cfreturn this /> |
|---|
| 186 | |
|---|
| 187 | </cffunction> |
|---|
| 188 | |
|---|
| 189 | <cffunction name="compile" returntype="void" access="public" output="false" |
|---|
| 190 | hint="I compile a given fuseaction within this circuit."> |
|---|
| 191 | <cfargument name="writer" type="any" required="false" |
|---|
| 192 | hint="I am the parsed file writer object. I am required but it's faster to specify that I am not required." /> |
|---|
| 193 | <cfargument name="fuseaction" type="any" required="false" |
|---|
| 194 | hint="I am the name of the fuseaction to compile. I am required but it's faster to specify that I am not required." /> |
|---|
| 195 | |
|---|
| 196 | <cfset var f = arguments.writer.setFuseaction(arguments.fuseaction) /> |
|---|
| 197 | <cfset var i = 0 /> |
|---|
| 198 | <cfset var n = 0 /> |
|---|
| 199 | |
|---|
| 200 | <cfset compilePreOrPostFuseaction(arguments.writer,"pre") /> |
|---|
| 201 | |
|---|
| 202 | <cfif not structKeyExists(this.fuseactions,arguments.fuseaction)> |
|---|
| 203 | <cfthrow type="fusebox.undefinedFuseaction" |
|---|
| 204 | message="undefined Fuseaction" |
|---|
| 205 | detail="You specified a Fuseaction of #arguments.fuseaction# which is not defined in Circuit #getAlias()#." /> |
|---|
| 206 | </cfif> |
|---|
| 207 | <cfset this.fuseactions[arguments.fuseaction].compile(arguments.writer) /> |
|---|
| 208 | |
|---|
| 209 | <cfset compilePreOrPostFuseaction(arguments.writer,"post") /> |
|---|
| 210 | |
|---|
| 211 | <cfset arguments.writer.setFuseaction(f) /> |
|---|
| 212 | |
|---|
| 213 | </cffunction> |
|---|
| 214 | |
|---|
| 215 | <cffunction name="compilePreOrPostFuseaction" returntype="void" access="public" output="false" |
|---|
| 216 | hint="I compile the pre/post-fuseaction for a circuit."> |
|---|
| 217 | <cfargument name="writer" type="any" required="false" |
|---|
| 218 | hint="I am the parsed file writer object. I am required but it's faster to specify that I am not required." /> |
|---|
| 219 | <cfargument name="preOrPost" type="string" required="false" |
|---|
| 220 | hint="I am either 'pre' or 'post' to indicate whether this is a prefuseaction or a postfuseaction. I am required but it's faster to specify that I am not required." /> |
|---|
| 221 | |
|---|
| 222 | <cfset var c = "" /> |
|---|
| 223 | |
|---|
| 224 | <cfif variables.hasAction[arguments.preOrPost]> |
|---|
| 225 | <cfif arguments.preOrPost is "pre" and variables.callsuper["pre"] and hasParent()> |
|---|
| 226 | <cfset getParent().compilePreOrPostFuseaction(arguments.writer,arguments.preOrPost) /> |
|---|
| 227 | </cfif> |
|---|
| 228 | <cfset c = arguments.writer.setCircuit(getAlias()) /> |
|---|
| 229 | <cfset variables.action[arguments.preOrPost].compile(arguments.writer) /> |
|---|
| 230 | <cfset arguments.writer.setCircuit(c) /> |
|---|
| 231 | <cfif arguments.preOrPost is "post" and variables.callsuper["post"] and hasParent()> |
|---|
| 232 | <cfset getParent().compilePreOrPostFuseaction(arguments.writer,arguments.preOrPost) /> |
|---|
| 233 | </cfif> |
|---|
| 234 | </cfif> |
|---|
| 235 | |
|---|
| 236 | </cffunction> |
|---|
| 237 | |
|---|
| 238 | <cffunction name="buildCircuitTrace" returntype="void" access="public" output="false" |
|---|
| 239 | hint="I build the 'circuit trace' structure - the array of parents. Required for Fusebox 4.1 compatibility."> |
|---|
| 240 | |
|---|
| 241 | <cfset var c = getParentName() /> |
|---|
| 242 | <cfset var seen = structNew() /> |
|---|
| 243 | |
|---|
| 244 | <cfset seen[getAlias()] = true /> |
|---|
| 245 | <cfset this.circuitTrace = arrayNew(1) /> |
|---|
| 246 | <cfset arrayAppend(this.circuitTrace,getAlias()) /> |
|---|
| 247 | <cfloop condition="c is not ''"> |
|---|
| 248 | <cfif structKeyExists(seen,c)> |
|---|
| 249 | <cfthrow type="fusebox.badGrammar.circularParent" |
|---|
| 250 | message="Circular parent for Circuit" |
|---|
| 251 | detail="You specified a parent Circuit of #c# (for Circuit #getAlias()#) which creates a circular dependency." /> |
|---|
| 252 | </cfif> |
|---|
| 253 | <cfset seen[c] = true /> |
|---|
| 254 | <cfif not structKeyExists(variables.fuseboxApplication.circuits,c)> |
|---|
| 255 | <cfthrow type="fusebox.undefinedCircuit" |
|---|
| 256 | message="undefined Circuit" |
|---|
| 257 | detail="You specified a parent Circuit of #c# (for Circuit #getAlias()#) which is not defined." /> |
|---|
| 258 | </cfif> |
|---|
| 259 | <cfset arrayAppend(this.circuitTrace,c) /> |
|---|
| 260 | <cfset c = variables.fuseboxApplication.circuits[c].getParentName() /> |
|---|
| 261 | </cfloop> |
|---|
| 262 | |
|---|
| 263 | </cffunction> |
|---|
| 264 | |
|---|
| 265 | <cffunction name="getOriginalPath" returntype="string" access="public" output="false" |
|---|
| 266 | hint="I return the original relative path specified in the circuit declaration."> |
|---|
| 267 | |
|---|
| 268 | <cfreturn variables.originalPath /> |
|---|
| 269 | |
|---|
| 270 | </cffunction> |
|---|
| 271 | |
|---|
| 272 | <cffunction name="getCircuitRoot" returntype="string" access="public" output="false" |
|---|
| 273 | hint="I return the full file system path to the circuit directory."> |
|---|
| 274 | |
|---|
| 275 | <cfreturn variables.fullPath /> |
|---|
| 276 | |
|---|
| 277 | </cffunction> |
|---|
| 278 | |
|---|
| 279 | <cffunction name="getCircuitXMLFilename" returntype="string" access="public" output="false" |
|---|
| 280 | hint="I return the actual name of the circuit XML file: circuit.xml or circuit.xml.cfm."> |
|---|
| 281 | |
|---|
| 282 | <cfreturn variables.circuitFile /> |
|---|
| 283 | |
|---|
| 284 | </cffunction> |
|---|
| 285 | |
|---|
| 286 | <cffunction name="getParentName" returntype="string" access="public" output="false" |
|---|
| 287 | hint="I return the name (alias) of this circuit's parent."> |
|---|
| 288 | |
|---|
| 289 | <cfreturn this.parent /> |
|---|
| 290 | |
|---|
| 291 | </cffunction> |
|---|
| 292 | |
|---|
| 293 | <cffunction name="hasParent" returntype="boolean" access="public" output="false" |
|---|
| 294 | hint="I return true if this circuit has a parent, otherwise I return false."> |
|---|
| 295 | |
|---|
| 296 | <cfreturn getParentName() is not "" /> |
|---|
| 297 | |
|---|
| 298 | </cffunction> |
|---|
| 299 | |
|---|
| 300 | <cffunction name="getParent" returntype="any" access="public" output="false" |
|---|
| 301 | hint="I return this circuit's parent circuit object. I throw an exception if hasParent() returns false."> |
|---|
| 302 | |
|---|
| 303 | <!--- |
|---|
| 304 | note that this will throw an exception if the circuit has no parent |
|---|
| 305 | code should call hasParent() first |
|---|
| 306 | ---> |
|---|
| 307 | <cfreturn variables.fuseboxApplication.circuits[getParentName()] /> |
|---|
| 308 | |
|---|
| 309 | </cffunction> |
|---|
| 310 | |
|---|
| 311 | <cffunction name="getPermissions" returntype="string" access="public" output="false" |
|---|
| 312 | hint="I return the aggregated permissions for this circuit."> |
|---|
| 313 | <cfargument name="useCircuitTrace" type="boolean" default="false" |
|---|
| 314 | hint="I indicate whether or not to inherit the parent circuit's permissions if this circuit has no permissions specified." /> |
|---|
| 315 | |
|---|
| 316 | <cfif this.permissions is "" and arguments.useCircuitTrace and hasParent()> |
|---|
| 317 | <cfreturn getParent().getPermissions(arguments.useCircuitTrace) /> |
|---|
| 318 | <cfelse> |
|---|
| 319 | <cfreturn this.permissions /> |
|---|
| 320 | </cfif> |
|---|
| 321 | |
|---|
| 322 | </cffunction> |
|---|
| 323 | |
|---|
| 324 | <cffunction name="getRelativePath" returntype="string" access="public" output="false" |
|---|
| 325 | hint="I return the normalized relative path from the application root to this circuit's directory."> |
|---|
| 326 | |
|---|
| 327 | <cfreturn variables.relativePath /> |
|---|
| 328 | |
|---|
| 329 | </cffunction> |
|---|
| 330 | |
|---|
| 331 | <cffunction name="getFuseactions" returntype="struct" access="public" output="false" |
|---|
| 332 | hint="I return the structure containing the definitions of the fuseactions within this circuit."> |
|---|
| 333 | |
|---|
| 334 | <cfreturn this.fuseactions /> |
|---|
| 335 | |
|---|
| 336 | </cffunction> |
|---|
| 337 | |
|---|
| 338 | <cffunction name="getLexiconDefinition" returntype="any" access="public" output="false" |
|---|
| 339 | hint="I return the definition of the specified lexicon."> |
|---|
| 340 | <cfargument name="namespace" type="any" required="false" |
|---|
| 341 | hint="I am the namespace whose lexicon is to be retrieved. I am required but it's faster to specify that I am not required." /> |
|---|
| 342 | |
|---|
| 343 | <cfif arguments.namespace is variables.fuseboxLexicon.namespace> |
|---|
| 344 | <cfreturn variables.fuseboxLexicon /> |
|---|
| 345 | <cfelse> |
|---|
| 346 | <cfreturn variables.lexicons[arguments.namespace] /> |
|---|
| 347 | </cfif> |
|---|
| 348 | |
|---|
| 349 | </cffunction> |
|---|
| 350 | |
|---|
| 351 | <cffunction name="getAccess" returntype="any" access="public" output="false" |
|---|
| 352 | hint="I return the access specified for this circuit."> |
|---|
| 353 | |
|---|
| 354 | <cfreturn this.access /> |
|---|
| 355 | |
|---|
| 356 | </cffunction> |
|---|
| 357 | |
|---|
| 358 | <cffunction name="getAlias" returntype="any" access="public" output="false" |
|---|
| 359 | hint="I return the circuit alias."> |
|---|
| 360 | |
|---|
| 361 | <cfreturn variables.alias /> |
|---|
| 362 | |
|---|
| 363 | </cffunction> |
|---|
| 364 | |
|---|
| 365 | <cffunction name="getApplication" returntype="any" access="public" output="false" |
|---|
| 366 | hint="I return the fusebox application object."> |
|---|
| 367 | |
|---|
| 368 | <cfreturn variables.fuseboxApplication /> |
|---|
| 369 | |
|---|
| 370 | </cffunction> |
|---|
| 371 | |
|---|
| 372 | <cffunction name="getCustomAttributes" returntype="struct" access="public" output="false" |
|---|
| 373 | hint="I return any custom attributes for the specified namespace prefix."> |
|---|
| 374 | <cfargument name="ns" type="string" required="true" |
|---|
| 375 | hint="I am the namespace for which to return custom attributes." /> |
|---|
| 376 | |
|---|
| 377 | <cfif structKeyExists(variables.customAttributes,arguments.ns)> |
|---|
| 378 | <!--- we structCopy() this so folks can't poke values back into the metadata! ---> |
|---|
| 379 | <cfreturn structCopy(variables.customAttributes[arguments.ns]) /> |
|---|
| 380 | <cfelse> |
|---|
| 381 | <cfreturn structNew() /> |
|---|
| 382 | </cfif> |
|---|
| 383 | |
|---|
| 384 | </cffunction> |
|---|
| 385 | |
|---|
| 386 | <cffunction name="loadLexicons" returntype="void" access="private" output="false" |
|---|
| 387 | hint="I load the lexicon definitions and custom attributes out of the namespace declarations in the circuit tag."> |
|---|
| 388 | <cfargument name="circuitCode" type="any" required="true" |
|---|
| 389 | hint="I am the XML representation of the circuit file." /> |
|---|
| 390 | |
|---|
| 391 | <cfset var attributes = circuitCode.xmlRoot.xmlAttributes /> |
|---|
| 392 | <cfset var attr = "" /> |
|---|
| 393 | <cfset var aLex = "" /> |
|---|
| 394 | <cfset var ns = "" /> |
|---|
| 395 | <cfset var strict = variables.fuseboxApplication.strictMode /> |
|---|
| 396 | |
|---|
| 397 | <!--- pass 1: pull out any namespace declarations ---> |
|---|
| 398 | <cfloop collection="#attributes#" item="attr"> |
|---|
| 399 | <cfif len(attr) gt 6 and left(attr,6) is "xmlns:"> |
|---|
| 400 | <!--- found a namespace declaration, pull it out: ---> |
|---|
| 401 | <cfset aLex = structNew() /> |
|---|
| 402 | <cfset aLex.namespace = listLast(attr,":") /> |
|---|
| 403 | <cfif aLex.namespace is variables.fuseboxLexicon.namespace> |
|---|
| 404 | <cfthrow type="fusebox.badGrammar.reservedName" |
|---|
| 405 | message="Attempt to use reserved namespace" |
|---|
| 406 | detail="You have attempted to declare a namespace '#aLex.namespace#' (in Circuit #getAlias()#) which is reserved by the Fusebox framework." /> |
|---|
| 407 | </cfif> |
|---|
| 408 | <cfset aLex.path = variables.fuseboxApplication.getCoreToAppRootPath() & variables.fuseboxApplication.lexiconPath & attributes[attr] /> |
|---|
| 409 | <cfset variables.lexicons[aLex.namespace] = aLex /> |
|---|
| 410 | <cfset variables.customAttributes[aLex.namespace] = structNew() /> |
|---|
| 411 | </cfif> |
|---|
| 412 | </cfloop> |
|---|
| 413 | |
|---|
| 414 | <!--- pass 2: pull out any custom attributes ---> |
|---|
| 415 | <cfloop collection="#attributes#" item="attr"> |
|---|
| 416 | <cfif listLen(attr,":") eq 2> |
|---|
| 417 | <!--- looks like a custom attribute: ---> |
|---|
| 418 | <cfset ns = listFirst(attr,":") /> |
|---|
| 419 | <cfif ns is "xmlns"> |
|---|
| 420 | <!--- special case - need to ignore xmlns:foo="bar" ---> |
|---|
| 421 | <cfelseif structKeyExists(variables.customAttributes,ns)> |
|---|
| 422 | <cfset variables.customAttributes[ns][listLast(attr,":")] = attributes[attr] /> |
|---|
| 423 | <cfelse> |
|---|
| 424 | <cfthrow type="fusebox.badGrammar.undeclaredNamespace" |
|---|
| 425 | message="Undeclared lexicon namespace" |
|---|
| 426 | detail="The lexicon prefix '#ns#' was found on a custom attribute in the <circuit> tag of Circuit #getAlias()# but no such lexicon namespace has been declared." /> |
|---|
| 427 | </cfif> |
|---|
| 428 | <cfelseif strict and listFind("access,permissions",attr) eq 0> |
|---|
| 429 | <cfthrow type="fusebox.badGrammar.unexpectedAttributes" |
|---|
| 430 | message="Unexpected attributes" |
|---|
| 431 | detail="Unexpected attributes were found in the 'circuit' tag of the '#getAlias()#' circuit.xml file." /> |
|---|
| 432 | </cfif> |
|---|
| 433 | </cfloop> |
|---|
| 434 | |
|---|
| 435 | </cffunction> |
|---|
| 436 | |
|---|
| 437 | <cffunction name="loadPreAndPostFuseactions" returntype="void" access="private" output="false" |
|---|
| 438 | hint="I load the prefuseaction and postfuseaction definitions from the circuit file."> |
|---|
| 439 | <cfargument name="circuitCode" type="any" required="true" |
|---|
| 440 | hint="I am the XML representation of the circuit file." /> |
|---|
| 441 | |
|---|
| 442 | <cfset variables.hasAction = structNew() /> |
|---|
| 443 | <cfset variables.action = structNew() /> |
|---|
| 444 | <cfset variables.callsuper = structNew() /> |
|---|
| 445 | <cfset loadPrePostFuseaction(arguments.circuitCode,"pre") /> |
|---|
| 446 | <cfset loadPrePostFuseaction(arguments.circuitCode,"post") /> |
|---|
| 447 | |
|---|
| 448 | </cffunction> |
|---|
| 449 | |
|---|
| 450 | <cffunction name="loadPrePostFuseaction" returntype="void" access="private" output="false" |
|---|
| 451 | hint="I load the either a prefuseaction or a postfuseaction definition from the circuit file."> |
|---|
| 452 | <cfargument name="circuitCode" type="any" required="true" |
|---|
| 453 | hint="I am the XML representation of the circuit file." /> |
|---|
| 454 | <cfargument name="prePost" type="string" required="true" |
|---|
| 455 | hint="I specify whether to load a 'pre'fuseaction or a 'post'fuseaction." /> |
|---|
| 456 | |
|---|
| 457 | <cfset var children = xmlSearch(arguments.circuitCode,"/circuit/#arguments.prePost#fuseaction") /> |
|---|
| 458 | <cfset var i = 0 /> |
|---|
| 459 | <cfset var n = arrayLen(children) /> |
|---|
| 460 | <cfset var nAttrs = 0 /> |
|---|
| 461 | |
|---|
| 462 | <cfif n eq 0> |
|---|
| 463 | <cfset variables.hasAction[arguments.prePost] = false /> |
|---|
| 464 | <cfelseif n eq 1> |
|---|
| 465 | <cfset variables.hasAction[arguments.prePost] = true /> |
|---|
| 466 | <cfif structKeyExists(children[1].xmlAttributes,"callsuper")> |
|---|
| 467 | <cfif listFind("true,false",children[1].xmlAttributes.callsuper) eq 0> |
|---|
| 468 | <cfthrow type="fusebox.badGrammar.invalidAttributeValue" |
|---|
| 469 | message="Attribute has invalid value" |
|---|
| 470 | detail="The attribute 'callsuper' must either be ""true"" or ""false"", for a '#arguments.prePost#fuseaction' in Circuit #getAlias()#." /> |
|---|
| 471 | </cfif> |
|---|
| 472 | <cfset nAttrs = 1 /> |
|---|
| 473 | <cfset variables.callsuper[arguments.prePost] = children[1].xmlAttributes.callsuper /> |
|---|
| 474 | <cfelse> |
|---|
| 475 | <cfset variables.callsuper[arguments.prePost] = false /> |
|---|
| 476 | </cfif> |
|---|
| 477 | <cfif variables.fuseboxApplication.strictMode and structCount(children[1].xmlAttributes) neq nAttrs> |
|---|
| 478 | <cfthrow type="fusebox.badGrammar.unexpectedAttributes" |
|---|
| 479 | message="Unexpected attributes" |
|---|
| 480 | detail="Unexpected attributes found on '#arguments.prePost#fuseaction' in Circuit #getAlias()#." /> |
|---|
| 481 | </cfif> |
|---|
| 482 | <cfset variables.action[arguments.prePost] = |
|---|
| 483 | createObject("component","fuseboxAction") |
|---|
| 484 | .init(this, |
|---|
| 485 | "$#arguments.prePost#fuseaction", |
|---|
| 486 | "internal", |
|---|
| 487 | children[1].xmlChildren) /> |
|---|
| 488 | <cfelse> |
|---|
| 489 | <cfthrow type="fusebox.badGrammar.nonUniqueDeclaration" |
|---|
| 490 | message="Declaration was not unique" |
|---|
| 491 | detail="More than one <#arguments.prePost#fuseaction> declaration was found in Circuit #getAlias()#." /> |
|---|
| 492 | </cfif> |
|---|
| 493 | |
|---|
| 494 | </cffunction> |
|---|
| 495 | |
|---|
| 496 | <cffunction name="loadFuseactions" returntype="void" access="private" output="false" |
|---|
| 497 | hint="I load all of the fuseaction definitions from the circuit file."> |
|---|
| 498 | <cfargument name="circuitCode" type="any" required="true" |
|---|
| 499 | hint="I am the XML representation of the circuit file." /> |
|---|
| 500 | |
|---|
| 501 | <cfset var children = xmlSearch(arguments.circuitCode,"/circuit/fuseaction") /> |
|---|
| 502 | <cfset var i = 0 /> |
|---|
| 503 | <cfset var n = arrayLen(children) /> |
|---|
| 504 | <cfset var attribs = 0 /> |
|---|
| 505 | <cfset var attr = "" /> |
|---|
| 506 | <cfset var ns = "" /> |
|---|
| 507 | <cfset var customAttribs = 0 /> |
|---|
| 508 | <cfset var access = "" /> |
|---|
| 509 | <cfset var permissions = "" /> |
|---|
| 510 | <cfset var strict = variables.fuseboxApplication.strictMode /> |
|---|
| 511 | |
|---|
| 512 | <cfset this.fuseactions = structNew() /> |
|---|
| 513 | <cfloop from="1" to="#n#" index="i"> |
|---|
| 514 | <!--- default fuseaction access to circuit access ---> |
|---|
| 515 | <cfset access = this.access /> |
|---|
| 516 | <cfset attribs = children[i].xmlAttributes /> |
|---|
| 517 | |
|---|
| 518 | <cfif not structKeyExists(attribs,"name")> |
|---|
| 519 | <cfthrow type="fusebox.badGrammar.requiredAttributeMissing" |
|---|
| 520 | message="Required attribute is missing" |
|---|
| 521 | detail="The attribute 'name' is required, for a 'fuseaction' declaration in circuit #getAlias()#." /> |
|---|
| 522 | </cfif> |
|---|
| 523 | |
|---|
| 524 | <!--- scan for custom attributes ---> |
|---|
| 525 | <cfset customAttribs = structNew() /> |
|---|
| 526 | <cfloop collection="#attribs#" item="attr"> |
|---|
| 527 | |
|---|
| 528 | <cfswitch expression="#attr#"> |
|---|
| 529 | <cfcase value="name"> |
|---|
| 530 | <cfif structKeyExists(this.fuseactions,attribs.name)> |
|---|
| 531 | <cfthrow type="fusebox.overloadedFuseaction" |
|---|
| 532 | message="overloaded Fuseaction" |
|---|
| 533 | detail="You referenced a fuseaction, #attribs.name#, which has been defined multiple times in circuit #getAlias()#. Fusebox does not allow overloaded methods." /> |
|---|
| 534 | </cfif> |
|---|
| 535 | </cfcase> |
|---|
| 536 | <cfcase value="access"> |
|---|
| 537 | <cfset access = attribs.access /> |
|---|
| 538 | <cfif listFind("private,internal,public",access) eq 0> |
|---|
| 539 | <cfthrow type="fusebox.badGrammar.illegalAccess" |
|---|
| 540 | message="Fuseaction access illegal" |
|---|
| 541 | detail="The 'access' value '#access#' is illegal on Fuseaction #attribs.name# in Circuit #getAlias()#. 'private', 'internal' or 'public' are the only legal values." /> |
|---|
| 542 | </cfif> |
|---|
| 543 | </cfcase> |
|---|
| 544 | <cfcase value="permissions"> |
|---|
| 545 | <cfset permissions = attribs.permissions /> |
|---|
| 546 | </cfcase> |
|---|
| 547 | <cfdefaultcase> |
|---|
| 548 | <cfif listLen(attr,":") eq 2> |
|---|
| 549 | <!--- looks like a custom attribute: ---> |
|---|
| 550 | <cfset ns = listFirst(attr,":") /> |
|---|
| 551 | <cfif structKeyExists(variables.customAttributes,ns)> |
|---|
| 552 | <cfset customAttribs[ns][listLast(attr,":")] = attribs[attr] /> |
|---|
| 553 | <cfelse> |
|---|
| 554 | <cfthrow type="fusebox.badGrammar.undeclaredNamespace" |
|---|
| 555 | message="Undeclared lexicon namespace" |
|---|
| 556 | detail="The lexicon prefix '#ns#' was found on a custom attribute in the Fuseaction #attribs.name# in Circuit #getAlias()# but no such lexicon namespace has been declared." /> |
|---|
| 557 | </cfif> |
|---|
| 558 | |
|---|
| 559 | <cfelseif strict> |
|---|
| 560 | <cfthrow type="fusebox.badGrammar.unexpectedAttributes" |
|---|
| 561 | message="Unexpected attributes" |
|---|
| 562 | detail="Unexpected attribute '#attr#' found on Fuseaction #attribs.name# in Circuit #getAlias()#." /> |
|---|
| 563 | </cfif> |
|---|
| 564 | </cfdefaultcase> |
|---|
| 565 | </cfswitch> |
|---|
| 566 | </cfloop> |
|---|
| 567 | |
|---|
| 568 | <cfset this.fuseactions[attribs.name] = |
|---|
| 569 | createObject("component","fuseboxAction") |
|---|
| 570 | .init(this,attribs.name,access,children[i].xmlChildren,false,customAttribs) /> |
|---|
| 571 | <!--- FB41 security plugin compatibility: ---> |
|---|
| 572 | <cfset this.fuseactions[attribs.name].permissions = permissions /> |
|---|
| 573 | </cfloop> |
|---|
| 574 | |
|---|
| 575 | </cffunction> |
|---|
| 576 | |
|---|
| 577 | </cfcomponent> |
|---|