| 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.6, 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 |
Object name: The json object name can be passed by adding |
|---|
| 26 |
"setappvar=objName(myobjname)" to the query string, allowing multiple |
|---|
| 27 |
json object calls on the same html page. If objName is not supplied, |
|---|
| 28 |
the default name is "bwObject". e.g.: |
|---|
| 29 |
<script src="http://localhost:8080/cal/main/listEvents.do?days=4&setappvar(objName=myobj)&skinName=json-list-src" type="text/javascript"></script> |
|---|
| 30 |
--> |
|---|
| 31 |
|
|---|
| 32 |
<!-- ********************************************************************** |
|---|
| 33 |
Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved. |
|---|
| 34 |
|
|---|
| 35 |
Redistribution and use of this distribution in source and binary forms, |
|---|
| 36 |
with or without modification, are permitted provided that: |
|---|
| 37 |
The above copyright notice and this permission notice appear in all |
|---|
| 38 |
copies and supporting documentation; |
|---|
| 39 |
|
|---|
| 40 |
The name, identifiers, and trademarks of Rensselaer Polytechnic |
|---|
| 41 |
Institute are not used in advertising or publicity without the |
|---|
| 42 |
express prior written permission of Rensselaer Polytechnic Institute; |
|---|
| 43 |
|
|---|
| 44 |
DISCLAIMER: The software is distributed" AS IS" without any express or |
|---|
| 45 |
implied warranty, including but not limited to, any implied warranties |
|---|
| 46 |
of merchantability or fitness for a particular purpose or any warrant)' |
|---|
| 47 |
of non-infringement of any current or pending patent rights. The authors |
|---|
| 48 |
of the software make no representations about the suitability of this |
|---|
| 49 |
software for any particular purpose. The entire risk as to the quality |
|---|
| 50 |
and performance of the software is with the user. Should the software |
|---|
| 51 |
prove defective, the user assumes the cost of all necessary servicing, |
|---|
| 52 |
repair or correction. In particular, neither Rensselaer Polytechnic |
|---|
| 53 |
Institute, nor the authors of the software are liable for any indirect, |
|---|
| 54 |
special, consequential, or incidental damages related to the software, |
|---|
| 55 |
to the maximum extent the law permits. |
|---|
| 56 |
--> |
|---|
| 57 |
|
|---|
| 58 |
<!-- DEFINE INCLUDES --> |
|---|
| 59 |
<!-- util.xsl belongs in bedework-common on your application server for use |
|---|
| 60 |
by all stylesheets: |
|---|
| 61 |
--> |
|---|
| 62 |
<xsl:include href="../../../bedework-common/default/default/util.xsl"/> |
|---|
| 63 |
<xsl:variable name="urlprefix" select="/bedework/urlprefix"/> |
|---|
| 64 |
<xsl:variable name="eventView" select="/bedework/urlPrefixes/event/eventView"/> |
|---|
| 65 |
|
|---|
| 66 |
<xsl:template match='/'> |
|---|
| 67 |
<xsl:choose> |
|---|
| 68 |
<xsl:when test="/bedework/appvar/key = 'objName'"> |
|---|
| 69 |
var <xsl:value-of select="/bedework/appvar[key='objName']/value"/> = {'bwEventList': { |
|---|
| 70 |
</xsl:when> |
|---|
| 71 |
<xsl:otherwise> |
|---|
| 72 |
{'bwEventList': { |
|---|
| 73 |
</xsl:otherwise> |
|---|
| 74 |
</xsl:choose> |
|---|
| 75 |
'events': [ |
|---|
| 76 |
<xsl:apply-templates select="/bedework/events/event"/> |
|---|
| 77 |
] |
|---|
| 78 |
}} |
|---|
| 79 |
</xsl:template> |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
<xsl:template match="event"> |
|---|
| 83 |
<!-- first, escape apostrophes --> |
|---|
| 84 |
<xsl:variable name="aposStrippedSummary"> |
|---|
| 85 |
<xsl:call-template name="replace"> |
|---|
| 86 |
<xsl:with-param name="string" select="summary"/> |
|---|
| 87 |
<xsl:with-param name="pattern" select='"'"'/> |
|---|
| 88 |
<xsl:with-param name="replacement" select='"\'"'/> |
|---|
| 89 |
</xsl:call-template> |
|---|
| 90 |
</xsl:variable> |
|---|
| 91 |
<xsl:variable name="aposStrippedDescription"> |
|---|
| 92 |
<xsl:call-template name="replace"> |
|---|
| 93 |
<xsl:with-param name="string" select="description"/> |
|---|
| 94 |
<xsl:with-param name="pattern" select='"'"'/> |
|---|
| 95 |
<xsl:with-param name="replacement" select='"\'"'/> |
|---|
| 96 |
</xsl:call-template> |
|---|
| 97 |
</xsl:variable> |
|---|
| 98 |
<xsl:variable name="aposStrippedLocAddress"> |
|---|
| 99 |
<xsl:call-template name="replace"> |
|---|
| 100 |
<xsl:with-param name="string" select="location/address"/> |
|---|
| 101 |
<xsl:with-param name="pattern" select='"'"'/> |
|---|
| 102 |
<xsl:with-param name="replacement" select='"\'"'/> |
|---|
| 103 |
</xsl:call-template> |
|---|
| 104 |
</xsl:variable> |
|---|
| 105 |
<!-- second, strip line breaks --> |
|---|
| 106 |
<xsl:variable name="strippedSummary" select='translate($aposStrippedSummary,"
"," ")'/> |
|---|
| 107 |
<xsl:variable name="strippedDescription" select='translate($aposStrippedDescription,"
"," ")'/> |
|---|
| 108 |
<xsl:variable name="strippedLocAddress" select='translate($aposStrippedLocAddress,"
"," ")'/> |
|---|
| 109 |
<!-- finally, produce the JSON output --> |
|---|
| 110 |
{ |
|---|
| 111 |
'summary' : '<xsl:value-of select="$strippedSummary"/>', |
|---|
| 112 |
'subscriptionId' : '<xsl:value-of select="subscription/id"/>', |
|---|
| 113 |
'calPath' : '<xsl:value-of select="calendar/encodedPath"/>', |
|---|
| 114 |
'guid' : '<xsl:call-template name="url-encode"><xsl:with-param name="str" select="guid"/></xsl:call-template>', |
|---|
| 115 |
'recurrenceId' : '<xsl:value-of select="recurrenceId"/>', |
|---|
| 116 |
'link' : '<xsl:value-of select='link'/>', |
|---|
| 117 |
'eventlink' : '<xsl:value-of select="$urlprefix"/><xsl:value-of select="$eventView"/>&calPath=<xsl:value-of select="calendar/encodedPath"/>&guid=<xsl:call-template name="url-encode"><xsl:with-param name="str" select="guid"/></xsl:call-template>&recurrenceId=<xsl:value-of select="recurrenceId"/>', // link of this event |
|---|
| 118 |
'status' : '<xsl:value-of select='status'/>', |
|---|
| 119 |
'start' : { |
|---|
| 120 |
'allday' : '<xsl:value-of select='start/allday'/>', |
|---|
| 121 |
'shortdate' : '<xsl:value-of select='start/shortdate'/>', |
|---|
| 122 |
'longdate' : '<xsl:value-of select='start/longdate'/>', |
|---|
| 123 |
'dayname' : '<xsl:value-of select='start/dayname'/>', |
|---|
| 124 |
'time' : '<xsl:value-of select='start/time'/>', |
|---|
| 125 |
'utcdate' : '<xsl:value-of select='start/utcdate'/>', |
|---|
| 126 |
'datetime' : '<xsl:value-of select='start/unformatted'/>', |
|---|
| 127 |
'timezone' : '<xsl:value-of select='start/timezone/id'/>' |
|---|
| 128 |
}, |
|---|
| 129 |
'end' : { |
|---|
| 130 |
'allday' : '<xsl:value-of select='end/allday'/>', |
|---|
| 131 |
'shortdate' : '<xsl:value-of select='end/shortdate'/>', |
|---|
| 132 |
'longdate' : '<xsl:value-of select='end/longdate'/>', |
|---|
| 133 |
'dayname' : '<xsl:value-of select='end/dayname'/>', |
|---|
| 134 |
'time' : '<xsl:value-of select='end/time'/>', |
|---|
| 135 |
'utcdate' : '<xsl:value-of select='end/utcdate'/>', |
|---|
| 136 |
'datetime' : '<xsl:value-of select='end/unformatted'/>', |
|---|
| 137 |
'timezone' : '<xsl:value-of select='end/timezone/id'/>' |
|---|
| 138 |
}, |
|---|
| 139 |
'location' : { |
|---|
| 140 |
'address' : '<xsl:value-of select="$strippedLocAddress"/>', |
|---|
| 141 |
'link' : '<xsl:value-of select='location/link'/>' |
|---|
| 142 |
}, |
|---|
| 143 |
'calendar' : { |
|---|
| 144 |
'name' : '<xsl:value-of select='calendar/name'/>', |
|---|
| 145 |
'path' : '<xsl:value-of select='calendar/path'/>', |
|---|
| 146 |
'encodedPath' : '<xsl:value-of select='calendar/encodedPath'/>' |
|---|
| 147 |
}, |
|---|
| 148 |
'categories' : [ |
|---|
| 149 |
<xsl:for-each select='categories/category'>'<xsl:value-of select='word'/>'<xsl:if test='position() != last()'>,</xsl:if></xsl:for-each> |
|---|
| 150 |
], |
|---|
| 151 |
'description' : '<xsl:value-of select='$strippedDescription'/>', |
|---|
| 152 |
'xproperties' : { |
|---|
| 153 |
<xsl:for-each select="xproperties/node()[name() != '']"> |
|---|
| 154 |
'<xsl:value-of select='name()'/>' : { |
|---|
| 155 |
'values' : { |
|---|
| 156 |
<xsl:for-each select="values/node()[name() != '']"> |
|---|
| 157 |
'<xsl:value-of select='name()'/>' : '<xsl:call-template name="replace"><xsl:with-param name="string" select="."/><xsl:with-param name="pattern" select='"'"'/><xsl:with-param name="replacement" select='"\'"'/></xsl:call-template>'<xsl:if test='position() != last()'>,</xsl:if> |
|---|
| 158 |
</xsl:for-each> |
|---|
| 159 |
} |
|---|
| 160 |
}<xsl:if test='position() != last()'>,</xsl:if> |
|---|
| 161 |
</xsl:for-each> |
|---|
| 162 |
} |
|---|
| 163 |
}<xsl:if test="position() != last()">,</xsl:if> |
|---|
| 164 |
</xsl:template> |
|---|
| 165 |
</xsl:stylesheet> |
|---|