AsynchDATARequest.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2012
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. function AsynchDATARequest(gateway, webContentRoot) {
  13. // initialize the base class
  14. AsynchDATARequest.baseConstructor.call(this, gateway, webContentRoot);
  15. this.m_oResponseState = null;
  16. this.m_sResponseState = null;
  17. this.m_endOfStateIdx = -1;
  18. this.cStatePrefix = "<xml><state>";
  19. this.cStateSuffix = "</state></xml>";
  20. }
  21. // A server request that expects a data response (state and HTML)
  22. // set up the base class
  23. AsynchDATARequest.prototype = new AsynchRequest();
  24. AsynchDATARequest.baseConstructor = AsynchRequest;
  25. AsynchDATARequest.prototype.getEndOfStateIdx = function() {
  26. if (this.m_endOfStateIdx==-1) {
  27. var prefix = this.getResponseText().substring(0,12);
  28. if (prefix==this.cStatePrefix) {
  29. this.m_endOfStateIdx = this.getResponseText().indexOf(this.cStateSuffix);
  30. if (this.m_endOfStateIdx!=-1) {
  31. this.m_endOfStateIdx+=this.cStateSuffix.length;
  32. }
  33. }
  34. }
  35. return this.m_endOfStateIdx;
  36. };
  37. AsynchDATARequest.prototype.getResponseStateText = function() {
  38. if (!this.m_sResponseState) {
  39. this.getResponseState();
  40. }
  41. return this.m_sResponseState;
  42. };
  43. AsynchDATARequest.prototype.getResponseState = function() {
  44. if(this.m_oResponseState==null && this.getEndOfStateIdx()!=-1) {
  45. this.m_sResponseState = this.getResponseText().substring(this.cStatePrefix.length, this.getEndOfStateIdx() - this.cStateSuffix.length);
  46. if(this.m_sResponseState != null) {
  47. this.m_sResponseState = xml_decode(this.m_sResponseState);
  48. this.m_oResponseState=eval("(" + this.m_sResponseState + ")");
  49. }
  50. }
  51. return this.m_oResponseState;
  52. };
  53. AsynchDATARequest.prototype.getAsynchStatus = function() {
  54. if (this.getResponseState()!=null && typeof this.getResponseState().m_sStatus != "undefined") {
  55. return this.getResponseState().m_sStatus;
  56. }
  57. return "unknown";
  58. };
  59. AsynchDATARequest.prototype.getTracking = function() {
  60. if (this.getResponseState()!=null && typeof this.getResponseState().m_sTracking != "undefined") {
  61. return this.getResponseState().m_sTracking;
  62. }
  63. return "";
  64. };
  65. AsynchDATARequest.prototype.getConversation = function() {
  66. if (this.getResponseState()!=null && typeof this.getResponseState().m_sConversation != "undefined") {
  67. return this.getResponseState().m_sConversation;
  68. }
  69. return "";
  70. };
  71. AsynchDATARequest.prototype.getPrimaryAction = function() {
  72. if (this.getResponseState()!=null && typeof this.getResponseState().envParams != "undefined" && this.getResponseState().envParams["ui.primaryAction"] != "undefined") {
  73. return this.getResponseState().envParams["ui.primaryAction"];
  74. }
  75. return "";
  76. };
  77. AsynchDATARequest.prototype.getActionState = function() {
  78. if (this.getResponseState()!=null && typeof this.getResponseState().m_sActionState != "undefined") {
  79. return this.getResponseState().m_sActionState;
  80. }
  81. return "";
  82. };
  83. AsynchDATARequest.prototype.getResult = function() {
  84. if (this.getEndOfStateIdx()!=-1) {
  85. return this.getResponseText().substring(this.getEndOfStateIdx(), this.getResponseText().length);
  86. }
  87. return "";
  88. };
  89. AsynchDATARequest.prototype.getDebugLogs = function() {
  90. if (this.getResponseState()!=null && typeof this.getResponseState().debugLogs != "undefined") {
  91. return this.getResponseState().debugLogs;
  92. }
  93. return "";
  94. };
  95. AsynchDATARequest.prototype.getPromptHTMLFragment = function() {
  96. return this.getResult();
  97. };
  98. AsynchDATARequest.prototype.constructFaultEnvelope = function() {
  99. if(this.m_soapFault == null) {
  100. var state = this.getResponseState();
  101. if(state != null) {
  102. if(state.m_sSoapFault) {
  103. var faultString = state.m_sSoapFault;
  104. this.m_soapFault = XMLBuilderLoadXMLFromString(faultString);
  105. }
  106. }
  107. }
  108. return this.m_soapFault;
  109. };
  110. AsynchDATARequest.prototype.construct = function() {
  111. var asynchRequest = new AsynchDATARequest(this.m_gateway, this.m_webContentRoot);
  112. asynchRequest.setCallbacks(this.m_callbacks);
  113. if (this.getFormFields().exists("cv.responseFormat")) {
  114. asynchRequest.addFormField("cv.responseFormat", this.getFormField("cv.responseFormat"));
  115. }
  116. else {
  117. asynchRequest.addFormField("cv.responseFormat", "data");
  118. }
  119. return asynchRequest;
  120. };
  121. AsynchDATARequest.prototype.getEnvParam = function(param) {
  122. var responseState = this.getResponseState();
  123. if (responseState && typeof responseState.envParams != "undefined" && typeof responseState.envParams[param] != "undefined") {
  124. return responseState.envParams[param];
  125. }
  126. return null;
  127. };
  128. AsynchDATARequest.prototype.isRAPWaitTrue = function() {
  129. var rapWait = this.getEnvParam("rapWait");
  130. if (rapWait != null) {
  131. return rapWait == "true" ? true : false;
  132. }
  133. return false;
  134. };
  135. AsynchDATARequest.prototype.getRAPRequestCache = function() {
  136. return this.getEnvParam("rapRequestCache");
  137. };
  138. AsynchDATARequest.prototype.getMainConversation = function() {
  139. return this.getEnvParam("mainConversation");
  140. };
  141. AsynchDATARequest.prototype.getMainTracking = function() {
  142. return this.getEnvParam("mainTracking");
  143. };