nav-common-include.xslt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. <!-- $Header: //cpscrn/main/templates/cps4/portlets/nav/includes/nav-common-include.xslt#1 $ -->
  13. <!-- $DateTime: 2008/10/22 11:12:04 $ -->
  14. <!-- $Change: 25109 $ -->
  15. <xsl:stylesheet version="1.0"
  16. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  17. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  18. xmlns:ui="http://developer.cognos.com/schemas/cps/logic/ui/1/"
  19. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/">
  20. <xsl:attribute-set name="anchor">
  21. <xsl:attribute name="class">cognos-anchor</xsl:attribute>
  22. <xsl:attribute name="onmouseover">window.status='';return true;</xsl:attribute>
  23. <xsl:attribute name="onmouseout">window.status='';return true;</xsl:attribute>
  24. </xsl:attribute-set>
  25. <xsl:variable name="href-prefix">
  26. <xsl:text>wsrp_rewrite?wsrp-urlType=render&amp;wsrp-windowState=</xsl:text>
  27. <xsl:choose>
  28. <xsl:when test="$display-maximize = 'true'">wsrp:maximized</xsl:when>
  29. <xsl:otherwise>
  30. <xsl:value-of select="$ui-window-state"/>
  31. </xsl:otherwise>
  32. </xsl:choose>
  33. <xsl:text>&amp;wsrp-navigationalState=</xsl:text>
  34. </xsl:variable>
  35. <xsl:variable name="href-suffix">/wsrp_rewrite</xsl:variable>
  36. <xsl:variable name="path-root" select="/root/portlet/consumer/layout/path/start"/>
  37. <xsl:variable name="path-separator" select="/root/portlet/consumer/layout/path/separator"/>
  38. <xsl:template name="nav-script-openWindow">
  39. <xsl:param name="redirectURL"/>
  40. <xsl:variable name="state-open-links" select="$ui-state-params[@name = 'open_links']"/>
  41. <!--
  42. This variable will decide whether the client side nav rewriting is enabled.
  43. We rewrite urls if we are in cc and "open links" is set to current window
  44. -->
  45. <xsl:variable name="is-client-rewrite-enabled" select="$state-open-links='current' and $ui-is-cognos-connection"/>
  46. <xsl:if test="$is-client-rewrite-enabled">
  47. <script language="javascript" src="{$ui-webcontent}cr1/caf.js"/>
  48. </xsl:if>
  49. <script language="javascript">
  50. <xsl:if test="$is-client-rewrite-enabled">
  51. <!--
  52. This javascript method is used when open-links is set to current and the portal agent is CC.
  53. It is used to insert the back url in a given url.
  54. -->
  55. <xsl:variable name="navState">
  56. <xsl:for-each select="$ui-navigational-params">
  57. <xsl:call-template name="gen-param">
  58. <xsl:with-param name="name" select="@name"/>
  59. <xsl:with-param name="value" select="."/>
  60. </xsl:call-template>
  61. </xsl:for-each>
  62. </xsl:variable>
  63. <xsl:value-of select="xtsext:cafaction('get_jsconfig', '')"/>
  64. <!--This rewritable url contains the "cps-rewrite-flags=p0" parameter telling the assembler not to protect it -->
  65. var wsrp_rewrite_backUrl_no_protect = "wsrp_rewrite?wsrp-urlType=render&amp;cps-rewrite-flags=p0/wsrp_rewrite";
  66. var wsrp_rewrite_backUrl = "wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite";
  67. <!--ask for rewritabe urls with no back url, in case the regular one breaks the url length limit, we can use this shorter version-->
  68. var wsrp_rewrite_backUrl_no_protect_nb = "wsrp_rewrite?wsrp-urlType=render&amp;cps-rewrite-flags=p0b0/wsrp_rewrite";
  69. var wsrp_rewrite_backUrl_nb = "wsrp_rewrite?wsrp-urlType=render&amp;cps-rewrite-flags=b0/wsrp_rewrite";
  70. function wsrp_rewrite_getBackUrlParam(shortVersion)
  71. {
  72. var backParam = "";
  73. if (shortVersion == 0){
  74. backParam = encodeURIComponent(wsrp_rewrite_backUrl);
  75. } else if (shortVersion == 1){
  76. backParam = encodeURIComponent(wsrp_rewrite_backUrl_nb);
  77. }
  78. return backParam;
  79. }
  80. function wsrp_rewrite_getAbsoluteBackUrlParam(shortVersion){
  81. var currentWindowWithoutParams = document.location.href;
  82. if (currentWindowWithoutParams.indexOf("?") != -1){
  83. currentWindowWithoutParams = currentWindowWithoutParams.substring(0, currentWindowWithoutParams.indexOf("?"));
  84. }
  85. var url = "";
  86. if (wsrp_rewrite_backUrl.indexOf("?") != -1){
  87. if (shortVersion == 0 ){
  88. url = currentWindowWithoutParams + wsrp_rewrite_backUrl_no_protect.substring(wsrp_rewrite_backUrl.indexOf("?"));
  89. } else if (shortVersion == 1 ){
  90. url = currentWindowWithoutParams + wsrp_rewrite_backUrl_no_protect_nb.substring(wsrp_rewrite_backUrl.indexOf("?"));
  91. }
  92. }
  93. return encodeURIComponent(url);
  94. }
  95. function wsrp_rewrite_rewriteBackUrlHelper(url, shortVersion)
  96. {
  97. if (url.indexOf("navrewritebackurlnoprotect") != -1){
  98. var backurl = wsrp_rewrite_getBackUrlParam(shortVersion);
  99. url = url.replace("navrewritebackurlnoprotect",backurl);
  100. }
  101. else if (url.indexOf("navrewritebackurl") != -1){
  102. var backurl = wsrp_rewrite_getBackUrlParam(shortVersion);
  103. // protect the back url
  104. if (CAFXSSEncode){
  105. backurl = CAFXSSEncode(backurl);
  106. }
  107. url = url.replace("navrewritebackurl",backurl);
  108. }
  109. else if (url.indexOf("navrewriteabsolutebackurl") != -1){
  110. var absolute_backurl = wsrp_rewrite_getAbsoluteBackUrlParam(shortVersion);
  111. url = url.replace("navrewriteabsolutebackurl",absolute_backurl);
  112. if (CAFS7XSSEncodeURL){
  113. url = CAFS7XSSEncodeURL(url);
  114. }
  115. }
  116. return url;
  117. }
  118. function wsrp_rewrite_rewriteBackUrl(url)
  119. {
  120. var r_url = wsrp_rewrite_rewriteBackUrlHelper(url, 0);
  121. if (r_url.length > 2048){
  122. // length exceeds the limit, use a short version of the back url ( one without a back url )
  123. r_url = wsrp_rewrite_rewriteBackUrlHelper(url, 1);
  124. if (r_url.length > 2048){
  125. // we again exceeded the limit, use a blank backurl
  126. r_url = wsrp_rewrite_rewriteBackUrlHelper(url, 2);
  127. }
  128. }
  129. return r_url;
  130. }
  131. </xsl:if>
  132. function wsrp_rewrite_openWindow( url, name, properties, e, redirect )
  133. {
  134. var targetUrl = encodeURIComponent(url);
  135. if ( redirect != null ) {
  136. wsrp_rewrite_post_window_open( redirect + targetUrl, name, properties );
  137. } else {
  138. wsrp_rewrite_post_window_open( "<xsl:value-of select="xtsext:javascriptencode(string($redirectURL))"/>" + targetUrl, name, properties );
  139. }
  140. // stop event propagation, no one above us needs to know about this.
  141. if ( e.srcElement ) {
  142. e.returnValue = false;
  143. } else {
  144. e.preventDefault();
  145. }
  146. }
  147. var wsrp_rewrite_post_window_uid = 0;
  148. function wsrp_rewrite_post_window_open(url, name, properties) {
  149. if (name==null || name=="" || name=="_blank") {
  150. if (properties==null || properties=="") {
  151. name = "_blank";
  152. } else {
  153. name= "wsrp_rewrite_post_window" + wsrp_rewrite_post_window_uid++;
  154. }
  155. }
  156. if (! (name=="_top" || name=="_parent" || name=="_self" || name=="_blank")) {
  157. window.open("about:blank",name,properties);
  158. }
  159. var formElement = document.createElement("form");
  160. formElement.setAttribute("name","wsrp_rewrite_post_window_form");
  161. formElement.setAttribute("method","POST");
  162. formElement.setAttribute("target", name);
  163. var qm_index = url.indexOf("?");
  164. var action = (qm_index==-1) ? url : url.substring(0, qm_index);
  165. formElement.setAttribute("action", action);
  166. if (qm_index != -1) {
  167. var paramString = url.substring(qm_index+1);
  168. var params = paramString.split("&amp;");
  169. var i;
  170. for (i=0; i &lt; params.length; ++i) {
  171. if (params[i].length>0) {
  172. var hiddenElement = document.createElement("input");
  173. hiddenElement.setAttribute("type","hidden");
  174. var eq_index = params[i].indexOf("=");
  175. if (eq_index != -1) {
  176. hiddenElement.setAttribute("name",decodeURIComponent(params[i].substring(0,eq_index)));
  177. hiddenElement.setAttribute("value",decodeURIComponent(params[i].substring(eq_index+1)));
  178. } else {
  179. hiddenElement.setAttribute("name",decodeURIComponent(params[i]));
  180. hiddenElement.setAttribute("value","");
  181. }
  182. formElement.appendChild(hiddenElement);
  183. }
  184. }
  185. }
  186. document.body.appendChild(formElement);
  187. formElement.submit();
  188. document.body.removeChild(formElement);
  189. formElement = null;
  190. }
  191. </script>
  192. </xsl:template>
  193. <xsl:template name="nav-script-keyPressed">
  194. <xsl:param name="browser"/>
  195. <xsl:param name="submit" select="'wsrp_rewrite_submit()'"/>
  196. <xsl:choose>
  197. <xsl:when test="$browser = 'ie' or $browser = 'safari'">
  198. function wsrp_rewrite_keyPressed()
  199. {
  200. if (13 == window.event.keyCode) {
  201. <xsl:value-of select="$submit"/>;
  202. event.returnValue = false;
  203. }
  204. return true;
  205. }
  206. </xsl:when>
  207. <xsl:otherwise>
  208. window.captureEvents(Event.KEYPRESS);
  209. function wsrp_rewrite_keyPressed(e)
  210. {
  211. if (e.which == 13) {
  212. <xsl:value-of select="$submit"/>;
  213. return false;
  214. }
  215. return true;
  216. }
  217. window.onkeypress=wsrp_rewrite_keyPressed;
  218. </xsl:otherwise>
  219. </xsl:choose>
  220. </xsl:template>
  221. <xsl:template name="gen-param">
  222. <xsl:param name="name" select="@name"/>
  223. <xsl:param name="value" select="."/>
  224. <xsl:text>&lt;param name="</xsl:text>
  225. <xsl:value-of select="$name"/>
  226. <xsl:text>"></xsl:text>
  227. <xsl:value-of select="xtsext:xmlencode(string($value))"/>
  228. <xsl:text>&lt;/param></xsl:text>
  229. </xsl:template>
  230. <xsl:template name="gen-anchor-attr">
  231. <xsl:param name="url" select="nav:url"/>
  232. <xsl:param name="window-properties" select="nav:windowProperties"/>
  233. <xsl:param name="redirectURL"/>
  234. <xsl:param name="open-links" select="'new'"/>
  235. <xsl:param name="channel-onclick"/>
  236. <xsl:param name="reset-channel-onclick"/>
  237. <xsl:param name="target"/>
  238. <xsl:variable name="check-redirect-url">
  239. <xsl:choose>
  240. <xsl:when test="nav:redirectURL != ''">
  241. <xsl:value-of select="nav:redirectURL"/>
  242. </xsl:when>
  243. <xsl:otherwise>
  244. <xsl:value-of select="$redirectURL"/>
  245. </xsl:otherwise>
  246. </xsl:choose>
  247. </xsl:variable>
  248. <xsl:variable name="new-window-override" select="$window-properties != ''"/>
  249. <xsl:variable name="p2pc-override" select="self::nav:container or nav:viewable='false' or self::nav:shortcut/nav:container or self::nav:shortcut/nav:item/nav:viewable = 'false'"/>
  250. <xsl:variable name="check-target">
  251. <xsl:choose>
  252. <xsl:when test="($open-links = 'current') and not($new-window-override) and not($ui-is-myportal)">
  253. <xsl:value-of select="'_self'"/>
  254. </xsl:when>
  255. <xsl:when test="($open-links = 'target') and not($new-window-override)">
  256. <xsl:value-of select="$target"/>
  257. </xsl:when>
  258. <xsl:otherwise>
  259. <xsl:value-of select="'_blank'"/>
  260. </xsl:otherwise>
  261. </xsl:choose>
  262. </xsl:variable>
  263. <!--
  264. When this template is called the current element could be the actual nav item or the nav action itself.
  265. If the current object is the nav item, the context should be the default action element, otherwise it's the action itself.
  266. -->
  267. <xsl:variable name="context" select="(self::nav:action | self::*/nav:defaultAction)[1]"/>
  268. <xsl:choose>
  269. <!--
  270. - p2pc is enabled
  271. - The object support p2pc (e.g. a container do not support p2pc)
  272. -->
  273. <xsl:when test="$channel-onclick != '' and not($p2pc-override)">
  274. <xsl:attribute name="href">#</xsl:attribute>
  275. <xsl:attribute name="onclick">
  276. <xsl:value-of select="$channel-onclick"/>
  277. </xsl:attribute>
  278. </xsl:when>
  279. <!--
  280. "Open in current window" is enabled, the url is not external and we are in CC.
  281. We need to add a back url using javscript
  282. -->
  283. <xsl:when test="$check-target = '_self' and not($url/@type = 'external') and $ui-is-cognos-connection">
  284. <xsl:attribute name="href">#</xsl:attribute>
  285. <xsl:choose>
  286. <xsl:when test="$check-redirect-url != ''">
  287. <xsl:attribute name="onclick">
  288. <xsl:text>wsrp_rewrite_openWindow(wsrp_rewrite_rewriteBackUrl('</xsl:text>
  289. <xsl:value-of select="xtsext:javascriptencode(string($url))"/>
  290. <xsl:text>'),'</xsl:text>
  291. <xsl:value-of select="$check-target"/>
  292. <xsl:text>','',event</xsl:text>
  293. <xsl:if test="nav:redirectURL != ''">
  294. <xsl:text>,wsrp_rewrite_rewriteBackUrl('</xsl:text>
  295. <xsl:value-of select="nav:redirectURL"/>
  296. <xsl:text>')</xsl:text>
  297. </xsl:if>
  298. <xsl:text>)</xsl:text>
  299. </xsl:attribute>
  300. </xsl:when>
  301. <xsl:otherwise>
  302. <xsl:attribute name="onclick">
  303. <xsl:text>document.location=wsrp_rewrite_rewriteBackUrl('</xsl:text>
  304. <xsl:value-of select="xtsext:javascriptencode(string($url))"/>
  305. <xsl:text>');</xsl:text>
  306. </xsl:attribute>
  307. </xsl:otherwise>
  308. </xsl:choose>
  309. </xsl:when>
  310. <!--
  311. We have a redirect url and the url is not external.
  312. -->
  313. <xsl:when test="$check-redirect-url != '' and not($url/@type = 'external')">
  314. <xsl:attribute name="href">#</xsl:attribute>
  315. <xsl:attribute name="onclick">
  316. <xsl:text>wsrp_rewrite_openWindow('</xsl:text>
  317. <xsl:value-of select="xtsext:javascriptencode(string($url))"/>
  318. <xsl:text>','</xsl:text>
  319. <xsl:value-of select="$check-target"/>
  320. <xsl:text>','</xsl:text>
  321. <xsl:value-of select="$window-properties"/>
  322. <xsl:text>',event</xsl:text>
  323. <xsl:if test="nav:redirectURL != ''">
  324. <xsl:text>,'</xsl:text>
  325. <xsl:value-of select="nav:redirectURL"/>
  326. <xsl:text>'</xsl:text>
  327. </xsl:if>
  328. <xsl:text>)</xsl:text>
  329. <xsl:if test="$reset-channel-onclick != '' ">
  330. <xsl:text>;</xsl:text>
  331. <xsl:value-of select="$reset-channel-onclick"/>
  332. </xsl:if>
  333. </xsl:attribute>
  334. </xsl:when>
  335. <!--
  336. We do not have a redirect url but we explicitly asked for POST
  337. -->
  338. <xsl:when test="$context/nav:usePost = 'true' ">
  339. <xsl:attribute name="href">#</xsl:attribute>
  340. <xsl:attribute name="onclick">
  341. <xsl:text>wsrp_rewrite_post_window_open('</xsl:text>
  342. <xsl:value-of select="xtsext:javascriptencode($url)"/>
  343. <xsl:text>','</xsl:text>
  344. <xsl:value-of select="$check-target"/>
  345. <xsl:text>','</xsl:text>
  346. <xsl:value-of select="$window-properties"/>
  347. <xsl:text>')</xsl:text>
  348. <xsl:if test="$reset-channel-onclick != '' ">
  349. <xsl:text>;</xsl:text>
  350. <xsl:value-of select="$reset-channel-onclick"/>
  351. </xsl:if>
  352. </xsl:attribute>
  353. </xsl:when>
  354. <!-- We do not have a redirect url but we have a window properties-->
  355. <xsl:when test="$window-properties != ''">
  356. <xsl:attribute name="href">#</xsl:attribute>
  357. <xsl:attribute name="onclick">
  358. <xsl:text>window.open('</xsl:text>
  359. <xsl:value-of select="xtsext:javascriptencode(string($url))"/>
  360. <xsl:text>','</xsl:text>
  361. <xsl:value-of select="$check-target"/>
  362. <xsl:text>','</xsl:text>
  363. <xsl:value-of select="$window-properties"/>
  364. <xsl:text>')</xsl:text>
  365. <xsl:if test="$reset-channel-onclick != '' ">
  366. <xsl:text>;</xsl:text>
  367. <xsl:value-of select="$reset-channel-onclick"/>
  368. </xsl:if>
  369. </xsl:attribute>
  370. </xsl:when>
  371. <!-- default -->
  372. <xsl:otherwise>
  373. <xsl:attribute name="href">
  374. <xsl:value-of select="$url"/>
  375. </xsl:attribute>
  376. <xsl:attribute name="target">
  377. <xsl:value-of select="$check-target"/>
  378. </xsl:attribute>
  379. </xsl:otherwise>
  380. </xsl:choose>
  381. </xsl:template>
  382. </xsl:stylesheet>