prepare.xslt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cpscrn
  5. (C) Copyright IBM Corp. 2005, 2011
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:encodingUtils="com.cognos.portal.utils.EncodingUtils">
  13. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  14. <xsl:variable name="controllerParams" select="/root/controllerParams/param"/>
  15. <xsl:variable name="customs" select="/root/customs/param"/>
  16. <xsl:variable name="meta" select="/root/fragment/meta"/>
  17. <xsl:variable name="backURL" select="/root/interactions/param[@name='backURL']"/>
  18. <xsl:template match="/">
  19. <response>
  20. <xsl:if test="not($controllerParams[@name='frag-directive'] = 'meta-only')">
  21. <xsl:variable name="pages">
  22. <xsl:choose>
  23. <!-- pages is statically defined as XML -->
  24. <xsl:when test="$customs[@name='pages']/pages">
  25. <xsl:copy-of select="$customs[@name='pages']/pages"/>
  26. </xsl:when>
  27. <!-- pages is statically defined as text, so convert it to XML -->
  28. <xsl:when test="normalize-space($customs[@name='pages']) != ''">
  29. <xsl:value-of select="$customs[@name='pages']" disable-output-escaping="yes"/>
  30. </xsl:when>
  31. </xsl:choose>
  32. </xsl:variable>
  33. <xsl:variable name="folder">
  34. <xsl:call-template name="get-custom">
  35. <xsl:with-param name="name">folder</xsl:with-param>
  36. </xsl:call-template>
  37. </xsl:variable>
  38. <xsl:variable name="maxlevels">
  39. <xsl:call-template name="get-custom">
  40. <xsl:with-param name="name">maxlevels</xsl:with-param>
  41. </xsl:call-template>
  42. </xsl:variable>
  43. <xsl:variable name="header">
  44. <xsl:call-template name="get-custom">
  45. <xsl:with-param name="name">header</xsl:with-param>
  46. </xsl:call-template>
  47. </xsl:variable>
  48. <xsl:variable name="footer">
  49. <xsl:call-template name="get-custom">
  50. <xsl:with-param name="name">footer</xsl:with-param>
  51. </xsl:call-template>
  52. </xsl:variable>
  53. <xsl:variable name="fixed">
  54. <xsl:call-template name="get-custom">
  55. <xsl:with-param name="name">fixed</xsl:with-param>
  56. </xsl:call-template>
  57. </xsl:variable>
  58. <xsl:variable name="view">
  59. <xsl:call-template name="get-custom">
  60. <xsl:with-param name="name">view</xsl:with-param>
  61. </xsl:call-template>
  62. </xsl:variable>
  63. <xsl:variable name="excludeEmptyFolders">
  64. <xsl:call-template name="get-custom">
  65. <xsl:with-param name="name">excludeEmptyFolders</xsl:with-param>
  66. </xsl:call-template>
  67. </xsl:variable>
  68. <fragment>
  69. <xsl:if test="$fixed = 'true'">
  70. <info>
  71. <xsl:copy-of select="/root/fragment/info/*"/>
  72. <display>fixed</display>
  73. </info>
  74. </xsl:if>
  75. <xsl:if test="$header != ''">
  76. <xsl:variable name="myHref">
  77. <xsl:call-template name="gen-href">
  78. <xsl:with-param name="value" select="$header"/>
  79. </xsl:call-template>
  80. </xsl:variable>
  81. <subfragment id="header" href="{$myHref}">
  82. <params><!-- backURL needs to be kept in a cdata block for now. This is due to a bug in the server, where text is being truncated at the first entity -->
  83. <param name="backURL">
  84. <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text><xsl:value-of select="$backURL" disable-output-escaping="yes"/><xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  85. </param>
  86. </params>
  87. </subfragment>
  88. </xsl:if>
  89. <xsl:if test="$footer != ''">
  90. <subfragment id="footer">
  91. <xsl:attribute name="href">
  92. <xsl:call-template name="gen-href">
  93. <xsl:with-param name="value" select="$footer"/>
  94. </xsl:call-template>
  95. </xsl:attribute>
  96. </subfragment>
  97. </xsl:if>
  98. <xsl:if test="not($controllerParams[@name='frag-view'])">
  99. <newView>
  100. <xsl:value-of select="$view"/>
  101. </newView>
  102. </xsl:if>
  103. </fragment>
  104. <xsl:choose>
  105. <xsl:when test="$pages/pages">
  106. <!-- copy as XML elements -->
  107. <xsl:copy-of select="$pages/pages"/>
  108. </xsl:when>
  109. <xsl:when test="$pages != ''">
  110. <!-- copy as disabled-escaping text -->
  111. <xsl:copy-of select="$pages"/>
  112. </xsl:when>
  113. <xsl:when test="$folder != ''">
  114. <!-- copy NAV request -->
  115. <xsl:variable name="classes">
  116. <class>analysis</class>
  117. <class>document</class>
  118. <class>package</class>
  119. <class>pagelet</class>
  120. <class>pageletFolder</class>
  121. <class>powerPlayCube</class>
  122. <class>powerPlayReport</class>
  123. <class>powerPlay8Report</class>
  124. <class>query</class>
  125. <class>report</class>
  126. <class>reportView</class>
  127. <class>shortcut</class>
  128. <class>URL</class>
  129. </xsl:variable>
  130. <xsl:variable name="filter">
  131. <xsl:text>[@objectClass='folder'</xsl:text>
  132. <xsl:for-each select="$classes/class">
  133. <xsl:text> or @objectClass='</xsl:text>
  134. <xsl:value-of select="."/>
  135. <xsl:text>'</xsl:text>
  136. </xsl:for-each>
  137. <xsl:text>][@shown='true']</xsl:text>
  138. </xsl:variable>
  139. <xsl:variable name="fragPortalAgent">
  140. <xsl:choose>
  141. <xsl:when test="$controllerParams[@name='frag-portalAgent'] != ''">
  142. <xsl:value-of select="$controllerParams[@name='frag-portalAgent']"/>
  143. </xsl:when>
  144. <xsl:otherwise>
  145. <xsl:text>cognosFragmentServer</xsl:text>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:variable>
  149. <xsl:variable name="frag-agent" select="/root/controllerParams/param[@name='frag-agent']"/>
  150. <xsl:variable name="browser">
  151. <xsl:choose>
  152. <xsl:when test="contains($frag-agent , 'MSIE')">ie</xsl:when> <!-- IE 4.xx and above -->
  153. <xsl:when test="contains($frag-agent , 'Safari')">safari</xsl:when> <!-- Safari -->
  154. <xsl:when test="contains($frag-agent , 'Mozilla/5.0')">moz</xsl:when> <!-- NS 6.xx and 7.xx -->
  155. <xsl:when test="contains($frag-agent , 'Mozilla/4.')">ns4</xsl:when> <!-- NS 4.xx -->
  156. <xsl:when test="string-length($frag-agent) = 0">undefined</xsl:when>
  157. <xsl:otherwise>other</xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:variable>
  160. <nav>
  161. <SOAP-ENV:Envelope xmlns:bus="http://developer.cognos.com/schemas/bibus/3/" xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  162. <SOAP-ENV:Header>
  163. <xsl:copy-of select="/root/bus:biBusHeader"/>
  164. </SOAP-ENV:Header>
  165. <SOAP-ENV:Body>
  166. <nav:request>
  167. <nav:param name="browserAgent"><xsl:value-of select="$browser"/></nav:param>
  168. <nav:param name="webContentURL">.</nav:param>
  169. <nav:param name="portalAgent"><xsl:value-of select="$fragPortalAgent"/></nav:param>
  170. <nav:queries>
  171. <nav:query>
  172. <nav:getContainer>
  173. <nav:id>
  174. <xsl:call-template name="gen-cmpath">
  175. <xsl:with-param name="value" select="$folder"/>
  176. </xsl:call-template>
  177. </nav:id>
  178. <nav:childObjectFilter>
  179. <xsl:text/><nav:itemType>folder</nav:itemType><xsl:text/>
  180. <xsl:for-each select="$classes/class">
  181. <xsl:text/><nav:itemType><xsl:value-of select="."/></nav:itemType><xsl:text/>
  182. </xsl:for-each>
  183. </nav:childObjectFilter>
  184. <nav:property name="baseType"/>
  185. <nav:property name="internalId"/>
  186. <nav:property name="permissions"/>
  187. <nav:property name="action"/>
  188. <nav:property name="hidden"/>
  189. <nav:property name="defaultPortalAction"/>
  190. <xsl:if test="$customs[@name='useProductLocaleForTabNames']='true'">
  191. <nav:property name="productLocaleName"/>
  192. </xsl:if>
  193. </nav:getContainer>
  194. </nav:query>
  195. <xsl:if test="number($maxlevels) > 1 or $excludeEmptyFolders='true'">
  196. <nav:query>
  197. <nav:search>
  198. <nav:searchType>normal</nav:searchType>
  199. <nav:scope>
  200. <xsl:call-template name="gen-cmpath">
  201. <xsl:with-param name="value" select="$folder"/>
  202. </xsl:call-template>
  203. <xsl:text>/*/*</xsl:text>
  204. <xsl:value-of select="$filter"/>
  205. </nav:scope>
  206. <nav:childObjects>none</nav:childObjects>
  207. <nav:sort order="descending">displaySequence</nav:sort>
  208. <nav:property name="baseType"/>
  209. <nav:property name="internalId"/>
  210. <nav:property name="parentId"/>
  211. <nav:property name="permissions"/>
  212. <nav:property name="action"/>
  213. <nav:property name="hidden"/>
  214. <nav:property name="defaultPortalAction"/>
  215. <xsl:if test="$customs[@name='useProductLocaleForTabNames']='true'">
  216. <nav:property name="productLocaleName"/>
  217. </xsl:if>
  218. </nav:search>
  219. </nav:query>
  220. </xsl:if>
  221. </nav:queries>
  222. </nav:request>
  223. </SOAP-ENV:Body>
  224. </SOAP-ENV:Envelope>
  225. </nav>
  226. </xsl:when>
  227. <xsl:otherwise>
  228. <!-- no pages xml or selected folder -->
  229. <pages no-source="true"/>
  230. </xsl:otherwise>
  231. </xsl:choose>
  232. </xsl:if>
  233. <xsl:if test="string(/root/interactions/param[@name='selectedTabs'])!=''">
  234. <state>
  235. <xsl:copy-of select="/root/interactions/param[@name='selectedTabs']"/>
  236. </state>
  237. </xsl:if>
  238. </response>
  239. </xsl:template>
  240. <!--
  241. gen-cmpath: generate a CM path syntax for NAV
  242. -->
  243. <xsl:template name="gen-cmpath">
  244. <xsl:param name="value"/>
  245. <xsl:choose>
  246. <xsl:when test="starts-with($value, 'path:')">
  247. <xsl:value-of select="$value"/>
  248. </xsl:when>
  249. <xsl:when test="starts-with($value, 'storeID(')">
  250. <xsl:text>path:</xsl:text>
  251. <xsl:value-of select="$value"/>
  252. </xsl:when>
  253. <xsl:otherwise>
  254. <xsl:text>path:storeID('</xsl:text>
  255. <xsl:value-of select="$value"/>
  256. <xsl:text>')</xsl:text>
  257. </xsl:otherwise>
  258. </xsl:choose>
  259. </xsl:template>
  260. <!--
  261. gen-href: generate href based on $value
  262. -->
  263. <xsl:template name="gen-href">
  264. <xsl:param name="value"/>
  265. <xsl:choose>
  266. <xsl:when test="starts-with($value, '/')">
  267. <xsl:value-of select="$value"/>
  268. </xsl:when>
  269. <xsl:when test="contains($value, '://')">
  270. <xsl:value-of select="$value"/>
  271. </xsl:when>
  272. <xsl:otherwise>
  273. <xsl:text>/cm?path=</xsl:text>
  274. <xsl:value-of select="$value"/>
  275. </xsl:otherwise>
  276. </xsl:choose>
  277. </xsl:template>
  278. <!--
  279. get-custom: get a value from either the customs or the META's default value
  280. -->
  281. <xsl:template name="get-custom">
  282. <xsl:param name="name"/>
  283. <xsl:choose>
  284. <xsl:when test="$customs[@name=$name]">
  285. <xsl:value-of select="$customs[@name=$name]"/>
  286. </xsl:when>
  287. <xsl:otherwise>
  288. <xsl:value-of select="$meta/customProperties[@name=$name]/default/value"/>
  289. </xsl:otherwise>
  290. </xsl:choose>
  291. </xsl:template>
  292. </xsl:stylesheet>