| 1 | <cfcomponent output="false" hint="A lo-fi ColdFusion code generator that uses content with ""<cg"" tags and ""<=--"" comments instead of XML or templating."> |
|---|
| 2 | |
|---|
| 3 | <cffunction name="init" output="false"> |
|---|
| 4 | <!--- <cfset variables.format = createObject("java", "org.jdom.output.Format") /> |
|---|
| 5 | <cfset variables.xmlOutputter = createObject("java", "org.jdom.output.XMLOutputter").init(variables.format.getPrettyFormat()) /> ---> |
|---|
| 6 | </cffunction> |
|---|
| 7 | |
|---|
| 8 | <cffunction name="clean" output="false"> |
|---|
| 9 | <cfargument name="content" /> |
|---|
| 10 | |
|---|
| 11 | <cfset arguments.content = replaceNoCase(content, "<cg", "<cf", "all") /> |
|---|
| 12 | <cfset arguments.content = replaceNoCase(content, "</cg", "</cf", "all") /> |
|---|
| 13 | <cfset arguments.content = replaceNoCase(content, "<=--", "<!--", "all") /> |
|---|
| 14 | |
|---|
| 15 | <cfreturn content /> |
|---|
| 16 | </cffunction> |
|---|
| 17 | |
|---|
| 18 | <cffunction name="write" output="false"> |
|---|
| 19 | <cfargument name="filename" /> |
|---|
| 20 | <cfargument name="content" /> |
|---|
| 21 | |
|---|
| 22 | <cfif not directoryExists(getDirectoryFromPath(arguments.filename))> |
|---|
| 23 | <cfdirectory action="create" directory="#getDirectoryFromPath(arguments.filename)#" mode="777" /> |
|---|
| 24 | </cfif> |
|---|
| 25 | |
|---|
| 26 | <cffile action="write" file="#arguments.filename#" output="#arguments.content#" mode="777" /> |
|---|
| 27 | </cffunction> |
|---|
| 28 | |
|---|
| 29 | <cffunction name="writeXML" output="false"> |
|---|
| 30 | <cfargument name="filename" /> |
|---|
| 31 | <cfargument name="content" /> |
|---|
| 32 | |
|---|
| 33 | <cfset var builder = "" /> |
|---|
| 34 | <cfset var format = "" /> |
|---|
| 35 | <cfset var out = "" /> |
|---|
| 36 | <cfset var xml = "" /> |
|---|
| 37 | <cfset var xsl = "" /> |
|---|
| 38 | <cfset var document = "" /> |
|---|
| 39 | <cfset var fileInStream = "" /> |
|---|
| 40 | <cfset var fileOutStream = "" /> |
|---|
| 41 | <cfset var fileObj = "" /> |
|---|
| 42 | <cfset var system = "" /> |
|---|
| 43 | |
|---|
| 44 | <cfset fileObj = createObject("java", "java.io.File").init(filename) /> |
|---|
| 45 | |
|---|
| 46 | <!--- Write it, read it to a jdom doc rather than ColdFusion node list, then pretty it ---> |
|---|
| 47 | <cfset write(filename, content) /> |
|---|
| 48 | |
|---|
| 49 | <cfset builder = createObject("java", "org.jdom.input.SAXBuilder").init() /> |
|---|
| 50 | <!--- <cfset format = createObject("java", "org.jdom.output.Format").getPrettyFormat() /> |
|---|
| 51 | <cfset out = createObject("java", "org.jdom.output.XMLOutputter").init(format) /> ---> |
|---|
| 52 | <cfset fileObj = createObject("java", "java.io.File").init(filename) /> |
|---|
| 53 | <cfset fileInStream = createObject("java", "java.io.FileInputStream").init(fileObj) /> |
|---|
| 54 | |
|---|
| 55 | <cfset system = createObject("java", "java.lang.System") /> |
|---|
| 56 | |
|---|
| 57 | <cfset document = builder.build(fileInStream) /> |
|---|
| 58 | |
|---|
| 59 | <cfset fileInStream.close() /> |
|---|
| 60 | |
|---|
| 61 | <cfset fileOutStream = createObject("java", "java.io.FileOutputStream").init(fileObj) /> |
|---|
| 62 | |
|---|
| 63 | <!--- <cfset out.output(document, fileOutStream) /> ---> |
|---|
| 64 | |
|---|
| 65 | <cfset fileOutStream.close() /> |
|---|
| 66 | </cffunction> |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | </cfcomponent> |
|---|