bridge.xts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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, 2017
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. This morphlet takes an external application-bound HTTP/CGI command and adds to it CRN environment variables as defined in an
  10. xml file specified by the "c_env" variable before executing the command. It can process a POST or a GET request.
  11. -->
  12. <xts:morphlet xmlns:xts="http://developer.cognos.com/schemas/xts/" messageBase="messages/portal.xml, messages/portalRL.xml">
  13. <!-- BLOCK: Read the redirection environment if one is specified -->
  14. <!-- ================================================================================================= -->
  15. <xts:block id="setRequestEnv" processor="XSLT" type="exec" mandatory="false" condition=".[/root/env/param[@name='c_env'] and not(contains(/root/env/param[@name='c_env'], 'sample_env.xml'))]" nodelist="env">
  16. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt">
  17. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  18. <xsl:template match="/root">
  19. <xsl:variable name="filename" select="env/param[@name='c_env']"/>
  20. <xsl:variable name="fileext" select="xtsext:substringAfterLast(string($filename), '.')"/>
  21. <xsl:if test="translate(translate($fileext, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), ' ', '') = 'xml'">
  22. <!-- Only support file with .xml extension -->
  23. <xts:sequence>
  24. <xts:append>
  25. <xts:request protocol="FILEREAD" cache="false">
  26. <xsl:attribute name="href"><xsl:value-of select="$filename"/></xsl:attribute>
  27. </xts:request>
  28. </xts:append>
  29. </xts:sequence>
  30. </xsl:if>
  31. </xsl:template>
  32. </xsl:stylesheet>
  33. </xts:block>
  34. <!-- BLOCK: If the requested env vars include CM vars then execute the CM request to get them. This will also validate the current passport.
  35. If there are no CM vars requested then execute a dummy CM request to validate the passport only. -->
  36. <!-- ================================================================================================= -->
  37. <xts:block id="validatePassport" processor="XSLT" type="exec" dependency="setRequestEnv" mandatory="false">
  38. <xts:logicsheet path="logicsheets/buslogic.xslt"/>
  39. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:send="http://developer.cognos.com/schemas/xts/logic-sheet/xslt/brl/1/" xmlns:cm="http://developer.cognos.com/schemas/xts-cm/1/">
  40. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  41. <xsl:template match="/root">
  42. <xts:sequence>
  43. <xts:append>
  44. <send:request provider="cm">
  45. <xts:transform src="transforms/CM/pre-process.xslt" processor="XSLT">
  46. <xsl:choose>
  47. <!-- Get any requested "account" properties -->
  48. <xsl:when test="CRNenv/cm/param">
  49. <cm:query>
  50. <cm:search>~</cm:search>
  51. <cm:properties>
  52. <xsl:for-each select="CRNenv/cm/param">
  53. <cm:property>
  54. <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
  55. </cm:property>
  56. </xsl:for-each>
  57. </cm:properties>
  58. </cm:query>
  59. </xsl:when>
  60. <!-- Just validate the passport -->
  61. <xsl:otherwise>
  62. <cm:query>
  63. <cm:search>~~</cm:search>
  64. <cm:properties>
  65. <cm:property name="defaultName"/>
  66. </cm:properties>
  67. </cm:query>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xts:transform>
  71. </send:request>
  72. </xts:append>
  73. </xts:sequence>
  74. </xsl:template>
  75. </xsl:stylesheet>
  76. </xts:block>
  77. <!-- BLOCK: Output a redirection page -->
  78. <!-- ================================================================================================= -->
  79. <xts:block id="format" mode="interpret" processor="XSLT" type="exec" mimeType="text/html" dependency="validatePassport">
  80. <xsl:stylesheet version="1.0"
  81. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  82. xmlns:cm="http://developer.cognos.com/schemas/xts-cm/1/"
  83. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  84. xmlns:xos="http://developer.cognos.com/schemas/xts/output/"
  85. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  86. xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
  87. xmlns:string="java:java.lang.String"
  88. exclude-result-prefixes="xsl cm xts xtsext bus">
  89. <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>
  90. <xsl:key name="session-param" match="/root/session/param" use="@name"/>
  91. <xsl:key name="cookies" match="/root/cookies/cookie" use="@name"/>
  92. <xsl:key name="setCookies" match="/root/setCookies/cookie" use="@name"/>
  93. <xsl:template match="/root">
  94. <!-- Request method -->
  95. <xsl:variable name="method">
  96. <xsl:choose>
  97. <xsl:when test="translate(CRNenv/redirect/@method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'post'">post</xsl:when>
  98. <xsl:when test="translate(env/param[@name='c_mode'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'post'">post</xsl:when>
  99. <xsl:when test="translate(env/param[@name='c_mode'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'mixed'">mixed</xsl:when>
  100. <xsl:otherwise>get</xsl:otherwise>
  101. </xsl:choose>
  102. </xsl:variable>
  103. <xsl:variable name="encoding">
  104. <xsl:choose>
  105. <xsl:when test="env/param[@name='c_encode'] != ''">
  106. <xsl:value-of select="env/param[@name='c_encode']"/>
  107. </xsl:when>
  108. <xsl:otherwise>utf-8</xsl:otherwise>
  109. </xsl:choose>
  110. </xsl:variable>
  111. <xsl:variable name="requestCommand" select="string(env/param[@name='c_cmd'])"/>
  112. <xsl:variable name="presetCommand" select="string(CRNenv/@c_cmd)"/>
  113. <xsl:variable name="is-lookupCommand-matched">
  114. <xsl:call-template name="verify-url">
  115. <xsl:with-param name="c_cmd" select="translate($requestCommand,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  116. </xsl:call-template>
  117. </xsl:variable>
  118. <!-- Target command -->
  119. <xsl:variable name="targetCommand">
  120. <xsl:choose>
  121. <xsl:when test="$presetCommand != ''">
  122. <xsl:value-of select="$presetCommand"/>
  123. </xsl:when>
  124. <xsl:when test="$is-lookupCommand-matched = 'true'">
  125. <xsl:value-of select="$requestCommand"/>
  126. </xsl:when>
  127. <!-- Return an error message later when blank -->
  128. </xsl:choose>
  129. </xsl:variable>
  130. <xts:sequence>
  131. <xts:append select="/root/output">
  132. <xos:part>
  133. <xos:entityHeader>
  134. <xos:param name="Content-Type">text/html; charset=<xsl:value-of select="$encoding"/></xos:param>
  135. <xos:param name="Cache-Control">no-cache</xos:param>
  136. </xos:entityHeader>
  137. <xos:entityBody>
  138. <html lang="{key('session-param','productLocale')}">
  139. <head>
  140. <!-- Specify custom encoding -->
  141. <meta http-equiv="Content-Type" content="text/html; charset={$encoding}"/>
  142. <!-- Don't let the page cache -->
  143. <meta content="0" http-equiv="expires"/>
  144. <!-- Build the redirection for a GET request (anything other than post) =========== -->
  145. <xsl:if test=" $method = 'get' and $targetCommand != ''">
  146. <!-- Build the part of the query string containing the CRN env variables -->
  147. <xsl:variable name="crn_env">
  148. <!-- State params -->
  149. <xsl:for-each select="CRNenv/cc_state/param">
  150. <xsl:text/>&amp;<xsl:value-of select="@name"/>=<xsl:value-of select="xtsext:urlencode(string(key('session-param', @name)), string($encoding))"/>
  151. </xsl:for-each>
  152. <!-- Cookie params -->
  153. <xsl:for-each select="CRNenv/cookies/param">
  154. <xsl:text/>&amp;<xsl:value-of select="@name"/>=<xsl:text/>
  155. <xsl:choose>
  156. <xsl:when test="key('setCookies', @name) != ''">
  157. <xsl:value-of select="string(key('setCookies', @name))"/>
  158. </xsl:when>
  159. <xsl:otherwise>
  160. <xsl:value-of select="string(key('cookies', @name))"/>
  161. </xsl:otherwise>
  162. </xsl:choose>
  163. </xsl:for-each>
  164. <!-- User prefs params -->
  165. <xsl:for-each select="CRNenv/user_pref/param">
  166. <xsl:text/>&amp;<xsl:value-of select="@name"/>=<xsl:value-of select="xtsext:urlencode(string(/root/user/param[@name = current()/@name]), string($encoding))"/>
  167. <xsl:text/>
  168. </xsl:for-each>
  169. <!-- CM data (account object) -->
  170. <xsl:for-each select="CRNenv/cm/param">
  171. <xsl:text/>&amp;<xsl:value-of select="@name"/>=<xsl:value-of select="xtsext:urlencode(string(/root/*[local-name()='queryResponse']/*[local-name()='queryResult']/*[local-name()='item']/*[local-name() = current()/@name]/*[local-name()='value']), string($encoding))"/>
  172. <xsl:text/>
  173. </xsl:for-each>
  174. </xsl:variable>
  175. <!-- build the redirection URL using the passed-in base application command -->
  176. <xsl:variable name="redirect-url">
  177. <xsl:value-of select="$targetCommand"/>
  178. <xsl:if test="not(contains($targetCommand, '?'))">?</xsl:if>
  179. <xsl:choose>
  180. <xsl:when test="contains($targetCommand, '=')">
  181. <xsl:value-of select="$crn_env"/>
  182. </xsl:when>
  183. <xsl:otherwise>
  184. <xsl:value-of select="substring-after( $crn_env, '&amp;') "/>
  185. </xsl:otherwise>
  186. </xsl:choose>
  187. <xsl:call-template name="getState">
  188. <xsl:with-param name="method" select=" 'get' "/>
  189. <xsl:with-param name="encoding" select="$encoding"/>
  190. </xsl:call-template>
  191. </xsl:variable>
  192. <!--
  193. Hand-code the meta tag to avoid problems with the output element
  194. double-encoding the URL value once it is inserted in the "content" attribute
  195. -->
  196. <xsl:text disable-output-escaping="yes">&lt;meta http-equiv="refresh" content="0; URL=</xsl:text>
  197. <xsl:value-of select="$redirect-url"/>
  198. <xsl:text disable-output-escaping="yes">"/&gt;</xsl:text>
  199. </xsl:if>
  200. </head>
  201. <body>
  202. <xsl:if test="($method = 'post' or $method = 'mixed') and $targetCommand != '' ">
  203. <xsl:attribute name="onload">document.redirect.submit()</xsl:attribute>
  204. <!-- Build the redirection for a POST or mixed request =========== -->
  205. <form name="redirect" method="post">
  206. <xsl:attribute name="action">
  207. <xsl:choose>
  208. <xsl:when test="$method = 'post'"><xsl:value-of select="$targetCommand"/></xsl:when>
  209. <xsl:otherwise>
  210. <xsl:value-of select="$targetCommand"/>
  211. <xsl:variable name="startNewQueryString" select="not(contains($targetCommand, '?')) and not(contains($targetCommand, '#'))"/>
  212. <xsl:call-template name="getState">
  213. <xsl:with-param name="method" select=" 'get' "/>
  214. <xsl:with-param name="encoding" select="$encoding"/>
  215. <xsl:with-param name="startNewQueryString" select="$startNewQueryString"/>
  216. </xsl:call-template>
  217. </xsl:otherwise>
  218. </xsl:choose>
  219. </xsl:attribute>
  220. <!-- State params -->
  221. <xsl:for-each select="CRNenv/cc_state/param">
  222. <input name="{@name}" type="hidden" value="{key('session-param', @name)}"/>
  223. </xsl:for-each>
  224. <!-- Cookie params -->
  225. <xsl:for-each select="CRNenv/cookies/param">
  226. <xsl:choose>
  227. <xsl:when test="key('setCookies', @name) != ''">
  228. <input name="{@name}" type="hidden" value="{key('setCookies', @name)}"/>
  229. </xsl:when>
  230. <xsl:otherwise>
  231. <input name="{@name}" type="hidden" value="{key('cookies', @name)}"/>
  232. </xsl:otherwise>
  233. </xsl:choose>
  234. </xsl:for-each>
  235. <!-- User prefs params -->
  236. <xsl:for-each select="CRNenv/user_pref/param">
  237. <input name="{@name}" type="hidden" value="{/root/header/*[local-name()='biBusHeader']/*[local-name() = 'userPreferenceVars']/*[name=current()/@name]/value}"/>
  238. </xsl:for-each>
  239. <!-- CM data (account object) -->
  240. <xsl:for-each select="CRNenv/cm/param">
  241. <input name="{@name}" type="hidden" value="{/root/*[local-name()='queryResponse']/*[local-name()='queryResult']/*[local-name()='item']/*[local-name() = current()/@name]/*[local-name()='value']}"/>
  242. </xsl:for-each>
  243. <xsl:if test="$method='post'">
  244. <!-- Regular POST, Add any passed-in params -->
  245. <xsl:call-template name="getState">
  246. <xsl:with-param name="method" select=" 'post' "/>
  247. <xsl:with-param name="encoding" select="$encoding"/>
  248. </xsl:call-template>
  249. </xsl:if>
  250. </form>
  251. </xsl:if>
  252. <xsl:if test="$targetCommand = '' ">
  253. <div style="font-family: Tahoma; color: #666699; padding: 50px; text-align: center;">
  254. <xts:string id="IDS_BRI_ERROR_URL"/>
  255. </div>
  256. </xsl:if>
  257. </body>
  258. </html>
  259. </xos:entityBody>
  260. </xos:part>
  261. </xts:append>
  262. </xts:sequence>
  263. </xsl:template>
  264. <xsl:template name="getState">
  265. <xsl:param name="method"/>
  266. <xsl:param name="encoding"/>
  267. <xsl:param name="startNewQueryString" select="false()"/>
  268. <!-- Add all other passed-in variables but exclude those used to execute this morphlet -->
  269. <xsl:for-each select="/root/env/param[not(starts-with(@name, 'c_')) and @name != 'b_action' and @name != 'm' and @name != 'encoding']">
  270. <xsl:choose>
  271. <xsl:when test="$method = 'post'">
  272. <input name="{@name}" type="hidden" value="{.}"/>
  273. </xsl:when>
  274. <xsl:otherwise>
  275. <xsl:variable name="delimeter">
  276. <xsl:choose>
  277. <xsl:when test="$startNewQueryString = 'true' and position() = '1'">?</xsl:when>
  278. <xsl:otherwise>&amp;</xsl:otherwise>
  279. </xsl:choose>
  280. </xsl:variable>
  281. <xsl:value-of select="concat($delimeter, @name, '=', xtsext:urlencode(string(.),string($encoding)))"/>
  282. </xsl:otherwise>
  283. </xsl:choose>
  284. </xsl:for-each>
  285. </xsl:template>
  286. <xsl:template name="verify-url">
  287. <xsl:param name="c_cmd" select="''"/>
  288. <xsl:param name="index" select="'1'"/>
  289. <xsl:variable name="acceptable-urls" select="/root/CRNenv/urls/url"/>
  290. <xsl:if test="$index &lt;= count($acceptable-urls)">
  291. <xsl:variable name="candidate-url" select="$acceptable-urls[$index]"/>
  292. <xsl:variable name="is-matched">
  293. <xsl:choose>
  294. <xsl:when test="$candidate-url/@is-regex='true'">
  295. <xsl:variable name="regex-nocase" select="translate($candidate-url,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  296. <xsl:value-of select="string:matches(string:new($c_cmd), $regex-nocase)"/>
  297. </xsl:when>
  298. <xsl:otherwise>
  299. <xsl:value-of select="translate(string($candidate-url),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = $c_cmd"/>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. </xsl:variable>
  303. <xsl:choose>
  304. <xsl:when test="$is-matched = 'true'">
  305. <xsl:value-of select="$is-matched"/>
  306. </xsl:when>
  307. <xsl:otherwise>
  308. <xsl:call-template name="verify-url">
  309. <xsl:with-param name="c_cmd" select="$c_cmd"/>
  310. <xsl:with-param name="index" select="$index + 1"/>
  311. </xsl:call-template>
  312. </xsl:otherwise>
  313. </xsl:choose>
  314. </xsl:if>
  315. </xsl:template>
  316. </xsl:stylesheet>
  317. </xts:block>
  318. <!-- Debug -->
  319. <!-- ============================================================================= -->
  320. <xts:block id="debug" dependency="format" type="exec" mode="output" condition=".[/root/env/param[@name='d'] = '1' or /root/session/param[@name='debug'] = '1']" processor="XSLT" mandatory="false" mimeType="text/html">
  321. <xts:logicsheet path="logicsheets/debuglogic.xslt"/>
  322. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dbg="http://developer.cognos.com/schemas/xts/logicsheets/xslt/debug/" exclude-result-prefixes="dbg">
  323. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
  324. <dbg:templates/>
  325. <xsl:template match="/">
  326. <dbg:dumpxml select="/root"/>
  327. </xsl:template>
  328. </xsl:stylesheet>
  329. </xts:block>
  330. </xts:morphlet>