| Package: MachII.framework |
| Manages registered views for the framework. |
<!--- 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: ViewManager.cfc 846 2008-06-22 10:03:14Z peterfarrell $ Created version: 1.0.0 Updated version: 1.6.0 Notes: ---> |
| Method Summary | |
|---|---|
| public ViewManager |
init(AppManager appManager, [any parentViewManager=""])
Initialization function called by the framework. |
| public void |
configure()
Prepares the manager for use. |
| public AppManager | getAppManager() |
| public any |
getParent()
Sets the parent ViewManager instance this ViewManager belongs to. It will return empty string if no parent is defined. |
| public string |
getViewPath(string viewName)
Gets the view path by view name. |
| public boolean |
isViewDefined(string viewName)
Checks if the view is defined. |
| public void |
loadXml(string configXML, [boolean override="false"])
Loads xml for the manager. |
| public void | setAppManager(AppManager appManager) |
| public void |
setParent(ViewManager parentViewManager)
Returns the parent ViewManager instance this ViewManager belongs to. |
| Method Detail |
|---|
| configure |
|---|
public void configure( )
Prepares the manager for use.
Parameters:
Code:
<cffunction name="configure" access="public" returntype="void" output="false" hint="Prepares the manager for use."> </cffunction>
| getAppManager |
|---|
public AppManager getAppManager( )
Parameters:
Code:
<cffunction name="getAppManager" access="public" returntype="MachII.framework.AppManager" output="false"> <cfreturn variables.appManager /> </cffunction>
| getParent |
|---|
public any getParent( )
Sets the parent ViewManager instance this ViewManager belongs to. It will return empty string if no parent is defined.
Parameters:
Code:
<cffunction name="getParent" access="public" returntype="any" output="false" hint="Sets the parent ViewManager instance this ViewManager belongs to. It will return empty string if no parent is defined."> <cfreturn variables.parentViewManager /> </cffunction>
| getViewPath |
|---|
public string getViewPath( string viewName )
Gets the view path by view name.
Parameters:
| string viewName |
Code:
<cffunction name="getViewPath" access="public" returntype="string" output="false" hint="Gets the view path by view name."> <cfargument name="viewName" type="string" required="true" hint="Name of the view path to get." /> <cfif isViewDefined(arguments.viewName)> <cfreturn variables.viewPaths[arguments.viewName] /> <cfelseif IsObject(getParent()) AND getParent().isViewDefined(arguments.viewName)> <cfreturn getParent().getViewPath(arguments.viewName) /> <cfelse> <cfthrow type="MachII.framework.ViewNotDefined" message="View with name '#arguments.viewName#' is not defined." /> </cfif> </cffunction>
| init |
|---|
public ViewManager init( AppManager appManager, [any parentViewManager=""] )
Initialization function called by the framework.
Parameters:
| AppManager appManager |
| [any parentViewManager=""] |
Code:
<cffunction name="init" access="public" returntype="ViewManager" output="false" hint="Initialization function called by the framework."> <cfargument name="appManager" type="MachII.framework.AppManager" required="true" /> <cfargument name="parentViewManager" type="any" required="false" default="" hint="Optional argument for a parent view manager. If there isn't one default to empty string." /> <cfset setAppManager(arguments.appManager) /> <cfif IsObject(arguments.parentViewManager)> <cfset setParent(arguments.parentViewManager) /> </cfif> <cfreturn this /> </cffunction>
| isViewDefined |
|---|
public boolean isViewDefined( string viewName )
Checks if the view is defined.
Parameters:
| string viewName |
Code:
<cffunction name="isViewDefined" access="public" returntype="boolean" output="false" hint="Checks if the view is defined."> <cfargument name="viewName" type="string" required="true" hint="Name of the view to check. Does not check parent ViewManager." /> <cfreturn StructKeyExists(variables.viewPaths, arguments.viewName) /> </cffunction>
| loadXml |
|---|
public void loadXml( string configXML, [boolean override="false"] )
Loads xml for the manager.
Parameters:
| string configXML |
| [boolean override="false"] |
Code:
<cffunction name="loadXml" access="public" returntype="void" output="false"
hint="Loads xml for the manager.">
<cfargument name="configXML" type="string" required="true" />
<cfargument name="override" type="boolean" required="false" default="false" />
<cfset var viewNodes = ArrayNew(1) />
<cfset var name = "" />
<cfset var page = "" />
<cfset var appRoot = getAppManager().getPropertyManager().getProperty("applicationRoot") />
<cfset var hasParent = IsObject(getParent()) />
<cfset var mapping = "" />
<cfset var i = 0 />
<cfif NOT arguments.override>
<cfset viewNodes = XMLSearch(arguments.configXML, "mach-ii/page-views/page-view") />
<cfelse>
<cfset viewNodes = XMLSearch(arguments.configXML, ".//page-views/page-view") />
</cfif>
<cfloop from="1" to="#ArrayLen(viewNodes)#" index="i">
<cfset name = viewNodes[i].xmlAttributes["name"] />
<cfif hasParent AND arguments.override AND StructKeyExists(viewNodes[i].xmlAttributes, "overrideAction")>
<cfif viewNodes[i].xmlAttributes["overrideAction"] EQ "useParent">
<cfset StructDelete(variables.viewPaths, name, false) />
<cfelseif viewNodes[i].xmlAttributes["overrideAction"] EQ "addFromParent">
<cfif StructKeyExists(viewNodes[i].xmlAttributes, "mapping")>
<cfset mapping = viewNodes[i].xmlAttributes["mapping"] />
<cfelse>
<cfset mapping = name />
</cfif>
<cfif NOT getParent().isViewDefined(mapping)>
<cfthrow type="MachII.framework.overrideViewNotDefined"
message="An view named '#mapping#' cannot be found in the parent view manager for the override named '#name#' in module '#getAppManager().getModuleName()#'." />
</cfif>
<cfset variables.viewPaths[name] = mapping />
</cfif>
<cfelse>
<cfif StructKeyExists(viewNodes[i].xmlAttributes, "useParentAppRoot") AND viewNodes[i].xmlAttributes["useParentAppRoot"]>
<cfset page = getAppManager().getParent().getPropertyManager().getProperty("applicationRoot") & viewNodes[i].xmlAttributes["page"] />
<cfelse>
<cfset page = appRoot & viewNodes[i].xmlAttributes["page"] />
</cfif>
<cfset variables.viewPaths[name] = page />
</cfif>
</cfloop>
</cffunction>
| setAppManager |
|---|
public void setAppManager( AppManager appManager )
Parameters:
| AppManager appManager |
Code:
<cffunction name="setAppManager" access="public" returntype="void" output="false"> <cfargument name="appManager" type="MachII.framework.AppManager" required="true" /> <cfset variables.appManager = arguments.appManager /> </cffunction>
| setParent |
|---|
public void setParent( ViewManager parentViewManager )
Returns the parent ViewManager instance this ViewManager belongs to.
Parameters:
| ViewManager parentViewManager |
Code:
<cffunction name="setParent" access="public" returntype="void" output="false" hint="Returns the parent ViewManager instance this ViewManager belongs to."> <cfargument name="parentViewManager" type="MachII.framework.ViewManager" required="true" /> <cfset variables.parentViewManager = arguments.parentViewManager /> </cffunction>