| 1 | <cfcomponent output="false" hint="Exposes Model-Glue application to remote clients."> |
|---|
| 2 | |
|---|
| 3 | <cfset variables.locator = createObject("component", "ModelGlue.Util.ModelGlueFrameworkLocator") /> |
|---|
| 4 | |
|---|
| 5 | <cffunction name="getModelGlue" output="false"> |
|---|
| 6 | <cfset var mg = "" /> |
|---|
| 7 | |
|---|
| 8 | <!--- Bootstrap MG by invoking the main template but blocking event execution. ---> |
|---|
| 9 | <cfset request._modelglue.bootstrap.blockEvent = 1 /> |
|---|
| 10 | |
|---|
| 11 | <cfmodule template="#template#" /> |
|---|
| 12 | |
|---|
| 13 | <cfset mg = variables.locator.findInScope(application, request._modelglue.bootstrap.appKey) /> |
|---|
| 14 | |
|---|
| 15 | <cfif not arrayLen(mg)> |
|---|
| 16 | <cfthrow message="Can't locate Model-Glue instance named #request._modelglue.bootstrap.appKey# in application scope!" /> |
|---|
| 17 | </cfif> |
|---|
| 18 | |
|---|
| 19 | <cfreturn mg[1] /> |
|---|
| 20 | </cffunction> |
|---|
| 21 | |
|---|
| 22 | <cffunction name="executeEvent" output="false" access="remote" returntype="struct"> |
|---|
| 23 | <cfargument name="eventName" type="string" required="true" /> |
|---|
| 24 | <cfargument name="values" type="struct" required="true" default="#structNew()#" > |
|---|
| 25 | <cfargument name="returnValues" type="string" required="false" default="" /> |
|---|
| 26 | |
|---|
| 27 | <cfset var i = "" /> |
|---|
| 28 | <cfset var event = getModelGlue().executeEvent(argumentCollection=arguments) /> |
|---|
| 29 | <cfset var result = structNew() /> |
|---|
| 30 | |
|---|
| 31 | <cfloop list="#arguments.returnValues#" index="i"> |
|---|
| 32 | <cfset result[i] = event.getValue(i) /> |
|---|
| 33 | </cfloop> |
|---|
| 34 | |
|---|
| 35 | <cfset resetCFHtmlHead() /> |
|---|
| 36 | <cfreturn result /> |
|---|
| 37 | </cffunction> |
|---|
| 38 | |
|---|
| 39 | <!--- |
|---|
| 40 | Based on original function by Elliot Sprehn, found here |
|---|
| 41 | http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000271.htm |
|---|
| 42 | BlueDragon and Railo by Chris Blackwell |
|---|
| 43 | ---> |
|---|
| 44 | <cffunction name="resetCFHtmlHead" output="false" access="public" returntype="void"> |
|---|
| 45 | <cfset var my = structnew() /> |
|---|
| 46 | |
|---|
| 47 | <cfswitch expression="#trim(server.coldfusion.productname)#"> |
|---|
| 48 | |
|---|
| 49 | <cfcase value="ColdFusion Server"> |
|---|
| 50 | <cfset my.out = getPageContext().getOut() /> |
|---|
| 51 | |
|---|
| 52 | <!--- It's necessary to iterate over this until we get to a coldfusion.runtime.NeoJspWriter ---> |
|---|
| 53 | <cfloop condition="getMetaData(my.out).getName() is 'coldfusion.runtime.NeoBodyContent'"> |
|---|
| 54 | <cfset my.out = my.out.getEnclosingWriter() /> |
|---|
| 55 | </cfloop> |
|---|
| 56 | |
|---|
| 57 | <cfset my.method = my.out.getClass().getDeclaredMethod("initHeaderBuffer", arrayNew(1)) /> |
|---|
| 58 | <cfset my.method.setAccessible(true) /> |
|---|
| 59 | <cfset my.method.invoke(my.out, arrayNew(1)) /> |
|---|
| 60 | |
|---|
| 61 | </cfcase> |
|---|
| 62 | |
|---|
| 63 | <cfcase value="BlueDragon"> |
|---|
| 64 | |
|---|
| 65 | <cfset my.resp = getPageContext().getResponse() /> |
|---|
| 66 | |
|---|
| 67 | <cfloop condition="true"> |
|---|
| 68 | <cfset my.parentf = my.resp.getClass().getDeclaredField('parent') /> |
|---|
| 69 | <cfset my.parentf.setAccessible(true) /> |
|---|
| 70 | <cfset my.parent = my.parentf.get(my.resp) /> |
|---|
| 71 | |
|---|
| 72 | <cfif isObject(my.parent) AND getMetaData(my.parent).getName() is 'com.naryx.tagfusion.cfm.engine.cfHttpServletResponse'> |
|---|
| 73 | <cfset my.resp = my.parent /> |
|---|
| 74 | <cfelse> |
|---|
| 75 | <cfbreak /> |
|---|
| 76 | </cfif> |
|---|
| 77 | </cfloop> |
|---|
| 78 | |
|---|
| 79 | <cfset my.writer = my.resp.getClass().getDeclaredField('writer') /> |
|---|
| 80 | <cfset my.writer.setAccessible(true) /> |
|---|
| 81 | <cfset my.writer = my.writer.get(my.resp) /> |
|---|
| 82 | |
|---|
| 83 | <cfset my.headbuf = my.writer.getClass().getDeclaredField('headElement') /> |
|---|
| 84 | <cfset my.headbuf.setAccessible(true) /> |
|---|
| 85 | <cfset my.headbuf.get(my.writer).setLength(0) /> |
|---|
| 86 | |
|---|
| 87 | </cfcase> |
|---|
| 88 | |
|---|
| 89 | <cfcase value="Railo"> |
|---|
| 90 | |
|---|
| 91 | <cfset my.out = getPageContext().getOut() /> |
|---|
| 92 | |
|---|
| 93 | <cfloop condition="getMetaData(my.out).getName() is 'railo.runtime.writer.BodyContentImpl'"> |
|---|
| 94 | <cfset my.out = my.out.getEnclosingWriter() /> |
|---|
| 95 | </cfloop> |
|---|
| 96 | |
|---|
| 97 | <cfset my.headData = my.out.getClass().getDeclaredField("headData") /> |
|---|
| 98 | <cfset my.headData.setAccessible(true) /> |
|---|
| 99 | <cfset my.headData.set(my.out, createObject("java", "java.lang.String").init("")) /> |
|---|
| 100 | |
|---|
| 101 | </cfcase> |
|---|
| 102 | |
|---|
| 103 | </cfswitch> |
|---|
| 104 | |
|---|
| 105 | </cffunction> |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | </cfcomponent> |
|---|