| 1 | <!--- |
|---|
| 2 | Fusebox Software License |
|---|
| 3 | Version 1.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 2003, 2004, 2005, 2006 The Fusebox Corporation. All rights reserved. |
|---|
| 6 | |
|---|
| 7 | Redistribution and use in source and binary forms, with or without modification, are permitted |
|---|
| 8 | provided that the following conditions are met: |
|---|
| 9 | |
|---|
| 10 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions |
|---|
| 11 | and the following disclaimer. |
|---|
| 12 | |
|---|
| 13 | 2. 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 | |
|---|
| 17 | 3. 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 | |
|---|
| 25 | 4. 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 | |
|---|
| 29 | 5. 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 | |
|---|
| 33 | If one or more of the above conditions are violated, then this license is immediately revoked and |
|---|
| 34 | can be re-instated only upon prior written authorization of the Fusebox Corporation. |
|---|
| 35 | |
|---|
| 36 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 38 | DISCLAIMED. IN NO EVENT SHALL THE FUSEBOX CORPORATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|---|
| 39 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 40 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 41 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|---|
| 42 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 43 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 44 | |
|---|
| 45 | ------------------------------------------------------------------------------- |
|---|
| 46 | |
|---|
| 47 | This software consists of voluntary contributions made by many individuals on behalf of the |
|---|
| 48 | Fusebox Corporation. For more information on Fusebox, please see <http://www.fusebox.org/>. |
|---|
| 49 | |
|---|
| 50 | ---> |
|---|
| 51 | <cfcomponent output="false" hint="I manage the creation of and writing to the parsed files."> |
|---|
| 52 | |
|---|
| 53 | <cffunction name="init" returntype="any" access="public" output="false" |
|---|
| 54 | hint="I am the constructor."> |
|---|
| 55 | <cfargument name="fbApp" type="any" required="false" |
|---|
| 56 | hint="I am the fusebox application object. I am required but it's faster to specify that I am not required." /> |
|---|
| 57 | <cfargument name="myFusebox" type="any" required="false" |
|---|
| 58 | hint="I am the myFusebox data structure. I am required but it's faster to specify that I am not required." /> |
|---|
| 59 | |
|---|
| 60 | <cfset variables.fuseboxApplication = arguments.fbApp /> |
|---|
| 61 | <cfset variables.myFusebox = arguments.myFusebox /> |
|---|
| 62 | <cfset variables.parsedDir = variables.fuseboxApplication.getApplicationRoot() & variables.fuseboxApplication.parsePath /> |
|---|
| 63 | <cfset variables.phase = "" /> |
|---|
| 64 | <cfset variables.circuit = "" /> |
|---|
| 65 | <cfset variables.fuseaction = "" /> |
|---|
| 66 | <cfset variables.newline = chr(13) & chr(10) /> |
|---|
| 67 | |
|---|
| 68 | <cfif not directoryExists(variables.parsedDir)> |
|---|
| 69 | <cflock name="#variables.parsedDir#" type="exclusive" timeout="30"> |
|---|
| 70 | <cfif not directoryExists(variables.parsedDir)> |
|---|
| 71 | <cftry> |
|---|
| 72 | <cfdirectory action="create" directory="#variables.parsedDir#" mode="777" /> |
|---|
| 73 | <cfcatch type="any"> |
|---|
| 74 | <cfthrow type="fusebox.missingParsedDirException" |
|---|
| 75 | message="The 'parsed' directory in the application root directory is missing, and could not be created" |
|---|
| 76 | detail="You must manually create this directory, and ensure that CF has the ability to write and change files within the directory." |
|---|
| 77 | extendedinfo="#cfcatch.detail#" /> |
|---|
| 78 | </cfcatch> |
|---|
| 79 | </cftry> |
|---|
| 80 | </cfif> |
|---|
| 81 | </cflock> |
|---|
| 82 | </cfif> |
|---|
| 83 | |
|---|
| 84 | <cfset reset() /> |
|---|
| 85 | |
|---|
| 86 | <cfreturn this /> |
|---|
| 87 | |
|---|
| 88 | </cffunction> |
|---|
| 89 | |
|---|
| 90 | <cffunction name="getMyFusebox" returntype="any" access="public" output="false"> |
|---|
| 91 | |
|---|
| 92 | <cfreturn variables.myFusebox /> |
|---|
| 93 | |
|---|
| 94 | </cffunction> |
|---|
| 95 | |
|---|
| 96 | <cffunction name="reset" returntype="void" access="public" output="false" |
|---|
| 97 | hint="I reset the phase, circuit and fuseaction as well as initializing the file content object."> |
|---|
| 98 | |
|---|
| 99 | <cfset variables.lastPhase = "" /> |
|---|
| 100 | <cfset variables.lastCircuit = "" /> |
|---|
| 101 | <cfset variables.lastFuseaction = "" /> |
|---|
| 102 | <cfset variables.content = createObject("java","java.lang.StringBuffer").init() /> |
|---|
| 103 | |
|---|
| 104 | </cffunction> |
|---|
| 105 | |
|---|
| 106 | <cffunction name="open" returntype="void" access="public" output="false" |
|---|
| 107 | hint="I 'open' the parsed file. In fact I just setup the writing process. The file is only created when this writer object is 'closed'."> |
|---|
| 108 | <cfargument name="filename" type="string" required="true" |
|---|
| 109 | hint="I am the name of the parsed file to be created." /> |
|---|
| 110 | |
|---|
| 111 | <cfset variables.filename = arguments.filename /> |
|---|
| 112 | <cfset reset() /> |
|---|
| 113 | <cfset rawPrintln('<cfsetting enablecfoutputonly="true" />') /> |
|---|
| 114 | <cfset rawPrintln('<cfprocessingdirective pageencoding="#variables.fuseboxApplication.characterEncoding#" />') /> |
|---|
| 115 | |
|---|
| 116 | </cffunction> |
|---|
| 117 | |
|---|
| 118 | <cffunction name="close" returntype="void" access="public" output="false" |
|---|
| 119 | hint="I 'close' the parsed file and write it to disk."> |
|---|
| 120 | |
|---|
| 121 | <cfset rawPrintln('<cfsetting enablecfoutputonly="false" />') /> |
|---|
| 122 | <cftry> |
|---|
| 123 | <cffile action="write" file="#variables.parsedDir#/#variables.filename#" |
|---|
| 124 | output="#variables.content.toString()#" |
|---|
| 125 | charset="#variables.fuseboxApplication.characterEncoding#" /> |
|---|
| 126 | <cfcatch type="any"> |
|---|
| 127 | <cfthrow type="fusebox.errorWritingParsedFile" |
|---|
| 128 | message="An Error during write of Parsed File or Parsing Directory not found." |
|---|
| 129 | detail="Attempting to write the parsed file '#variables.filename#' threw an error. This can also occur if the parsed file directory cannot be found." |
|---|
| 130 | extendedinfo="#cfcatch.detail#" /> |
|---|
| 131 | </cfcatch> |
|---|
| 132 | </cftry> |
|---|
| 133 | |
|---|
| 134 | </cffunction> |
|---|
| 135 | |
|---|
| 136 | <cffunction name="setPhase" returntype="any" access="public" output="false" |
|---|
| 137 | hint="I remember the currently executing plugin phase."> |
|---|
| 138 | <cfargument name="phase" type="any" required="false" |
|---|
| 139 | hint="I am the name of the current phase. I am required but it's faster to specify that I am not required." /> |
|---|
| 140 | |
|---|
| 141 | <cfset var p = variables.phase /> |
|---|
| 142 | |
|---|
| 143 | <cfset variables.phase = arguments.phase /> |
|---|
| 144 | |
|---|
| 145 | <cfreturn p /> |
|---|
| 146 | |
|---|
| 147 | </cffunction> |
|---|
| 148 | |
|---|
| 149 | <cffunction name="setCircuit" returntype="any" access="public" output="false" |
|---|
| 150 | hint="I remember the currently executing circuit alias."> |
|---|
| 151 | <cfargument name="circuit" type="any" required="false" |
|---|
| 152 | hint="I am the name of the current circuit. I am required but it's faster to specify that I am not required." /> |
|---|
| 153 | |
|---|
| 154 | <cfset var c = variables.circuit /> |
|---|
| 155 | |
|---|
| 156 | <cfset variables.circuit = arguments.circuit /> |
|---|
| 157 | |
|---|
| 158 | <cfreturn c /> |
|---|
| 159 | |
|---|
| 160 | </cffunction> |
|---|
| 161 | |
|---|
| 162 | <cffunction name="setFuseaction" returntype="any" access="public" output="false" |
|---|
| 163 | hint="I remember the currently executing fuseaction name."> |
|---|
| 164 | <cfargument name="fuseaction" type="any" required="false" |
|---|
| 165 | hint="I am the name of the current fuseaction. I am required but it's faster to specify that I am not required." /> |
|---|
| 166 | |
|---|
| 167 | <cfset var f = variables.fuseaction /> |
|---|
| 168 | |
|---|
| 169 | <cfset variables.fuseaction = arguments.fuseaction /> |
|---|
| 170 | |
|---|
| 171 | <cfreturn f /> |
|---|
| 172 | |
|---|
| 173 | </cffunction> |
|---|
| 174 | |
|---|
| 175 | <cffunction name="print" returntype="void" access="public" output="false" |
|---|
| 176 | hint="I print a string to the parsed file. I set the phase, circuit and fuseaction variables if necessary in the myFusebox structure."> |
|---|
| 177 | <cfargument name="text" type="any" required="false" |
|---|
| 178 | hint="I am the string to be printed. I am required but it's faster to specify that I am not required." /> |
|---|
| 179 | |
|---|
| 180 | <cfif variables.lastPhase is not variables.phase> |
|---|
| 181 | <cfset rawPrintln('<cfset myFusebox.thisPhase = "#variables.phase#">') /> |
|---|
| 182 | <cfset variables.lastPhase = variables.phase /> |
|---|
| 183 | </cfif> |
|---|
| 184 | <cfif variables.lastCircuit is not variables.circuit> |
|---|
| 185 | <cfset rawPrintln('<cfset myFusebox.thisCircuit = "#variables.circuit#">') /> |
|---|
| 186 | <cfset variables.lastCircuit = variables.circuit /> |
|---|
| 187 | </cfif> |
|---|
| 188 | <cfif variables.lastFuseaction is not variables.fuseaction> |
|---|
| 189 | <cfset rawPrintln('<cfset myFusebox.thisFuseaction = "#variables.fuseaction#">') /> |
|---|
| 190 | <cfset variables.lastFuseaction = variables.fuseaction /> |
|---|
| 191 | </cfif> |
|---|
| 192 | <cfset variables.content.append(arguments.text) /> |
|---|
| 193 | |
|---|
| 194 | </cffunction> |
|---|
| 195 | |
|---|
| 196 | <cffunction name="println" returntype="void" access="public" output="false" |
|---|
| 197 | hint="I print a string to the parsed file, followed by a newline. I set the phase, circuit and fuseaction variables if necessary in the myFusebox structure."> |
|---|
| 198 | <cfargument name="text" type="any" required="false" |
|---|
| 199 | hint="I am the string to be printed. I am required but it's faster to specify that I am not required." /> |
|---|
| 200 | |
|---|
| 201 | <cfset print(arguments.text) /> |
|---|
| 202 | <cfset variables.content.append(variables.newline) /> |
|---|
| 203 | |
|---|
| 204 | </cffunction> |
|---|
| 205 | |
|---|
| 206 | <cffunction name="rawPrint" returntype="void" access="public" output="false" |
|---|
| 207 | hint="I print a string to the parsed file, without setting any variables."> |
|---|
| 208 | <cfargument name="text" type="any" required="false" |
|---|
| 209 | hint="I am the string to be printed. I am required but it's faster to specify that I am not required." /> |
|---|
| 210 | |
|---|
| 211 | <cfset variables.content.append(arguments.text) /> |
|---|
| 212 | |
|---|
| 213 | </cffunction> |
|---|
| 214 | |
|---|
| 215 | <cffunction name="rawPrintln" returntype="void" access="public" output="false" |
|---|
| 216 | hint="I print a string to the parsed file, followed by a newline, without setting any variables."> |
|---|
| 217 | <cfargument name="text" type="any" required="false" |
|---|
| 218 | hint="I am the string to be printed. I am required but it's faster to specify that I am not required." /> |
|---|
| 219 | |
|---|
| 220 | <cfset variables.content.append(arguments.text).append(variables.newline) /> |
|---|
| 221 | |
|---|
| 222 | </cffunction> |
|---|
| 223 | |
|---|
| 224 | </cfcomponent> |
|---|