root/trunk/deployment/feeder/webapp/resources/demoskins/MainCampus/default/default/grid-json.xsl

Revision 2419 (checked in by bleibson, 3 years ago)

Checkpoint of new json skin for setViewPeriod method. It produces valid json, but beyond that I'm not making any claims at this point.

  • Property svn:mime-type set to text/plain
Line 
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3   <xsl:output method="html" omit-xml-declaration="yes" indent="no" media-type="text/javascript" standalone="yes"/>
4  
5   <!-- **********************************************************************
6     Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
7
8     Redistribution and use of this distribution in source and binary forms,
9     with or without modification, are permitted provided that:
10        The above copyright notice and this permission notice appear in all
11         copies and supporting documentation;
12
13         The name, identifiers, and trademarks of Rensselaer Polytechnic
14         Institute are not used in advertising or publicity without the
15         express prior written permission of Rensselaer Polytechnic Institute;
16
17     DISCLAIMER: The software is distributed" AS IS" without any express or
18     implied warranty, including but not limited to, any implied warranties
19     of merchantability or fitness for a particular purpose or any warrant)'
20     of non-infringement of any current or pending patent rights. The authors
21     of the software make no representations about the suitability of this
22     software for any particular purpose. The entire risk as to the quality
23     and performance of the software is with the user. Should the software
24     prove defective, the user assumes the cost of all necessary servicing,
25     repair or correction. In particular, neither Rensselaer Polytechnic
26     Institute, nor the authors of the software are liable for any indirect,
27     special, consequential, or incidental damages related to the software,
28     to the maximum extent the law permits.
29   -->
30
31   <!-- DEFINE INCLUDES -->
32   <!-- util.xsl belongs in bedework-common on your application server for use
33        by all stylesheets:
34   -->
35   <xsl:include href="../../../bedework-common/default/default/util.xsl"/>
36   <xsl:variable name="urlprefix" select="/bedework/urlprefix"/>
37   <xsl:variable name="eventView" select="/bedework/urlPrefixes/event/eventView"/>
38  
39   <xsl:template match='/'>
40     <xsl:choose>
41       <xsl:when test="/bedework/appvar/key = 'objName'">
42         var <xsl:value-of select="/bedework/appvar[key='objName']/value"/> = {'bwEventCalendar': {
43       </xsl:when>
44       <xsl:otherwise>
45       {"bwEventCalendar": {
46       </xsl:otherwise>
47     </xsl:choose>
48         "year": {
49           "value": "<xsl:value-of select='/bedework/eventscalendar/year/value'/>",
50                <xsl:apply-templates select="/bedework/eventscalendar/year/month" />
51             }
52       }}
53   </xsl:template>
54
55   <xsl:template name="processGrpAndCats">
56     <xsl:param name="list" />
57     <xsl:variable name="group" select="substring-before($list, '~')" />
58     <xsl:variable name="remaining" select="substring-after($list, '~')" />
59     <xsl:call-template name="processCategories">
60           <xsl:with-param name="group" select="$group" />
61       <xsl:with-param name="list" select="$remaining" />
62     </xsl:call-template>
63   </xsl:template>
64
65   <xsl:template name="processCategories">
66         <xsl:param name="group" />
67     <xsl:param name="list" />
68     <xsl:choose>
69           <xsl:when test="contains($list, '~')">
70                 <!-- Grab the first off the list and process -->
71                 <xsl:variable name="catid" select="substring-before($list, '~')" />
72             <xsl:variable name="remaining" select="substring-after($list, '~')" />
73             <xsl:choose>
74                   <xsl:when test="$group = 'all'">
75                 <xsl:apply-templates select="/bedework/events/event[categories/category/id = $catid]" />
76               </xsl:when>
77               <xsl:otherwise>
78                 <xsl:apply-templates select="/bedework/events/event[categories/category/id = $catid]" />
79               </xsl:otherwise>
80             </xsl:choose>
81        
82                 <!-- now use recursion to process the remaining categories -->
83             <xsl:call-template name="processCategories">
84               <xsl:with-param name="list" select="$remaining" />
85             </xsl:call-template>
86           </xsl:when>
87           <xsl:otherwise>
88             <!-- No more tildes, so this is the last category.  Process it -->
89                 <xsl:choose>
90                   <xsl:when test="$group = 'all'">
91                         <xsl:choose>
92                           <xsl:when test="$list = 'all'">
93                     <xsl:apply-templates select="/bedework/events/event" />
94                   </xsl:when>
95                   <xsl:otherwise>
96                         <xsl:apply-templates select="/bedework/events/event[categories/category/id = $list]" />
97                       </xsl:otherwise>
98                 </xsl:choose>
99               </xsl:when>
100               <xsl:otherwise>
101                     <xsl:choose>
102                           <xsl:when test="$list = 'all'">
103                     <xsl:apply-templates select="/bedework/events/event[creator = $group]" />
104                   </xsl:when>
105                   <xsl:otherwise>
106                         <xsl:choose>
107                           <xsl:when test="/bedework/events/events/creator = $group">
108                             <xsl:apply-templates select="/bedework/events/event[categories/category/id = $list]" />
109                           </xsl:when>
110                         </xsl:choose>
111                       </xsl:otherwise>
112                         </xsl:choose>
113               </xsl:otherwise>
114             </xsl:choose>
115           </xsl:otherwise>
116         </xsl:choose>
117   </xsl:template>
118
119   <xsl:template match="month">
120             "month": {
121               "value" : "<xsl:value-of select='value'/>",
122               "longname" : "<xsl:value-of select='longname'/>",
123               "shortname" : "<xsl:value-of select='shortname'/>",
124           <xsl:apply-templates select="week" />
125         }<xsl:if test="position() != last()">,</xsl:if>
126   </xsl:template>
127
128   <xsl:template match="week">
129               "week": {
130                 "value" : "<xsl:value-of select='value'/>",
131                 <xsl:apply-templates select="day" />
132               }<xsl:if test="position() != last()">,</xsl:if>
133   </xsl:template>
134  
135  
136
137   <xsl:template match="day">
138                 "day": {
139                   <xsl:choose>
140                         <xsl:when test="filler = 'true'">
141                           "filler" : "<xsl:value-of select='filler'/>"
142                         </xsl:when>
143                         <xsl:otherwise>
144                           "filler" : "<xsl:value-of select='filler'/>",
145                   "value" : "<xsl:value-of select='value'/>",
146                   "name" : "<xsl:value-of select='name'/>",
147                   "date" : "<xsl:value-of select='date'/>",
148                   "longdate" : "<xsl:value-of select='longdate'/>",
149                   "shortdate" : "<xsl:value-of select='shortdate'/>"
150                       <xsl:choose>
151                             <xsl:when test="/bedework/appvar/key = 'filter'">
152                               <xsl:variable name="filterName" select="substring-before(/bedework/appvar[key='filter']/value,':')"/>
153                               <xsl:variable name="filterVal" select="substring-after(/bedework/appvar[key='filter']/value,':')"/>
154                               <!-- Define filters here: -->
155                               <xsl:choose>
156                                 <xsl:when test="$filterName = 'grpAndCats'">
157                                       <xsl:call-template name="processGrpAndCats"><xsl:with-param name="list" select="$filterVal"/></xsl:call-template>
158                                 </xsl:when>
159                                 <xsl:otherwise>
160                                   <!-- Filter name not defined? Turn off filtering. -->
161                                   <xsl:apply-templates select="event"/>
162                                 </xsl:otherwise>
163                               </xsl:choose>
164                             </xsl:when>
165                             <xsl:otherwise>
166                               <xsl:apply-templates select="event"/>
167                             </xsl:otherwise>
168                           </xsl:choose>
169                         </xsl:otherwise>
170                       </xsl:choose>
171                     }<xsl:if test="position() != last()">,</xsl:if>
172   </xsl:template>       
173
174   <xsl:template match="event">
175     <!-- first, escape apostrophes -->
176     <xsl:variable name="aposStrippedSummary">
177       <xsl:call-template name="replace">
178         <xsl:with-param name="string" select="summary"/>
179         <xsl:with-param name="pattern" select='"&apos;"'/>
180         <xsl:with-param name="replacement" select='"\&apos;"'/>
181       </xsl:call-template>
182     </xsl:variable>
183     <xsl:variable name="aposStrippedDescription">
184       <xsl:call-template name="replace">
185         <xsl:with-param name="string" select="description"/>
186         <xsl:with-param name="pattern" select='"&apos;"'/>
187         <xsl:with-param name="replacement" select='"\&apos;"'/>
188       </xsl:call-template>
189     </xsl:variable>
190     <xsl:variable name="aposStrippedLocAddress">
191       <xsl:call-template name="replace">
192         <xsl:with-param name="string" select="location/address"/>
193         <xsl:with-param name="pattern" select='"&apos;"'/>
194         <xsl:with-param name="replacement" select='"\&apos;"'/>
195       </xsl:call-template>
196     </xsl:variable>
197     <!-- second, strip line breaks -->
198     <xsl:variable name="strippedSummary" select='translate($aposStrippedSummary,"&#xA;"," ")'/>
199     <xsl:variable name="strippedDescription" select='translate($aposStrippedDescription,"&#xA;"," ")'/>
200     <xsl:variable name="strippedLocAddress" select='translate($aposStrippedLocAddress,"&#xA;"," ")'/>
201     <!-- finally, produce the JSON output -->
202                   , "event": {
203                     "summary" : "<xsl:value-of select="$strippedSummary"/>",
204                     "subscriptionId" : "<xsl:value-of select="subscription/id"/>",
205                     "calPath" : "<xsl:value-of select="calendar/encodedPath"/>",
206                     "guid" : "<xsl:call-template name="url-encode"><xsl:with-param name="str" select="guid"/></xsl:call-template>",
207                     "recurrenceId" : "<xsl:value-of select="recurrenceId"/>",
208                     "link" : "<xsl:value-of select='link'/>",
209                     "eventlink" : "<xsl:value-of select="$urlprefix"/><xsl:value-of select="$eventView"/>&amp;calPath=<xsl:value-of select="calendar/encodedPath"/>&amp;guid=<xsl:call-template name="url-encode"><xsl:with-param name="str" select="guid"/></xsl:call-template>&amp;recurrenceId=<xsl:value-of select="recurrenceId"/>",
210                     "status" : "<xsl:value-of select='status'/>",
211                     "start" : {
212                       "allday" : "<xsl:value-of select='start/allday'/>",
213                       "shortdate" : "<xsl:value-of select='start/shortdate'/>",
214                       "longdate" : "<xsl:value-of select='start/longdate'/>",
215                       "dayname" : "<xsl:value-of select='start/dayname'/>",
216                       "time" : "<xsl:value-of select='start/time'/>",
217                       "utcdate" : "<xsl:value-of select='start/utcdate'/>",
218                       "datetime" : "<xsl:value-of select='start/unformatted'/>",
219                       "timezone" : "<xsl:value-of select='start/timezone/id'/>"
220                     },
221                     "end" : {
222                       "allday" : "<xsl:value-of select='end/allday'/>",
223                       "shortdate" : "<xsl:value-of select='end/shortdate'/>",
224                       "longdate" : "<xsl:value-of select='end/longdate'/>",
225                       "dayname" : "<xsl:value-of select='end/dayname'/>",
226                       "time" : "<xsl:value-of select='end/time'/>",
227                       "utcdate" : "<xsl:value-of select='end/utcdate'/>",
228                       "datetime" : "<xsl:value-of select='end/unformatted'/>",
229                       "timezone" : "<xsl:value-of select='end/timezone/id'/>"
230                     },
231                     "location" : {
232                       "address" : "<xsl:value-of select="$strippedLocAddress"/>",
233                       "link" : "<xsl:value-of select='location/link'/>"
234                     },
235                     "calendar" : {
236                       "name" : "<xsl:value-of select='calendar/name'/>",
237                       "path" : "<xsl:value-of select='calendar/path'/>",
238                       "encodedPath" : "<xsl:value-of select='calendar/encodedPath'/>"
239                     },
240                     "categories" : [
241                       <xsl:for-each select='categories/category'>"<xsl:value-of select='word'/>"<xsl:if test='position() != last()'>,</xsl:if></xsl:for-each>
242                     ],
243                     "description" : "<xsl:value-of select='$strippedDescription'/>",
244                     "xproperties" : {
245                       <xsl:for-each select="xproperties/node()[name() != '']">
246                        "<xsl:value-of select='name()'/>" : {
247                        "values" : {
248                            <xsl:for-each select="values/node()[name() != '']">
249                              "<xsl:value-of select='name()'/>" : "<xsl:call-template name="replace"><xsl:with-param name="string" select="."/><xsl:with-param name="pattern" select='"&apos;"'/><xsl:with-param name="replacement" select='"\&apos;"'/></xsl:call-template>"<xsl:if test='position() != last()'>,</xsl:if>
250                            </xsl:for-each>
251                         }
252                       }<xsl:if test='position() != last()'>,</xsl:if>
253                   </xsl:for-each>
254                     }
255                  }<xsl:if test="position() != last()">,</xsl:if>
256   </xsl:template>
257 </xsl:stylesheet>
Note: See TracBrowser for help on using the browser.