| Package: MachII.framework |
| Handles view display for an EventContext. |
<!--- License: Copyright 2008 GreatBizTools, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright: GreatBizTools, LLC Author: Ben Edwards (ben@ben-edwards.com) $Id: ViewContext.cfc 1087 2008-09-25 23:31:51Z peterfarrell $ Created version: 1.0.0 Updated version: 1.6.0 Notes: ---> |
| Method Summary | |
|---|---|
| public ViewContext |
init(AppManager appManager)
Used by the framework for initialization. Do not override. |
| public void |
addHTMLHeadElement(string text)
Adds a HTML head element. |
| public void |
addHTTPHeader([string name], [string value], [numeric statusCode], [string statusText], [string charset])
Adds a HTTP header. You must use named arguments or addHTTPHeaderByName/addHTTPHeaderByStatus helper methods. |
| public void |
addHTTPHeaderByName(string name, string value, [string charset])
Adds a HTTP header by name/value. |
| public void |
addHTTPHeaderByStatus(string statuscode, [string statustext])
Adds a HTTP header by statusCode/statusText. |
| public string |
buildUrl(string eventName, [any urlParameters=""], [string urlBase])
Builds a framework specific url and automatically escapes entities for html display. |
| public string |
buildUrlToModule(string moduleName, string eventName, [any urlParameters=""], [string urlBase])
Builds a framework specific url with module name and automatically escapes entities for html display. |
| public void |
displayView(Event event, string viewName, [string contentKey=""], [string contentArg=""], [boolean append="false"])
Displays a view by view name and peforms contentKey, contentArg and append functions. |
| public AppManager |
getAppManager()
Gets the AppManager instance this ViewContext belongs to. |
| private string |
getFullPath(string viewName)
Gets the full path of a view by view name from the view manager. |
| public Log |
getLog()
Gets the log. |
| public any |
getProperty(string propertyName)
Gets the specified property - this is just a shortcut for getAppManager().getPropertyManager().getProperty() |
| public PropertyManager |
getPropertyManager()
Gets the components PropertyManager instance. |
| private void |
setAppManager(AppManager appManager)
Sets the AppManager instance this ViewContext belongs to. |
| public void |
setLog(LogFactory logFactory)
Uses the log factory to create a log. |
| public void |
setProperty(string propertyName, any propertyValue)
Sets the specified property - this is just a shortcut for getAppManager().getPropertyManager().setProperty() |
| private void |
setPropertyManager(PropertyManager propertyManager)
Sets the components PropertyManager instance. |
| Method Detail |
|---|
| addHTMLHeadElement |
|---|
public void addHTMLHeadElement( string text )
Adds a HTML head element.
Parameters:
| string text |
Code:
<cffunction name="addHTMLHeadElement" access="public" returntype="void" output="false" hint="Adds a HTML head element."> <cfargument name="text" type="string" required="true" /> <cfset var appKey = getAppManager().getAppKey() /> <cfif StructKeyExists(request, "_MachIIRequestHandler_" & appKey)> <cfset request["_MachIIRequestHandler_" & appKey].getEventContext().addHTMLHeadElement(arguments.text) /> <cfelse> <cfthrow message="The required RequestHandler is necessary to add HTML head elements is not set in 'request['_MachIIRequestHandler_#appKey#']'." /> </cfif> </cffunction>
| addHTTPHeader |
|---|
public void addHTTPHeader( [string name], [string value], [numeric statusCode], [string statusText], [string charset] )
Adds a HTTP header. You must use named arguments or addHTTPHeaderByName/addHTTPHeaderByStatus helper methods.
Parameters:
| [string name] |
| [string value] |
| [numeric statusCode] |
| [string statusText] |
| [string charset] |
Code:
<cffunction name="addHTTPHeader" access="public" returntype="void" output="false" hint="Adds a HTTP header. You must use named arguments or addHTTPHeaderByName/addHTTPHeaderByStatus helper methods."> <cfargument name="name" type="string" required="false" /> <cfargument name="value" type="string" required="false" /> <cfargument name="statusCode" type="numeric" required="false" /> <cfargument name="statusText" type="string" required="false" /> <cfargument name="charset" type="string" required="false" /> <cfset var appKey = getAppManager().getAppKey() /> <cfif StructKeyExists(request, "_MachIIRequestHandler_" & appKey)> <cfset request["_MachIIRequestHandler_" & appKey].getEventContext().addHTTPHeader(argumentcollection=arguments) /> <cfelse> <cfthrow message="The required RequestHandler is necessary to add HTTP headers is not set in 'request['_MachIIRequestHandler_#appKey#']'." /> </cfif> </cffunction>
| addHTTPHeaderByName |
|---|
public void addHTTPHeaderByName( string name, string value, [string charset] )
Adds a HTTP header by name/value.
Parameters:
| string name |
| string value |
| [string charset] |
Code:
<cffunction name="addHTTPHeaderByName" access="public" returntype="void" output="false" hint="Adds a HTTP header by name/value."> <cfargument name="name" type="string" required="true" /> <cfargument name="value" type="string" required="true" /> <cfargument name="charset" type="string" required="false" /> <cfset addHTTPHeader(argumentcollection=arguments) /> </cffunction>
| addHTTPHeaderByStatus |
|---|
public void addHTTPHeaderByStatus( string statuscode, [string statustext] )
Adds a HTTP header by statusCode/statusText.
Parameters:
| string statuscode |
| [string statustext] |
Code:
<cffunction name="addHTTPHeaderByStatus" access="public" returntype="void" output="false" hint="Adds a HTTP header by statusCode/statusText."> <cfargument name="statuscode" type="string" required="true" /> <cfargument name="statustext" type="string" required="false" /> <cfset addHTTPHeader(argumentcollection=arguments) /> </cffunction>
| buildUrl |
|---|
public string buildUrl( string eventName, [any urlParameters=""], [string urlBase] )
Builds a framework specific url and automatically escapes entities for html display.
Parameters:
| string eventName |
| [any urlParameters=""] |
| [string urlBase] |
Code:
<cffunction name="buildUrl" access="public" returntype="string" output="false" hint="Builds a framework specific url and automatically escapes entities for html display."> <cfargument name="eventName" type="string" required="true" hint="Name of the event to build the url with." /> <cfargument name="urlParameters" type="any" required="false" default="" hint="Name/value pairs (urlArg1=value1|urlArg2=value2) to build the url with or a struct of data." /> <cfargument name="urlBase" type="string" required="false" hint="Base of the url. Defaults to the value of the urlBase property." /> <cfset arguments.moduleName = getAppManager().getModuleName() /> <cfreturn HtmlEditFormat(getAppManager().getRequestManager().buildUrl(argumentcollection=arguments)) /> </cffunction>
| buildUrlToModule |
|---|
public string buildUrlToModule( string moduleName, string eventName, [any urlParameters=""], [string urlBase] )
Builds a framework specific url with module name and automatically escapes entities for html display.
Parameters:
| string moduleName |
| string eventName |
| [any urlParameters=""] |
| [string urlBase] |
Code:
<cffunction name="buildUrlToModule" access="public" returntype="string" output="false" hint="Builds a framework specific url with module name and automatically escapes entities for html display."> <cfargument name="moduleName" type="string" required="true" hint="Name of the module to build the url with. Defaults to current module if empty string." /> <cfargument name="eventName" type="string" required="true" hint="Name of the event to build the url with." /> <cfargument name="urlParameters" type="any" required="false" default="" hint="Name/value pairs (urlArg1=value1|urlArg2=value2) to build the url with or a struct of data." /> <cfargument name="urlBase" type="string" required="false" hint="Base of the url. Defaults to the value of the urlBase property." /> <cfreturn HtmlEditFormat(getAppManager().getRequestManager().buildUrl(argumentcollection=arguments)) /> </cffunction>
| displayView |
|---|
public void displayView( Event event, string viewName, [string contentKey=""], [string contentArg=""], [boolean append="false"] )
Displays a view by view name and peforms contentKey, contentArg and append functions.
Parameters:
| Event event |
| string viewName |
| [string contentKey=""] |
| [string contentArg=""] |
| [boolean append="false"] |
Code:
<cffunction name="displayView" access="public" returntype="void" output="true"
hint="Displays a view by view name and peforms contentKey, contentArg and append functions.">
<cfargument name="event" type="MachII.framework.Event" required="true"
hint="The current Event object." />
<cfargument name="viewName" type="string" required="true"
hint="The view name to display." />
<cfargument name="contentKey" type="string" required="false" default=""
hint="The contentKey name if defined." />
<cfargument name="contentArg" type="string" required="false" default=""
hint="The contentArg name if defined." />
<cfargument name="append" type="boolean" required="false" default="false"
hint="Directive to append event." />
<cfset var viewPath = getFullPath(arguments.viewName) />
<cfset var viewContent = "" />
<cfset var log = getLog() />
<cfif log.isDebugEnabled()>
<cfif Len(arguments.contentKey)>
<cfset log.debug("Rendering view '#arguments.viewName#' in ContentKey '#arguments.contentKey#'.") />
</cfif>
<cfif Len(arguments.contentArg)>
<cfset log.debug("Rendering view '#arguments.viewName#' in ContentArg '#arguments.contentArg#'.") />
</cfif>
<cfif NOT Len(arguments.contentKey) AND NOT Len(arguments.ContentArg)>
<cfset log.debug("Rendering view '#arguments.viewName#'.") />
</cfif>
</cfif>
<cfset request.event = arguments.event />
<cfif arguments.contentKey NEQ ''>
<cfif log.isWarnEnabled()>
<cfset log.warn("DEPRECATED: The ContentKey attribute has been deprecated. This was called by view '#arguments.viewName#'.") />
</cfif>
<cfsavecontent variable="viewContent">
<cfinclude template="#viewPath#" />
</cfsavecontent>
<cfif arguments.append AND IsDefined(arguments.contentKey)>
<cfset viewContent = Evaluate(arguments.contentKey) & viewContent />
</cfif>
<cfset setVariable(arguments.contentKey, viewContent) />
</cfif>
<cfif arguments.contentArg NEQ ''>
<cfsavecontent variable="viewContent">
<cfinclude template="#viewPath#" />
</cfsavecontent>
<cfif arguments.append>
<cfset viewContent = arguments.event.getArg(arguments.contentArg, "") & viewContent />
</cfif>
<cfset arguments.event.setArg(arguments.contentArg, viewContent) />
</cfif>
<cfif arguments.contentKey EQ '' AND arguments.contentArg EQ ''>
<cfinclude template="#viewPath#" />
</cfif>
</cffunction>
| getAppManager |
|---|
public AppManager getAppManager( )
Gets the AppManager instance this ViewContext belongs to.
Parameters:
Code:
<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false" hint="Gets the AppManager instance this ViewContext belongs to."> <cfreturn variables.appManager /> </cffunction>
| getFullPath |
|---|
private string getFullPath( string viewName )
Gets the full path of a view by view name from the view manager.
Parameters:
| string viewName |
Code:
<cffunction name="getFullPath" access="private" returntype="string" output="false" hint="Gets the full path of a view by view name from the view manager."> <cfargument name="viewName" type="string" required="true" /> <cfreturn getAppManager().getViewManager().getViewPath(arguments.viewName) /> </cffunction>
| getLog |
|---|
public Log getLog( )
Gets the log.
Parameters:
Code:
<cffunction name="getLog" access="public" returntype="MachII.logging.Log" output="false" hint="Gets the log."> <cfreturn variables.log /> </cffunction>
| getProperty |
|---|
public any getProperty( string propertyName )
Gets the specified property - this is just a shortcut for getAppManager().getPropertyManager().getProperty()
Parameters:
| string propertyName |
Code:
<cffunction name="getProperty" access="public" returntype="any" output="false" hint="Gets the specified property - this is just a shortcut for getAppManager().getPropertyManager().getProperty()"> <cfargument name="propertyName" type="string" required="yes" hint="The name of the property to return." /> <cfreturn getPropertyManager().getProperty(arguments.propertyName) /> </cffunction>
| getPropertyManager |
|---|
public PropertyManager getPropertyManager( )
Gets the components PropertyManager instance.
Parameters:
Code:
<cffunction name="getPropertyManager" access="public" returntype="MachII.framework.PropertyManager" output="false" hint="Gets the components PropertyManager instance."> <cfreturn variables.propertyManager /> </cffunction>
| init |
|---|
public ViewContext init( AppManager appManager )
Used by the framework for initialization. Do not override.
Parameters:
| AppManager appManager |
Code:
<cffunction name="init" access="public" returntype="ViewContext" output="false" hint="Used by the framework for initialization. Do not override."> <cfargument name="appManager" type="MachII.framework.AppManager" required="true" /> <cfset setAppManager(arguments.appManager) /> <cfset setPropertyManager(getAppManager().getPropertyManager()) /> <cfset setLog(getAppManager().getLogFactory()) /> <cfreturn this /> </cffunction>
| setAppManager |
|---|
private void setAppManager( AppManager appManager )
Sets the AppManager instance this ViewContext belongs to.
Parameters:
| AppManager appManager |
Code:
<cffunction name="setAppManager" access="private" returntype="void" output="false" hint="Sets the AppManager instance this ViewContext belongs to."> <cfargument name="appManager" type="MachII.framework.AppManager" required="true" /> <cfset variables.appManager = arguments.appManager /> </cffunction>
| setLog |
|---|
public void setLog( LogFactory logFactory )
Uses the log factory to create a log.
Parameters:
| LogFactory logFactory |
Code:
<cffunction name="setLog" access="public" returntype="void" output="false" hint="Uses the log factory to create a log."> <cfargument name="logFactory" type="MachII.logging.LogFactory" required="true" /> <cfset variables.log = arguments.logFactory.getLog(getMetadata(this).name) /> </cffunction>
| setProperty |
|---|
public void setProperty( string propertyName, any propertyValue )
Sets the specified property - this is just a shortcut for getAppManager().getPropertyManager().setProperty()
Parameters:
| string propertyName |
| any propertyValue |
Code:
<cffunction name="setProperty" access="public" returntype="void" output="false" hint="Sets the specified property - this is just a shortcut for getAppManager().getPropertyManager().setProperty()"> <cfargument name="propertyName" type="string" required="yes" hint="The name of the property to set." /> <cfargument name="propertyValue" type="any" required="yes" hint="The value to store in the property." /> <cfset getPropertyManager().setProperty(arguments.propertyName, arguments.propertyValue) /> </cffunction>
| setPropertyManager |
|---|
private void setPropertyManager( PropertyManager propertyManager )
Sets the components PropertyManager instance.
Parameters:
| PropertyManager propertyManager |
Code:
<cffunction name="setPropertyManager" access="private" returntype="void" output="false" hint="Sets the components PropertyManager instance."> <cfargument name="propertyManager" type="MachII.framework.PropertyManager" required="true" hint="The PropertyManager instance to set." /> <cfset variables.propertyManager = arguments.propertyManager /> </cffunction>