root / framework / tags / fusebox5A2 / fuseboxWriter.cfc

Revision 67, 7.0 kB (checked in by scorfield, 3 years ago)

Made the writer aware of phases.
Added code to set myFusebox.thisPhase correctly.

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 output="false">
52
53        <cffunction name="init" returntype="fuseboxWriter" access="public" output="false">
54                <cfargument name="fbApp" type="fuseboxApplication" required="true" />
55               
56                <cfset variables.parsedDir = arguments.fbApp.getApplicationRoot() & arguments.fbApp.parsePath />
57                <cfset variables.phase = "" />
58                <cfset variables.circuit = "" />
59                <cfset variables.fuseaction = "" />
60                <cfset variables.newline = chr(13) & chr(10) />
61               
62                <cfif not directoryExists(variables.parsedDir)>
63                        <cflock name="#variables.parsedDir#" type="exclusive" timeout="30">
64                                <cfif not directoryExists(variables.parsedDir)>
65                                        <cftry>
66                                                <cfdirectory action="create" directory="#variables.parsedDir#" mode="777" />
67                                        <cfcatch>
68                                                <cfthrow type="fusebox.missingParsedDirException"
69                                                        message="The 'parsed' directory in the application root directory is missing, and could not be created"
70                                                        detail="You must manually create this directory, and ensure that CF has the ability to write and change files within the directory." />
71                                        </cfcatch>
72                                        </cftry>
73                                </cfif>
74                        </cflock>
75                </cfif>
76
77                <cfset reset() />
78
79                <cfreturn this />
80
81        </cffunction>
82
83        <cffunction name="reset" returntype="void" access="public" output="false">
84
85                <cfset variables.lastPhase = "" />
86                <cfset variables.lastCircuit = "" />
87                <cfset variables.lastFuseaction = "" />
88                <cfset variables.content = "" />
89
90        </cffunction>   
91
92        <cffunction name="open" returntype="void" access="public" output="false">
93                <cfargument name="filename" type="string" required="true" />
94               
95                <cfset variables.filename = arguments.filename />
96                <cfset reset() />
97                <cfset rawPrintln('<cfsetting enablecfoutputonly="true" />') />
98                <cfset rawPrintln('<cfprocessingdirective pageencoding="utf-8" />') />
99               
100        </cffunction>
101       
102        <cffunction name="close" returntype="void" access="public" output="false">
103               
104                <cfset rawPrintln('<cfsetting enablecfoutputonly="false" />') />
105                <cffile action="write" file="#variables.parsedDir#/#variables.filename#"
106                                output="#variables.content#" charset="utf-8" />
107               
108        </cffunction>
109       
110        <cffunction name="setPhase" returntype="string" access="public" output="false">
111                <cfargument name="phase" type="string" required="true" />
112               
113                <cfset var p = variables.phase />
114               
115                <cfset variables.phase = arguments.phase />
116               
117                <cfreturn p />
118               
119        </cffunction>
120       
121        <cffunction name="setCircuit" returntype="string" access="public" output="false">
122                <cfargument name="circuit" type="string" required="true" />
123               
124                <cfset var c = variables.circuit />
125               
126                <cfset variables.circuit = arguments.circuit />
127               
128                <cfreturn c />
129               
130        </cffunction>
131       
132        <cffunction name="setFuseaction" returntype="string" access="public" output="false">
133                <cfargument name="fuseaction" type="string" required="true" />
134               
135                <cfset var f = variables.fuseaction />
136               
137                <cfset variables.fuseaction = arguments.fuseaction />
138               
139                <cfreturn f />
140               
141        </cffunction>
142       
143        <cffunction name="print" returntype="void" access="public" output="false">
144                <cfargument name="text" type="string" required="true" />
145               
146                <cfif variables.lastPhase is not variables.phase>
147                        <cfset rawPrintln('<cfset myFusebox.thisPhase = "#variables.phase#">') />
148                        <cfset variables.lastPhase = variables.phase />
149                </cfif>
150                <cfif variables.lastCircuit is not variables.circuit>
151                        <cfset rawPrintln('<cfset myFusebox.thisCircuit = "#variables.circuit#">') />
152                        <cfset variables.lastCircuit = variables.circuit />
153                </cfif>
154                <cfif variables.lastFuseaction is not variables.fuseaction>
155                        <cfset rawPrintln('<cfset myFusebox.thisFuseaction = "#variables.fuseaction#">') />
156                        <cfset variables.lastFuseaction = variables.fuseaction />
157                </cfif>
158                <cfset rawPrint(arguments.text) />
159               
160        </cffunction>
161       
162        <cffunction name="println" returntype="void" access="public" output="false">
163                <cfargument name="text" type="string" required="true" />
164               
165                <cfset print(arguments.text) />
166                <cfset variables.content = variables.content & variables.newline />
167               
168        </cffunction>
169       
170        <cffunction name="rawPrint" returntype="void" access="public" output="false">
171                <cfargument name="text" type="string" required="true" />
172
173                <cfset variables.content = variables.content & arguments.text />
174
175        </cffunction>
176       
177        <cffunction name="rawPrintln" returntype="void" access="public" output="false">
178                <cfargument name="text" type="string" required="true" />
179
180                <cfset rawPrint(arguments.text) />
181                <cfset variables.content = variables.content & variables.newline />
182
183        </cffunction>
184       
185</cfcomponent>
Note: See TracBrowser for help on using the browser.