| [5] | 1 | <cfcomponent output="false" displayName="Pods"> |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | <cffunction name="getPods" access="public" returnType="struct" output="false" hint="Gets pods"> |
|---|
| 5 | <cfargument name="directory" type="string" required="true"> |
|---|
| 6 | <cfset var pod = ""> |
|---|
| 7 | |
|---|
| 8 | <cfset pod = getInfo(arguments.directory)> |
|---|
| 9 | |
|---|
| 10 | <cfreturn pod> |
|---|
| 11 | </cffunction> |
|---|
| 12 | |
|---|
| 13 | <cffunction name="getInfo" access="public" returnType="struct" output="false" hint="Try to find an xml file and parse it."> |
|---|
| 14 | <cfargument name="directory" type="string" required="true"> |
|---|
| 15 | <cfset var result = structNew()> |
|---|
| 16 | <cfset var xmlFile = arguments.directory & "/pods.xml"> |
|---|
| 17 | <cfset var xmlPacket = ""> |
|---|
| 18 | <cfset var x = ""> |
|---|
| 19 | <cfset var pod = structNew()> |
|---|
| 20 | <cfset var podNode = ""> |
|---|
| 21 | |
|---|
| 22 | <cfset result.name = ""> |
|---|
| 23 | <cfset result.pods = structNew()> |
|---|
| 24 | |
|---|
| 25 | <cfif not directoryExists(arguments.directory) or not fileExists(xmlFile)> |
|---|
| 26 | <cfreturn result> |
|---|
| 27 | </cfif> |
|---|
| 28 | |
|---|
| 29 | <cfset result.name = listLast(arguments.directory, "/\")> |
|---|
| 30 | |
|---|
| 31 | <cffile action="read" file="#xmlFile#" variable="xmlPacket"> |
|---|
| 32 | <cfset xmlPacket = xmlParse(xmlPacket)> |
|---|
| 33 | |
|---|
| 34 | <cfif not structKeyExists(xmlPacket, "pods")> |
|---|
| 35 | <cfreturn result> |
|---|
| 36 | </cfif> |
|---|
| 37 | |
|---|
| 38 | <cfif structKeyExists(xmlPacket.pods, "files") and arrayLen(xmlPacket.pods.files.xmlChildren)> |
|---|
| 39 | <cfloop index="x" from="1" to="#arrayLen(xmlPacket.pods.files.xmlChildren)#"> |
|---|
| 40 | <cfset podNode = xmlPacket.pods.files.xmlChildren[x]> |
|---|
| 41 | <cfif structKeyExists(podNode.xmlAttributes, "name") and structKeyExists(podNode.xmlAttributes, "sortorder")> |
|---|
| 42 | <cfset pod.filename = podNode.xmlAttributes.name> |
|---|
| 43 | <cfset pod.sortOrder = podNode.xmlAttributes.sortorder> |
|---|
| 44 | <cfset result.pods[pod.filename] = pod.sortorder> |
|---|
| 45 | </cfif> |
|---|
| 46 | </cfloop> |
|---|
| 47 | </cfif> |
|---|
| 48 | |
|---|
| 49 | <cfreturn result> |
|---|
| 50 | </cffunction> |
|---|
| 51 | |
|---|
| 52 | <cffunction name="updateInfo" access="public" returnType="void" output="false" hint="Updates the XML packet."> |
|---|
| 53 | <cfargument name="directory" type="string" required="true"> |
|---|
| 54 | <cfargument name="md" type="struct" required="true"> |
|---|
| 55 | <cfset var xmlFile = arguments.directory & "/pods.xml"> |
|---|
| 56 | <cfset var packet = ""> |
|---|
| 57 | <cfset var image = ""> |
|---|
| 58 | <cfset var pod = ""> |
|---|
| 59 | |
|---|
| 60 | <cfxml variable="packet"> |
|---|
| 61 | <cfoutput> |
|---|
| 62 | <pods> |
|---|
| 63 | <files> |
|---|
| 64 | <cfloop item="pod" collection="#arguments.md.pods#"> |
|---|
| 65 | <pod name="#lcase(pod)#" sortorder="#arguments.md.pods[pod]#" /> |
|---|
| 66 | </cfloop> |
|---|
| 67 | </files> |
|---|
| 68 | </pods> |
|---|
| 69 | </cfoutput> |
|---|
| 70 | </cfxml> |
|---|
| 71 | |
|---|
| 72 | <cffile action="write" file="#xmlFile#" output="#toString(packet)#"> |
|---|
| 73 | </cffunction> |
|---|
| 74 | |
|---|
| 75 | </cfcomponent> |
|---|