formlogic_init.xslt 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: ps
  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:xtsext="xalan://com.cognos.xts.ext.XTSExt" xmlns:xts="http://developer.cognos.com/schemas/xts/">
  13. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  14. <xsl:template match="/">
  15. <xsl:variable name="current-stack-level" select="count( /root/env/param[ starts-with( @name, 'stack_' ) ] ) - 1"/>
  16. <xsl:variable name="current-stack-name" select="concat( 'stack_', $current-stack-level )"/>
  17. <xsl:variable name="op" select="/root/env/param[@name = 'ps_nav_op']"/>
  18. <!-- This is a comma-delimited list of template names representing the navigation path up a "push" or a "stack-up" navigation operations. -->
  19. <xsl:variable name="current-nav-stack" select=" /root/env/param[@name = 'ps_nav_stack'] "/>
  20. <xsl:variable name="passport" select="/root/credential/param[@name='CAM']/*[local-name() ='CAM']/*[local-name() = 'CAMPassport']/*[local-name() = 'id']"/>
  21. <!--
  22. Use this to delimit template names in the navigation stack. Use * since it is the least likely char to be used in a folder or file name.
  23. This is also defined in formlogic.xslt
  24. -->
  25. <xsl:variable name="nav-stack-delimiter" select="'*'"/>
  26. <!-- This represents the template where we came from -->
  27. <xsl:variable name="nav-source" select=" /root/env/param[@name = 'ps_nav_source']"/>
  28. <xts:sequence>
  29. <xsl:choose>
  30. <!-- Stack Up =================================================== -->
  31. <xsl:when test="$op = 'push' or $op = 'stack-up'">
  32. <!-- Save current data... -->
  33. <xts:append select="/root/env">
  34. <param name="{concat( 'stack_', string( $current-stack-level + 1 ) )}">
  35. <xsl:variable name="markup">
  36. <!-- we don't want to package up variables that contain information about the page being rendered... -->
  37. <xsl:apply-templates mode="markup" select="/root/env/param[not(starts-with(@name, 'stack_') or @name = 'ps_nav_source' or @name = 'ps_nav_stack' or @name = 'm' or @name = 'ps_nav_op')]"/>
  38. </xsl:variable>
  39. <xsl:value-of select="xtsext:cafaction( concat('sign_wrap_setpassportid_', $passport), xtsext:web64encode( string( $markup ), true() ))"/>
  40. </param>
  41. </xts:append>
  42. <!-- Update the navigation stack .. -->
  43. <xts:replace select="/root/env/param[@name='ps_nav_stack']">
  44. <xsl:choose>
  45. <xsl:when test="$current-nav-stack = ''">
  46. <!-- There is nothing on the stack. Initialize it with the name of the source template. -->
  47. <param name="ps_nav_stack">
  48. <xsl:value-of select="$nav-source"/>
  49. </param>
  50. </xsl:when>
  51. <xsl:otherwise>
  52. <!-- There is something in the navigation stack. Push the name of the source template on it. -->
  53. <param name="ps_nav_stack">
  54. <xsl:value-of select="concat($nav-source, $nav-stack-delimiter, $current-nav-stack ) "/>
  55. </param>
  56. </xsl:otherwise>
  57. </xsl:choose>
  58. </xts:replace>
  59. </xsl:when>
  60. <!-- Stack Down ================================================= -->
  61. <xsl:when test="$op = 'pop' or $op = 'stack-down'">
  62. <!-- setup stacking data... -->
  63. <xsl:if test="$current-stack-level > -1">
  64. <!-- we don't want to overwrite variables that contain information about the page being rendered... -->
  65. <xts:delete select="/root/env/param[not( starts-with( @name, 'stack_' ) or @name = 'ps_nav_stack' or @name = 'm' or @name = 'ps_nav_op')]"/>
  66. <xsl:variable name="xml-encoded-stack" select="xtsext:web64decode( xtsext:cafaction( 'sign_unwrap', string( /root/env/param[@name = $current-stack-name] )), true())"/>
  67. <xsl:if test="$xml-encoded-stack != ''">
  68. <xts:append select="/root/env">
  69. <xts:transform name="XMLDecode">
  70. <xsl:value-of select="$xml-encoded-stack"/>
  71. </xts:transform>
  72. </xts:append>
  73. </xsl:if>
  74. <xts:delete select="/root/env/param[@name = '{$current-stack-name}']"/>
  75. <xsl:choose>
  76. <xsl:when test="$current-stack-level = 0">
  77. <!-- Get rid of the navigation stack. UTML will insert a new one in. -->
  78. <xts:delete select="/root/env/param[@name = 'ps_nav_stack']"/>
  79. </xsl:when>
  80. <xsl:otherwise>
  81. <!-- Pop the navigation stack -->
  82. <xts:replace select="/root/env/param[@name='ps_nav_stack']">
  83. <param name="ps_nav_stack">
  84. <xsl:value-of select="substring-after(/root/env/param[@name = 'ps_nav_stack'], $nav-stack-delimiter)"/>
  85. </param>
  86. </xts:replace>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:if>
  90. </xsl:when>
  91. <!-- Stack Down Save ========================================== -->
  92. <xsl:when test="$op = 'drop' or $op = 'stack-down-save'">
  93. <xsl:if test="$current-stack-level > -1">
  94. <xts:delete select="/root/env/param[@name = '{$current-stack-name}']"/>
  95. <xsl:choose>
  96. <xsl:when test="$current-stack-level = 0">
  97. <!-- Get rid of the navigation stack. UTML will insert a new one in. -->
  98. <xts:delete select="/root/env/param[@name = 'ps_nav_stack']"/>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <!-- Pop the navigation stack. -->
  102. <xts:replace select="/root/env/param[@name='ps_nav_stack']">
  103. <param name="ps_nav_stack">
  104. <xsl:value-of select="substring-after(/root/env/param[@name = 'ps_nav_stack'], $nav-stack-delimiter)"/>
  105. </param>
  106. </xts:replace>
  107. </xsl:otherwise>
  108. </xsl:choose>
  109. </xsl:if>
  110. </xsl:when>
  111. </xsl:choose>
  112. <!-- We place the value in the "m" variable in the "ps_nav_source" for future navigation. -->
  113. <xts:replace select="/root/env/param[@name='ps_nav_source']">
  114. <param name="ps_nav_source">
  115. <xsl:value-of select=" /root/env/param[@name='m'] "/>
  116. </param>
  117. </xts:replace>
  118. <!-- Reset the operation. UTML logic will automatically insert a new (blank) field for this in the generated utml:form . -->
  119. <xts:delete select="/root/env/param[@name = 'ps_nav_op']"/>
  120. <!-- If ui.backURL is passed in, replace any backURL value with it -->
  121. <xsl:if test="/root/env/param[@name='ui.backURL'] and /root/env/param[@name='ui.backURL'] != ''">
  122. <xsl:choose>
  123. <xsl:when test="/root/env/param[@name='backURL']">
  124. <xts:replace select="/root/env/param[@name='backURL']">
  125. <param name="backURL"><xsl:value-of select="/root/env/param[@name='ui.backURL']"/></param>
  126. </xts:replace>
  127. </xsl:when>
  128. <xsl:otherwise>
  129. <xts:append select="/root/env">
  130. <param name="backURL"><xsl:value-of select="/root/env/param[@name='ui.backURL']"/></param>
  131. </xts:append>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. <xts:delete select="/root/env/param[@name='ui.backURL']"/>
  135. </xsl:if>
  136. <!-- If we are supposed to ensure that any passed back url is in the same domain as CRN then make that check and replace it if necessary -->
  137. <xsl:if test=" /root/system/param[@name = 'allowExternalURLs'] = 'false' and /root/env/param[@name = 'backURL'] and not(starts-with(/root/env/param[@name = 'backURL'], /root/http/param[@name='SCRIPT_NAME'])) ">
  138. <xts:replace select="/root/env/param[@name = 'backURL']">
  139. <param name="backURL"><xsl:value-of select="/root/http/param[@name='SCRIPT_NAME']"/>?<xsl:value-of select="/root/system/param[@name = 'COGNOSHome']"/></param>
  140. </xts:replace>
  141. </xsl:if>
  142. <!-- If this request is not carrying a caf contextid and caf_extendedContextId is true then make sure it does from now on. -->
  143. <xsl:if test="not(/root/env/param[@name='ui.cafcontextid']) and xtsext:cafaction('get_extendedcontextid', '') = 'true'">
  144. <xts:append select="/root/env">
  145. <param name="ui.cafcontextid"><xsl:value-of select="xtsext:cafaction(concat('get_contextid_settemplatename_formlogicinitxslt_setcomponent_ps_setpassportid_', $passport), '')"/></param>
  146. </xts:append>
  147. </xsl:if>
  148. </xts:sequence>
  149. </xsl:template>
  150. <!-- TODO: MOVE THE BELOW TO AN EXTENSTION FUNCTION...IT'S TOO SLOW!!!! -->
  151. <!-- generate text for simple element -->
  152. <xsl:template match="*" mode="markup">
  153. <xsl:text>&lt;</xsl:text>
  154. <xsl:value-of select="name()"/>
  155. <xsl:apply-templates select="@*" mode="markup"/>
  156. <xsl:text>/&gt;</xsl:text>
  157. </xsl:template>
  158. <!-- generate text for an element with children or text -->
  159. <xsl:template match="*[* | text()]" mode="markup">
  160. <xsl:text>&lt;</xsl:text>
  161. <xsl:value-of select="name()"/>
  162. <xsl:apply-templates select="@*" mode="markup"/>
  163. <xsl:text>&gt;</xsl:text>
  164. <xsl:apply-templates select="* | text()" mode="markup"/>
  165. <xsl:text>&lt;/</xsl:text>
  166. <xsl:value-of select="name()"/>
  167. <xsl:text>&gt;</xsl:text>
  168. </xsl:template>
  169. <!-- generate text for an attribute -->
  170. <xsl:template match="@*" mode="markup">
  171. <xsl:text>&#32;</xsl:text>
  172. <xsl:value-of select="name()"/>
  173. <xsl:text>="</xsl:text>
  174. <xsl:value-of select="."/>
  175. <xsl:text>"</xsl:text>
  176. </xsl:template>
  177. <!-- generate text -->
  178. <xsl:template match="text()" mode="markup">
  179. <xsl:value-of select="xtsext:xmlencode( string( . ) )"/>
  180. </xsl:template>
  181. </xsl:stylesheet>