xhttpDispatcher.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2008 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. function XHTTPDispatcher(callBackFunc, arguments)
  11. {
  12. this.callBackFunc = callBackFunc;
  13. this.request_url = this.processRequest(arguments);
  14. }
  15. XHTTPDispatcher.prototype.dispatch = function()
  16. {
  17. // send off the request
  18. sendDispatcherRequestWithXMLTextResponse(this.request_url, this.callBackFunc);
  19. }
  20. // utility function
  21. XHTTPDispatcher.prototype.processRequest = function(arguments)
  22. {
  23. var sURL = "";
  24. var clk = "cl";
  25. var plk = "pl";
  26. var b_action = "b_action";
  27. var locales = getLocales(clk, plk);
  28. // have to add b_action in by hand - URIEncode always prepends a '&' to it
  29. if (arguments[b_action]) {
  30. sURL = b_action + "=" + encodeURIComponent(arguments[b_action]);
  31. delete arguments[b_action];
  32. } else {
  33. sURL = b_action + "=xts.run";
  34. }
  35. // add some values into the URL if they don't exist in the arguments
  36. sURL += this.addDefaultValue(clk, locales[clk], arguments);
  37. sURL += this.addDefaultValue(plk, locales[plk], arguments);
  38. // add in all the other arguments - NB - arguments for the defaults
  39. // above won't be added again - if they existed in the argument array
  40. // they were removed in the addDefaultValue function.
  41. for (i in arguments) {
  42. // arguments i might be an array in which case we add all the contents of the array
  43. var values = makeArray(arguments[i]);
  44. for (var value in values) {
  45. sURL += URIEncode(i,values[value]);
  46. }
  47. }
  48. // add a cafContextId if there is one
  49. if (cafContextId != "") {
  50. sURL += URIEncode("cafcontextid",cafContextId);
  51. }
  52. // return the request
  53. return sURL;
  54. }
  55. // build a URIEncoded argument pair from the name/value passed in. If the
  56. // name is in the argument array - use that in preference
  57. XHTTPDispatcher.prototype.addDefaultValue = function(sName, sValue, arguments)
  58. {
  59. var sURL = "";
  60. if (arguments[sName]) {
  61. sURL += URIEncode(sName, arguments[sName]);
  62. // remove it
  63. delete arguments[sName];
  64. } else {
  65. sURL += URIEncode(sName, sValue);
  66. }
  67. return sURL;
  68. }