Sorcerer's IsleCode QueryParam Scanner / files

     1<!---
     2Copyright 2006-2007 TeraTech, Inc. http://teratech.com/
     3
     4Licensed under the Apache License, Version 2.0 (the "License");
     5you may not use this file except in compliance with the License.
     6You may obtain a copy of the License at
     7
     8http://www.apache.org/licenses/LICENSE-2.0
     9
    10Unless required by applicable law or agreed to in writing, software
    11distributed under the License is distributed on an "AS IS" BASIS,
    12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13See the License for the specific language governing permissions and
    14limitations under the License.
    15--->
    16<cfcomponent output="false" hint="I represent a verb that is implemented as part of a lexicon.">
    17	
    18	<cffunction name="init" returntype="any" access="public" output="false" 
    19				hint="I am the constructor.">
    20		<cfargument name="action" type="any" required="true" 
    21					hint="I am the enclosing fuseaction object." />
    22		<cfargument name="customVerb" type="string" required="true" 
    23					hint="I am the name of this (custom) verb." />
    24		<cfargument name="attributes" type="struct" required="true" 
    25					hint="I am the attributes for this verb." />
    26		<cfargument name="children" type="any" required="true" 
    27					hint="I am the XML representation of any children this verb has." />
    28
    29		<cfset var ns = listFirst(arguments.customVerb,".:") />		
    30		<cfset var i = 0 />
    31		<cfset var verb = "" />
    32		<cfset var factory = arguments.action.getCircuit().getApplication().getFuseactionFactory() />
    33		
    34		<cfset variables.action = arguments.action />
    35		<cfset variables.attributes = arguments.attributes />
    36		<!--- we will create our children below --->
    37		<cfset variables.verb = listLast(arguments.customVerb,".:") />
    38		<cfset variables.children = structNew() />
    39		
    40		<cfset variables.factory = factory />
    41		<cfset variables.nChildren = arrayLen(arguments.children) />
    42		
    43		<cfloop from="1" to="#variables.nChildren#" index="i">
    44			<cfset verb = arguments.children[i].xmlName />
    45			<cfset variables.children[i] = factory.create(verb,
    46						variables.action,
    47							arguments.children[i].xmlAttributes,
    48								arguments.children[i].xmlChildren) />
    49		</cfloop>
    50
    51		<cfset variables.fb41style = listLen(arguments.customVerb,".") eq 2 />
    52		<cfif variables.fb41style>
    53			<cfset variables.lexicon = variables.action.getCircuit().getApplication().getLexiconDefinition(ns) />
    54		<cfelse>
    55			<cfset variables.lexicon = variables.action.getCircuit().getLexiconDefinition(ns) />
    56		</cfif>
    57		
    58		<cfreturn this />
    59		
    60	</cffunction>
    61	
    62	<cffunction name="compile" returntype="void" access="public" output="false" 
    63				hint="I compile a custom lexicon verb. I create the thread-safe context and perform the start and end execution, as well as compiling any children.">
    64		<cfargument name="writer" type="any" required="false" 
    65					hint="I am the parsed file writer object. I am required but it's faster to specify that I am not required." />
    66		<cfargument name="context" type="any" required="false" 
    67					hint="I am the context in which this verb is compiled. I can be omitted if the verb has no enclosing parent." />
    68
    69		<!---
    70			the following is purely a device to allow nested custom verbs:
    71			we pass the struct reference into the lexicon compiler but then we
    72			fill in the fields here *afterwards* - relies on pass by reference!
    73			because we are recursive, we need to create a new lexicon compiler
    74			on each 'call' of the (static) compiler (i.e., this method)
    75			trust me! -- sean corfield
    76		--->
    77		<cfset var verbInfo = structNew() />
    78		<cfset var compiler = variables.factory.createLexiconCompiler()
    79				.init(arguments.writer,verbInfo,variables) />
    80		<cfset var i = 0 />
    81
    82		<cfset verbInfo.lexicon = variables.lexicon.namespace />
    83		<cfset verbInfo.lexiconVerb = variables.verb />
    84		<cfset verbInfo.attributes = variables.attributes />
    85		<!---
    86			change to FB41 lexicons (but needed for FB5):
    87				circuit - alias of current circuit
    88				fuseaction - name of current fuseaction
    89				action - fuseaction object for more complex usage
    90		--->
    91		<cfset verbInfo.circuit = variables.action.getCircuit().getAlias() />
    92		<cfset verbInfo.fuseaction = variables.action.getName() />
    93		<cfset verbInfo.action = variables.action />
    94		
    95		<cfif variables.fb41style>
    96
    97			<!--- FB41: just compile the lexicon once with no executionMode --->
    98			<cfset compiler.compile() />
    99
   100		<cfelse>
   101
   102			<!---
   103				FB5 has new fields in verbInfo:
   104				skipBody - false, can be set to true by start tag to skip compilation of child tags
   105				hasChildren - true if there are nested tags, else false
   106				parent - present if we are nested (the verbInfo of the parent tag)
   107				executionMode - start|inactive|end, just like custom tags
   108			--->
   109			<cfset verbInfo.skipBody = false />
   110			<cfset verbInfo.hasChildren = variables.nChildren neq 0 />
   111			<!---
   112				Fusebox 5.1: make children available to nested verbs.
   113				This actually opens up some frightening possibilities
   114				which I'd prefer not to document but no doubt someone
   115				will discover what you can do...
   116				This was originally done for ticket 180 to allow <if>
   117				to verify its own children to make sure on <true> and
   118				<false> are present.
   119			--->
   120			<cfset verbInfo.nChildren = variables.nChildren />
   121			<cfset verbInfo.children = variables.children />
   122
   123			<cfif structKeyExists(arguments,"context")>
   124				<cfset verbInfo.parent = arguments.context />
   125			</cfif>
   126
   127			<cfset verbInfo.executionMode = "start" />
   128			<cfset compiler.compile() />
   129
   130			<cfif structKeyExists(verbInfo,"skipBody") and isBoolean(verbInfo.skipBody) and verbInfo.skipBody>
   131				<!--- the verb decided not to compile its children --->
   132			<cfelse>
   133				<cfif variables.nChildren gt 0>
   134					<cfset verbInfo.executionMode = "inactive" />
   135					<cfloop from="1" to="#variables.nChildren#" index="i">
   136						<cfset variables.children[i].compile(arguments.writer,verbInfo) />
   137					</cfloop>		
   138				</cfif>
   139			</cfif>
   140
   141			<cfset verbInfo.executionMode = "end" />
   142			<cfset compiler.compile() />
   143
   144		</cfif>
   145		
   146		<cfset variables.factory.freeLexiconCompiler(compiler) />
   147
   148	</cffunction>
   149
   150	<cffunction name="getNamespace" returntype="string" access="public" output="false"
   151				hint="I return the namespace for this verb.">
   152
   153		<!--- make sure we hide the Fuebox lexicon name --->
   154		<cfif variables.factory.getBuiltinLexicon().namespace is variables.lexicon.namespace>
   155			<cfreturn "" />
   156		<cfelse>
   157			<cfreturn variables.lexicon.namespace />
   158		</cfif>
   159
   160	</cffunction>	
   161	
   162	<cffunction name="getVerb" returntype="string" access="public" output="false">
   163
   164		<cfreturn variables.verb />
   165
   166	</cffunction>
   167	
   168</cfcomponent>