search.xslt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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"
  13. xmlns:out="dummy-uri"
  14. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  15. xmlns:sr="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/dialog/search"
  16. xmlns:cf="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/controls/framework/"
  17. xmlns:dp="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/dialog/presentation/"
  18. xmlns:cml="http://developer.cognos.com/schemas/xts/logic-sheet/xslt/cml/1/"
  19. xmlns:lyt="http://developer.cognos.com/schemas/xts/logicsheets/xslt/presentation/layout/"
  20. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  21. xmlns:xts="http://developer.cognos.com/schemas/xts/">
  22. <xsl:output method="xml" encoding="UTF-8" indent="no"/>
  23. <xsl:namespace-alias stylesheet-prefix="out" result-prefix="xsl"/>
  24. <!--
  25. This stylesheet (search.xsl) consists of the following templates:
  26. mt:search - generate main search area for page.
  27. mt:directPath - used in lieu of path control in search dialog (only tools).
  28. mt:scopes - generates select element
  29. mt:scope - generate scope list for tools search dialog.
  30. mt:stypes - placeholder.
  31. mt:stype - generate type list for tools search dialog.
  32. -->
  33. <!--
  34. Template - search:gen-search-exp:
  35. This template generates the expression when a search is launched
  36. Operation:
  37. Generates /root/search/expression search results or /root/search/emptySearchExpression when there are no search results.
  38. -->
  39. <xsl:template match="sr:generate-exp" priority="1">
  40. <xts:append>
  41. <search>
  42. <out:variable name="search_string" select="/root/env/param[@name = 'search_text']"/>
  43. <out:variable name="search_modified_filter" select="/root/env/param[@name = 'search_modified']"/>
  44. <out:variable name="search_type_filter" select="/root/env/param[@name = 'search_type']"/>
  45. <out:variable name="search_show_filter" select="/root/env/param[@name = 'search_show']"/>
  46. <!-- if there is something to search on then build a search expression and append it to the imput doc. -->
  47. <out:choose>
  48. <out:when test="$search_string != '' or $search_modified_filter != 'any' or $search_type_filter != 'any' or $search_show_filter != ''">
  49. <out:variable name="sq">'</out:variable>
  50. <!-- must escape the ' to '' to make the search expression CM safe. -->
  51. <out:variable name="text" select=" xtsext:replace(string($search_string), string($sq), concat($sq,$sq)) "/>
  52. <expression>
  53. <!-- Scope ==== -->
  54. <out:variable name="scope" select="string(/root/env/param[@name = 'search_scope'])"/>
  55. <out:variable name="isAdminUser" select="boolean(/root/session/param[@name='capabilities']/canUseAdministrationPortal)"/>
  56. <out:variable name="defaultContentRoot">
  57. <out:choose>
  58. <out:when test="/root/session/param[@name='e_root'] and /root/session/param[@name='e_root'] != ''">
  59. <out:value-of select="/root/session/param[@name='e_root']"/>
  60. </out:when>
  61. <out:otherwise>
  62. <out:value-of select="'/content'"/>
  63. </out:otherwise>
  64. </out:choose>
  65. </out:variable>
  66. <out:choose>
  67. <!-- current folder and subfolders -->
  68. <out:when test="$scope = 'fb'"><out:value-of select="$path"/>/descendant::*</out:when>
  69. <!-- current folder only -->
  70. <out:when test="$scope = 'fo'"><out:value-of select="$path"/>/*</out:when>
  71. <!-- personal folders -->
  72. <out:when test="$scope = 'm'">~/folder/descendant::*</out:when>
  73. <!-- public folders -->
  74. <out:when test="$scope = 'p'"><out:value-of select="$defaultContentRoot"/>/descendant::*</out:when>
  75. <!-- tool root ( i.e. /configuration for server admin tool, /content for schedule tool, /directory for directory tool -->
  76. <out:when test="$scope = 'any'"><out:value-of select="$defaultPath"/>/descendant::*</out:when>
  77. <!-- no scope is defined, default to tool root -->
  78. <out:otherwise>
  79. <xsl:choose>
  80. <xsl:when test="@defaultRoot and @defaultRoot != '$defaultPath'">
  81. <out:value-of select="concat('/', {@defaultRoot}, '/descendant::*')"/>
  82. </xsl:when>
  83. <xsl:otherwise>/descendant::*</xsl:otherwise>
  84. </xsl:choose>
  85. </out:otherwise>
  86. </out:choose>
  87. <!-- Field / Search Type ==== -->
  88. <out:if test="$text != ''">
  89. <out:variable name="method" select="string(/root/env/param[@name = 'search_method'])"/>
  90. <out:choose>
  91. <out:when test="string(/root/env/param[@name = 'sfield'])='' or /root/env/param[@name = 'sfield'] = 'n'">
  92. <out:choose>
  93. <out:when test="$method = '3'">[@defaultName = '<out:value-of select="$text"/>']</out:when>
  94. <out:when test="$method = '2'">[starts-with(@defaultName, '<out:value-of select="$text"/>' )]</out:when>
  95. <out:otherwise>[contains(@defaultName, '<out:value-of select="$text"/>' )]</out:otherwise>
  96. </out:choose>
  97. </out:when>
  98. <out:when test="/root/env/param[@name = 'sfield'] = 'd'">
  99. <out:choose>
  100. <out:when test="$method = '3'">[@defaultDescription = '<out:value-of select="$text"/>']</out:when>
  101. <out:when test="$method = '2'">[starts-with(@defaultDescription, '<out:value-of select="$text"/>' )]</out:when>
  102. <out:otherwise>[contains(@defaultDescription, '<out:value-of select="$text"/>' )]</out:otherwise>
  103. </out:choose>
  104. </out:when>
  105. <out:otherwise>
  106. <out:choose>
  107. <out:when test="$method = '3'">[@defaultDescription = '<out:value-of select="$text"/>' or @defaultName = '<out:value-of select="$text"/>']</out:when>
  108. <out:when test="$method = '2'">[starts-with(@defaultDescription, '<out:value-of select="$text"/>' ) or starts-with(@defaultName, '<out:value-of select="$text"/>' )]</out:when>
  109. <out:otherwise>[contains(@defaultDescription, '<out:value-of select="$text"/>' ) or contains(@defaultName, '<out:value-of select="$text"/>' )]</out:otherwise>
  110. </out:choose>
  111. </out:otherwise>
  112. </out:choose>
  113. </out:if>
  114. <!-- Object Filter ==== -->
  115. <out:choose>
  116. <out:when test="$search_type_filter != 'any'">
  117. <out:choose>
  118. <out:when test="$search_type_filter = 'service' ">
  119. <out:text>[</out:text>
  120. <out:for-each select="/root/system/param[@name='ui_objects']/object[@service='T'][position()!=last()]">
  121. <out:value-of select="concat('@objectClass=&quot;', @class, '&quot; or ')"/>
  122. </out:for-each>
  123. <out:text>@objectClass="</out:text>
  124. <out:value-of select="/root/system/param[@name='ui_objects']/object[@service='T'][position()=last()]/@class"/>
  125. <out:text>"]</out:text>
  126. </out:when>
  127. <out:otherwise>
  128. <out:text/>[@objectClass = '<out:value-of select="$search_type_filter"/>']<out:text/>
  129. </out:otherwise>
  130. </out:choose>
  131. </out:when>
  132. <out:otherwise>
  133. <xsl:choose>
  134. <xsl:when test="sr:defaultTypes">
  135. <out:text/>[<out:text/>
  136. <!--xsl:apply-templates select="sr:defaultTypes/child::node()"/-->
  137. <xsl:apply-templates select="sr:defaultTypes/child::node()"/>
  138. <out:text/>]<out:text/>
  139. </xsl:when>
  140. <xsl:otherwise>
  141. <out:text/>[@usage != 'subObject']<out:text/>
  142. </xsl:otherwise>
  143. </xsl:choose>
  144. </out:otherwise>
  145. </out:choose>
  146. <!-- Modified date ==== -->
  147. <out:if test="$search_modified_filter != 'any'">
  148. <out:variable name="offsetamt">
  149. <out:choose>
  150. <out:when test="$search_modified_filter = 't'">0</out:when>
  151. <out:when test="$search_modified_filter = 'l3d'">-259200</out:when>
  152. <out:when test="$search_modified_filter = 'lw'">-604800</out:when>
  153. <out:when test="$search_modified_filter = 'lm'">-2629743</out:when>
  154. <out:when test="$search_modified_filter = 'l3m'">-7889231</out:when>
  155. <out:when test="$search_modified_filter = 'l6m'">-15778463</out:when>
  156. <out:when test="$search_modified_filter = 'ly'">-31556926</out:when>
  157. <out:when test="$search_modified_filter = 'l3y'">-94670777</out:when>
  158. </out:choose>
  159. </out:variable>
  160. <out:variable name="offsetunit">second</out:variable>
  161. <out:text/>[@modificationTime &gt; '<out:value-of select="xtsext:formatDateToUTC(xtsext:getDateTimeOffset(concat(xtsext:substringBeforeLast(xtsext:getCurrentDateTime(/root/user/param[@name='timeZoneID']), 'T'), 'T00:00:00Z'), $offsetamt, $offsetunit),/root/user/param[@name='timeZoneID'])"/>']<out:text/>
  162. </out:if>
  163. <!-- Default security filters ==== -->
  164. <xsl:choose>
  165. <xsl:when test="not(@defaultRoot)">
  166. <out:value-of select="$visibility-predicate"/>
  167. </xsl:when>
  168. <xsl:otherwise>
  169. <out:if test="starts-with($path, &quot;CAMID(&apos;:&quot;) or starts-with($path, 'CAMID(&quot;:')">
  170. <!-- only add the security filter if we're in the Cognos namespace -->
  171. <out:value-of select="$visibility-predicate"/>
  172. </out:if>
  173. <!-- no need to check for permissions in a third party namespace. Security is configured by the third party tool -->
  174. </xsl:otherwise>
  175. </xsl:choose>
  176. </expression>
  177. </out:when>
  178. <!-- when we only search on one object then there won't be an stype -->
  179. <out:when test="$search_string = '' and $search_modified_filter = 'any' and ($search_type_filter = 'any' or not(/root/env/param[@name = 'stype']))">
  180. <emptySearchExpression/>
  181. </out:when>
  182. </out:choose>
  183. </search>
  184. </xts:append>
  185. </xsl:template>
  186. <xsl:template match="sr:defaultType" priority="1">
  187. <xsl:choose>
  188. <xsl:when test="string(.) = 'service' ">
  189. <out:for-each select="/root/system/param[@name='ui_objects']/object[@service='T'][position()!=last()]">
  190. <out:text>@objectClass='</out:text>
  191. <out:value-of select="@class"/>
  192. <out:text>' or </out:text>
  193. </out:for-each>
  194. <out:text>@objectClass='</out:text>
  195. <out:value-of select="/root/system/param[@name='ui_objects']/object[@service='T'][position()=last()]/@class"/>
  196. <out:text>'</out:text>
  197. </xsl:when>
  198. <xsl:otherwise>
  199. <xsl:if test="preceding-sibling::sr:defaultType"><out:text/> or <out:text/></xsl:if>
  200. <out:text/>@objectClass='<xsl:value-of select="string(.)"/>'<out:text/>
  201. </xsl:otherwise>
  202. </xsl:choose>
  203. </xsl:template>
  204. <xsl:template match="*">
  205. <xsl:copy>
  206. <xsl:copy-of select="@*"/>
  207. <xsl:apply-templates/>
  208. </xsl:copy>
  209. </xsl:template>
  210. </xsl:stylesheet>