| 1 | <cftry><cfsilent> <!--- on one line to avoid leading whitespace ---> |
|---|
| 2 | <!--- |
|---|
| 3 | Copyright 2006 TeraTech, Inc. http://teratech.com/ |
|---|
| 4 | |
|---|
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 6 | you may not use this file except in compliance with the License. |
|---|
| 7 | You may obtain a copy of the License at |
|---|
| 8 | |
|---|
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 10 | |
|---|
| 11 | Unless required by applicable law or agreed to in writing, software |
|---|
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 14 | See the License for the specific language governing permissions and |
|---|
| 15 | limitations under the License. |
|---|
| 16 | ---> |
|---|
| 17 | |
|---|
| 18 | <!--- FB5: allow "" default - FB41 required this variable: ---> |
|---|
| 19 | <cfparam name="variables.FUSEBOX_APPLICATION_PATH" default="" /> |
|---|
| 20 | <!--- FB5: application key - FB41 always uses 'fusebox': ---> |
|---|
| 21 | <cfparam name="variables.FUSEBOX_APPLICATION_KEY" default="fusebox" /> |
|---|
| 22 | <!--- FB5.1: allow application to be included from other directories: ---> |
|---|
| 23 | <cfparam name="variables.FUSEBOX_CALLER_PATH" default="#replace(getDirectoryFromPath(getBaseTemplatePath()),"\","/","all")#" /> |
|---|
| 24 | <!--- FB6: easy way to override fusebox.xml parameters programmatically: ---> |
|---|
| 25 | <cfparam name="variables.FUSEBOX_PARAMETERS" default="#structNew()#" /> |
|---|
| 26 | |
|---|
| 27 | <cfparam name="variables.attributes" default="#structNew()#" /> |
|---|
| 28 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 29 | <cfset structAppend(attributes,form,true) /> |
|---|
| 30 | <!--- FB51: ticket 164: add OO synonym for attributes scope ---> |
|---|
| 31 | <cfparam name="variables.event" default="#createObject('component','fuseboxEvent').init(attributes)#" /> |
|---|
| 32 | |
|---|
| 33 | <!--- FB5: myFusebox is an object but has FB41-compatible public properties ---> |
|---|
| 34 | <cfset myFusebox = createObject("component","myFusebox").init(FUSEBOX_APPLICATION_KEY,attributes,variables) /> |
|---|
| 35 | <!--- FB5: indicates whether application was started on this request ---> |
|---|
| 36 | <cfset myFusebox.applicationStart = false /> |
|---|
| 37 | <!--- FB5: uses request.__fusebox for internal tracking of compiler / runtime operations: ---> |
|---|
| 38 | <cfset request.__fusebox = structNew() /> |
|---|
| 39 | <!--- |
|---|
| 40 | complex condition allows FB5 to drop into a running FB41 site and force re-init because |
|---|
| 41 | FB41 application.fusebox will not have compileRequest() method - this should make upgrades |
|---|
| 42 | to FB5 easier! |
|---|
| 43 | ---> |
|---|
| 44 | <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.load> |
|---|
| 45 | <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300"> |
|---|
| 46 | <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.load> |
|---|
| 47 | <!--- if it doesn't exisit or the user explicitly requested a load, it ---> |
|---|
| 48 | <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.userProvidedLoadParameter> |
|---|
| 49 | <!--- can't be conditional: we don't know the state of the debug flag yet ---> |
|---|
| 50 | <cfset myFusebox.trace("Fusebox","Creating Fusebox application object") /> |
|---|
| 51 | <cfset _fba = createObject("component","fuseboxApplication") /> |
|---|
| 52 | <cfset application[FUSEBOX_APPLICATION_KEY] = _fba.init(FUSEBOX_APPLICATION_KEY,FUSEBOX_APPLICATION_PATH,myFusebox,FUSEBOX_CALLER_PATH,FUSEBOX_PARAMETERS) /> |
|---|
| 53 | <cfelse> |
|---|
| 54 | <!--- can't be conditional: we don't know the state of the debug flag yet ---> |
|---|
| 55 | <cfset myFusebox.trace("Fusebox","Reloading Fusebox application object") /> |
|---|
| 56 | <cfset _fba = application[FUSEBOX_APPLICATION_KEY] /> |
|---|
| 57 | <!--- it exists and the load is implicit, not explicit (via user) so just reload XML ---> |
|---|
| 58 | <cfset _fba.reload(FUSEBOX_APPLICATION_KEY,FUSEBOX_APPLICATION_PATH,myFusebox,FUSEBOX_PARAMETERS) /> |
|---|
| 59 | </cfif> |
|---|
| 60 | <!--- fix attributes precedence ---> |
|---|
| 61 | <cfif _fba.precedenceFormOrURL is "URL"> |
|---|
| 62 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 63 | </cfif> |
|---|
| 64 | <!--- set the default fuseaction if necessary ---> |
|---|
| 65 | <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is ""> |
|---|
| 66 | <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction /> |
|---|
| 67 | </cfif> |
|---|
| 68 | <!--- set this up for fusebox.appinit.cfm ---> |
|---|
| 69 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 70 | <!--- flag this as the first request for the application ---> |
|---|
| 71 | <cfset myFusebox.applicationStart = true /> |
|---|
| 72 | <!--- force parse after reload for consistency in development modes ---> |
|---|
| 73 | <cfif _fba.mode is not "production" or myFusebox.parameters.userProvidedLoadParameter> |
|---|
| 74 | <cfset myFusebox.parameters.parse = true /> |
|---|
| 75 | </cfif> |
|---|
| 76 | <!--- need all of the above set before we attempt any compiles! ---> |
|---|
| 77 | <cfif myFusebox.parameters.parseall> |
|---|
| 78 | <cfset _fba.compileAll(myFusebox) /> |
|---|
| 79 | </cfif> |
|---|
| 80 | <!--- FB5: new appinit include file ---> |
|---|
| 81 | <cfif _fba.debug> |
|---|
| 82 | <cfset myFusebox.trace("Fusebox","Including fusebox.appinit.cfm") /> |
|---|
| 83 | </cfif> |
|---|
| 84 | <cftry> |
|---|
| 85 | <cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.appinit.cfm" /> |
|---|
| 86 | <cfcatch type="missinginclude" /> |
|---|
| 87 | </cftry> |
|---|
| 88 | <cfelse> |
|---|
| 89 | <cfset _fba = application[FUSEBOX_APPLICATION_KEY] /> |
|---|
| 90 | <!--- fix attributes precedence ---> |
|---|
| 91 | <cfif _fba.precedenceFormOrURL is "URL"> |
|---|
| 92 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 93 | </cfif> |
|---|
| 94 | <!--- set the default fuseaction if necessary ---> |
|---|
| 95 | <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is ""> |
|---|
| 96 | <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction /> |
|---|
| 97 | </cfif> |
|---|
| 98 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 99 | </cfif> |
|---|
| 100 | </cflock> |
|---|
| 101 | <cfelse> |
|---|
| 102 | <cfset _fba = application[FUSEBOX_APPLICATION_KEY] /> |
|---|
| 103 | <!--- fix attributes precedence ---> |
|---|
| 104 | <cfif _fba.precedenceFormOrURL is "URL"> |
|---|
| 105 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 106 | </cfif> |
|---|
| 107 | <!--- set the default fuseaction if necessary ---> |
|---|
| 108 | <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is ""> |
|---|
| 109 | <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction /> |
|---|
| 110 | </cfif> |
|---|
| 111 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 112 | </cfif> |
|---|
| 113 | <!--- |
|---|
| 114 | Fusebox 4.1 did not set attributes.fuseaction or default the fuseaction variable until |
|---|
| 115 | *after* fusebox.init.cfm had run. This made it hard for fusebox.init.cfm to do URL |
|---|
| 116 | rewriting. For Fusebox 5, we default the fuseaction variable and set attributes.fuseaction |
|---|
| 117 | before fusebox.init.cfm so it can rely on attributes.fuseaction and rewrite that. However, |
|---|
| 118 | in order to maintain backward compatibility, we need to allow fusebox.init.cfm to set |
|---|
| 119 | attributes[_fba.fuseactionVariable] and still have that reflected in attributes.fuseaction |
|---|
| 120 | and for that to actually be the request that gets processed. |
|---|
| 121 | ---> |
|---|
| 122 | <cfif _fba.debug> |
|---|
| 123 | <cfset myFusebox.trace("Fusebox","Including fusebox.init.cfm") /> |
|---|
| 124 | </cfif> |
|---|
| 125 | <cftry> |
|---|
| 126 | <cfset _fba_attr_fav = attributes[_fba.fuseactionVariable] /> |
|---|
| 127 | <cfset _fba_attr_fa = attributes.fuseaction /> |
|---|
| 128 | <cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.init.cfm" /> |
|---|
| 129 | <cfif attributes.fuseaction is not _fba_attr_fa> |
|---|
| 130 | <cfif attributes.fuseaction is not attributes[_fba.fuseactionVariable]> |
|---|
| 131 | <cfif attributes[_fba.fuseactionVariable] is not _fba_attr_fav> |
|---|
| 132 | <!--- inconsistent modification of both variables?!? ---> |
|---|
| 133 | <cfthrow type="fusebox.inconsistentFuseaction" |
|---|
| 134 | message="Inconsistent fuseaction variables" |
|---|
| 135 | detail="Both attributes.fuseaction and attributes[{fusebox}.fuseactionVariable] changed in fusebox.init.cfm so Fusebox doesn't know what to do with the values!" /> |
|---|
| 136 | <cfelse> |
|---|
| 137 | <!--- ok, only attributes.fuseaction changed ---> |
|---|
| 138 | <cfset attributes[_fba.fuseactionVariable] = attributes.fuseaction /> |
|---|
| 139 | </cfif> |
|---|
| 140 | <cfelse> |
|---|
| 141 | <!--- ok, they were both changed and they match ---> |
|---|
| 142 | </cfif> |
|---|
| 143 | <cfelse> |
|---|
| 144 | <!--- attributes.fuseaction did not change ---> |
|---|
| 145 | <cfif attributes[_fba.fuseactionVariable] is not _fba_attr_fav> |
|---|
| 146 | <!--- make attributes.fuseaction match the other changed variable ---> |
|---|
| 147 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 148 | <cfelse> |
|---|
| 149 | <!--- ok, neither variable changed ---> |
|---|
| 150 | </cfif> |
|---|
| 151 | </cfif> |
|---|
| 152 | <cfcatch type="missinginclude" /> |
|---|
| 153 | </cftry> |
|---|
| 154 | <!--- |
|---|
| 155 | must special case development-circuit-load mode since it causes circuits to reload during |
|---|
| 156 | the compile (post-load) phase and therefore must be exclusive |
|---|
| 157 | ---> |
|---|
| 158 | <cfif _fba.debug> |
|---|
| 159 | <cfset myFusebox.trace("Fusebox","Compiling requested fuseaction '#attributes.fuseaction#'") /> |
|---|
| 160 | </cfif> |
|---|
| 161 | <cfif _fba.mode is "development-circuit-load"> |
|---|
| 162 | <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300"> |
|---|
| 163 | <cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) /> |
|---|
| 164 | </cflock> |
|---|
| 165 | <cfelse> |
|---|
| 166 | <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="readonly" timeout="300"> |
|---|
| 167 | <cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) /> |
|---|
| 168 | </cflock> |
|---|
| 169 | </cfif> |
|---|
| 170 | </cfsilent><cfprocessingdirective suppresswhitespace="true"> |
|---|
| 171 | <cfif myFusebox.parameters.execute> |
|---|
| 172 | <cfif _fba.debug> |
|---|
| 173 | <cfset myFusebox.trace("Fusebox","Including parsed file for '#attributes.fuseaction#'") /> |
|---|
| 174 | </cfif> |
|---|
| 175 | <cftry> |
|---|
| 176 | <!--- |
|---|
| 177 | readonly lock protects against including the parsed file while |
|---|
| 178 | another threading is writing it... |
|---|
| 179 | ---> |
|---|
| 180 | <cflock name="#_parsedFileData.lockName#" type="readonly" timeout="30"> |
|---|
| 181 | <cfinclude template="#_parsedFileData.parsedFile#" /> |
|---|
| 182 | </cflock> |
|---|
| 183 | <cfcatch type="missinginclude"> |
|---|
| 184 | <cfif right(cfcatch.missingFileName, len(_parsedFileData.parsedName)) is _parsedFileData.parsedName> |
|---|
| 185 | <cfthrow type="fusebox.missingParsedFile" |
|---|
| 186 | message="Parsed File or Directory not found." |
|---|
| 187 | detail="Attempting to execute the parsed file '#_parsedFileData.parsedName#' threw an error. This can occur if the parsed file does not exist in the parsed directory or if the parsed directory itself is missing." /> |
|---|
| 188 | <cfelse> |
|---|
| 189 | <cfrethrow /> |
|---|
| 190 | </cfif> |
|---|
| 191 | </cfcatch> |
|---|
| 192 | </cftry> |
|---|
| 193 | </cfif> |
|---|
| 194 | </cfprocessingdirective> |
|---|
| 195 | <cfcatch type="fusebox"> |
|---|
| 196 | <cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")> |
|---|
| 197 | <cfset myFusebox.trace("Fusebox","Caught Fusebox exception '#cfcatch.type#'") /> |
|---|
| 198 | </cfif> |
|---|
| 199 | <cfif not isDefined("_fba.errortemplatesPath") or |
|---|
| 200 | not _fba.handleFuseboxException(cfcatch,attributes,myFusebox,variables.FUSEBOX_APPLICATION_KEY)> |
|---|
| 201 | <cfrethrow /> |
|---|
| 202 | </cfif> |
|---|
| 203 | </cfcatch> |
|---|
| 204 | <cfcatch type="any"> |
|---|
| 205 | <cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")> |
|---|
| 206 | <cfset myFusebox.trace("Fusebox","Request failed with exception '#cfcatch.type#' (#cfcatch.message#)") /> |
|---|
| 207 | <cfoutput>#myFusebox.renderTrace()#</cfoutput> |
|---|
| 208 | </cfif> |
|---|
| 209 | <cfrethrow /> |
|---|
| 210 | </cfcatch> |
|---|
| 211 | </cftry> |
|---|
| 212 | <cfset myFusebox.trace("Fusebox","Request completed") /> |
|---|
| 213 | <cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")> |
|---|
| 214 | <cfoutput>#myFusebox.renderTrace()#</cfoutput> |
|---|
| 215 | </cfif> |
|---|