Spectra's XML Flashes, by Matt Tata
Volume 3 Issue 5


<SLMELEMENT
  PARENTCOMPOSITIONID=""
  ELEMENTPOSITIONINDEX=""
  DEPTH=""
  COMPOSITIONTYPE=""
  COMPOSITIONID=""
  ELEMENTNAME=""
  TARGET="">
</SLMELEMENT>



Description:
       This custom tag outputs the Site layout XML data
Parameters:
       Elements = an array of structs with
--->
<cfif isdefined("attributes.Elements") and isArray
(attributes.Elements)>
               <cfloop from="1" to="#Arraylen(attributes.Elements)#"
   index="countrSLMXMLElement">
                       <cfif structkeyexists(attributes.Elements
   [countrSLMXMLElement],
"COMPOSITIONID")>
               <!--- Outputs the XML to the page --->
                               <cfoutput>
<SLMELEMENT
PARENTCOMPOSITIONID="#attributes.Elements
[countrSLMXMLElement].PARENTCOMPOSITIONID#"
ELEMENTPOSITIONINDEX="#attributes.Elements
[countrSLMXMLElement].ELEMENTPOSITIONINDEX#" DEPTH="#attributes.Elements[countrSLMXMLElement].DEPTH#"
COMPOSITIONTYPE ="#attributes.Elements[countrSLMXMLElement]
.COMPOSITIONTYPE#"    COMPOSITIONID="#attributes.Elements[countrSLMXMLElement]
.COMPOSITIONID#" ELEMENTNAME="#attributes.Elements[countrSLMXMLElement]
.ELEMENTNAME#" TARGET="#attributes.Elements[countrSLMXMLElement].TARGET#" >
</SLMELEMENT>
#chr(10)#
       </cfoutput>
                                       </cfif>
               </cfloop>
</cfif>


Description:
This is a controller page which directs requests to relevent Model and View pages
Parameters:
       Model = Business logic and/or Data Access Model to use
       ModelKey = Data access key used by the model
       View = Display logic for Data From Model
--->
<cfif isdefined("url.model") AND isdefined("url.View")
and isdefined("url.modelkey")>
       <cfif url.model eq "invoke" AND len("#url.view#") GT 1>
<!---  Invokes an Object with method = url.view --->
                    <cfa_contentobject datasource="#request.cfa
      .objectstore.dsn#" method="#url.view#"
      objectid="#url.modelkey#">
       <cfelseif url.model eq "SLM"  AND url.View eq "XML">
<!--- This if section displays the SLM XML Data --->
<!--- Calls the Model --->
               <cf_SLMModel siteuuid="#url.modelkey#"
  r_aSiteElements="aElements">
<!--- Calls the View --->
               <cf_SLMXMLView Elements="#aElements#">
       </cfif>
</cfif>


Description:
       This custom tag retrieves the SLM and returns an array


Parameters:
       siteUUID = UUID for site that is passed to the
cfa_sitemodeltraverse  Tag
                       i.e.    <cfa_sitemodeltraverse rootElementID =
  siteUUID>
Return variable
       r_aSiteElements - return parameter name
--->
<CFTRY>
       <cfsetting enablecfoutputonly="Yes" SHOWDEBUGOUTPUT="No" >
<!--- attributes.siteUUID is a required parameter to the        cfa_sitemodeltraverse (rootElementID parameter) --->
       <cfparam name="attributes.siteUUID" type="UUID">
<!--- This assumes all pages in SLM are for public viewing and that we do not want Containers --->
       <cfa_sitemodeltraverse
   rootElementID = "#attributes.siteUUID#"
   datasource = "#request.cfa.objectstore.dsn#"
   bIncludeSecurity = "no"
   bIncludeContainers = "no"
   bIncludePages = "yes"
   r_aTraverse = "aSortedSLMPageDetails">      <cfset aElementXML  = arraynew(1)>
       <cfset setArrayTempVar = ArraySet(aElementXML,1,Arraylen(aSortedSLMPageDetails),
structnew())>
       <cfloop from="1" to="#Arraylen(aSortedSLMPageDetails)#"
index="countrSiteElement">
<!--- Loops thru the array of structs returned from the         cfa_sitemodeltraverse tag to gather Section and Page info--->
               <cfif aSortedSLMPageDetails[countrSiteElement]
  .COMPOSITIONTYPE neq "SITE">
<!--- As the COMPOSITIONLABEL is composed of page name as well as Section and site labels this just gets the name of the element --->
                               <cfset siteElementName= listgetat
   ("#aSortedSLMPageDetails[countrSiteElement].
COMPOSITIONLABEL#",1,"_____")>
                               <cfset stElement = structnew()>
<!--- Creates  struct that will be used to produce the
XML output --->
<!--- This loop can be used to add additional properties that may be needed for the client Flash --->
                               <cfset stElement.COMPOSITIONID ="#asortedslmpagedetails
    [countrsiteelement].COMPOSITIONID#">
                               <cfset stElement.COMPOSITIONTYPE = "#aSortedSLMPageDetails[countrSiteElement]
  .COMPOSITIONTYPE#">
                               <cfset stElement.ELEMENTNAME ="#siteElementName#" >
                               <cfset stElement.DEPTH ="#asortedslmpagedetails
   [countrsiteelement].DEPTH#" >
                               <cfset stElement.TARGET = "#asortedslmpagedetails
   [countrsiteelement].TARGET#">
                               <cfset stElement.ELEMENTPOSITIONINDEX ="
    #asortedslmpagedetails[countrsiteelement]
    .ELEMENTPOSITIONINDEX#" >
                               <cfset stElement.PARENTCOMPOSITIONID ="#asortedslmpagedetails
   [countrsiteelement].PARENTCOMPOSITIONID#" >
<!--- Populates an array of structs used to produce
    the XML output                     --->
                               <cfset aElementXML[countrSiteElement] = stElement>
                       </cfif>
               </cfloop>
<!--- returns the array  --->
               <cfset "caller.#attributes.r_aSiteElements#" =
  aElementXML>
<CFCATCH>
       <cfoutput>
<!--- Outputs the ERROR XML to the page --->
               <ERROR MESSAGE="#cfcatch.message#" ></ERROR>
       </cfoutput>
</CFCATCH>
</CFTRY>



function getsitemodel()
{
       siteModelXML = new XML();
       SiteElementXMLReply = new XML();
       SiteElementXMLReply.onLoad = onSiteElementXMLReply;
       currentsite = "79267565-2234-4DAF-9F9F08AB04E758A6";
       siteModelXML.sendAndLoad("http://127.0.0.1/flash/
  controller.cfm?Model=SLM&View=XML&ModelKey="
+currentsite+"",SiteElementXMLReply);
}
function onSiteElementXMLReply() {
       SLMElementArray = new Array();
       var sitecopy = new XML();
       sitecopy = this;
       var sitecopychildren = sitecopy.firstChild;
       var asitecopychildren = sitecopy.childNodes;
       var asitecopychildrenLength = asitecopychildren.length;


       for (var countr = 0; countr<=asitecopychildrenLength;
countr++)
{
               if (sitecopychildren.nodeName == "SLMELEMENT")
{
                       addElementToArray(sitecopychildren);
               }
               sitecopychildren.removeNode();
               sitecopychildren = sitecopy.firstChild;
       }


}


function addElementToArray(element) {
       var elementObject = new Object();


       elementObject.PARENTCOMPOSITIONID =
       element.attributes.PARENTCOMPOSITIONID;
       elementObject.DEPTH = element.attributes.DEPTH;
       elementObject.ELEMENTPOSITIONINDEX =
       element.attributes.ELEMENTPOSITIONINDEX;
       elementObject.COMPOSITIONTYPE = element.attributes
.COMPOSITIONTYPE;
       elementObject.ELEMENTNAME = element.attributes
.ELEMENTNAME;
       elementObject.COMPOSITIONID = element.attributes
.COMPOSITIONID;
       elementObject.TARGET = element.attributes.TARGET;


       SLMElementArray.push(elementObject);
       trace(SLMElementArray.length+"="+ element.attributes
.ELEMENTNAME);
}