cm-fault.xslt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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"
  13. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  14. xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  15. xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
  16. xmlns:xts="http://developer.cognos.com/schemas/xts/">
  17. <!-- Fault block for handling CM faults -->
  18. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  19. <xsl:template match="/root">
  20. <xsl:apply-templates select="fault"/>
  21. </xsl:template>
  22. <xsl:template match="fault">
  23. <xsl:copy>
  24. <SOAP-ENV:Envelope>
  25. <xsl:choose>
  26. <xsl:when test="SOAP-ENV:Envelope/SOAP-ENV:Header">
  27. <xsl:copy-of select="SOAP-ENV:Envelope/SOAP-ENV:Header"/>
  28. </xsl:when>
  29. <xsl:otherwise>
  30. <SOAP-ENV:Header/>
  31. </xsl:otherwise>
  32. </xsl:choose>
  33. <SOAP-ENV:Body>
  34. <xsl:apply-templates/>
  35. </SOAP-ENV:Body>
  36. </SOAP-ENV:Envelope>
  37. </xsl:copy>
  38. </xsl:template>
  39. <xsl:template match="error">
  40. <xsl:choose>
  41. <xsl:when test="descendant::SOAP-ENV:Fault">
  42. <xsl:apply-templates/>
  43. </xsl:when>
  44. <xsl:otherwise>
  45. <!-- This section handles xts exceptions that occur as part of the xts:request such as "connection refused" -->
  46. <SOAP-ENV:Fault>
  47. <xsl:copy-of select="faultcode"/>
  48. <xsl:copy-of select="faultstring"/>
  49. <detail>
  50. <bus:exception>
  51. <xsl:choose>
  52. <xsl:when test="faultcode = 'Server.protocol.bibusrequestfailed'">
  53. <!-- Can't connect to content manager -->
  54. <errorCode>ccError</errorCode>
  55. <bus:message>
  56. <messageString><xts:string id="IDS_ERR_CM_CONNECT"/></messageString>
  57. </bus:message>
  58. <!-- copy the existing messages and increase their nestingLevel -->
  59. <xsl:call-template name="copy-xts-msg">
  60. <xsl:with-param name="level" select="1"/>
  61. </xsl:call-template>
  62. </xsl:when>
  63. <xsl:otherwise>
  64. <!-- just copy the existing messages -->
  65. <xsl:call-template name="copy-xts-msg">
  66. <xsl:with-param name="level" select="0"/>
  67. </xsl:call-template>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </bus:exception>
  71. </detail>
  72. </SOAP-ENV:Fault>
  73. </xsl:otherwise>
  74. </xsl:choose>
  75. </xsl:template>
  76. <xsl:template match="SOAP-ENV:Fault">
  77. <xsl:choose>
  78. <xsl:when test="not(descendant::SOAP-ENV:Fault)">
  79. <xsl:copy>
  80. <xsl:copy-of select="faultcode"/>
  81. <xsl:copy-of select="faultstring"/>
  82. <detail>
  83. <xsl:apply-templates select="detail/bus:exception"/>
  84. </detail>
  85. </xsl:copy>
  86. </xsl:when>
  87. <xsl:otherwise>
  88. <xsl:apply-templates select="descendant::SOAP-ENV:Fault"/>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. </xsl:template>
  92. <xsl:template match="bus:exception">
  93. <!-- this section handles errors where the result of an xts:request is a soap fault such as cm's duplicate name error -->
  94. <xsl:copy>
  95. <xsl:copy-of select="severity"/>
  96. <errorCode>ccError</errorCode>
  97. <bus:message>
  98. <messageString>
  99. <xsl:variable name="cr"><xts:string id="IDS_ERR_CREATE"/></xsl:variable>
  100. <xsl:variable name="co"><xts:string id="IDS_ERR_COPY"/></xsl:variable>
  101. <xsl:variable name="mo"><xts:string id="IDS_ERR_MOVE"/></xsl:variable>
  102. <xsl:choose>
  103. <xsl:when test="starts-with(errorCode, 'cmNameConflict') or starts-with(errorCode, 'cmDuplicateName')">
  104. <xts:string id="IDS_ERR_CM_OP_DUP"> <!-- duplicate name error -->
  105. <xts:param name="op">
  106. <xsl:variable name="op" select="/root/env/param[@name='ifrmcmd']"/>
  107. <xsl:choose>
  108. <xsl:when test="$op='create'"><xsl:value-of select="$cr"/></xsl:when>
  109. <xsl:when test="$op='copy'"><xsl:value-of select="$co"/></xsl:when>
  110. <xsl:when test="$op='move'"><xsl:value-of select="$mo"/></xsl:when>
  111. </xsl:choose>
  112. </xts:param>
  113. </xts:string>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xts:string id="IDS_ERR_CM_OP"> <!-- generic operation failed message -->
  117. <xts:param name="op">
  118. <xsl:variable name="op" select="/root/env/param[@name='ifrmcmd']"/>
  119. <xsl:choose>
  120. <xsl:when test="$op='create'"><xsl:value-of select="$cr"/></xsl:when>
  121. <xsl:when test="$op='copy'"><xsl:value-of select="$co"/></xsl:when>
  122. <xsl:when test="$op='move'"><xsl:value-of select="$mo"/></xsl:when>
  123. </xsl:choose>
  124. </xts:param>
  125. </xts:string>
  126. </xsl:otherwise>
  127. </xsl:choose>
  128. </messageString>
  129. </bus:message>
  130. <!-- copy the existing messages and increase their nestingLevel -->
  131. <xsl:call-template name="copy-msg">
  132. <xsl:with-param name="level" select="'1'"/>
  133. </xsl:call-template>
  134. </xsl:copy>
  135. </xsl:template>
  136. <xsl:template name="copy-msg">
  137. <xsl:param name="level"/>
  138. <xsl:for-each select="bus:message">
  139. <xsl:copy>
  140. <nestingLevel>
  141. <xsl:choose>
  142. <xsl:when test="not(nestingLevel)">
  143. <xsl:value-of select="$level"/>
  144. </xsl:when>
  145. <xsl:otherwise>
  146. <xsl:value-of select="number(nestingLevel) + number($level)"/>
  147. </xsl:otherwise>
  148. </xsl:choose>
  149. </nestingLevel>
  150. <xsl:copy-of select="messageString"/>
  151. </xsl:copy>
  152. </xsl:for-each>
  153. </xsl:template>
  154. <xsl:template name="copy-xts-msg">
  155. <!-- turn xts:exception into bus:message -->
  156. <xsl:param name="level"/>
  157. <xsl:for-each select="detail/xts:exception">
  158. <bus:message>
  159. <nestingLevel>
  160. <xsl:choose>
  161. <xsl:when test="not(nestingLevel)">
  162. <xsl:value-of select="$level"/>
  163. </xsl:when>
  164. <xsl:otherwise>
  165. <xsl:value-of select="number(nestingLevel) + number($level)"/>
  166. </xsl:otherwise>
  167. </xsl:choose>
  168. </nestingLevel>
  169. <messageString>
  170. <xsl:value-of select="xts:exceptionMsg"/>
  171. </messageString>
  172. </bus:message>
  173. </xsl:for-each>
  174. </xsl:template>
  175. <xsl:template match="*">
  176. <xsl:apply-templates/>
  177. </xsl:template>
  178. <xsl:template match="text()"/>
  179. </xsl:stylesheet>