| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | Author : Luis Majano |
|---|
| 3 | Date : September 25, 2005 |
|---|
| 4 | Description : |
|---|
| 5 | General handler for my hello application. Please remember to alter |
|---|
| 6 | your extends base component using the Coldfusion Mapping. |
|---|
| 7 | |
|---|
| 8 | example: |
|---|
| 9 | Mapping: fwsample |
|---|
| 10 | Argument Type: fwsample.system.eventhandler |
|---|
| 11 | Modification History: |
|---|
| 12 | Sep/25/2005 - Luis Majano |
|---|
| 13 | -Created the template. |
|---|
| 14 | -----------------------------------------------------------------------> |
|---|
| 15 | <cfcomponent name="ehGeneral" |
|---|
| 16 | extends="baseHandler" |
|---|
| 17 | output="false" |
|---|
| 18 | autowire="true" |
|---|
| 19 | autowire_setterinjection="false"> |
|---|
| 20 | |
|---|
| 21 | <!--- Autowire Properties ---> |
|---|
| 22 | <cfproperty name="myMailSettings" type="ioc" scope="instance"> |
|---|
| 23 | <cfproperty name="ColdBox" type="coldbox" scope="instance"> |
|---|
| 24 | <cfproperty name="ModelsPath" type="coldbox:setting:ModelsPath" scope="instance"> |
|---|
| 25 | <cfproperty name="Utilities" type="coldbox:plugin:Utilities" scope="instance"> |
|---|
| 26 | <cfproperty name="ConfigBean" type="coldbox:configbean" scope="instance"> |
|---|
| 27 | <cfproperty name="MailSettingsBean" type="coldbox:mailsettingsBean" scope="instance"> |
|---|
| 28 | <cfproperty name="MySiteDSN" type="coldbox:datasource:mysite" scope="instance"> |
|---|
| 29 | <cfproperty name="testModel" type="coldbox:model:testModel" scope="instance"> |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | <cffunction name="init" access="public" returntype="any" output="false"> |
|---|
| 33 | <cfargument name="controller" type="any" required="true"> |
|---|
| 34 | <cfset super.init(arguments.controller)> |
|---|
| 35 | <!--- Any constructor code here ---> |
|---|
| 36 | <cfreturn this> |
|---|
| 37 | </cffunction> |
|---|
| 38 | |
|---|
| 39 | <cffunction name="onApplicationStart" access="public" output="false" returntype="void"> |
|---|
| 40 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 41 | <cfset var isColdFusionMX7 = server.coldfusion.productname is "ColdFusion Server" and server.coldfusion.productversion gte 7> |
|---|
| 42 | |
|---|
| 43 | <cfset getColdboxOCM().set("isColdfusionMX7",isColdfusionMX7,0)> |
|---|
| 44 | |
|---|
| 45 | <cfif isColdfusionMX7> |
|---|
| 46 | <cfif not event.isProxyRequest()> |
|---|
| 47 | <cfset getPlugin("JavaLoader").setup( listToArray( ExpandPath("/coldbox/testharness/includes/helloworld.jar")) )> |
|---|
| 48 | </cfif> |
|---|
| 49 | </cfif> |
|---|
| 50 | |
|---|
| 51 | <cfset getColdboxOCM().set("mysiteDSNBean",getDatasource("mysite"),0)> |
|---|
| 52 | <cfset getPlugin("logger").logEntry("information","AppStart Fired")> |
|---|
| 53 | </cffunction> |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | <cffunction name="onSessionStart" access="public" output="false" returntype="void"> |
|---|
| 57 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 58 | <cfscript> |
|---|
| 59 | var logger = controller.getPlugin("logger"); |
|---|
| 60 | logger.logEntry("information","I am in the onSessionStart baby."); |
|---|
| 61 | </cfscript> |
|---|
| 62 | </cffunction> |
|---|
| 63 | |
|---|
| 64 | <cffunction name="onSessionEnd" access="public" output="false" returntype="void"> |
|---|
| 65 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 66 | <cfscript> |
|---|
| 67 | var logger = controller.getPlugin("logger"); |
|---|
| 68 | logger.logEntry("information","I am in the onSessionEnd baby."); |
|---|
| 69 | </cfscript> |
|---|
| 70 | </cffunction> |
|---|
| 71 | |
|---|
| 72 | <cffunction name="preHandler" access="public" output="false" returntype="void"> |
|---|
| 73 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 74 | <cfscript> |
|---|
| 75 | var logger = controller.getPlugin("logger"); |
|---|
| 76 | logger.logEntry("information","I am just inside the pre-handler method. #logger.getHash()#"); |
|---|
| 77 | </cfscript> |
|---|
| 78 | </cffunction> |
|---|
| 79 | |
|---|
| 80 | <cffunction name="postHandler" access="public" output="false" returntype="void"> |
|---|
| 81 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 82 | <cfscript> |
|---|
| 83 | var logger = controller.getPlugin("logger"); |
|---|
| 84 | logger.logEntry("information","I am inside the post-handler method. #logger.getHash()#"); |
|---|
| 85 | </cfscript> |
|---|
| 86 | </cffunction> |
|---|
| 87 | |
|---|
| 88 | <cffunction name="dspHello" access="public" returntype="void" output="false"> |
|---|
| 89 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 90 | <cfset var logger = controller.getPlugin("logger")> |
|---|
| 91 | <cfset var storage = controller.getPlugin("clientstorage")> |
|---|
| 92 | <cfset var complexStruct = ""> |
|---|
| 93 | <cfset var complete = ""> |
|---|
| 94 | <cfdump var="#instance#"><cfabort> |
|---|
| 95 | <!--- <cfset Event.setValue("MailBean",getmyMailSettings())> ---> |
|---|
| 96 | <cfset Event.setValue("MailBean",getmyMailSettings())> |
|---|
| 97 | |
|---|
| 98 | <cfset getPlugin("timer").start("New Instance Creation")> |
|---|
| 99 | |
|---|
| 100 | <!--- Get a new instance plugin ---> |
|---|
| 101 | <cfset event.setValue("mylogger", getPlugin("logger",false,true) )> |
|---|
| 102 | <cfset event.getValue("mylogger").setLogFullPath(ExpandPath("./config/luis.log"))> |
|---|
| 103 | <cfset getPlugin("timer").stop("New Instance Creation")> |
|---|
| 104 | |
|---|
| 105 | <!--- Create a tracer message ---> |
|---|
| 106 | <cfset logger.tracer("Starting dspHello. Using default name")> |
|---|
| 107 | <cfset logger.tracer("arguments: #arguments.toString()#")> |
|---|
| 108 | |
|---|
| 109 | <!--- Set the firstname Value ---> |
|---|
| 110 | <cfset Event.setValue("firstname",getSetting("Codename", true) & getSetting("Version", true))> |
|---|
| 111 | |
|---|
| 112 | <!--- Set another tracer variable ---> |
|---|
| 113 | <cfset logger.tracer("View has been set")> |
|---|
| 114 | |
|---|
| 115 | <!--- Create a simple permanent variable ---> |
|---|
| 116 | <cfset storage.setvar("luis","Luis Majano")> |
|---|
| 117 | |
|---|
| 118 | <!--- Permanent Complex Variable ---> |
|---|
| 119 | <cfset complexStruct = structnew()> |
|---|
| 120 | <cfset complexStruct.today = now()> |
|---|
| 121 | <cfset complexStruct.message = "This is a complex variable."> |
|---|
| 122 | <cfset complexStruct.BitFlag = "1"> |
|---|
| 123 | <cfset storage.setvar("complexStruct",complexStruct)> |
|---|
| 124 | <cfset complete = isEmail("info@coldboxframework.com")> |
|---|
| 125 | |
|---|
| 126 | <!--- Java Loader ---> |
|---|
| 127 | <cfif getColdboxOCM().lookup("isColdfusionMX7") and getColdboxOCM().get("isColdfusionMX7") eq true> |
|---|
| 128 | <cfset Event.setvalue("HelloWorldObj", getPlugin("JavaLoader").create("HelloWorld").init())> |
|---|
| 129 | </cfif> |
|---|
| 130 | |
|---|
| 131 | <!--- Create an info MessageBox ---> |
|---|
| 132 | <cfset getPlugin("messagebox").setMessage("info", "Hello and welcome to the ColdBox' message box. You can place messages here from any of your applications. You can also choose the desired image to display. You can set error message, warning messages or just plain informative messages like this one. You can do this by using the <b>messagebox</b> plugin.")> |
|---|
| 133 | |
|---|
| 134 | <!--- Get view contents ----> |
|---|
| 135 | <cfset Event.setValue("MyQuote", renderView("vwQuote"))> |
|---|
| 136 | |
|---|
| 137 | <!--- Run Private Event ---> |
|---|
| 138 | <cfset runEvent(event="ehGeneral.myPrivateEvent",private=1)> |
|---|
| 139 | |
|---|
| 140 | <!--- Set the view to render ---> |
|---|
| 141 | <cfset Event.setView(name="Hello")> |
|---|
| 142 | </cffunction> |
|---|
| 143 | |
|---|
| 144 | <cffunction name="doChangeLocale" access="public" returntype="void" output="false"> |
|---|
| 145 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 146 | <!--- Change Locale ---> |
|---|
| 147 | <cfset controller.getPlugin("i18n").setfwLocale(Event.getValue("locale"))> |
|---|
| 148 | <cfset dspHello(Event)> |
|---|
| 149 | </cffunction> |
|---|
| 150 | |
|---|
| 151 | <cffunction name="testflash" access="public" output="false" returntype="void"> |
|---|
| 152 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 153 | <cfscript> |
|---|
| 154 | var rc = event.getCollection(); |
|---|
| 155 | rc.lname = "majano"; |
|---|
| 156 | rc.fname = "luis"; |
|---|
| 157 | setNextEvent(event='ehGeneral.dspFlash',persist='lname,fname'); |
|---|
| 158 | </cfscript> |
|---|
| 159 | </cffunction> |
|---|
| 160 | |
|---|
| 161 | <cffunction name="dspFlash" access="public" output="false" returntype="void"> |
|---|
| 162 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 163 | <cfscript> |
|---|
| 164 | var rc = event.getCollection(); |
|---|
| 165 | |
|---|
| 166 | event.setView("dspFlash"); |
|---|
| 167 | </cfscript> |
|---|
| 168 | </cffunction> |
|---|
| 169 | |
|---|
| 170 | <cffunction name="doLog" access="public" returntype="void" output="false"> |
|---|
| 171 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 172 | <cfscript> |
|---|
| 173 | var logger = getPlugin("logger"); |
|---|
| 174 | var interceptorMetadata = structnew(); |
|---|
| 175 | |
|---|
| 176 | interceptorMetadata.name = "Luis Majano"; |
|---|
| 177 | interceptorMetadata.currentDateTime = now(); |
|---|
| 178 | announceInterception("onLog",interceptorMetadata); |
|---|
| 179 | |
|---|
| 180 | logger.logEntry("error","This is an error message that I logged.","Home Portals is the best."); |
|---|
| 181 | logger.logEntry("information","This is an information message that I logged."); |
|---|
| 182 | logger.logEntry("warning","This is an warning message that I logged."); |
|---|
| 183 | logger.logEntry("fatal","The whole thing crashed man"); |
|---|
| 184 | dspHello(Event); |
|---|
| 185 | </cfscript> |
|---|
| 186 | </cffunction> |
|---|
| 187 | |
|---|
| 188 | <cffunction name="doClearLog" access="public" returntype="void" output="false"> |
|---|
| 189 | <cfscript> |
|---|
| 190 | getPlugin("Utilities").removeFile(controller.getSetting("ExpandedColdboxLogsLocation")); |
|---|
| 191 | setnextevent("ehGeneral.dspHello","fwreinit=1"); |
|---|
| 192 | </cfscript> |
|---|
| 193 | </cffunction> |
|---|
| 194 | |
|---|
| 195 | <cffunction name="docustomplugin" access="public" returntype="void" output="false"> |
|---|
| 196 | <cfset var stime = getTickcount()> |
|---|
| 197 | <cfset getMyPlugin("myclientstorage").setvar("MyCustomVariable","Custom Variable has been set by custom plugin at #timeformat(now(),"HH:MM:SS TT")#.")> |
|---|
| 198 | <cfset getPlugin("logger").tracer("Testing Flash Persistance", "Total Execution Time: #getTickCount()-stime#")> |
|---|
| 199 | <cfset setNextEvent("","usecustomplugin=true")> |
|---|
| 200 | </cffunction> |
|---|
| 201 | |
|---|
| 202 | <cffunction name="doFormBean" access="public" returntype="void" output="false"> |
|---|
| 203 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 204 | <cfscript> |
|---|
| 205 | var rc = Event.getCollection(); |
|---|
| 206 | //populate bean |
|---|
| 207 | rc.FormBean = controller.getPlugin("beanfactory").populateBean("#controller.getSetting("AppMapping")#.model.formBean"); |
|---|
| 208 | Event.setView("vwFormBean"); |
|---|
| 209 | </cfscript> |
|---|
| 210 | </cffunction> |
|---|
| 211 | |
|---|
| 212 | <cffunction name="purgeEvents" access="public" returntype="void" output="false"> |
|---|
| 213 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 214 | <cfscript> |
|---|
| 215 | getColdboxOCM().clearAllEvents(); |
|---|
| 216 | setNextEvent(); |
|---|
| 217 | </cfscript> |
|---|
| 218 | </cffunction> |
|---|
| 219 | |
|---|
| 220 | <cffunction name="dspFolderTester1" access="public" returntype="void" output="false" cache="true" cacheTimeout="5"> |
|---|
| 221 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 222 | <cfscript> |
|---|
| 223 | var rc = Event.getCollection(); |
|---|
| 224 | Event.setView("tags/test1"); |
|---|
| 225 | </cfscript> |
|---|
| 226 | </cffunction> |
|---|
| 227 | |
|---|
| 228 | <cffunction name="dspFolderTester2" access="public" returntype="void" output="false" cache="true" cacheTimeout="5"> |
|---|
| 229 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 230 | <cfscript> |
|---|
| 231 | var rc = Event.getCollection(); |
|---|
| 232 | Event.setView("pdf/single/test"); |
|---|
| 233 | </cfscript> |
|---|
| 234 | </cffunction> |
|---|
| 235 | |
|---|
| 236 | <!--- externalView ---> |
|---|
| 237 | <cffunction name="externalView" access="public" returntype="void" output="false" hint=""> |
|---|
| 238 | <cfargument name="Event" type="coldbox.system.beans.requestContext" required="yes"> |
|---|
| 239 | |
|---|
| 240 | <cfset event.setView('externalview')> |
|---|
| 241 | </cffunction> |
|---|
| 242 | |
|---|
| 243 | <!--- display login form (testing security interceptor) ---> |
|---|
| 244 | <cffunction name="dspLogin" access="public" returntype="Void" output="false"> |
|---|
| 245 | <cfargument name="Event" type="coldbox.system.beans.requestContext" required="yes"> |
|---|
| 246 | <cfset var rc = event.getCollection()> |
|---|
| 247 | <!--- testing secure handlers/methods ---> |
|---|
| 248 | <cfset event.setView('vwLoginForm')> |
|---|
| 249 | </cffunction> |
|---|
| 250 | |
|---|
| 251 | <!------------------------------------------- PRIVATE METHDOS -------------------------------------------> |
|---|
| 252 | |
|---|
| 253 | <cffunction name="getmyMailSettings" access="public" output="false" returntype="any" hint="Get myMailSettings"> |
|---|
| 254 | <cfreturn instance.myMailSettings/> |
|---|
| 255 | </cffunction> |
|---|
| 256 | <cffunction name="setmyMailSettings" access="public" output="false" returntype="void" hint="Set myMailSettings"> |
|---|
| 257 | <cfargument name="myMailSettings" type="any" required="true"/> |
|---|
| 258 | <cfset instance.myMailSettings = arguments.myMailSettings/> |
|---|
| 259 | </cffunction> |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | <cffunction name="myPrivateEvent" access="private" returntype="void" output="false"> |
|---|
| 263 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 264 | <cfscript> |
|---|
| 265 | var rc = Event.getCollection(); |
|---|
| 266 | /* Private */ |
|---|
| 267 | rc.privateEventCalled = true; |
|---|
| 268 | </cfscript> |
|---|
| 269 | </cffunction> |
|---|
| 270 | |
|---|
| 271 | </cfcomponent> |
|---|