123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Licensed Materials - Property of IBM
- IBM Cognos Products: ps
- (C) Copyright IBM Corp. 2005, 2017
- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- -->
- <!--
- This morphlet takes an external application-bound HTTP/CGI command and adds to it CRN environment variables as defined in an
- xml file specified by the "c_env" variable before executing the command. It can process a POST or a GET request.
- -->
- <xts:morphlet xmlns:xts="http://developer.cognos.com/schemas/xts/" messageBase="messages/portal.xml, messages/portalRL.xml">
-
- <!-- BLOCK: Read the redirection environment if one is specified -->
- <!-- ================================================================================================= -->
- <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">
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt">
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
- <xsl:template match="/root">
-
- <xsl:variable name="filename" select="env/param[@name='c_env']"/>
- <xsl:variable name="fileext" select="xtsext:substringAfterLast(string($filename), '.')"/>
-
- <xsl:if test="translate(translate($fileext, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), ' ', '') = 'xml'">
- <!-- Only support file with .xml extension -->
- <xts:sequence>
- <xts:append>
- <xts:request protocol="FILEREAD" cache="false">
- <xsl:attribute name="href"><xsl:value-of select="$filename"/></xsl:attribute>
- </xts:request>
- </xts:append>
- </xts:sequence>
- </xsl:if>
- </xsl:template>
- </xsl:stylesheet>
- </xts:block>
-
- <!-- BLOCK: If the requested env vars include CM vars then execute the CM request to get them. This will also validate the current passport.
- If there are no CM vars requested then execute a dummy CM request to validate the passport only. -->
- <!-- ================================================================================================= -->
- <xts:block id="validatePassport" processor="XSLT" type="exec" dependency="setRequestEnv" mandatory="false">
- <xts:logicsheet path="logicsheets/buslogic.xslt"/>
- <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/">
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
- <xsl:template match="/root">
- <xts:sequence>
- <xts:append>
- <send:request provider="cm">
- <xts:transform src="transforms/CM/pre-process.xslt" processor="XSLT">
- <xsl:choose>
-
- <!-- Get any requested "account" properties -->
- <xsl:when test="CRNenv/cm/param">
- <cm:query>
- <cm:search>~</cm:search>
- <cm:properties>
- <xsl:for-each select="CRNenv/cm/param">
- <cm:property>
- <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
- </cm:property>
- </xsl:for-each>
- </cm:properties>
- </cm:query>
- </xsl:when>
-
- <!-- Just validate the passport -->
- <xsl:otherwise>
- <cm:query>
- <cm:search>~~</cm:search>
- <cm:properties>
- <cm:property name="defaultName"/>
- </cm:properties>
- </cm:query>
- </xsl:otherwise>
- </xsl:choose>
- </xts:transform>
- </send:request>
- </xts:append>
- </xts:sequence>
- </xsl:template>
- </xsl:stylesheet>
- </xts:block>
-
-
- <!-- BLOCK: Output a redirection page -->
- <!-- ================================================================================================= -->
- <xts:block id="format" mode="interpret" processor="XSLT" type="exec" mimeType="text/html" dependency="validatePassport">
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:cm="http://developer.cognos.com/schemas/xts-cm/1/"
- xmlns:xts="http://developer.cognos.com/schemas/xts/"
- xmlns:xos="http://developer.cognos.com/schemas/xts/output/"
- xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
- xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
- xmlns:string="java:java.lang.String"
- exclude-result-prefixes="xsl cm xts xtsext bus">
- <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no"/>
- <xsl:key name="session-param" match="/root/session/param" use="@name"/>
- <xsl:key name="cookies" match="/root/cookies/cookie" use="@name"/>
- <xsl:key name="setCookies" match="/root/setCookies/cookie" use="@name"/>
-
- <xsl:template match="/root">
- <!-- Request method -->
- <xsl:variable name="method">
- <xsl:choose>
- <xsl:when test="translate(CRNenv/redirect/@method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'post'">post</xsl:when>
- <xsl:when test="translate(env/param[@name='c_mode'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'post'">post</xsl:when>
- <xsl:when test="translate(env/param[@name='c_mode'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'mixed'">mixed</xsl:when>
- <xsl:otherwise>get</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="encoding">
- <xsl:choose>
- <xsl:when test="env/param[@name='c_encode'] != ''">
- <xsl:value-of select="env/param[@name='c_encode']"/>
- </xsl:when>
- <xsl:otherwise>utf-8</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="requestCommand" select="string(env/param[@name='c_cmd'])"/>
- <xsl:variable name="presetCommand" select="string(CRNenv/@c_cmd)"/>
-
- <xsl:variable name="is-lookupCommand-matched">
- <xsl:call-template name="verify-url">
- <xsl:with-param name="c_cmd" select="translate($requestCommand,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
- </xsl:call-template>
- </xsl:variable>
-
- <!-- Target command -->
-
- <xsl:variable name="targetCommand">
- <xsl:choose>
- <xsl:when test="$presetCommand != ''">
- <xsl:value-of select="$presetCommand"/>
- </xsl:when>
-
- <xsl:when test="$is-lookupCommand-matched = 'true'">
- <xsl:value-of select="$requestCommand"/>
- </xsl:when>
-
- <!-- Return an error message later when blank -->
- </xsl:choose>
- </xsl:variable>
-
- <xts:sequence>
- <xts:append select="/root/output">
- <xos:part>
- <xos:entityHeader>
- <xos:param name="Content-Type">text/html; charset=<xsl:value-of select="$encoding"/></xos:param>
- <xos:param name="Cache-Control">no-cache</xos:param>
- </xos:entityHeader>
- <xos:entityBody>
- <html lang="{key('session-param','productLocale')}">
- <head>
- <!-- Specify custom encoding -->
- <meta http-equiv="Content-Type" content="text/html; charset={$encoding}"/>
- <!-- Don't let the page cache -->
- <meta content="0" http-equiv="expires"/>
-
- <!-- Build the redirection for a GET request (anything other than post) =========== -->
- <xsl:if test=" $method = 'get' and $targetCommand != ''">
- <!-- Build the part of the query string containing the CRN env variables -->
- <xsl:variable name="crn_env">
-
- <!-- State params -->
- <xsl:for-each select="CRNenv/cc_state/param">
- <xsl:text/>&<xsl:value-of select="@name"/>=<xsl:value-of select="xtsext:urlencode(string(key('session-param', @name)), string($encoding))"/>
- </xsl:for-each>
-
- <!-- Cookie params -->
- <xsl:for-each select="CRNenv/cookies/param">
- <xsl:text/>&<xsl:value-of select="@name"/>=<xsl:text/>
- <xsl:choose>
- <xsl:when test="key('setCookies', @name) != ''">
- <xsl:value-of select="string(key('setCookies', @name))"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="string(key('cookies', @name))"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
-
- <!-- User prefs params -->
- <xsl:for-each select="CRNenv/user_pref/param">
- <xsl:text/>&<xsl:value-of select="@name"/>=<xsl:value-of select="xtsext:urlencode(string(/root/user/param[@name = current()/@name]), string($encoding))"/>
- <xsl:text/>
- </xsl:for-each>
-
- <!-- CM data (account object) -->
- <xsl:for-each select="CRNenv/cm/param">
- <xsl:text/>&<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))"/>
- <xsl:text/>
- </xsl:for-each>
-
- </xsl:variable>
-
- <!-- build the redirection URL using the passed-in base application command -->
- <xsl:variable name="redirect-url">
- <xsl:value-of select="$targetCommand"/>
- <xsl:if test="not(contains($targetCommand, '?'))">?</xsl:if>
- <xsl:choose>
- <xsl:when test="contains($targetCommand, '=')">
- <xsl:value-of select="$crn_env"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="substring-after( $crn_env, '&') "/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:call-template name="getState">
- <xsl:with-param name="method" select=" 'get' "/>
- <xsl:with-param name="encoding" select="$encoding"/>
- </xsl:call-template>
- </xsl:variable>
-
- <!--
- Hand-code the meta tag to avoid problems with the output element
- double-encoding the URL value once it is inserted in the "content" attribute
- -->
- <xsl:text disable-output-escaping="yes"><meta http-equiv="refresh" content="0; URL=</xsl:text>
- <xsl:value-of select="$redirect-url"/>
- <xsl:text disable-output-escaping="yes">"/></xsl:text>
- </xsl:if>
- </head>
-
- <body>
- <xsl:if test="($method = 'post' or $method = 'mixed') and $targetCommand != '' ">
- <xsl:attribute name="onload">document.redirect.submit()</xsl:attribute>
-
- <!-- Build the redirection for a POST or mixed request =========== -->
- <form name="redirect" method="post">
- <xsl:attribute name="action">
- <xsl:choose>
- <xsl:when test="$method = 'post'"><xsl:value-of select="$targetCommand"/></xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$targetCommand"/>
- <xsl:variable name="startNewQueryString" select="not(contains($targetCommand, '?')) and not(contains($targetCommand, '#'))"/>
- <xsl:call-template name="getState">
- <xsl:with-param name="method" select=" 'get' "/>
- <xsl:with-param name="encoding" select="$encoding"/>
- <xsl:with-param name="startNewQueryString" select="$startNewQueryString"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- <!-- State params -->
- <xsl:for-each select="CRNenv/cc_state/param">
- <input name="{@name}" type="hidden" value="{key('session-param', @name)}"/>
- </xsl:for-each>
- <!-- Cookie params -->
- <xsl:for-each select="CRNenv/cookies/param">
- <xsl:choose>
- <xsl:when test="key('setCookies', @name) != ''">
- <input name="{@name}" type="hidden" value="{key('setCookies', @name)}"/>
- </xsl:when>
- <xsl:otherwise>
- <input name="{@name}" type="hidden" value="{key('cookies', @name)}"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <!-- User prefs params -->
- <xsl:for-each select="CRNenv/user_pref/param">
- <input name="{@name}" type="hidden" value="{/root/header/*[local-name()='biBusHeader']/*[local-name() = 'userPreferenceVars']/*[name=current()/@name]/value}"/>
- </xsl:for-each>
- <!-- CM data (account object) -->
- <xsl:for-each select="CRNenv/cm/param">
- <input name="{@name}" type="hidden" value="{/root/*[local-name()='queryResponse']/*[local-name()='queryResult']/*[local-name()='item']/*[local-name() = current()/@name]/*[local-name()='value']}"/>
- </xsl:for-each>
-
- <xsl:if test="$method='post'">
- <!-- Regular POST, Add any passed-in params -->
- <xsl:call-template name="getState">
- <xsl:with-param name="method" select=" 'post' "/>
- <xsl:with-param name="encoding" select="$encoding"/>
- </xsl:call-template>
- </xsl:if>
-
- </form>
- </xsl:if>
- <xsl:if test="$targetCommand = '' ">
- <div style="font-family: Tahoma; color: #666699; padding: 50px; text-align: center;">
- <xts:string id="IDS_BRI_ERROR_URL"/>
- </div>
- </xsl:if>
- </body>
- </html>
- </xos:entityBody>
- </xos:part>
- </xts:append>
- </xts:sequence>
- </xsl:template>
- <xsl:template name="getState">
- <xsl:param name="method"/>
- <xsl:param name="encoding"/>
- <xsl:param name="startNewQueryString" select="false()"/>
-
- <!-- Add all other passed-in variables but exclude those used to execute this morphlet -->
- <xsl:for-each select="/root/env/param[not(starts-with(@name, 'c_')) and @name != 'b_action' and @name != 'm' and @name != 'encoding']">
- <xsl:choose>
- <xsl:when test="$method = 'post'">
- <input name="{@name}" type="hidden" value="{.}"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="delimeter">
- <xsl:choose>
- <xsl:when test="$startNewQueryString = 'true' and position() = '1'">?</xsl:when>
- <xsl:otherwise>&</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:value-of select="concat($delimeter, @name, '=', xtsext:urlencode(string(.),string($encoding)))"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </xsl:template>
-
- <xsl:template name="verify-url">
- <xsl:param name="c_cmd" select="''"/>
- <xsl:param name="index" select="'1'"/>
-
- <xsl:variable name="acceptable-urls" select="/root/CRNenv/urls/url"/>
-
- <xsl:if test="$index <= count($acceptable-urls)">
- <xsl:variable name="candidate-url" select="$acceptable-urls[$index]"/>
- <xsl:variable name="is-matched">
- <xsl:choose>
- <xsl:when test="$candidate-url/@is-regex='true'">
- <xsl:variable name="regex-nocase" select="translate($candidate-url,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
- <xsl:value-of select="string:matches(string:new($c_cmd), $regex-nocase)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="translate(string($candidate-url),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = $c_cmd"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:choose>
- <xsl:when test="$is-matched = 'true'">
- <xsl:value-of select="$is-matched"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="verify-url">
- <xsl:with-param name="c_cmd" select="$c_cmd"/>
- <xsl:with-param name="index" select="$index + 1"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:if>
- </xsl:template>
- </xsl:stylesheet>
- </xts:block>
-
- <!-- Debug -->
- <!-- ============================================================================= -->
- <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">
- <xts:logicsheet path="logicsheets/debuglogic.xslt"/>
- <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">
- <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no"/>
- <dbg:templates/>
- <xsl:template match="/">
- <dbg:dumpxml select="/root"/>
- </xsl:template>
- </xsl:stylesheet>
- </xts:block>
- </xts:morphlet>
|