| 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" extends="coldbox.system.eventhandler"> |
|---|
| 16 | |
|---|
| 17 | <!--- ************************************************************* ---> |
|---|
| 18 | |
|---|
| 19 | <cffunction name="init" access="public" returntype="any" output="false"> |
|---|
| 20 | <cfargument name="controller" type="any" required="true"> |
|---|
| 21 | <cfset super.init(arguments.controller)> |
|---|
| 22 | <!--- Any constructor code here ---> |
|---|
| 23 | <cfreturn this> |
|---|
| 24 | </cffunction> |
|---|
| 25 | |
|---|
| 26 | <!--- ************************************************************* ---> |
|---|
| 27 | |
|---|
| 28 | <cffunction name="onRequestStart" access="public" output="false" returntype="void"> |
|---|
| 29 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 30 | </cffunction> |
|---|
| 31 | |
|---|
| 32 | <!--- ************************************************************* ---> |
|---|
| 33 | |
|---|
| 34 | <cffunction name="onApplicationStart" access="public" output="false" returntype="void"> |
|---|
| 35 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 36 | <cfset var isColdFusionMX7 = server.coldfusion.productname is "ColdFusion Server" and server.coldfusion.productversion gte 7> |
|---|
| 37 | <cfset var loader = ""> |
|---|
| 38 | |
|---|
| 39 | <cfset getColdboxOCM().set("isColdfusionMX7",isColdfusionMX7,0)> |
|---|
| 40 | |
|---|
| 41 | <cfif isColdfusionMX7> |
|---|
| 42 | <cfset loader = getPlugin("JavaLoader").setup("includes/helloworld.jar")> |
|---|
| 43 | <cfset getColdboxOCM().set("loader",loader,0)> |
|---|
| 44 | </cfif> |
|---|
| 45 | |
|---|
| 46 | <cfset getColdboxOCM().set("mysiteDSNBean",getDatasource("mysite"),0)> |
|---|
| 47 | </cffunction> |
|---|
| 48 | |
|---|
| 49 | <!--- ************************************************************* ---> |
|---|
| 50 | |
|---|
| 51 | <cffunction name="onRequestEnd" access="public" output="false" returntype="void"> |
|---|
| 52 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 53 | </cffunction> |
|---|
| 54 | |
|---|
| 55 | <!--- ************************************************************* ---> |
|---|
| 56 | |
|---|
| 57 | <cffunction name="onSessionStart" access="public" output="false" returntype="void"> |
|---|
| 58 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 59 | <cfscript> |
|---|
| 60 | var logger = controller.getPlugin("logger"); |
|---|
| 61 | logger.logEntry("information","I am in the onSessionStart baby."); |
|---|
| 62 | //set the default event to fire or relocate. |
|---|
| 63 | setNextEvent(); |
|---|
| 64 | </cfscript> |
|---|
| 65 | </cffunction> |
|---|
| 66 | |
|---|
| 67 | <!--- ************************************************************* ---> |
|---|
| 68 | |
|---|
| 69 | <cffunction name="preHandler" access="public" output="false" returntype="void"> |
|---|
| 70 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 71 | <cfscript> |
|---|
| 72 | var logger = controller.getPlugin("logger"); |
|---|
| 73 | logger.logEntry("information","I am just inside the pre-handler method. #logger.getHash()#"); |
|---|
| 74 | </cfscript> |
|---|
| 75 | </cffunction> |
|---|
| 76 | |
|---|
| 77 | <cffunction name="postHandler" access="public" output="false" returntype="void"> |
|---|
| 78 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 79 | <cfscript> |
|---|
| 80 | var logger = controller.getPlugin("logger"); |
|---|
| 81 | logger.logEntry("information","I am inside the post-handler method. #logger.getHash()#"); |
|---|
| 82 | </cfscript> |
|---|
| 83 | </cffunction> |
|---|
| 84 | |
|---|
| 85 | <!--- ************************************************************* ---> |
|---|
| 86 | |
|---|
| 87 | <cffunction name="dspHello" access="public" returntype="void" output="false"> |
|---|
| 88 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 89 | <cfset var logger = controller.getPlugin("logger")> |
|---|
| 90 | <cfset var storage = controller.getPlugin("clientstorage")> |
|---|
| 91 | <cfset var complexStruct = ""> |
|---|
| 92 | <cfset var complete = ""> |
|---|
| 93 | |
|---|
| 94 | <cfset Event.setValue("MailBean",getMailSettings())> |
|---|
| 95 | |
|---|
| 96 | <cfset getPlugin("timer").start("New Instance Creation")> |
|---|
| 97 | <!--- Get a new instance plugin ---> |
|---|
| 98 | <cfset event.setValue("mylogger", getPlugin("logger",false,true) )> |
|---|
| 99 | <cfset event.getValue("mylogger").setLogFullPath(ExpandPath("./config/luis.log"))> |
|---|
| 100 | <cfset getPlugin("timer").stop("New Instance Creation")> |
|---|
| 101 | |
|---|
| 102 | <!--- Create a tracer message ---> |
|---|
| 103 | <cfset logger.tracer("Starting dspHello. Using default name")> |
|---|
| 104 | |
|---|
| 105 | <cfset logger.tracer("arguments: #arguments.toString()#")> |
|---|
| 106 | |
|---|
| 107 | <!--- Set the firstname Value ---> |
|---|
| 108 | <cfset Event.setValue("firstname",controller.getSetting("Codename", true) & controller.getSetting("Version", true))> |
|---|
| 109 | |
|---|
| 110 | <!--- Set another tracer variable ---> |
|---|
| 111 | <cfset logger.tracer("View has been set")> |
|---|
| 112 | |
|---|
| 113 | <!--- Create a simple permanent variable ---> |
|---|
| 114 | <cfset storage.setvar("luis","Luis Majano")> |
|---|
| 115 | |
|---|
| 116 | <!--- Permanent Complex Variable ---> |
|---|
| 117 | <cfset complexStruct = structnew()> |
|---|
| 118 | <cfset complexStruct.today = now()> |
|---|
| 119 | <cfset complexStruct.message = "This is a complex variable."> |
|---|
| 120 | <cfset complexStruct.BitFlag = "1"> |
|---|
| 121 | <cfset storage.setvar("complexStruct",complexStruct)> |
|---|
| 122 | <cfset complete = isEmail("info@coldboxframework.com")> |
|---|
| 123 | |
|---|
| 124 | <!--- Java Loader ---> |
|---|
| 125 | <cfset getPlugin("logger").logEntry("error","isColdfusionMX7 : #getColdboxOCM().get("isColdfusionMX7")#")> |
|---|
| 126 | <cfif getColdboxOCM().get("isColdfusionMX7") eq true> |
|---|
| 127 | <cfset Event.setvalue("HelloWorldObj", getColdboxOCM().get("loader").create("HelloWorld").init())> |
|---|
| 128 | </cfif> |
|---|
| 129 | |
|---|
| 130 | <!--- Create an info MessageBox ---> |
|---|
| 131 | <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.")> |
|---|
| 132 | |
|---|
| 133 | <!--- Get view contents ----> |
|---|
| 134 | <cfset Event.setValue("MyQuote", renderView("vwQuote"))> |
|---|
| 135 | <!--- Set the view to render, done via config now. |
|---|
| 136 | <cfset Event.setView("vwHello")>---> |
|---|
| 137 | </cffunction> |
|---|
| 138 | |
|---|
| 139 | <!--- ************************************************************* ---> |
|---|
| 140 | |
|---|
| 141 | <cffunction name="doChangeLocale" access="public" returntype="void" output="false"> |
|---|
| 142 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 143 | <!--- Change Locale ---> |
|---|
| 144 | <cfset controller.getPlugin("i18n").setfwLocale(Event.getValue("locale"))> |
|---|
| 145 | <cfset dspHello(Event)> |
|---|
| 146 | </cffunction> |
|---|
| 147 | |
|---|
| 148 | <!--- ************************************************************* ---> |
|---|
| 149 | |
|---|
| 150 | <cffunction name="testflash" access="public" output="false" returntype="void"> |
|---|
| 151 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 152 | <cfscript> |
|---|
| 153 | var rc = event.getCollection(); |
|---|
| 154 | rc.lname = "majano"; |
|---|
| 155 | rc.fname = "luis"; |
|---|
| 156 | setNextEvent(event='ehGeneral.dspHello',persist='lname,fname'); |
|---|
| 157 | </cfscript> |
|---|
| 158 | </cffunction> |
|---|
| 159 | |
|---|
| 160 | <cffunction name="doLog" access="public" returntype="void" output="false"> |
|---|
| 161 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 162 | <cfscript> |
|---|
| 163 | var logger = getPlugin("logger"); |
|---|
| 164 | logger.logEntry("error","This is an error message that I logged.","Home Portals is the best."); |
|---|
| 165 | logger.logEntry("information","This is an information message that I logged."); |
|---|
| 166 | logger.logEntry("warning","This is an warning message that I logged."); |
|---|
| 167 | logger.logEntry("fatal","The whole thing crashed man"); |
|---|
| 168 | dspHello(Event); |
|---|
| 169 | </cfscript> |
|---|
| 170 | </cffunction> |
|---|
| 171 | |
|---|
| 172 | <cffunction name="doClearLog" access="public" returntype="void" output="false"> |
|---|
| 173 | <cfscript> |
|---|
| 174 | controller.getPlugin("fileUtilities").removeFile(controller.getSetting("ColdboxLogsLocation")); |
|---|
| 175 | controller.setnextevent("ehGeneral.dspHello","fwreinit=1"); |
|---|
| 176 | </cfscript> |
|---|
| 177 | </cffunction> |
|---|
| 178 | |
|---|
| 179 | <cffunction name="docustomplugin" access="public" returntype="void" output="false"> |
|---|
| 180 | <cfset controller.getMyPlugin("myclientstorage").setvar("MyCustomVariable","Custom Variable has been set by custom plugin at #timeformat(now(),"HH:MM:SS TT")#.")> |
|---|
| 181 | <cfset controller.setNextEvent("","usecustomplugin=true")> |
|---|
| 182 | </cffunction> |
|---|
| 183 | |
|---|
| 184 | <cffunction name="doFormBean" access="public" returntype="void" output="false"> |
|---|
| 185 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 186 | <cfscript> |
|---|
| 187 | var rc = Event.getCollection(); |
|---|
| 188 | //populate bean |
|---|
| 189 | rc.FormBean = controller.getPlugin("beanfactory").populateBean("#controller.getSetting("AppMapping")#.model.formBean"); |
|---|
| 190 | Event.setView("vwFormBean"); |
|---|
| 191 | </cfscript> |
|---|
| 192 | </cffunction> |
|---|
| 193 | |
|---|
| 194 | <cffunction name="doColdboxFactoryTests" access="public" returntype="any" hint="" output="false" > |
|---|
| 195 | <cfargument name="Event" type="coldbox.system.beans.requestContext"> |
|---|
| 196 | <cfscript> |
|---|
| 197 | var rc = event.getCollection(); |
|---|
| 198 | |
|---|
| 199 | rc.testModel = getPlugin("ioc").getBean("testModel"); |
|---|
| 200 | |
|---|
| 201 | event.setView("coldboxfactory"); |
|---|
| 202 | </cfscript> |
|---|
| 203 | </cffunction> |
|---|
| 204 | |
|---|
| 205 | </cfcomponent> |
|---|