123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- // Licensed Materials - Property of IBM
- //
- // IBM Cognos Products: cpscrn
- //
- // (C) Copyright IBM Corp. 2005, 2014
- //
- // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- //
- //
- (function() {
- // define namespace
- if (!window.com_ibm_cognos_cps){
- com_ibm_cognos_cps = {}
- }
-
- if (com_ibm_cognos_cps.ApplicationContext){
- // Stop if the ApplicationContext is alread defined.
- return;
- }
- // Helper object used to create the xmlHttpRequest based on the current browser
- var CPSConfig = {
- browser: 'unknown',
- browserVersion: 'unknown',
- OS: 'unknown',
- xmlHttpDefault: null,
- initialize: function()
- {
- this.browser = this.lookup(this.browsers).toLowerCase() || 'unknown';
- this.browserVersion = this.parseVersion(navigator.userAgent) || this.parseVersion(navigator.appVersion) || 'unknown';
- this.OS = this.lookup(this.systems) || 'unknown';
- this.xmlHttpDefault = this.findXMLHttpActiveXVersion();
- },
- lookup: function(data)
- {
- var i, l = data.length;
- for (i = 0; i < l; i++)
- {
- this.versionKey = data[i].partialKey || data[i].identity;
- var agent = data[i].agent;
- if (agent)
- {
- if (agent.indexOf(data[i].key) != -1)
- return data[i].identity;
- }
- else if (data[i].prop)
- return data[i].identity;
- }
- },
- parseVersion: function(s)
- {
- var index = s.indexOf(this.versionKey);
- if (index == -1)
- return;
- return parseFloat(s.substring(index + this.versionKey.length + 1).replace(/[^\d\.\-\+]/g, '_')); //sanitize before parse to avoid XSS vulnerability!
- },
- findXMLHttpActiveXVersion: function()
- {
- if (window.ActiveXObject)
- {
- var i, l = this.xmlHttpVersions.length;
- for (i = 0; i < l; i++)
- {
- try
- {
- // Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
- var xmlhttp = new ActiveXObject(this.xmlHttpVersions[i]);
- if (xmlhttp)
- return this.xmlHttpVersions[i];
- }
- catch (e)
- {
- // this ActiveX is not there, continue with next one in list
- }
- }
- }
- return null;
- },
- browsers: [
- { agent: navigator.userAgent, key: 'MSIE', identity: 'Explorer', partialKey: 'MSIE' },
- { agent: navigator.userAgent, key: 'Firefox', identity: 'Firefox' },
- { agent: navigator.userAgent, key: 'Gecko', identity: 'Mozilla', partialKey: 'rv' },
- { agent: navigator.userAgent, key: 'Mozilla', identity: 'Netscape', partialKey: 'Mozilla' },
- { agent: navigator.userAgent, key: 'Netscape', identity: 'Netscape' },
- { prop: window.opera, identity: 'Opera' },
- { agent: navigator.vendor, key: 'Apple', identity: 'Safari' }
- ],
- systems: [
- { agent: navigator.platform, key: 'Win', identity: 'Windows' },
- { agent: navigator.platform, key: 'Mac', identity: 'Mac' },
- { agent: navigator.platform, key: 'Linux', identity: 'Linux' }
- ],
- xmlHttpVersions: [
- 'Msxml2.XMLHTTP.6.0',
- 'Msxml2.XMLHTTP.3.0',
- 'Msxml2.XMLHTTP',
- 'Microsoft.XMLHTTP'
- ]
-
- }
- CPSConfig.initialize();
- /*
- Helper DOM utils.
- */
- com_ibm_cognos_cps._F_DOM =
- {
- selectNodes: function(node, xpath)
- {
- if (document.all)
- {
- var arr = new Array();
- var nodes = node.selectNodes(xpath);
- var i, l = nodes.length;
- for (i=0; i<l; i++)
- {
- arr.push(nodes.item(i));
- }
- return arr;
- }
- else
- {
- var doc = (node.ownerDocument) ? node.ownerDocument : node;
- var results = doc.evaluate(xpath, node, doc.createNSResolver(doc.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
- if (results)
- {
- var arr = new Array();
- var node = results.iterateNext();
- while (node != null)
- {
- arr.push(node);
- node = results.iterateNext();
- }
- return arr;
- }
- return null;
- }
- },
-
- selectSingleNode: function (node, xpath)
- {
- if (document.all)
- {
- return node.selectSingleNode(xpath);
- }
- else
- {
- var doc = (node.ownerDocument) ? node.ownerDocument : node;
- var results = doc.evaluate(xpath, node, doc.createNSResolver(doc.documentElement), XPathResult.FIRST_ORDERED_NODE_TYPE, null);
- if (results && results.singleNodeValue)
- return results.singleNodeValue;
- return null;
- }
- },
-
- getAttribute: function(node, name)
- {
- return node.getAttribute(name);
- },
-
- text: function(node)
- {
- function deepScanText(node)
- {
- var v = '';
- var n = node.firstChild;
- while (n != null)
- {
- if (n.nodeType == 3)
- v += n.nodeValue;
- else if (n.nodeType == 4)
- v += n.data;
- else if (n.nodeType == 1)
- v += deepScanText(n);
- n = n.nextSibling;
- }
- return v;
- }
- if (node == null || node === undefined)
- return '';
- if (document.all)
- return node.text;
- else if (node.nodeValue)
- return node.nodeValue;
- return deepScanText(node);
- },
-
- parseXml: function(xmlString)
- {
- var xmlDoc = null;
- if (window.ActiveXObject){
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(xmlString);
- }
-
- if (xmlDoc == null){
- var parser = new DOMParser();
- xmlDoc = parser.parseFromString(xmlString,"text/xml");
- }
-
- return xmlDoc;
- }
- }
- /*
- This class provides the APS that enables our content to work in enterprise portals.
- getWebContentResource: return an absolute url that will be used to retrieve a webcontent resource
- getGatewayResource: return an absolute url that will be used to retrieve a gateway resource
- getProxiedResource: return a url that can be used to do ajax request without running into cross domain issues
- getXHR: creates an xmlHttpRequest object.
-
- */
- com_ibm_cognos_cps.ApplicationContext = function(spec){
- this.getProperty = function(name){
- return spec[name];
- }
- }
- com_ibm_cognos_cps.ApplicationContext.prototype = {
- getWebContentResource: function(resource) {
- return this._getAbsoluteUrl(this.getProperty('webcontent'), resource);
- },
- getGatewayResource: function(resource) {
- return this._getAbsoluteUrl(this.getProperty('gateway'), resource);
- },
- _getAbsoluteUrl: function(base, url){
- if(url.indexOf(base) !== 0){
- var index = base.indexOf('://');
- if (index !== -1){
- index = base.indexOf('/', index + 3);
- if (index !== -1){
- return base.substring(0, index) + (url.charAt(0) === '/' ? '' : '/' ) + url;
- }
- }
- }
- return url;
- },
- getProxiedResource:function(url){
- var proxyTemplate = this.getProperty('proxyTemplate');
- // no proxying in CC
- if (proxyTemplate && !('cognos' == this.getProperty('portalAgent'))){
- return this._cpsresourceurl(this.getProperty('proxyTemplate'), url);
- }
- return url;
- },
- getXHR: function(){
- // plumtree xhr (knows how to handle timeouts ..)
- if (window.CustomPTHttpRequest !== undefined)
- return new CustomPTHttpRequest();
-
- if (CPSConfig.xmlHttpDefault != null)
- return new ActiveXObject(CPSConfig.xmlHttpDefault);
- // Well if there is no ActiveXObject available it must be firefox, opera, or something else
- if (typeof XMLHttpRequest != 'undefined')
- {
- return new XMLHttpRequest();
- }
- throw 'No XMLHttpRequest object is available';
- },
-
- _cpsresourceurl: function(resourceTemplate, target){
- var begin = resourceTemplate.indexOf('_cpsresourceurl');
- if (begin != -1){
- var endMarker='cpsendmarker_';
- var end = resourceTemplate.indexOf(endMarker, begin);
- if (end != -1){
- var marker = resourceTemplate.substring(begin, end + endMarker.length);
- var decodeCount = 0;
- var decodedMarker = marker;
- while(decodedMarker != '_cpsresourceurl:cpsendmarker_' && decodeCount ++ < 10){
- decodedMarker = decodeURIComponent(decodedMarker);
- }
- if (decodeCount < 10){
- var encodedTarget = target;
- for (i =0; i < decodeCount ; i++){
- encodedTarget = encodeURIComponent(encodedTarget);
- }
- target = resourceTemplate.replace(marker, encodedTarget);
- }
- }
- }
-
- // Plumtree portletIds.. so we can synchronize passports.
- if (window.cognosPortletIds){
- if(target.indexOf('?') != -1)
- target += '&';
- else
- target += '?';
- target += 'cognosPortletIds='+encodeURIComponent(cognosPortletIds.join('_'));
- }
-
- return target;
- }
- }
- })();
|