common-include.xslt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  15. xmlns:ui="http://developer.cognos.com/schemas/cps/logic/ui/1/"
  16. xmlns:xts="http://developer.cognos.com/schemas/xts/"
  17. xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
  18. xmlns:nav="http://developer.cognos.com/schemas/cps/navigation/1/">
  19. <xsl:variable name="params" select="/root/interactions/param | /root/state/param | /root/transients/param | /root/customs/param"/>
  20. <!-- Preferences vars -->
  21. <xsl:variable name="preferences" select="/root/bus:biBusHeader/bus:userPreferenceVars"/>
  22. <xsl:variable name="linesPerPage" select="$preferences/item[name = 'linesPerPage']/value"/>
  23. <xsl:variable name="productLocale" select="$preferences/item[name = 'productLocale']/value"/>
  24. <xsl:variable name="contentLocale" select="$preferences/item[name = 'contentLocale']/value"/>
  25. <xsl:variable name="display-separator" select="$preferences/item[name = 'listViewSeparator']/value"/>
  26. <xsl:variable name="skin">
  27. <xsl:choose>
  28. <xsl:when test="string($params[@name='skin']) != ''"><xsl:value-of select="$params[@name='skin']"/></xsl:when>
  29. <xsl:otherwise><xsl:value-of select="$preferences/item[name = 'skin']/value"/></xsl:otherwise>
  30. </xsl:choose>
  31. </xsl:variable>
  32. <xsl:variable name="webRoot">
  33. <xsl:choose>
  34. <xsl:when test="string($params[@name='webRoot']) != ''"><xsl:value-of select="$params[@name='webRoot']"/></xsl:when>
  35. <xsl:otherwise><xsl:call-template name="calculateWebContent"/></xsl:otherwise>
  36. </xsl:choose>
  37. </xsl:variable>
  38. <!-- HTTP env vars -->
  39. <xsl:variable name="environmentVars" select="/root/bus:biBusHeader/*[local-name() = 'hdrSession']/bus:environmentVars"/>
  40. <xsl:variable name="mvc-virtualRootName"><xts:string id="IDS_MVC_VIRTUALROOT_NAME"/></xsl:variable>
  41. <xsl:attribute-set name="anchor"/>
  42. <xsl:template name="calculateWebContent">
  43. <xsl:variable name="webContentRoot" select="$environmentVars/item[name = 'WEB_CONTENT_ROOT']/value"/>
  44. <xsl:variable name="configured-gateway" select="/root//configured-gateway/configuration/property[@name='gateway']"/>
  45. <xsl:choose>
  46. <xsl:when test="starts-with($webContentRoot, 'http')">
  47. <xsl:value-of select="$webContentRoot"/>
  48. </xsl:when>
  49. <xsl:otherwise>
  50. <xsl:choose>
  51. <xsl:when test="starts-with($webContentRoot, '..')">
  52. <xsl:variable name="v" select="xtsext:substringBeforeLast($configured-gateway, '/')"/>
  53. <xsl:value-of select="$v"/>/<xsl:value-of select="$webContentRoot"/>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:variable name="protocol" select="substring-before($configured-gateway, '//')"/>
  57. <xsl:variable name="after-protocol" select="substring-after($configured-gateway, '//')"/>
  58. <xsl:variable name="server" select="substring-before($after-protocol, '/')"/>
  59. <xsl:value-of select="$protocol"/>//<xsl:value-of select="$server"/><xsl:value-of select="$webContentRoot"/>
  60. </xsl:otherwise>
  61. </xsl:choose>
  62. </xsl:otherwise>
  63. </xsl:choose>
  64. </xsl:template>
  65. <xsl:template name="build-url">
  66. <xsl:param name="action"/>
  67. <xsl:param name="is-defaultAction"/>
  68. <xsl:variable name="isTraverseAction" select="$action/nav:name = 'traverse'"/>
  69. <xsl:choose>
  70. <xsl:when test="$isTraverseAction">
  71. <xsl:text/>_THIS_navigate('<xsl:value-of select="$action/../nav:id"/>')<xsl:text/>
  72. </xsl:when>
  73. <xsl:otherwise>
  74. <xsl:variable name="submitMethod">
  75. <xsl:choose>
  76. <xsl:when test="$is-defaultAction">GET</xsl:when>
  77. <xsl:otherwise>POST</xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:variable>
  80. <xsl:variable name="gateway">
  81. <xsl:choose>
  82. <xsl:when test="$action/nav:url and $action/nav:url[@type='external']">
  83. <xsl:value-of select="xtsext:javascriptencode($action/nav:url[@type='external'])"/>
  84. </xsl:when>
  85. <xsl:otherwise>
  86. <xsl:value-of select="xtsext:javascriptencode($action/nav:urlParts/nav:gateway)"/>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:variable>
  90. <xsl:variable name="formParams">
  91. <xsl:text/>_THIS_formParams('<xsl:value-of select="$submitMethod"/>'<xsl:text/>
  92. <xsl:for-each select="$action/nav:urlParts/nav:param[@name != 'cv.header']">
  93. <xsl:text/>,'<xsl:value-of select="@name"/>','<xsl:text/>
  94. <xsl:choose>
  95. <xsl:when test="$submitMethod = 'POST'">
  96. <xsl:value-of select="xtsext:javascriptencode(string(.))"/>
  97. </xsl:when>
  98. <xsl:when test="@name='m_path' or @name='m_obj'">
  99. <xsl:value-of select="xtsext:javascriptencode(xtsext:protect(xtsext:urlencode(string(.)),'url','searchPath','getdata'))"/><xsl:text/>
  100. </xsl:when>
  101. <xsl:otherwise>
  102. <xsl:value-of select="xtsext:javascriptencode(xtsext:protect(xtsext:urlencode(string(.)),'url','userData','getdata'))"/><xsl:text/>
  103. </xsl:otherwise>
  104. </xsl:choose>
  105. <xsl:text/>'<xsl:text/>
  106. </xsl:for-each>
  107. <xsl:text/>)<xsl:text/>
  108. </xsl:variable>
  109. <xsl:text/>javascript:_THIS_run_url(<xsl:text/>
  110. <xsl:text/>'<xsl:value-of select="$gateway"/>',<xsl:text/>
  111. <xsl:value-of select="$formParams"/>
  112. <xsl:choose>
  113. <xsl:when test="$action/nav:windowProperties">
  114. <xsl:text/>, '_blank'<xsl:text/>
  115. </xsl:when>
  116. <xsl:otherwise>
  117. <xsl:text/>, '_parent'<xsl:text/>
  118. </xsl:otherwise>
  119. </xsl:choose>
  120. <xsl:text/>, '<xsl:value-of select="$submitMethod"/>'<xsl:text/>
  121. <xsl:if test="$action/nav:windowProperties">
  122. <xsl:text/>, '<xsl:value-of select="$action/nav:windowProperties"/>'<xsl:text/>
  123. </xsl:if>
  124. <xsl:text/>)<xsl:text/>
  125. </xsl:otherwise>
  126. </xsl:choose>
  127. </xsl:template>
  128. <xsl:template name="common-include">
  129. <script language="javascript">
  130. function _THIS_retrieve(params) {
  131. var webRoot = '<xsl:value-of select="xtsext:javascriptencode(xtsext:urlencode($webRoot))"/>';
  132. var skin = '<xsl:value-of select="xtsext:javascriptencode(xtsext:urlencode($skin))"/>';
  133. var env_params = "&amp;webRoot=" + webRoot + "&amp;skin=" + skin;
  134. _THIS_.retrieve(params + env_params);
  135. }
  136. function _THIS_goto(from, to) {
  137. if (isNaN(from) || parseInt(from, 10) &lt;= 0) {
  138. alert("<xts:string id="IDS_MVC_ERR_FROM_INVALID" encode="javascript"/>");
  139. return false;
  140. }
  141. if (isNaN(to) || parseInt(to, 10) &lt;= 0) {
  142. alert("<xts:string id="IDS_MVC_ERR_TO_INVALID" encode="javascript"/>");
  143. return false;
  144. }
  145. from = parseInt(from, 10);
  146. to = parseInt(to, 10);
  147. if (from &gt; to) {
  148. window.alert('<xts:string id="IDS_MVC_ERR_FIRST_BIGGER_SECOND" encode="javascript"/>');
  149. return false;
  150. }
  151. var skip = from - 1;
  152. var maxobjs = to - from + 1;
  153. _THIS_retrieve('skip=' + skip + '&amp;maxobjs=' + maxobjs);
  154. }
  155. function _THIS_sort(category, currentSort) {
  156. var sort = "";
  157. if (currentSort.indexOf(category + '_') == 0) {
  158. if (currentSort.indexOf("_a") != -1) {
  159. sort = category + "_d";
  160. } else if (currentSort.indexOf("_d") != -1) {
  161. sort = "";
  162. } else {
  163. sort = category + "_a";
  164. }
  165. } else {
  166. sort= category + "_a";
  167. }
  168. _THIS_retrieve('sort=' + encodeURIComponent(sort));
  169. }
  170. </script>
  171. <!-- Scripts to handle running report, editing on objects in remote system -->
  172. <script language="javascript">
  173. var _THIS_post_window_name = "_self";
  174. var _THIS_post_window_uid = 0;
  175. function _THIS_run_url(gateway, paramsArray, name, submitMethod, properties) {
  176. if (name == null || name == "" || name == "_blank") {
  177. if (properties == null || properties == "") {
  178. name = "_blank";
  179. } else {
  180. name= "_THIS_post_window" + _THIS_post_window_uid++;
  181. }
  182. }
  183. if (!(name == "_top" || name == "_parent" || name == "_self" || name == "_blank")) {
  184. window.open("about:blank", name, properties);
  185. }
  186. var formElement = document.createElement("form");
  187. formElement.setAttribute("name", "_THIS_post_window_form");
  188. formElement.setAttribute("method", submitMethod);
  189. formElement.setAttribute("target", name);
  190. formElement.setAttribute("action", gateway);
  191. for (i = 0; i &lt; paramsArray.length; i+=2) {
  192. var name = paramsArray[i];
  193. var value = paramsArray[i+1];
  194. if (submitMethod == "GET") {
  195. value = decodeURIComponent(value);
  196. }
  197. var hiddenElement = document.createElement("input");
  198. hiddenElement.setAttribute("type","hidden");
  199. hiddenElement.setAttribute("name", name);
  200. hiddenElement.setAttribute("value", value);
  201. formElement.appendChild(hiddenElement);
  202. }
  203. document.body.appendChild(formElement);
  204. formElement.submit();
  205. document.body.removeChild(formElement);
  206. formElement = null;
  207. }
  208. function _THIS_formParams(submitMethod) {
  209. var paramsArray = new Array();
  210. for (i = 1; i &lt; arguments.length; i+=2) {
  211. var name = arguments[i];
  212. var value = arguments[i+1];
  213. paramsArray[i-1] = name;
  214. if (value == "navrewritebackurl" || value == "navrewriteabsolutebackurl") {
  215. paramsArray[i] = _THIS_rewriteBackUrlHelper(submitMethod);
  216. } else {
  217. paramsArray[i] = value;
  218. }
  219. }
  220. return paramsArray;
  221. }
  222. <!-- rewrite of backURL -->
  223. function _THIS_rewriteBackUrlHelper(submitMethod) {
  224. var backURL;
  225. if (submitMethod == "POST" &amp;&amp; typeof _THIS_.mvc_back_url != 'undefined') {
  226. backURL = _THIS_.mvc_back_url;
  227. } else if (submitMethod == "GET" &amp;&amp; typeof _THIS_.encoded_mvc_back_url != 'undefined') {
  228. backURL = _THIS_.encoded_mvc_back_url;
  229. } else {
  230. backURL = "javascript:window.close();";
  231. }
  232. return backURL;
  233. }
  234. <!-- DOM helpers -->
  235. function _THIS_getElementText(element) {
  236. if (element.childNodes &amp;&amp; element.childNodes.length > 1) {
  237. return element.childNodes[1].nodeValue;
  238. } else if(element.firstChild) {
  239. return element.firstChild.nodeValue;
  240. } else {
  241. return "";
  242. }
  243. }
  244. function _THIS_getSingleElementByTagName(element,tagName) {
  245. var results = element.getElementsByTagName(tagName);
  246. if (results) {
  247. if (results.length &gt; 0) {
  248. return results[0];
  249. }
  250. }
  251. return null;
  252. }
  253. function _THIS_getvalueOfSingleElementByTagName(element,tagName) {
  254. var e = _THIS_getSingleElementByTagName(element, tagName);
  255. if (e) {
  256. return _THIS_getElementText(e);
  257. }
  258. return "";
  259. }
  260. </script>
  261. </xsl:template>
  262. </xsl:stylesheet>