initial
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<cfcomponent displayname="AnythingToXML" namespace="AnythingToXML" output="no">
|
||||
<!--- Anything To XML by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008 --->
|
||||
<!---
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfargument name="Include_Type_Hinting" type="numeric" required="no" default="1" />
|
||||
<cfset variables.TabUtils = createObject('component', 'TabUtils').init() />
|
||||
<cfset variables.XMLutils = createObject('component', 'XMLutils').init() />
|
||||
<cfset variables.StructToXML = createObject('component','StructToXML').init(arguments.Include_Type_Hinting,XMLutils,TabUtils) />
|
||||
<cfset variables.QueryToXML = createObject('component','QueryToXML').init(arguments.Include_Type_Hinting,XMLutils,TabUtils) />
|
||||
<cfset variables.ArrayToXML = createObject('component','ArrayToXML').init(arguments.Include_Type_Hinting,XMLutils,TabUtils) />
|
||||
<cfset variables.ObjectToXML = createObject('component','ObjectToXML').init(arguments.Include_Type_Hinting,XMLutils,TabUtils) />
|
||||
<cfset variables.Include_Type_Hinting = arguments.Include_Type_Hinting />
|
||||
<cfset variables.StructToXML.setAnythingToXML(this) />
|
||||
<cfset variables.QueryToXML.setAnythingToXML(this) />
|
||||
<cfset variables.ArrayToXML.setAnythingToXML(this) />
|
||||
<cfset variables.ObjectToXML.setAnythingToXML(this) />
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="ToXML" access="public" output="no" returntype="string" hint="This function converts simple types, arrays, queries, structures, objects with properties, or any combination of these to XML">
|
||||
<cfargument name="ThisItem" type="any" required="yes" hint="simple type, array, query, structure, object with properties, or any combination of previous">
|
||||
<cfargument name="NodeName" type="string" required="no" default="XML_ELEMENT" hint="name of a node">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="" hint="List of Column Names/Struct Keys that should become Attributes of the XML Node" />
|
||||
<cfset var returnstring = "">
|
||||
|
||||
<!---initalize cfc if it is not --->
|
||||
<cfif not structkeyexists(variables, "TabUtils") >
|
||||
<cfset init() />
|
||||
</cfif>
|
||||
|
||||
<!--- If this is the 1st time add XML encoding. Comment this out for Debugging --->
|
||||
<cfif variables.TabUtils.tabs eq 0 >
|
||||
<!---cfcontent type="text/xml; charset=utf-8">--->
|
||||
<cfset returnstring = '<?xml version="1.0" encoding="utf-8"?>' />
|
||||
</cfif>
|
||||
|
||||
<!--- Decide how to create the XML --->
|
||||
<cfif isSimpleValue(ThisItem) >
|
||||
<cfset returnstring = returnstring & "#variables.TabUtils.printtabs()#<#variables.XMLutils.NodeNameCheck(arguments.NodeName)#><![CDATA[#trim(ThisItem)#]]></#variables.XMLutils.NodeNameCheck(arguments.NodeName)#>" />
|
||||
<cfelseif isArray(ThisItem)>
|
||||
<cfset returnstring = returnstring & variables.ArrayToXML.ArrayToXML(arguments.ThisItem,arguments.NodeName,arguments.AttributeList)>
|
||||
<cfelseif isQuery(ThisItem)>
|
||||
<cfset returnstring = returnstring & variables.QueryToXML.QueryToXML(arguments.ThisItem,arguments.NodeName,arguments.AttributeList)>
|
||||
<cfelseif structkeyexists(getMetaData(ThisItem), "properties") >
|
||||
<cfset returnstring = returnstring & variables.ObjectToXML.ObjectToXML(arguments.ThisItem,arguments.NodeName,arguments.AttributeList)>
|
||||
<cfelseif isStruct(ThisItem)>
|
||||
<cfset returnstring = returnstring & variables.StructToXML.StructToXML(arguments.ThisItem,arguments.NodeName,arguments.AttributeList)>
|
||||
<cfelseif IsCustomFunction(ThisItem)>
|
||||
<!--- ignore --->
|
||||
<cfelse>
|
||||
<cfset returnstring = returnstring & "#variables.TabUtils.printtabs()#<ERROR>Unable to Convert this element to XML</ERROR>" />
|
||||
<!---<cfdump var="#arguments.ThisItem#" /><cfabort />--->
|
||||
</cfif>
|
||||
|
||||
<cfreturn returnstring>
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,74 @@
|
||||
<cfcomponent namespace="ArrayToXML" displayname="ArrayToXML" output="no" >
|
||||
<!--- Array to XML by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008 --->
|
||||
<!---
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfargument name="Include_Type_Hinting" type="numeric" required="no" default="1" />
|
||||
<cfargument name="XMLutils" type="any" required="yes" />
|
||||
<cfargument name="TabUtils" type="any" required="yes" />
|
||||
<cfset variables.Include_Type_Hinting = arguments.Include_Type_Hinting />
|
||||
<cfset variables.XMLutils = arguments.XMLutils />
|
||||
<cfset variables.TabUtils = arguments.TabUtils />
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="setAnythingToXML" access="public" output="no" returntype="void">
|
||||
<cfargument name="AnythingToXML" type="any" required="yes" />
|
||||
<cfset variables.AnythingToXML = arguments.AnythingToXML />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="ArrayToXML" access="public" output="no" returntype="string" >
|
||||
<cfargument name="TheseItems" type="array" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfoutput>#variables.TabUtils.printtabs()#<#variables.XMLutils.getNodePlural(arguments.rootNodeName)# <cfif variables.Include_Type_Hinting eq 1>CF_TYPE='array'</cfif>></cfoutput>
|
||||
<cfoutput>#createXML(arguments.TheseItems,arguments.rootNodeName,arguments.AttributeList)#</cfoutput>
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</#variables.XMLutils.getNodePlural(arguments.rootNodeName)#></cfoutput>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
|
||||
<cffunction name="createXML" access="public" output="no" returntype="string">
|
||||
<cfargument name="thisArray" type="Array" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var thisSize = thisArray.size() />
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
<cfset var CurrentNode = '' />
|
||||
<cfset variables.TabUtils.addtab() />
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfloop from="1" to="#thisSize#" index="i" >
|
||||
<cfif IsSimpleValue(thisArray[i])>
|
||||
<cfset CurrentNode = variables.XMLutils.NodeNameCheck(rootNodeName) />
|
||||
<cfoutput>#variables.TabUtils.printtabs()#<#CurrentNode#><![CDATA[#trim(thisArray[i])#]]></#CurrentNode#></cfoutput>
|
||||
<cfelse>
|
||||
<!--- Yay for Recursion!--->
|
||||
<cfoutput>#variables.AnythingToXML.ToXML(thisArray[i],arguments.rootNodeName,arguments.AttributeList)#</cfoutput>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfset variables.TabUtils.removetab() />
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,121 @@
|
||||
<cfcomponent namespace="ObjectToXML" displayname="ObjectToXML" output="no" >
|
||||
<!--- Object to XML by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008
|
||||
Thanks to Brian Rinaldi for getting the function introspection working. --->
|
||||
<!---
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfargument name="Include_Type_Hinting" type="numeric" required="no" default="1" />
|
||||
<cfargument name="XMLutils" type="any" required="yes" />
|
||||
<cfargument name="TabUtils" type="any" required="yes" />
|
||||
<cfset variables.Include_Type_Hinting = arguments.Include_Type_Hinting />
|
||||
<cfset variables.XMLutils = arguments.XMLutils />
|
||||
<cfset variables.TabUtils = arguments.TabUtils />
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="setAnythingToXML" access="public" output="no" returntype="void">
|
||||
<cfargument name="AnythingToXML" type="any" required="yes" />
|
||||
<cfset variables.AnythingToXML = arguments.AnythingToXML />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="ObjectToXML" access="public" output="no" returntype="string" >
|
||||
<cfargument name="ThisObj" type="any" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
<cfset var AttributeCollection = getMetaData(arguments.ThisObj).properties />
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</cfoutput>
|
||||
<cfoutput><#addNodeAttributes(arguments.rootNodeName,AttributeCollection,arguments.ThisObj,arguments.AttributeList)# <cfif variables.Include_Type_Hinting eq 1>CF_TYPE='object'</cfif>></cfoutput>
|
||||
<cfoutput>#createXML(arguments.ThisObj,arguments.rootNodeName,arguments.AttributeList)#</cfoutput>
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</#variables.XMLutils.NodeNameCheck(arguments.rootNodeName)#></cfoutput>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="createXML" access="public" output="no" returntype="string">
|
||||
<cfargument name="ThisObj" type="any" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var aProperties = getMetaData(ThisObj).properties />
|
||||
<cfset var aMethods = getMetaData(ThisObj).functions />
|
||||
<cfset var methodName = "" />
|
||||
<cfset var tmp = "" />
|
||||
<cfset var thisSize = ArrayLen(aProperties) />
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
<cfset var CurrentNode = '' />
|
||||
<cfset variables.TabUtils.addtab() />
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfloop from="1" to="#thisSize#" index="i" >
|
||||
<cfset methodName = "get" & aProperties[i].name />
|
||||
<cfif structkeyexists(ThisObj, aProperties[i].name)>
|
||||
<cfif IsSimpleValue(evaluate("ThisObj." & aProperties[i].name))>
|
||||
<cfif not ListFindNoCase(arguments.AttributeList,aProperties[i].name)>
|
||||
<cfset CurrentNode = variables.XMLutils.NodeNameCheck(aProperties[i].name) />
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</cfoutput>
|
||||
<cfoutput><#CurrentNode#><![CDATA[#trim(evaluate("ThisObj." & aProperties[i].name))#]]></#CurrentNode#></cfoutput>
|
||||
</cfif>
|
||||
<cfelse>
|
||||
<!--- Yay for Recursion!--->
|
||||
<cfoutput>#variables.AnythingToXML.ToXML(ThisObj[aProperties[i].name], aProperties[i].name,arguments.AttributeList)#</cfoutput>
|
||||
</cfif>
|
||||
<cfelse>
|
||||
<cfif isdefined("ThisObj." & methodName) >
|
||||
<cfinvoke component="#ThisObj#" method="#methodName#" returnvariable="tmp" />
|
||||
<cfif IsSimpleValue(tmp)>
|
||||
<cfif not ListFindNoCase(arguments.AttributeList,aProperties[i].name)>
|
||||
<cfset CurrentNode = variables.XMLutils.NodeNameCheck(aProperties[i].name) />
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</cfoutput>
|
||||
<cfoutput><#CurrentNode#><![CDATA[#trim(tmp)#]]></#CurrentNode#></cfoutput>
|
||||
</cfif>
|
||||
<cfelse>
|
||||
<!--- Yay for Recursion!--->
|
||||
<cfoutput>#variables.AnythingToXML.ToXML(tmp, aProperties[i].name,arguments.AttributeList)#</cfoutput>
|
||||
</cfif>
|
||||
</cfif>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfset variables.TabUtils.removetab() />
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="addNodeAttributes" access="public" output="no" returntype="string" >
|
||||
<cfargument name="thisNode" required="yes" type="string" hint="Name of XML the Tag" />
|
||||
<cfargument name="thisKeyList" required="yes" type="string" hint="List of Column names, Struct Keys, object properties" />
|
||||
<cfargument name="thisElement" required="yes" type="any" hint="a Query or a Struct" />
|
||||
<cfargument name="thisAttributeList" required="yes" type="string" hint="List of Column Names/Struct Keys that should become Attributes of the XML Node" />
|
||||
<cfset var returnString = variables.XMLutils.NodeNameCheck(arguments.thisNode) />
|
||||
<cfset var i = 1 />
|
||||
|
||||
|
||||
<cfloop from="1" to="#arraylen(arguments.thisKeyList)#" index="j">
|
||||
<cfloop from="1" to="#ListLen(arguments.thisAttributeList)#" index="i">
|
||||
<cfif ListFindNoCase(arguments.thisKeyList[j].name, ListGetAt(arguments.thisAttributeList,i), ',' )>
|
||||
<cfset returnString = returnString & ' ' & lCase(ListGetAt(arguments.thisAttributeList,i)) & '="' />
|
||||
<cfset returnString = returnString & xmlformat(evaluate("arguments.thisElement." & ListGetAt(arguments.thisAttributeList,i))) & '"' />
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfloop>
|
||||
|
||||
<cfreturn returnString />
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,102 @@
|
||||
<cfcomponent namespace="QueryToXML" displayname="QueryToXML" output="no" >
|
||||
<!--- Query to XML by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008 --->
|
||||
<!---
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfargument name="Include_Type_Hinting" type="numeric" required="no" default="1" />
|
||||
<cfargument name="XMLutils" type="any" required="yes" />
|
||||
<cfargument name="TabUtils" type="any" required="yes" />
|
||||
<cfset variables.Include_Type_Hinting = arguments.Include_Type_Hinting />
|
||||
<cfset variables.XMLutils = arguments.XMLutils />
|
||||
<cfset variables.TabUtils = arguments.TabUtils />
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="setAnythingToXML" access="public" output="no" returntype="void">
|
||||
<cfargument name="AnythingToXML" type="any" required="yes" />
|
||||
<cfset variables.AnythingToXML = arguments.AnythingToXML />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="QueryToXML" access="public" output="no" returntype="string" >
|
||||
<cfargument name="ThisQuery" type="Query" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfoutput>#variables.TabUtils.printtabs()#<#variables.XMLutils.getNodePlural(arguments.rootNodeName)#></cfoutput>
|
||||
<cfset variables.TabUtils.addtab() />
|
||||
<cfloop query="arguments.ThisQuery" >
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</cfoutput>
|
||||
<cfoutput><#addNodeAttributes(arguments.rootNodeName,arguments.ThisQuery.columnlist,arguments.ThisQuery,arguments.AttributeList)# <cfif variables.Include_Type_Hinting eq 1>CF_TYPE='query'</cfif>></cfoutput>
|
||||
<cfoutput>#createXML(arguments.ThisQuery,arguments.rootNodeName,arguments.AttributeList)#</cfoutput>
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</#variables.XMLutils.NodeNameCheck(arguments.rootNodeName)#></cfoutput>
|
||||
</cfloop>
|
||||
<cfset variables.TabUtils.removetab() />
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</#variables.XMLutils.getNodePlural(arguments.rootNodeName)#></cfoutput>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="createXML" access="public" output="no" returntype="string">
|
||||
<cfargument name="thisQuery" type="Query" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var aColumns = ListToArray(thisQuery.columnList) />
|
||||
<cfset var thisSize = aColumns.size() />
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var CurrentNode = '' />
|
||||
<cfset var i = 1 />
|
||||
<cfset variables.TabUtils.addtab() />
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfloop from="1" to="#thisSize#" index="i" >
|
||||
<cfif IsSimpleValue(evaluate("thisQuery." & aColumns[i]))>
|
||||
<cfif not ListFindNoCase(arguments.AttributeList,aColumns[i])>
|
||||
<cfset CurrentNode= variables.XMLutils.NodeNameCheck(aColumns[i]) />
|
||||
<cfoutput>#variables.TabUtils.printtabs()#<#CurrentNode#><![CDATA[#trim(evaluate("thisQuery." & aColumns[i]))#]]></#CurrentNode#></cfoutput>
|
||||
</cfif>
|
||||
<cfelse>
|
||||
<!--- Yay for Recursion!--->
|
||||
<cfoutput>#variables.AnythingToXML.ToXML(evaluate("thisQuery." & aColumns[i]), aColumns[i],arguments.AttributeList)#</cfoutput>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfset variables.TabUtils.removetab() />
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="addNodeAttributes" access="public" output="no" returntype="string" >
|
||||
<cfargument name="thisNode" required="yes" type="string" hint="Name of XML the Tag" />
|
||||
<cfargument name="thisKeyList" required="yes" type="string" hint="List of Column names, Struct Keys, object properties" />
|
||||
<cfargument name="thisElement" required="yes" type="any" hint="a Query or a Struct" />
|
||||
<cfargument name="thisAttributeList" required="yes" type="string" hint="List of Column Names/Struct Keys that should become Attributes of the XML Node" />
|
||||
<cfset var returnString = variables.XMLutils.NodeNameCheck(arguments.thisNode) />
|
||||
<cfset var i = 1 />
|
||||
|
||||
<cfloop from="1" to="#ListLen(arguments.thisAttributeList)#" index="i">
|
||||
<cfif ListFindNoCase(arguments.thisKeyList, ListGetAt(arguments.thisAttributeList,i), ',' )>
|
||||
<cfset returnString = returnString & ' ' & lCase(ListGetAt(arguments.thisAttributeList,i)) & '="' />
|
||||
<cfset returnString = returnString & xmlformat(trim(evaluate("arguments.thisElement." & ListGetAt(arguments.thisAttributeList,i)))) & '"' />
|
||||
</cfif>
|
||||
</cfloop>
|
||||
|
||||
<cfreturn returnString />
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,95 @@
|
||||
<cfcomponent namespace="StructToXML" displayname="StructToXML" output="no" >
|
||||
<!--- Structure to XML by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008 --->
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfargument name="Include_Type_Hinting" type="numeric" required="no" default="1" />
|
||||
<cfargument name="XMLutils" type="any" required="yes" />
|
||||
<cfargument name="TabUtils" type="any" required="yes" />
|
||||
<cfset variables.Include_Type_Hinting = arguments.Include_Type_Hinting />
|
||||
<cfset variables.XMLutils = arguments.XMLutils />
|
||||
<cfset variables.TabUtils = arguments.TabUtils />
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="setAnythingToXML" access="public" output="no" returntype="void">
|
||||
<cfargument name="AnythingToXML" type="any" required="yes" />
|
||||
<cfset variables.AnythingToXML = arguments.AnythingToXML />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="StructToXML" access="public" output="no" returntype="string" >
|
||||
<cfargument name="ThisStruct" type="struct" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</cfoutput>
|
||||
<cfoutput><#addNodeAttributes(arguments.rootNodeName,StructKeyList(arguments.ThisStruct),arguments.ThisStruct,arguments.AttributeList)# <cfif variables.Include_Type_Hinting eq 1>CF_TYPE='struct'</cfif>></cfoutput>
|
||||
<cfoutput>#createXML(arguments.ThisStruct,arguments.rootNodeName,arguments.AttributeList)#</cfoutput>
|
||||
<cfoutput>#variables.TabUtils.printtabs()#</#variables.XMLutils.NodeNameCheck(arguments.rootNodeName)#></cfoutput>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="createXML" access="public" output="no" returntype="string">
|
||||
<cfargument name="thisStruct" type="struct" required="yes">
|
||||
<cfargument name="rootNodeName" type="string" required="no" default="">
|
||||
<cfargument name="AttributeList" type="string" required="no" default="">
|
||||
<cfset var aKeys = ListToArray(StructKeyList(arguments.thisStruct)) />
|
||||
<cfset var thisStructSize = StructCount(arguments.thisStruct) />
|
||||
<cfset var xmlString = "" />
|
||||
<cfset var i = 1 />
|
||||
<cfset var CurrentNode = '' />
|
||||
<cfset variables.TabUtils.addtab() />
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsavecontent variable="xmlString" >
|
||||
<cfloop from="1" to="#thisStructSize#" index="i" >
|
||||
<cfif IsSimpleValue(thisStruct[aKeys[i]])>
|
||||
<cfif not ListFindNoCase(arguments.AttributeList,aKeys[i])>
|
||||
<cfset CurrentNode= variables.XMLutils.NodeNameCheck(aKeys[i]) />
|
||||
<cfoutput>#variables.TabUtils.printtabs()#<#CurrentNode#><![CDATA[#trim(thisStruct[aKeys[i]])#]]></#CurrentNode#></cfoutput>
|
||||
</cfif>
|
||||
<cfelse>
|
||||
<!--- Yay for Recursion!--->
|
||||
<cfoutput>#variables.AnythingToXML.ToXML(thisStruct[aKeys[i]],aKeys[i],arguments.AttributeList)#</cfoutput>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<cfset variables.TabUtils.removetab() />
|
||||
<cfreturn xmlString />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="addNodeAttributes" access="public" output="no" returntype="string" >
|
||||
<cfargument name="thisNode" required="yes" type="string" hint="Name of XML the Tag" />
|
||||
<cfargument name="thisKeyList" required="yes" type="string" hint="List of Column names, Struct Keys, object properties" />
|
||||
<cfargument name="thisElement" required="yes" type="any" hint="a Query or a Struct" />
|
||||
<cfargument name="thisAttributeList" required="yes" type="string" hint="List of Column Names/Struct Keys that should become Attributes of the XML Node" />
|
||||
<cfset var returnString = variables.XMLutils.NodeNameCheck(arguments.thisNode) />
|
||||
<cfset var i = 1 />
|
||||
|
||||
<cfloop from="1" to="#ListLen(arguments.thisAttributeList)#" index="i">
|
||||
<cfif ListFindNoCase(arguments.thisKeyList, ListGetAt(arguments.thisAttributeList,i), ',' )>
|
||||
<cfset returnString = returnString & ' ' & lCase(ListGetAt(arguments.thisAttributeList,i)) & '="' />
|
||||
<cfset returnString = returnString & xmlformat(arguments.thisElement[ListGetAt(arguments.thisAttributeList,i)]) & '"' />
|
||||
</cfif>
|
||||
</cfloop>
|
||||
|
||||
<cfreturn returnString />
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,55 @@
|
||||
<cfcomponent displayname="TabUtils" namespace="TabUtils" output="no">
|
||||
<!--- Tab Utilities by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008 --->
|
||||
<!--- Keeps track of tabs 'n prints them -Dg--->
|
||||
<!---
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
<cfproperty name="tabs" default="0" type="numeric" />
|
||||
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfargument name="tabs" type="numeric" required="no" default="0" />
|
||||
<cfset this.tabs = arguments.tabs />
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="setTabs" access="public" output="no" returntype="any">
|
||||
<cfargument name="tabs" type="numeric" required="no" default="#this.tabs#" />
|
||||
<cfset this.tabs = arguments.tabs />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="addtab" access="public" output="no" returntype="void">
|
||||
<cfargument name="num" type="numeric" required="no" default="1" />
|
||||
<cfset this.tabs = this.tabs + arguments.num />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="removetab" access="public" output="no" returntype="void">
|
||||
<cfargument name="num" type="numeric" required="no" default="1" />
|
||||
<cfset this.tabs = this.tabs - arguments.num />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="printtabs" access="public" output="no" returntype="string" >
|
||||
<cfargument name="tabs" type="numeric" required="no" default="#this.tabs#" />
|
||||
<cfset var returnstring = "" />
|
||||
<cfset var i = 1 />
|
||||
<!---<cfif this.tabs gt 0 > --->
|
||||
<cfprocessingdirective suppresswhitespace="yes">
|
||||
<cfsetting enablecfoutputonly="yes">
|
||||
<cfsavecontent variable="returnstring" >
|
||||
<cfoutput>#chr(10)#</cfoutput>
|
||||
<cfloop from="1" to="#arguments.tabs#" index="i" >
|
||||
<cfoutput>#chr(09)#</cfoutput>
|
||||
</cfloop>
|
||||
</cfsavecontent>
|
||||
</cfprocessingdirective>
|
||||
<!---</cfif>--->
|
||||
<cfreturn returnstring>
|
||||
</cffunction>
|
||||
</cfcomponent>
|
||||
@@ -0,0 +1,79 @@
|
||||
<cfcomponent displayname="XMLutils" namespace="XMLutils" output="no">
|
||||
<!--- XML Utility functions by Daniel Gaspar <daniel.gaspar@gmail.com> 5/1/2008 --->
|
||||
<!--- Global functionality for XML creation: deciding on plural node names -Dg--->
|
||||
<!---
|
||||
|
||||
Copyright 2008 Daniel Gaspar Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
|
||||
agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing permissions and limitations under the License.
|
||||
|
||||
|
||||
--->
|
||||
<cffunction name="init" access="public" output="no" returntype="any">
|
||||
<cfreturn this>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="getNodePlural" access="public" output="no" >
|
||||
<cfargument name="ThisNode" type="string" required="yes" />
|
||||
<cfset var Plural = "" />
|
||||
|
||||
<cfif PluralExceptions(ThisNode) neq "" >
|
||||
<cfset plural = PluralExceptions(ThisNode)>
|
||||
<cfelseif right(ThisNode,2) eq 'ey'>
|
||||
<cfset plural = left(ThisNode,(len(ThisNode)-2)) & "IES" />
|
||||
<cfelseif right(ThisNode,1) eq 'y'>
|
||||
<cfset plural = left(ThisNode,(len(ThisNode)-1)) & "IES" />
|
||||
<cfelseif right(ThisNode,1) eq 's'>
|
||||
<cfset plural = ThisNode & "ES" />
|
||||
<cfelse>
|
||||
<cfset Plural = ThisNode & "S" />
|
||||
</cfif>
|
||||
<cfreturn NodeNameCheck(Plural) />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="PluralExceptions" access="private" output="no" >
|
||||
<cfargument name="ThisNode" type="string" required="yes" />
|
||||
<cfset var Plural = "" />
|
||||
<!--- 1st pass at naming. --->
|
||||
<cfswitch expression="#ucase(arguments.ThisNode)#">
|
||||
<cfcase value="SURVEY">
|
||||
<cfset Plural = "SURVEYS" />
|
||||
</cfcase>
|
||||
<cfcase value="METADATA">
|
||||
<cfset Plural = "METADATA" />
|
||||
</cfcase>
|
||||
<cfdefaultcase>
|
||||
<cfset Plural = "" />
|
||||
</cfdefaultcase>
|
||||
</cfswitch>
|
||||
<cfreturn ucase(Plural) />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="NodeNameCheck" access="public" output="no" >
|
||||
<cfargument name="ThisNode" type="string" required="yes" />
|
||||
<cfset var rename = "" />
|
||||
<!--- For adding hacks/ renaming nodes. --->
|
||||
<!---
|
||||
A trick here is that you could let things get missnamed in the plural exceptions list,
|
||||
then fix them here if you need to.
|
||||
For example:
|
||||
"related_images" plural is "related_imageses" the sub-node of this is "related_image" which plural is "related_images"
|
||||
We'd need to let "related_images" get missnamed then fix both afterwards so that we can filter properly.
|
||||
--->
|
||||
<cfswitch expression="#ucase(arguments.ThisNode)#">
|
||||
<cfcase value="IMAGESES">
|
||||
<cfset rename = "IMAGES" />
|
||||
</cfcase>
|
||||
<cfcase value="IMAGES">
|
||||
<cfset rename = "IMAGE" />
|
||||
</cfcase>
|
||||
<cfdefaultcase>
|
||||
<cfset rename = arguments.ThisNode />
|
||||
</cfdefaultcase>
|
||||
</cfswitch>
|
||||
<cfreturn ucase(rename) />
|
||||
</cffunction>
|
||||
</cfcomponent>
|
||||
Reference in New Issue
Block a user