root/trunk/deployment/feeder/webapp/resources/demoskins/MainCampus/default/default/tofreshen/json-list-src.xsl

Revision 2520 (checked in by johnsa, 3 years ago)

all webclients: update references to categories

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   <!-- JSON feed of Bedework events,
5        Bedework v3.4.x, Arlen Johnson
6
7        Purpose: produces an array of javascript objects representing events.
8
9        Usage: call the JSON feed from an html file by embedding a script tag.
10        Examples:
11
12        The next four days (max days = 31):
13        <script src="http://localhost:8080/cal/main/listEvents.do?days=4&skinName=json-list-src" type="text/javascript"></script>
14
15        A range of dates:
16        <script src="http://localhost:8080/cal/main/listEvents.do?start=2008-10-03&end=2008-11-02&skinName=json-list-src" type="text/javascript"></script>
17
18        The next ten days limited by category (you can append as many categories as you like):
19        <script src="http://localhost:8080/cal/main/listEvents.do?days=10&cat=Concerts&skinName=json-list-src" type="text/javascript"></script>
20
21        Filters: Arbitrary filters can be sent to this stylesheet using the query
22        parameter "setappvar=filter(somekey:somevalue)".  Group (creator) and
23        location filters are included here, but you can add more under line 82.
24
25        The next ten days filtered by a group (creator):
26        <script src="http://localhost:8080/cal/main/listEvents.do?days=10&setappvar=filter(creator:agrp_Library)&skinName=json-list-src" type="text/javascript"></script>
27
28        Object name: The json object name can be passed by adding
29        "setappvar=objName(myobjname)" to the query string, allowing multiple
30        json object calls on the same html page.  If objName is not supplied,
31        the default name is "bwObject".  e.g.:
32        <script src="http://localhost:8080/cal/main/listEvents.do?days=4&setappvar(objName=myobj)&skinName=json-list-src" type="text/javascript"></script>
33   -->
34
35   <!-- **********************************************************************
36     Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
37
38     Redistribution and use of this distribution in source and binary forms,
39     with or without modification, are permitted provided that:
40        The above copyright notice and this permission notice appear in all
41         copies and supporting documentation;
42
43         The name, identifiers, and trademarks of Rensselaer Polytechnic
44         Institute are not used in advertising or publicity without the
45         express prior written permission of Rensselaer Polytechnic Institute;
46
47     DISCLAIMER: The software is distributed" AS IS" without any express or
48     implied warranty, including but not limited to, any implied warranties
49     of merchantability or fitness for a particular purpose or any warrant)'
50     of non-infringement of any current or pending patent rights. The authors
51     of the software make no representations about the suitability of this
52     software for any particular purpose. The entire risk as to the quality
53     and performance of the software is with the user. Should the software
54     prove defective, the user assumes the cost of all necessary servicing,
55     repair or correction. In particular, neither Rensselaer Polytechnic
56     Institute, nor the authors of the software are liable for any indirect,
57     special, consequential, or incidental damages related to the software,
58     to the maximum extent the law permits. -->
59
60   <!-- DEFINE INCLUDES -->
61   <!-- util.xsl belongs in bedework-common on your application server for use
62        by all stylesheets: -->
63   <xsl:include href="../../../bedework-common/default/default/util.xsl"/>
64
65   <xsl:variable name="urlprefix" select="/bedework/urlprefix"/>
66   <xsl:variable name="eventView" select="/bedework/urlPrefixes/event/eventView"/>
67   <xsl:template match='/'>
68     <xsl:choose>
69       <xsl:when test="/bedework/appvar/key = 'objName'">
70         var <xsl:value-of select="/bedework/appvar[key='objName']/value"/> = {'bwEventList': {
71       </xsl:when>
72       <xsl:otherwise>
73         var bwObject = {'bwEventList': {
74       </xsl:otherwise>
75     </xsl:choose>
76         'events': [
77           <xsl:choose>
78             <xsl:when test="/bedework/appvar/key = 'filter'">
79               <xsl:variable name="filterName" select="substring-before(/bedework/appvar[key='filter']/value,':')"/>
80               <xsl:variable name="filterVal" select="substring-after(/bedework/appvar[key='filter']/value,':')"/>
81               <!-- Define filters here: -->
82               <xsl:choose>
83                 <xsl:when test="$filterName = 'creator'">
84                   <xsl:apply-templates select="/bedework/events//event[creator = $filterVal]"/>
85                 </xsl:when>
86                 <xsl:when test="$filterName = 'location'">
87                   <xsl:apply-templates select="/bedework/events//event[location/address = $filterVal]"/>
88                 </xsl:when>
89                 <xsl:otherwise>
90                   <!-- Filter name not defined? Turn off filtering. -->
91                   <xsl:apply-templates select="/bedework/events//event"/>
92                 </xsl:otherwise>
93               </xsl:choose>
94             </xsl:when>
95             <xsl:otherwise>
96               <xsl:apply-templates select="/bedework/events//event"/>
97             </xsl:otherwise>
98           </xsl:choose>
99         ]
100     }}
101   </xsl:template>
102
103   <xsl:template match="event">
104     <!-- first, escape apostrophes -->
105     <xsl:variable name="aposStrippedSummary">
106       <xsl:call-template name="replace">
107         <xsl:with-param name="string" select="summary"/>
108         <xsl:with-param name="pattern" select='"&apos;"'/>
109         <xsl:with-param name="replacement" select='"\&apos;"'/>
110       </xsl:call-template>
111     </xsl:variable>
112     <xsl:variable name="aposStrippedDescription">
113       <xsl:call-template name="replace">
114         <xsl:with-param name="string" select="description"/>
115         <xsl:with-param name="pattern" select='"&apos;"'/>
116         <xsl:with-param name="replacement" select='"\&apos;"'/>
117       </xsl:call-template>
118     </xsl:variable>
119     <xsl:variable name="aposStrippedLocAddress">
120       <xsl:call-template name="replace">
121         <xsl:with-param name="string" select="location/address"/>
122         <xsl:with-param name="pattern" select='"&apos;"'/>
123         <xsl:with-param name="replacement" select='"\&apos;"'/>
124       </xsl:call-template>
125     </xsl:variable>
126     <!-- second, strip line breaks -->
127     <xsl:variable name="strippedSummary" select='translate($aposStrippedSummary,"&#xA;"," ")'/>
128     <xsl:variable name="strippedDescription" select='translate($aposStrippedDescription,"&#xA;"," ")'/>
129     <xsl:variable name="strippedLocAddress" select='translate($aposStrippedLocAddress,"&#xA;"," ")'/>
130     <!-- finally, produce the JSON output -->
131             {
132                 'summary' : '<xsl:value-of select="$strippedSummary"/>',
133                 'subscriptionId' : '<xsl:value-of select="subscription/id"/>',
134                 'calPath' : '<xsl:value-of select="calendar/encodedPath"/>',
135                 'guid' : '<xsl:call-template name="url-encode"><xsl:with-param name="str" select="guid"/></xsl:call-template>',
136                 'recurrenceId' : '<xsl:value-of select="recurrenceId"/>',
137                 'link' : '<xsl:value-of select='link'/>',
138                 '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"/>', // link of this event
139                 'status' : '<xsl:value-of select='status'/>',
140                 'start' : {
141                     'allday' : '<xsl:value-of select='start/allday'/>',
142                     'shortdate' : '<xsl:value-of select='start/shortdate'/>',
143                     'longdate' : '<xsl:value-of select='start/longdate'/>',
144                     'dayname' : '<xsl:value-of select='start/dayname'/>',
145                     'time' : '<xsl:value-of select='start/time'/>',
146                     'utcdate' : '<xsl:value-of select='start/utcdate'/>',
147                     'datetime' : '<xsl:value-of select='start/unformatted'/>',
148                     'timezone' : '<xsl:value-of select='start/timezone/id'/>'
149                 },
150                 'end' : {
151                     'allday' : '<xsl:value-of select='end/allday'/>',
152                     'shortdate' : '<xsl:value-of select='end/shortdate'/>',
153                     'longdate' : '<xsl:value-of select='end/longdate'/>',
154                     'dayname' : '<xsl:value-of select='end/dayname'/>',
155                     'time' : '<xsl:value-of select='end/time'/>',
156                     'utcdate' : '<xsl:value-of select='end/utcdate'/>',
157                     'datetime' : '<xsl:value-of select='end/unformatted'/>',
158                     'timezone' : '<xsl:value-of select='end/timezone/id'/>'
159                 },
160                 'location' : {
161                     'address' : '<xsl:value-of select="$strippedLocAddress"/>',
162                     'link' : '<xsl:value-of select='location/link'/>'
163                 },
164                 'calendar' : {
165                     'name' : '<xsl:value-of select='calendar/name'/>',
166                     'path' : '<xsl:value-of select='calendar/path'/>',
167                     'encodedPath' : '<xsl:value-of select='calendar/encodedPath'/>'
168                 },
169                 'categories' : [
170                     <xsl:for-each select='categories/category'>'<xsl:value-of select='value'/>'<xsl:if test='position() != last()'>,</xsl:if></xsl:for-each>
171                 ],
172                 'description' : '<xsl:value-of select='$strippedDescription'/>',
173                 'xproperties' : {
174                   <xsl:for-each select="xproperties/node()[name() != '']">
175                     '<xsl:value-of select='name()'/>' : {
176                        'values' : {
177                            <xsl:for-each select="values/node()[name() != '']">
178                              '<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>
179                            </xsl:for-each>
180                         }
181                     }<xsl:if test='position() != last()'>,</xsl:if>
182                   </xsl:for-each>
183                 }
184             }<xsl:if test="position() != last()">,</xsl:if>
185   </xsl:template>
186 </xsl:stylesheet>
Note: See TracBrowser for help on using the browser.