ViewManager

Package: MachII.framework
Manages registered views for the framework.
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 = "" />
		<cfset var name = "" />
		<cfset var page = "" />
		<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 = getAppManager().getPropertyManager().getProperty("applicationRoot") & 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>