| 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 | |
|---|
| 25 | <cfparam name="variables.attributes" default="#structNew()#" /> |
|---|
| 26 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 27 | <cfset structAppend(attributes,form,true) /> |
|---|
| 28 | <!--- FB51: ticket 164: add OO synonym for attributes scope ---> |
|---|
| 29 | <cfparam name="variables.event" default="#createObject('component','fuseboxEvent').init(attributes)#" /> |
|---|
| 30 | |
|---|
| 31 | <!--- FB5: myFusebox is an object but has FB41-compatible public properties ---> |
|---|
| 32 | <cfset myFusebox = createObject("component","myFusebox").init(FUSEBOX_APPLICATION_KEY,attributes) /> |
|---|
| 33 | <!--- FB5: indicates whether application was started on this request ---> |
|---|
| 34 | <cfset myFusebox.applicationStart = false /> |
|---|
| 35 | <!--- FB5: uses request.__fusebox for internal tracking of compiler / runtime operations: ---> |
|---|
| 36 | <cfset request.__fusebox = structNew() /> |
|---|
| 37 | <!--- |
|---|
| 38 | complex condition allows FB5 to drop into a running FB41 site and force re-init because |
|---|
| 39 | FB41 application.fusebox will not have compileRequest() method - this should make upgrades |
|---|
| 40 | to FB5 easier! |
|---|
| 41 | ---> |
|---|
| 42 | <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.load> |
|---|
| 43 | <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300"> |
|---|
| 44 | <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.load> |
|---|
| 45 | <!--- if it doesn't exisit or the user explicitly requested a load, it ---> |
|---|
| 46 | <cfif not structKeyExists(application,FUSEBOX_APPLICATION_KEY) or myFusebox.parameters.userProvidedLoadParameter> |
|---|
| 47 | <!--- can't be conditional: we don't know the state of the debug flag yet ---> |
|---|
| 48 | <cfset myFusebox.trace("Fusebox","Creating Fusebox application object") /> |
|---|
| 49 | <cfset _fba = createObject("component","fuseboxApplication") /> |
|---|
| 50 | <cfset application[FUSEBOX_APPLICATION_KEY] = _fba.init(FUSEBOX_APPLICATION_KEY,FUSEBOX_APPLICATION_PATH,myFusebox,FUSEBOX_CALLER_PATH) /> |
|---|
| 51 | <cfelse> |
|---|
| 52 | <!--- can't be conditional: we don't know the state of the debug flag yet ---> |
|---|
| 53 | <cfset myFusebox.trace("Fusebox","Reloading Fusebox application object") /> |
|---|
| 54 | <cfset _fba = application[FUSEBOX_APPLICATION_KEY] /> |
|---|
| 55 | <!--- it exists and the load is implicit, not explicit (via user) so just reload XML ---> |
|---|
| 56 | <cfset _fba.reload(FUSEBOX_APPLICATION_KEY,FUSEBOX_APPLICATION_PATH,myFusebox) /> |
|---|
| 57 | </cfif> |
|---|
| 58 | <!--- fix attributes precedence ---> |
|---|
| 59 | <cfif _fba.precedenceFormOrURL is "URL"> |
|---|
| 60 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 61 | </cfif> |
|---|
| 62 | <!--- set the default fuseaction if necessary ---> |
|---|
| 63 | <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is ""> |
|---|
| 64 | <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction /> |
|---|
| 65 | </cfif> |
|---|
| 66 | <!--- set this up for fusebox.appinit.cfm ---> |
|---|
| 67 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 68 | <!--- flag this as the first request for the application ---> |
|---|
| 69 | <cfset myFusebox.applicationStart = true /> |
|---|
| 70 | <!--- force parse after reload for consistency in development modes ---> |
|---|
| 71 | <cfif _fba.mode is not "production" or myFusebox.parameters.userProvidedLoadParameter> |
|---|
| 72 | <cfset myFusebox.parameters.parse = true /> |
|---|
| 73 | </cfif> |
|---|
| 74 | <!--- need all of the above set before we attempt any compiles! ---> |
|---|
| 75 | <cfif myFusebox.parameters.parseall> |
|---|
| 76 | <cfset _fba.compileAll(myFusebox) /> |
|---|
| 77 | </cfif> |
|---|
| 78 | <!--- FB5: new appinit include file ---> |
|---|
| 79 | <cfif _fba.debug> |
|---|
| 80 | <cfset myFusebox.trace("Fusebox","Including fusebox.appinit.cfm") /> |
|---|
| 81 | </cfif> |
|---|
| 82 | <cftry> |
|---|
| 83 | <cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.appinit.cfm" /> |
|---|
| 84 | <cfcatch type="missinginclude" /> |
|---|
| 85 | </cftry> |
|---|
| 86 | <cfelse> |
|---|
| 87 | <cfset _fba = application[FUSEBOX_APPLICATION_KEY] /> |
|---|
| 88 | <!--- fix attributes precedence ---> |
|---|
| 89 | <cfif _fba.precedenceFormOrURL is "URL"> |
|---|
| 90 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 91 | </cfif> |
|---|
| 92 | <!--- set the default fuseaction if necessary ---> |
|---|
| 93 | <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is ""> |
|---|
| 94 | <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction /> |
|---|
| 95 | </cfif> |
|---|
| 96 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 97 | </cfif> |
|---|
| 98 | </cflock> |
|---|
| 99 | <cfelse> |
|---|
| 100 | <cfset _fba = application[FUSEBOX_APPLICATION_KEY] /> |
|---|
| 101 | <!--- fix attributes precedence ---> |
|---|
| 102 | <cfif _fba.precedenceFormOrURL is "URL"> |
|---|
| 103 | <cfset structAppend(attributes,URL,true) /> |
|---|
| 104 | </cfif> |
|---|
| 105 | <!--- set the default fuseaction if necessary ---> |
|---|
| 106 | <cfif not structKeyExists(attributes,_fba.fuseactionVariable) or attributes[_fba.fuseactionVariable] is ""> |
|---|
| 107 | <cfset attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction /> |
|---|
| 108 | </cfif> |
|---|
| 109 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 110 | </cfif> |
|---|
| 111 | <!--- |
|---|
| 112 | Fusebox 4.1 did not set attributes.fuseaction or default the fuseaction variable until |
|---|
| 113 | *after* fusebox.init.cfm had run. This made it hard for fusebox.init.cfm to do URL |
|---|
| 114 | rewriting. For Fusebox 5, we default the fuseaction variable and set attributes.fuseaction |
|---|
| 115 | before fusebox.init.cfm so it can rely on attributes.fuseaction and rewrite that. However, |
|---|
| 116 | in order to maintain backward compatibility, we need to allow fusebox.init.cfm to set |
|---|
| 117 | attributes[_fba.fuseactionVariable] and still have that reflected in attributes.fuseaction |
|---|
| 118 | and for that to actually be the request that gets processed. |
|---|
| 119 | ---> |
|---|
| 120 | <cfif _fba.debug> |
|---|
| 121 | <cfset myFusebox.trace("Fusebox","Including fusebox.init.cfm") /> |
|---|
| 122 | </cfif> |
|---|
| 123 | <cftry> |
|---|
| 124 | <cfset _fba_attr_fav = attributes[_fba.fuseactionVariable] /> |
|---|
| 125 | <cfset _fba_attr_fa = attributes.fuseaction /> |
|---|
| 126 | <cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.init.cfm" /> |
|---|
| 127 | <cfif attributes.fuseaction is not _fba_attr_fa> |
|---|
| 128 | <cfif attributes.fuseaction is not attributes[_fba.fuseactionVariable]> |
|---|
| 129 | <cfif attributes[_fba.fuseactionVariable] is not _fba_attr_fav> |
|---|
| 130 | <!--- inconsistent modification of both variables?!? ---> |
|---|
| 131 | <cfthrow type="fusebox.inconsistentFuseaction" |
|---|
| 132 | message="Inconsistent fuseaction variables" |
|---|
| 133 | detail="Both attributes.fuseaction and attributes[{fusebox}.fuseactionVariable] changed in fusebox.init.cfm so Fusebox doesn't know what to do with the values!" /> |
|---|
| 134 | <cfelse> |
|---|
| 135 | <!--- ok, only attributes.fuseaction changed ---> |
|---|
| 136 | <cfset attributes[_fba.fuseactionVariable] = attributes.fuseaction /> |
|---|
| 137 | </cfif> |
|---|
| 138 | <cfelse> |
|---|
| 139 | <!--- ok, they were both changed and they match ---> |
|---|
| 140 | </cfif> |
|---|
| 141 | <cfelse> |
|---|
| 142 | <!--- attributes.fuseaction did not change ---> |
|---|
| 143 | <cfif attributes[_fba.fuseactionVariable] is not _fba_attr_fav> |
|---|
| 144 | <!--- make attributes.fuseaction match the other changed variable ---> |
|---|
| 145 | <cfset attributes.fuseaction = attributes[_fba.fuseactionVariable] /> |
|---|
| 146 | <cfelse> |
|---|
| 147 | <!--- ok, neither variable changed ---> |
|---|
| 148 | </cfif> |
|---|
| 149 | </cfif> |
|---|
| 150 | <cfcatch type="missinginclude" /> |
|---|
| 151 | </cftry> |
|---|
| 152 | <!--- |
|---|
| 153 | must special case development-circuit-load mode since it causes circuits to reload during |
|---|
| 154 | the compile (post-load) phase and therefore must be exclusive |
|---|
| 155 | ---> |
|---|
| 156 | <cfif _fba.debug> |
|---|
| 157 | <cfset myFusebox.trace("Fusebox","Compiling requested fuseaction '#attributes.fuseaction#'") /> |
|---|
| 158 | </cfif> |
|---|
| 159 | <cfif _fba.mode is "development-circuit-load"> |
|---|
| 160 | <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300"> |
|---|
| 161 | <cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) /> |
|---|
| 162 | </cflock> |
|---|
| 163 | <cfelse> |
|---|
| 164 | <cflock name="#application.ApplicationName#_fusebox_#FUSEBOX_APPLICATION_KEY#" type="readonly" timeout="300"> |
|---|
| 165 | <cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) /> |
|---|
| 166 | </cflock> |
|---|
| 167 | </cfif> |
|---|
| 168 | </cfsilent><cfprocessingdirective suppresswhitespace="true"> |
|---|
| 169 | <cfif myFusebox.parameters.execute> |
|---|
| 170 | <cfif _fba.debug> |
|---|
| 171 | <cfset myFusebox.trace("Fusebox","Including parsed file for '#attributes.fuseaction#'") /> |
|---|
| 172 | </cfif> |
|---|
| 173 | <cftry> |
|---|
| 174 | <!--- |
|---|
| 175 | readonly lock protects against including the parsed file while |
|---|
| 176 | another threading is writing it... |
|---|
| 177 | ---> |
|---|
| 178 | <cflock name="#_parsedFileData.lockName#" type="readonly" timeout="30"> |
|---|
| 179 | <cfinclude template="#_parsedFileData.parsedFile#" /> |
|---|
| 180 | </cflock> |
|---|
| 181 | <cfcatch type="missinginclude"> |
|---|
| 182 | <cfif right(cfcatch.missingFileName, len(_parsedFileData.parsedName)) is _parsedFileData.parsedName> |
|---|
| 183 | <cfthrow type="fusebox.missingParsedFile" |
|---|
| 184 | message="Parsed File or Directory not found." |
|---|
| 185 | 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." /> |
|---|
| 186 | <cfelse> |
|---|
| 187 | <cfrethrow /> |
|---|
| 188 | </cfif> |
|---|
| 189 | </cfcatch> |
|---|
| 190 | </cftry> |
|---|
| 191 | </cfif> |
|---|
| 192 | </cfprocessingdirective> |
|---|
| 193 | <cfcatch type="fusebox"> |
|---|
| 194 | <cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")> |
|---|
| 195 | <cfset myFusebox.trace("Fusebox","Caught Fusebox exception '#cfcatch.type#'") /> |
|---|
| 196 | </cfif> |
|---|
| 197 | <cfif not isDefined("_fba.errortemplatesPath") or |
|---|
| 198 | not _fba.handleFuseboxException(cfcatch,attributes,myFusebox,variables.FUSEBOX_APPLICATION_KEY)> |
|---|
| 199 | <cfrethrow /> |
|---|
| 200 | </cfif> |
|---|
| 201 | </cfcatch> |
|---|
| 202 | </cftry> |
|---|
| 203 | <cfset myFusebox.trace("Fusebox","Request completed") /> |
|---|
| 204 | <cfif isDefined("_fba.debug") and _fba.debug and isDefined("myFusebox")> |
|---|
| 205 | <cfoutput>#myFusebox.renderTrace()#</cfoutput> |
|---|
| 206 | </cfif> |
|---|