root / framework / tags / fusebox5A2 / fuseboxPlugin.cfc

Revision 92, 6.0 kB (checked in by scorfield, 3 years ago)

Addressed file extension issue.

Line 
1<!---
2Fusebox Software License
3Version 1.0
4
5Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved.
6
7Redistribution and use in source and binary forms, with or without modification, are permitted
8provided that the following conditions are met:
9
101. Redistributions of source code must retain the above copyright notice, this list of conditions
11   and the following disclaimer.
12
132. Redistributions in binary form or otherwise encrypted form must reproduce the above copyright
14   notice, this list of conditions and the following disclaimer in the documentation and/or other
15   materials provided with the distribution.
16
173. The end-user documentation included with the redistribution, if any, must include the following
18   acknowledgment:
19
20   "This product includes software developed by the Fusebox Corporation (http://www.fusebox.org/)."
21
22   Alternately, this acknowledgment may appear in the software itself, if and wherever such
23   third-party acknowledgments normally appear.
24
254. The names "Fusebox" and "Fusebox Corporation" must not be used to endorse or promote products
26   derived from this software without prior written (non-electronic) permission. For written
27   permission, please contact fusebox@fusebox.org.
28
295. Products derived from this software may not be called "Fusebox", nor may "Fusebox" appear in
30   their name, without prior written (non-electronic) permission of the Fusebox Corporation. For
31   written permission, please contact fusebox@fusebox.org.
32
33If one or more of the above conditions are violated, then this license is immediately revoked and
34can be re-instated only upon prior written authorization of the Fusebox Corporation.
35
36THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY
39DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
45-------------------------------------------------------------------------------
46
47This software consists of voluntary contributions made by many individuals on behalf of the
48Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>.
49
50--->
51<cfcomponent extends="fuseboxBaseAction" output="false">
52
53        <cffunction name="init" returntype="fuseboxPlugin" access="public" output="false">
54                <cfargument name="phase" type="string" required="true" />
55                <cfargument name="pluginXML" type="any" required="true" />
56                <cfargument name="fbApp" type="fuseboxApplication" required="true" />
57       
58                <cfset var i = 0 />
59                <cfset var n = arrayLen(arguments.pluginXML.xmlChildren) />
60                <cfset var attr = 0 />
61                <cfset var verbChildren = arrayNew(1) />
62                <cfset var factory = arguments.fbApp.getFuseactionFactory() />
63                <cfset var ext = "." & arguments.fbApp.scriptFileDelimiter />
64               
65                <cfset super.init(arguments.pluginXML.xmlAttributes.name,arguments.fbApp) />
66               
67                <cfset variables.phase = arguments.phase />
68                <cfif arguments.pluginXML.xmlName is "plugin">
69                        <cfset this.path = arguments.fbApp.getPluginsPath() />
70                        <cfif structKeyExists(arguments.pluginXML.xmlAttributes,"path")>
71                                <cfset this.path = this.path & replace(arguments.pluginXML.xmlAttributes.path,"\","/","all") />
72                        </cfif>
73                        <cfif right(this.path,1) is not "/">
74                                <cfset this.path = this.path & "/" />
75                        </cfif>
76                        <cfset variables.template = arguments.pluginXML.xmlAttributes.template />
77                        <cfif len(variables.template) lt 4 or right(variables.template,4) is not ext>
78                                <cfset variables.template = variables.template & ext />
79                        </cfif>
80                        <cfset this.rootpath =
81                                        arguments.fbApp.relativePath(arguments.fbApp.getApplicationRoot() &
82                                                                                                        this.path,arguments.fbApp.getApplicationRoot()) />
83                        <!--- remove pairs of directory/../ to form canonical path: --->
84                        <cfloop condition="find('/../',this.rootpath) gt 0">
85                                <cfset this.rootpath = REreplace(this.rootpath,"[^\.:/]*/\.\./","") />
86                        </cfloop>
87                        <cfset variables.parameters = arguments.pluginXML.xmlChildren />
88                        <cfset variables.paramVerbs = structNew() />
89                        <cfloop from="1" to="#n#" index="i">
90                                <cfset attr = structNew() />
91                                <cfset attr.name = "myFusebox.plugins.#getName()#.parameters." & variables.parameters[i].xmlAttributes.name />
92                                <cfset attr.value = variables.parameters[i].xmlAttributes.value />
93                                <cfset variables.paramVerbs[i] = factory.create("set",this,attr,verbChildren) />
94                        </cfloop>
95                <cfelse>
96                        <!--- TODO: illegal plugin spec --->
97                </cfif>
98       
99                <cfreturn this />
100               
101        </cffunction>
102       
103        <cffunction name="compile" returntype="void" access="public" output="false">
104                <cfargument name="writer" type="fuseboxWriter" required="true" />
105               
106                <cfset var i = 0 />
107                <cfset var n = structCount(variables.paramVerbs) />
108                <cfset var file = "" />
109                <cfset var p = "" />
110               
111                <cfswitch expression="#variables.phase#">
112                <cfcase value="processError,fuseactionException">
113                        <cffile action="read" file="#getCircuit().getApplicationRoot()##this.path##variables.template#" variable="file" />
114                        <cfset arguments.writer.rawPrintln(file) />
115                </cfcase>
116                <cfdefaultcase>
117                        <cfloop from="1" to="#n#" index="i">
118                                <cfset variables.paramVerbs[i].compile(arguments.writer) />
119                        </cfloop>
120                        <cfset p = arguments.writer.setPhase(variables.phase) />
121                        <cfset arguments.writer.println('<cfset myFusebox.thisPlugin = "#getName()#"/>') />
122                        <cfset arguments.writer.print('<' & 'cfoutput><cfinclude template="') />
123                        <cfset arguments.writer.print(getCircuit().parseRootPath & this.path & variables.template) />
124                        <cfset arguments.writer.println('"/><' & '/cfoutput>') />
125                        <cfset arguments.writer.setPhase(p) />
126                </cfdefaultcase>
127                </cfswitch>
128
129        </cffunction>
130       
131</cfcomponent>
Note: See TracBrowser for help on using the browser.