pagelet-rewrite.xslt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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"
  13. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  15. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  16. xmlns:wsrp="urn:oasis:names:tc:wsrp:v1:types"
  17. exclude-result-prefixes="xts xtsext wsrp">
  18. <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="no"/>
  19. <!--
  20. <xsl:variable name="page-context">
  21. <xsl:choose>
  22. <xsl:when test="/root/newPageContext/*[local-name()='pageletContext']"><xsl:value-of select="/root/newPageContext/*[local-name()='pageletContext']"/></xsl:when>
  23. <xsl:otherwise><xsl:value-of select="/root/currentPageContext/*[local-name()='pageletContext']"/></xsl:otherwise>
  24. </xsl:choose>
  25. </xsl:variable>
  26. -->
  27. <xsl:variable name="new-page-context" select="/root/newPageContext/*[local-name()='pageletContext']"/>
  28. <xsl:variable name="current-page-context" select="/root/currentPageContext/*[local-name()='pageletContext']"/>
  29. <xsl:variable name="ui-state-params" select="/root/portletState/param"/>
  30. <xsl:variable name="ui-session-params" select="/root/session/param"/>
  31. <xsl:variable name="ui-window-state" select="/root/windowState"/>
  32. <xsl:template match="/">
  33. <wsrp:markupString>
  34. <xsl:if test="$ui-session-params[@name='display_id'] != ''">
  35. <xsl:text>&lt;a href="wsrp_rewrite?wsrp-urlType=blockingAction&amp;wsrp-interactionState=set:</xsl:text>
  36. <xsl:value-of select="$ui-state-params[@name = 'channel']"/>
  37. <xsl:text>&amp;wsrp-windowState=</xsl:text>
  38. <xsl:value-of select="$ui-window-state"/>
  39. <xsl:text>&amp;wsrp-navigationalState=&amp;display_id=/wsrp_rewrite"></xsl:text><xts:string id="IDS_NAV_VEW_BACK_TO_DEFAULT"/><xsl:text>&lt;/a>&lt;br></xsl:text>
  40. </xsl:if>
  41. <xsl:call-template name="rewrite">
  42. <xsl:with-param name="string" select="/root/*[local-name()='getPageletResponse']/*[local-name()='pageletMarkup']/*[local-name()='markupString']"/>
  43. </xsl:call-template>
  44. <xsl:value-of select="/root/preview-markup"/>
  45. </wsrp:markupString>
  46. <wsrp:requiresUrlRewriting>true</wsrp:requiresUrlRewriting>
  47. </xsl:template>
  48. <xsl:variable name="STARTMARKER" select="'wsrp_rewrite?'"/>
  49. <xsl:variable name="ENDMARKER" select="'/wsrp_rewrite'"/>
  50. <xsl:template name="rewrite">
  51. <xsl:param name="string" select="."/>
  52. <xsl:variable name="before" select="substring-before($string, $STARTMARKER)"/>
  53. <xsl:choose>
  54. <xsl:when test="$before = ''">
  55. <xsl:value-of select="$string"/>
  56. </xsl:when>
  57. <xsl:otherwise>
  58. <xsl:variable name="content" select="substring-after(substring-before($string, $ENDMARKER), $STARTMARKER)"/>
  59. <xsl:choose>
  60. <xsl:when test="contains($content, 'wsrp-urlType=resource')">
  61. <xsl:value-of select="concat($before, $STARTMARKER, $content, $ENDMARKER)"/>
  62. </xsl:when>
  63. <xsl:otherwise>
  64. <!-- package everything in the new navigational state -->
  65. <xsl:variable name="new-navigational-state">
  66. <!-- pagelet id -->
  67. <xsl:text>&lt;param name="pagelet-id"&gt;</xsl:text>
  68. <xsl:value-of select="/root/pageletId"/>
  69. <xsl:text>&lt;/param&gt;</xsl:text>
  70. <!-- original url params -->
  71. <xsl:text>&lt;param name="pagelet-params"&gt;</xsl:text>
  72. <xsl:value-of select="xtsext:xmlencode($content)"/>
  73. <xsl:text>&lt;/param&gt;</xsl:text>
  74. <!-- pagelet state path-->
  75. <xsl:text>&lt;param name="pageletStatePath"&gt;</xsl:text>
  76. <xsl:choose>
  77. <xsl:when test="$new-page-context"><xsl:value-of select="$new-page-context/*[local-name()='path']"/></xsl:when>
  78. <xsl:otherwise><xsl:value-of select="$current-page-context/*[local-name()='path']"/></xsl:otherwise>
  79. </xsl:choose>
  80. <xsl:text>&lt;/param&gt;</xsl:text>
  81. <!-- pagelet state -->
  82. <xsl:text>&lt;param name="pageletState"&gt;</xsl:text>
  83. <xsl:choose>
  84. <xsl:when test="$new-page-context"><xsl:value-of select="$new-page-context/*[local-name()='state']"/></xsl:when>
  85. <xsl:otherwise><xsl:value-of select="$current-page-context/*[local-name()='state']"/></xsl:otherwise>
  86. </xsl:choose>
  87. <xsl:text>&lt;/param&gt;</xsl:text>
  88. </xsl:variable>
  89. <xsl:choose>
  90. <xsl:when test="contains($content,'wsrp-urlType=render')">
  91. <xsl:value-of select="concat($before, $STARTMARKER, 'wsrp-urlType=render&amp;wsrp-requiresUrlRewriting=true&amp;wsrp-navigationalState=', xtsext:urlencode(xtsext:validator('prepare','new-navigational-state',xtsext:base64encode($new-navigational-state, true()))), $ENDMARKER)"/>
  92. </xsl:when>
  93. <xsl:otherwise>
  94. <xsl:value-of select="concat($before, $STARTMARKER, 'wsrp-urlType=blockingAction&amp;wsrp-interactionState=merge&amp;wsrp-requiresUrlRewriting=true&amp;wsrp-navigationalState=', xtsext:urlencode(xtsext:validator('prepare','new-navigational-state',xtsext:base64encode($new-navigational-state, true()))), $ENDMARKER)"/>
  95. </xsl:otherwise>
  96. </xsl:choose>
  97. </xsl:otherwise>
  98. </xsl:choose>
  99. <xsl:call-template name="rewrite">
  100. <xsl:with-param name="string" select="substring-after($string, $ENDMARKER)"/>
  101. </xsl:call-template>
  102. </xsl:otherwise>
  103. </xsl:choose>
  104. </xsl:template>
  105. </xsl:stylesheet>