rendered paste body<cfsilent>
<!--- Read in the XSL templates --->
<cfset abstractXsl = "#absPath#news_and_events/news_archive/abstract.xsl">
<cfset metadataXsl = "#absPath#news_and_events/news_archive/metadata.xsl">
<cffile action="read" file="#abstractXsl#" variable="abstractXsl">
<cffile action="read" file="#metadataXsl#" variable="metadataXsl">
<!--- Get a list of presskit folders --->
<cfset tFolder = "#absPath#news_and_events/news_archive/">
<cfdirectory action="list" directory="#tFolder#" name="presskits" filter="presskit_*" sort="name asc">
<!--- Make a list of presskit folders to loop through --->
<cfset pkFolderList = "">
<cfloop query="presskits">
<cfif (type is "Dir") and (left(name, 8) is "presskit")>
<cfset pkFolderList = listAppend(pkFolderList, "#tFolder##name#/")>
</cfif>
</cfloop>
<!--- Loop through the presskits making a catalog file for each presskit --->
<cfloop index="pkFolder" list="#pkFolderList#">
<cfdirectory action="list" directory="#pkFolder#" name="pkFiles" filter="news*.xml" sort="name desc">
<!--- Create a single catalog entry as xml --->
<cfxml variable="pkXml">
<!-- FIXME: declare the doctype URI generically. -->
<!DOCTYPE article SYSTEM "http://chemusdev.us.intranet.lanxess/news_and_events/news_archive/lanxessNews.dtd">
<presskit>
<!--- Set insane defaults for the date placeholders, so they are certain to be overwritten --->
<cfset startDate = Now()>
<cfset endDate = createDate(1900,1,1)>
<!--- Loop through the presskit's files --->
<cfloop query="pkFiles">
<!--- Read and transform the current article --->
<cffile action="read" file="#pkFolder##name#" variable="abstract">
<cfset abstract = xmlTransform(abstract, abstractXsl)>
<!--- Insert the filename --->
<cfset xmlDate = xmlParse(abstract).xmlRoot.date>
<cfset date = createDate(xmlDate.year.xmlText, xmlDate.month.xmlText, xmlDate.day.xmlText)>
<cfset abstract = replaceNoCase(abstract, "<file/>", "<file>#xmlFormat(name)#</file>")>
<cfoutput>#abstract#</cfoutput>
<cfif dateCompare(date, startDate) is -1>
<!--- date is before startDate: reassign startDate --->
<cfset startDate = date>
</cfif>
<cfif dateCompare(date, endDate) is 1>
<!--- date is after endDate: reassign endDate --->
<cfset endDate = date>
</cfif>
</cfloop>
<!--- Attach metadata from the metadata file. --->
<cffile action="read" file="#pkFolder#metadata.xml" variable="metadata">
<cfset metadata=xmlTransform(metadata, metadataXsl)>
<metadata>
<cfoutput>
#metadata#
<date>
<start>
<year>#year(startDate)#</year>
<month>#month(startDate)#</month>
<day>#day(startDate)#</day>
</start>
<end>
<year>#year(endDate)#</year>
<month>#month(endDate)#</month>
<day>#day(endDate)#</day>
</end>
</date>
</cfoutput>
</metadata>
</presskit>
</cfxml>
<!--- Write pkXml to a file --->
<cfset pkFile = "#left(pkFolder, len(pkFolder) - 1)#.xml">
<cffile action="write" file="#pkFile#" output="#toString(pkXml)#">
</cfloop>
<!--- Run the cfdirectory again to include any new xml files --->
<cfdirectory action="list" directory="#tFolder#" name="newsFiles" filter="*.xml" sort="name desc">
<!--- Create an XML document to hold the catalog of news articles. --->
<cfxml variable="newsXml">
<news>
<!---
Loop over every XML news file in the directory and add it to the news
catalog.
--->
<cfloop query="newsFiles">
<cfif (name is not "allNews.xml")>
<!--- Read in the current XML file --->
<cffile action="read" file="#tFolder##name#" variable="abstractXml">
<cfset abstractXml = xmlTransform(abstractXml, abstractXsl)>
<cfset abstractXml = replaceNoCase(abstractXml, "<file/>", "<file>#xmlFormat(name)#</file>")>
<cfoutput>
#abstractXml#
</cfoutput>
</cfif>
</cfloop>
</news>
</cfxml>
<!--- Write it to a file --->
<cfset xml = "#tFolder#allNews.xml">
<cffile action="write" file="#xml#" output="#toString(newsXml)#">
</cfsilent>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Catalog the News</title>
<link href="/style/ext/catalogNews.css" rel="stylesheet" type="text/css" />
</head>
<body>
<cftry>
<table summary="Catalog of News Articles">
<col />
<col />
<col />
<col />
<col />
<thead>
<tr>
<th>File</th>
<th>Location</th>
<th>Date</th>
<th>Title</th>
<th>Teaser</th>
</tr>
</thead>
<tbody>
<cfset xml = newsXml.xmlRoot>
<cfset numArts = arrayLen(xml.xmlChildren)>
<cfloop index="i" from="1" to="#numArts#">
<cfset row = xml.xmlChildren[i]>
<!--- begin tr tag --->
<tr class="
<cfif StructKeyExists(row.xmlAttributes, "problem")>problem</cfif>
<cfif row.xmlName is "presskit">presskit</cfif>
<cfif (i mod 2)>stripe</cfif>
">
<!--- end tr tag --->
<cfoutput>
<cfif row.xmlName is "presskit">
<td><a href="news.cfm?presskit=#row.file.xmlText#">
#row.file.xmlText#
</a>
</td>
<cfelse>
<td><a href="news.cfm?art=#row.file.xmlText#">
#row.file.xmlText#
</a>
</td>
</cfif>
<td><cfif structKeyExists(row, "location")>
#row.location.xmlText#
</cfif>
</td>
<td><cfif row.xmlName is "presskit">
#row.date.start.year.xmlText#-#row.date.start.month.xmlText#-#row.date.start.day.xmlText# - #row.date.end.year.xmlText#-#row.date.end.month.xmlText#-#row.date.end.day.xmlText#
<cfelse>
#row.date.year.xmlText#-#row.date.month.xmlText#-#row.date.day.xmlText#
</cfif>
</td>
<td>#row.title.xmlText#
</td>
<td>#row.teaser.xmlText#
</td>
</cfoutput>
</tr>
</cfloop>
</tbody>
</table><cfcatch><cfdump var="#row#"></cfcatch></cftry>
</body>
</html>