soap_page.xsl 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ## HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®. All rights reserved.
  4. -->
  5. <!DOCTYPE xsl:stylesheet [
  6. <!ENTITY nbsp "&#160;">
  7. <!ENTITY apos "&#39;">
  8. ]>
  9. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
  10. exclude-result-prefixes="fo">
  11. <xsl:output method="html" indent="yes" omit-xml-declaration="yes"
  12. doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
  13. <!-- ===============================================================================
  14. parameters
  15. ================================================================================ -->
  16. <xsl:param name="pageName" select="'SOAP Test'"/>
  17. <xsl:param name="serviceName" select="'FormTest'"/>
  18. <xsl:param name="methodName" select="'BasicTest'"/>
  19. <xsl:param name="destination" select="'zz'"/>
  20. <xsl:param name="header" select="'xx'"/>
  21. <xsl:param name="soapbody" select="'yy'"/>
  22. <xsl:param name="inhouseUser" select="false()"/>
  23. <xsl:param name="showhttp" select="false()"/>
  24. <xsl:param name="showLogout" select="showLogout"/>
  25. <!-- ===============================================================================-->
  26. <xsl:template match="/">
  27. <html>
  28. <head>
  29. <title>Soap Test Page</title>
  30. <link rel="stylesheet" type="text/css" href="files_/yui/build/fonts/fonts-min.css" />
  31. <link rel="stylesheet" type="text/css" href="files_/css/espdefault.css" />
  32. <script type="text/javascript" src="files_/get_input.js"/>
  33. <script type="text/javascript" src="files_/stack.js"/>
  34. <script type="text/javascript" src="files_/stringbuffer.js"/>
  35. <script type="text/javascript" src="files_/logout.js"/>
  36. <script type="text/javascript">
  37. var showhttp = '<xsl:value-of select="$showhttp"/>';
  38. <![CDATA[
  39. var xmlhttp = null;
  40. function isSpace(ch) {
  41. if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
  42. return true;
  43. return false;
  44. }
  45. // return true if succeeded
  46. function loadXMLDoc(url)
  47. {
  48. // code for Mozilla, etc.
  49. if (window.XMLHttpRequest) {
  50. xmlhttp=new XMLHttpRequest();
  51. }
  52. // code for IE
  53. else if (window.ActiveXObject) {
  54. try {
  55. xmlhttp=new ActiveXObject("Msxml2.XMLHTTP.4.0");
  56. } catch (e) {
  57. try {
  58. xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  59. } catch (e) {
  60. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  61. }
  62. }
  63. if (xmlhttp == null) {
  64. alert("Can not create XMLHTTP in IE");
  65. return false;
  66. }
  67. }
  68. if (xmlhttp) {
  69. xmlhttp.onreadystatechange = xmlhttpChange;
  70. // alert("url: "+url);
  71. xmlhttp.open("POST",url);
  72. //Set headers
  73. try {
  74. var header = document.getElementById("req_header").value;
  75. var lines = header.split('\n');
  76. for (var i = 0; i<lines.length;i++) {
  77. var line = lines[i];
  78. var idx = line.indexOf(':');
  79. if (idx <= 0) {
  80. alert("Invalid header line: "+line);
  81. return false;
  82. }
  83. //alert("Set header: " + line.substring(0, idx) + "=" +line.substring(idx+1,line.length));
  84. xmlhttp.setRequestHeader(line.substring(0, idx), line.substring(idx+1,line.length));
  85. }
  86. } catch (e) {
  87. alert("Exception when setRequestHeader(): "+e);
  88. }
  89. // alert("Request: "+document.getElementById("req_body").value);
  90. var xml = document.getElementById("req_body").value;
  91. // alert("Trying: url="+url+"\nuser="+user+"\npasswd="+passwd+"\nxml="+xml);
  92. var button = document.getElementById("sendButton");
  93. if (button)
  94. {
  95. button.value = "Please wait ...";
  96. button.disabled = true;
  97. }
  98. document.getElementById("body").style.cursor = "wait";
  99. xmlhttp.send(xml);
  100. }
  101. return true;
  102. }
  103. function xmlEncode(val)
  104. {
  105. return val.toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
  106. }
  107. function getAttrs(node)
  108. {
  109. var attrs = node.attributes;
  110. if (attrs==null)
  111. return "";
  112. var s = "";
  113. for (var i = 0; i<attrs.length; i++) {
  114. var node = attrs.item(i);
  115. s += ' ' + node.nodeName + '=' + '"' + xmlEncode(node.nodeValue) + '"';
  116. }
  117. //alert("Node: "+node.tagName + "; attrs=" + node.attributes + "; s="+s);
  118. return s;
  119. }
  120. function allSpaces(s)
  121. {
  122. if (s==null) return true;
  123. for (var i=0; i<s.length; i++)
  124. if ( !isSpace(s.charAt(i)) )
  125. return false;
  126. return true;
  127. }
  128. function toXML2(buf, tree)
  129. {
  130. //alert("toXML2: name="+tree.tagName + "; type="+tree.nodeType);
  131. switch (tree.nodeType)
  132. {
  133. case 1: // document.ELEMENT_NODE:
  134. var count = tree.childNodes.length;
  135. if (count==0) {
  136. buf.push("<" + tree.tagName + getAttrs(tree) + "/>");
  137. } else {
  138. var val = "";
  139. var started = false;
  140. for (var i=0; i<count; i++)
  141. {
  142. var node = tree.childNodes[i];
  143. switch (node.nodeType)
  144. {
  145. case 3: // document.TEXT_NODE:
  146. if (!allSpaces(node.nodeValue))
  147. val += xmlEncode(node.nodeValue);
  148. //else alert("Ignore text node: ["+node.nodeValue+"]");
  149. break;
  150. case 8: // document.COMMENT_NODE:
  151. val += "<!" + "--"+node.nodeValue+"--" + ">";
  152. break;
  153. case 4: // document.CDATA_SECTION_NODE:
  154. val += "<![" + "CDATA[" + node.nodeValue + "]]" + ">";
  155. break;
  156. case 7: // document.PROCESSING_INSTRUCTION_NODE:
  157. val += "<?"+node.target + " " + node.data + "?>";
  158. break;
  159. case 1: // document.ELEMENT_NODE:
  160. if (!started) {
  161. buf.push( "<"+tree.tagName+getAttrs(tree)+">");
  162. started = true;
  163. }
  164. if (val.length>0) {
  165. buf.push(val);
  166. val = '';
  167. }
  168. toXML2(buf, node);
  169. break;
  170. default:
  171. alert("Unhandled node [1]: <" + node.tagName + ">; type: " + node.nodeType );
  172. }
  173. }
  174. if (!started)
  175. buf.push( "<"+tree.tagName+getAttrs(tree) + ">");
  176. buf.push(val + "</" + tree.tagName + ">");
  177. }
  178. break;
  179. case 7: // document.PROCESSING_INSTRUCTION_NODE:
  180. buf.push( "<?"+tree.target + " " + tree.data + "?>");
  181. break;
  182. case 8: // document.COMMENT_NODE:
  183. buf.push("<!" + "--"+node.nodeValue+"--" + ">");
  184. break;
  185. defailt:
  186. alert("Unhandled node [2]: <" + tree.tagName + ">; type: " + tree.nodeType );
  187. }
  188. //alert("buf = " + buf.join('|'));
  189. }
  190. function toXML(tree)
  191. {
  192. var buf = new Array();
  193. if (tree)
  194. toXML2(buf,tree);
  195. return buf.join('');
  196. }
  197. function toXMLIndented2(buf, tree, indent)
  198. {
  199. //alert("toXML2: name="+tree.tagName + "; type="+tree.nodeType);
  200. switch (tree.nodeType)
  201. {
  202. case 1: // document.ELEMENT_NODE:
  203. var count = tree.childNodes.length;
  204. if (count==0) {
  205. buf.push(indent + "<" + tree.tagName + getAttrs(tree) + "/>");
  206. } else {
  207. var val = "";
  208. var started = false;
  209. for (var i=0; i<count; i++)
  210. {
  211. var node = tree.childNodes[i];
  212. switch (node.nodeType)
  213. {
  214. case 3: // document.TEXT_NODE:
  215. if (!allSpaces(node.nodeValue))
  216. val += xmlEncode(node.nodeValue);
  217. //alert("Text node: ["+node.nodeValue+"]");
  218. break;
  219. case 8: // document.COMMENT_NODE:
  220. val += "<!" + "--"+node.nodeValue+"--" + ">";
  221. break;
  222. case 4: // document.CDATA_SECTION_NODE:
  223. val += "<![" + "CDATA[" + node.nodeValue + "]]" + ">";
  224. break;
  225. case 7: // document.PROCESSING_INSTRUCTION_NODE:
  226. if (val.length==0)
  227. val += indent + " <?"+node.target + " " + node.data + "?>\n";
  228. else // in mixed content environment
  229. val += "<?"+node.target + " " + node.data + "?>";
  230. break;
  231. case 1: // document.ELEMENT_NODE:
  232. if (!started) {
  233. buf.push( indent + "<"+tree.tagName+getAttrs(tree) + ">");
  234. started = true;
  235. }
  236. if (val.length>0) {
  237. buf.push(val);
  238. val = '';
  239. }
  240. toXMLIndented2(buf, node,indent+' ');
  241. break;
  242. default:
  243. alert("Unhandled node [1]: <" + node.tagName + ">; type: " + node.nodeType );
  244. }
  245. }
  246. if (!started)
  247. buf.push( indent + "<"+tree.tagName+getAttrs(tree) + ">" + val + "</" + tree.tagName + ">");
  248. else
  249. buf.push(indent + val + "</" + tree.tagName + ">");
  250. }
  251. break;
  252. case 7: // document.PROCESSING_INSTRUCTION_NODE:
  253. buf.push(indent+ "<?"+tree.target + " " + tree.data + "?>");
  254. break;
  255. case 8: // document.COMMENT_NODE:
  256. buf.push("<!" + "--"+node.nodeValue+"--" + ">");
  257. break;
  258. defailt:
  259. alert("Unhandled node [2]: <" + tree.tagName + ">; type: " + tree.nodeType );
  260. }
  261. //alert("buf = " + buf.join('|'));
  262. }
  263. function toXMLIndented(tree)
  264. {
  265. var buf = new Array();
  266. if (tree)
  267. toXMLIndented2(buf,tree,"");
  268. return buf.join('\n');
  269. }
  270. function setResponseBodyHeader()
  271. {
  272. if (document.getElementById("prettify_resp").checked && xmlhttp.responseXML && xmlhttp.responseXML.documentElement)
  273. document.getElementById("resp_body").value = prettifyXMLDom(xmlhttp.responseXML);
  274. else
  275. document.getElementById("resp_body").value = xmlhttp.responseText;
  276. if (showhttp == 'true')
  277. document.getElementById("resp_header").value = xmlhttp.getAllResponseHeaders();
  278. if (xmlhttp.responseXML && xmlhttp.responseXML.parseError && xmlhttp.responseXML.parseError.errorCode!=0)
  279. {
  280. var parseError = xmlhttp.responseXML.parseError;
  281. alert("\nError in line " + parseError.line + "\nposition " + parseError.linePos + "\nError Code: " + parseError.errorCode + "\nError Reason: " + parseError.reason + "\nError Line: " + parseError.srcText);
  282. }
  283. }
  284. function xmlhttpChange()
  285. {
  286. // if xmlhttp shows "loaded"
  287. if (xmlhttp.readyState==4)
  288. {
  289. var button = document.getElementById("sendButton");
  290. if (button)
  291. {
  292. button.value = "Send Request";
  293. button.disabled = false;
  294. }
  295. document.getElementById("body").style.cursor = "default";
  296. // if "OK"
  297. if (xmlhttp.status==200)
  298. setResponseBodyHeader();
  299. else
  300. {
  301. setResponseBodyHeader();
  302. var msg = "Problem occurred in response:\n ";
  303. msg += "Status Code: " + xmlhttp.status+"\n";
  304. msg += "Messsage: "+xmlhttp.statusText + "\n";
  305. msg += "Response: see Response Body";
  306. alert(msg);
  307. }
  308. }
  309. }
  310. function onSendRequest()
  311. {
  312. // check well-formness
  313. if (document.getElementById("check_req").checked)
  314. {
  315. var doc = parseXmlString(document.getElementById("req_body").value);
  316. if (!doc) return;
  317. }
  318. // clear
  319. document.getElementById("resp_body").value = "";
  320. if (showhttp == 'true')
  321. document.getElementById("resp_header").value = "";
  322. var url = "]]><xsl:value-of select="$destination"/><![CDATA[";
  323. loadXMLDoc(url);
  324. return true;
  325. }
  326. //-------------------------------------------------------------------
  327. // mozilla only
  328. function checkForParseError (xmlDocument)
  329. {
  330. var errorNamespace = 'http://www.mozilla.org/newlayout/xml/parsererror.xml';
  331. var documentElement = xmlDocument.documentElement;
  332. var parseError = { errorCode : 0 };
  333. if (documentElement.nodeName == 'parsererror' &&
  334. documentElement.namespaceURI == errorNamespace) {
  335. parseError.errorCode = 1;
  336. var sourceText = documentElement.getElementsByTagNameNS(errorNamespace, 'sourcetext')[0];
  337. if (sourceText != null) {
  338. parseError.srcText = sourceText.firstChild.data
  339. }
  340. parseError.reason = documentElement.firstChild.data;
  341. }
  342. return parseError;
  343. }
  344. function parseXmlString(xml)
  345. {
  346. var xmlDoc = null;
  347. try {
  348. var dom = new DOMParser();
  349. xmlDoc = dom.parseFromString(xml, 'text/xml');
  350. var error = checkForParseError(xmlDoc);
  351. if (error.errorCode!=0)
  352. {
  353. alert(error.reason + "\n" + error.srcText);
  354. return null;
  355. }
  356. } catch (e) {
  357. try {
  358. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  359. xmlDoc.async="false";
  360. xmlDoc.loadXML(xml);
  361. if (xmlDoc.parseError != 0)
  362. {
  363. alert("XML Parse Error: " + xmlDoc.parseError.reason);
  364. return null;
  365. }
  366. } catch(e) {
  367. alert("Error: " + e.name + "\n" + e.message);
  368. return null;
  369. }
  370. }
  371. if (!xmlDoc)
  372. alert("Create xmlDoc failed! You browser is not supported yet.");
  373. return xmlDoc;
  374. }
  375. function getRootElement(xmlDom)
  376. {
  377. var root = null;
  378. if (xmlDom)
  379. {
  380. root = xmlDom.firstChild;
  381. if (root && root.nodeType!=1) // IE treat <?xml ?> as first child
  382. {
  383. //alert("firstChild type = " + root.nodeType);
  384. root = xmlDom.childNodes[1];
  385. }
  386. }
  387. return root;
  388. }
  389. function isBlank(s)
  390. {
  391. var len = s ? s.length : 0;
  392. for (var i=0; i<len; i++)
  393. {
  394. var ch = s.charAt(i);
  395. if (ch != ' ' && ch != '\t' && ch!='\n')
  396. return false;
  397. }
  398. return true;
  399. }
  400. //-------------------------------------------------------------------
  401. function hasAttr(tree)
  402. {
  403. // some browser (such as IE) does not support hasAttributes()
  404. if (tree.hasAttributes)
  405. return tree.hasAttributes();
  406. else
  407. return tree.attributes!=null && tree.attributes.length>0;
  408. }
  409. function removeEmptyNodes(tree, remove_empty, remove_zero)
  410. {
  411. // alert("Node type: " + tree.nodeType + "\nNode value:"+tree.nodeValue+"\nTag name:"+tree.tagName);
  412. if (tree.nodeType==1) // ELEMENT_NODE
  413. {
  414. var count = tree.childNodes.length;
  415. if (count==0 && !hasAttr(tree))
  416. return null;
  417. for (var i = count-1; i>=0; i--) // do backward so the remove would not invalid the list
  418. {
  419. var node = tree.childNodes[i];
  420. var newnode = removeEmptyNodes(node, remove_empty, remove_zero);
  421. if (!newnode)
  422. tree.removeChild(node);
  423. else
  424. tree.replaceChild(newnode,node);
  425. }
  426. return (tree.hasChildNodes() || hasAttr(tree)) ? tree : null;
  427. } else if (tree.nodeType==3) {
  428. if (!hasAttr(tree) && ((remove_empty && isBlank(tree.nodeValue)) || (remove_zero && tree.nodeValue=='0')) )
  429. return null;
  430. }
  431. return tree;
  432. }
  433. function getFirstElementNode(tree)
  434. {
  435. if (tree)
  436. {
  437. var nodes = tree.childNodes;
  438. for (var i=0; i<nodes.length; i++)
  439. {
  440. var node = nodes[i];
  441. if (node.nodeType == 1)
  442. return node;
  443. }
  444. }
  445. return null;
  446. }
  447. function clearEmptySoapFields(doc, root, remove_empty, remove_zero)
  448. {
  449. var body = getFirstElementNode(root);
  450. if (!body) return null;
  451. var req = getFirstElementNode(body);
  452. if (!req) return null;
  453. var reqTag = req.tagName;
  454. var newreq = removeEmptyNodes(req, remove_empty, remove_zero);
  455. if (!newreq)
  456. newreq = doc.createElement(reqTag);
  457. body.replaceChild(newreq,req);
  458. return root;
  459. }
  460. function clearEmptyFields(xml, remove_empty, remove_zero)
  461. {
  462. var doc = parseXmlString(xml);
  463. if (!doc) return null;
  464. var root = doc.documentElement;
  465. if (!root) return null;
  466. if (root.getLocalName=='Envelope')
  467. return clearEmptySoapFields(doc, root);
  468. else
  469. {
  470. var reqTag = root.tagName;
  471. var newreq = removeEmptyNodes(root, remove_empty, remove_zero);
  472. if (!newreq)
  473. newreq = doc.createElement(reqTag);
  474. doc.replaceChild(newreq,root);
  475. }
  476. return root;
  477. }
  478. function onClearEmptyFields(remove_empty, remove_zero)
  479. {
  480. var ctrl = document.getElementById("req_body");
  481. var xml = ctrl.value;
  482. var tree = clearEmptyFields(xml, remove_empty, remove_zero);
  483. if (tree)
  484. {
  485. var newxml;
  486. var prettify = document.getElementById("prettify_req").checked;
  487. if (prettify)
  488. newxml = toXMLIndented(tree);
  489. else
  490. newxml = toXML(tree);
  491. ctrl.value = '<?xml version="1.0" encoding="UTF-8"?>' + (prettify?'\n':'') + newxml;
  492. }
  493. }
  494. function prettifyXML(inXML)
  495. {
  496. var doc = parseXmlString(inXML);
  497. return prettifyXMLDom(doc);
  498. }
  499. function prettifyXMLDom(doc)
  500. {
  501. if (doc)
  502. {
  503. // IE, Opera do not support xmlVersion, xmlEncoding
  504. var version = (doc.xmlVersion==undefined)?"1.0":doc.xmlVersion;
  505. var encoding = (doc.xmlEncoding==undefined) ? "utf-8" : doc.xmlEncoding;
  506. var xmlDeclare = '<?xml version="' + version + '" encoding="' + encoding + '"?>';
  507. return xmlDeclare + "\n" + toXMLIndented(doc.documentElement);
  508. }
  509. return "";
  510. }
  511. function onPrettifyXML(txtCtrl, chkCtrl)
  512. {
  513. var ctrl = document.getElementById(txtCtrl);
  514. if (isBlank(ctrl.value))
  515. return;
  516. var doc = parseXmlString(ctrl.value);
  517. var chkbox = document.getElementById(chkCtrl);
  518. var checked = chkbox.checked;
  519. var xmlDeclare = null;
  520. if (doc) {
  521. var version = (doc.xmlVersion==undefined)?"1.0":doc.xmlVersion;
  522. var encoding = (doc.xmlEncoding==undefined) ? "utf-8" : doc.xmlEncoding;
  523. xmlDeclare = '<?xml version="' + version + '" encoding="' + encoding + '"?>';
  524. doc = doc.documentElement;
  525. }
  526. else
  527. chkbox.checked = !checked;
  528. var value = ctrl.value;
  529. if (doc)
  530. {
  531. if (checked)
  532. value = toXMLIndented(doc);
  533. else
  534. value = toXML(doc);
  535. }
  536. ctrl.value = xmlDeclare + (checked?'\n':'') + value;
  537. }
  538. function constructXmlFromConciseForm(txt)
  539. {
  540. var ret = new StringBuffer();
  541. var stack = new Stack();
  542. var curIdx = 0;
  543. var len = txt.length;
  544. while (curIdx<len)
  545. {
  546. while ( isSpace(txt.charAt(curIdx)) ) { curIdx++; }
  547. if (txt.charAt(curIdx) == ']')
  548. {
  549. var tag = stack.pop();
  550. if (!tag) {
  551. var msg = "Invalid data: no tag for ]:\n";
  552. msg += txt.substr(0,curIdx+1)+ "<<ERROR<<" + txt.substring(curIdx+1);
  553. alert(msg);
  554. return null;
  555. }
  556. ret.append("</" + tag + ">");
  557. curIdx++;
  558. continue;
  559. }
  560. // parse tag
  561. var idx =curIdx;
  562. while (idx<len) {
  563. var ch = txt.charAt(idx);
  564. if (ch=='(' || ch =='[')
  565. break;
  566. idx++;
  567. }
  568. // trim spaces
  569. var end = idx-1;
  570. while ( isSpace(txt.charAt(end)) ) { end--; }
  571. var tag = txt.substring(curIdx,end+1);
  572. //alert("tag: ["+tag+']');
  573. if (ch=='(')
  574. {
  575. curIdx = idx+1;
  576. idx = txt.indexOf(')',curIdx);
  577. if (idx<0) { alert("Invalid input: not ending '(' for <"+tag+">"); return null; }
  578. ret.append('<'+tag+'>' + txt.substring(curIdx, idx) + '</' + tag + '>');
  579. curIdx = idx+1;
  580. } else if (ch=='[') {
  581. stack.push(tag);
  582. //alert("stack.push: [" + tag+']');
  583. ret.append('<' + tag + '>');
  584. curIdx = idx+1;
  585. } else {
  586. alert("Invalid input: ["+ ch + "]; only '(' or '[' is valid after tag <"+tag+">.");
  587. return null;
  588. }
  589. }
  590. return ret.toString();
  591. }
  592. function inputReturnMethod()
  593. {
  594. var txt = gWndObj.value;
  595. gWndObjRemoveWatch();
  596. if (txt!=null && txt!="")
  597. {
  598. var xml = constructXmlFromConciseForm(txt)
  599. var tagLen = gMethodName.length+2;
  600. if ( xml.substr(0, tagLen) != ('<'+gMethodName+'>') ) {
  601. alert("The request must starts with <"+gMethodName+">");
  602. return;
  603. }
  604. var head = '<?xml version="1.0" encoding="UTF-8"?>'
  605. + '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'
  606. + ' xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"'
  607. + ' xmlns="http://webservices.seisint.com/' + gServiceName + '">'
  608. + ' <soap:Body><'
  609. + gMethodName + 'Request>';
  610. var end = '</' + gMethodName + 'Request></soap:Body></soap:Envelope>';
  611. xml = head + xml.substring(tagLen, xml.length-tagLen-1) + end;
  612. document.getElementById('req_body').value = xml;
  613. /*TODO: request prettify_req. Why this does not work??
  614. var checked = document.getElementById('prettify_req').checked;
  615. if (checked) { xml = prettifyXml(xml); }
  616. alert(document.getElementById('req_body'));
  617. document.getElementById('req_body').value = xml;
  618. alert(document.getElementById('req_body').value);
  619. */
  620. }
  621. document.getElementById('import').disabled = false;
  622. }
  623. function onImportConciseRequest()
  624. {
  625. document.getElementById('import').disabled = true;
  626. showGetInputWnd('The Concise Request Text (from esp log):', 'inputReturnMethod()');
  627. }
  628. var soapBody = ']]><xsl:value-of select="$soapbody"/><![CDATA[';
  629. function setSoapBody()
  630. {
  631. var ctrl = document.getElementById("req_body");
  632. if (!ctrl) return;
  633. ctrl.value = prettifyXML(soapBody);
  634. return true;
  635. }
  636. ]]>
  637. var gServiceName = "<xsl:value-of select="$serviceName"/>";
  638. var gMethodName = "<xsl:value-of select="$methodName"/>";;
  639. </script>
  640. </head>
  641. <body class="yui-skin-sam" id="body" onload="setSoapBody()">
  642. <h3>
  643. <table cellSpacing="0" cellPadding="1" width="100%" bgColor="#4775FF" border="0" >
  644. <tr align="left">
  645. <td height="23" bgcolor="000099" align="center"><font color="#ffffff"><b><xsl:value-of select="concat(' ', $pageName, ' ')"/></b></font></td>
  646. <td height="23" align="center"><font color="#ffffff"><b><xsl:value-of select="concat($serviceName, ' / ', $methodName)"/></b></font></td>
  647. <xsl:if test="$showLogout">
  648. <td><a href="javascript:void(0)" onclick="logout();">Log Out</a></td>
  649. </xsl:if>
  650. </tr>
  651. </table>
  652. </h3>
  653. <b>&nbsp;&nbsp;Destination: </b> <xsl:value-of select="$destination"/>
  654. <p/>
  655. <table width="100%">
  656. <tr><th align="left">Request: </th> <th align="left">Response: </th></tr>
  657. <tr>
  658. <td width="50%">
  659. <table width="100%" border="0" cellspacing="0" cellpadding="1">
  660. <xsl:choose>
  661. <xsl:when test="$showhttp">
  662. <tr>
  663. <td>
  664. <b>Headers:</b>
  665. </td>
  666. </tr>
  667. <tr>
  668. <td>
  669. <textarea id="req_header" style="width:100%" rows="4">
  670. <xsl:value-of select="$header"/>
  671. </textarea>
  672. </td>
  673. </tr>
  674. </xsl:when>
  675. <xsl:otherwise>
  676. <input type="hidden" id="req_header" name="req_header" value="{$header}"/>
  677. </xsl:otherwise>
  678. </xsl:choose>
  679. <tr>
  680. <td>
  681. <table width="100%">
  682. <tr> <!--td align="left"><b>Request Body:</b></td-->
  683. <td align="right">
  684. <input type="button" value="Remove Empty" onclick="onClearEmptyFields(true, false)"/>
  685. <input type="button" value="Remove Zeros" onclick="onClearEmptyFields(false, true)"/>
  686. <xsl:if test="$inhouseUser">&nbsp;<input id="import" type="button" value="Import..." onclick="onImportConciseRequest()"/></xsl:if>
  687. <input type="checkbox" id="prettify_req" checked="true" onclick="onPrettifyXML('req_body','prettify_req')"/><label for='prettify_req'>Prettify XML</label>
  688. </td></tr>
  689. </table>
  690. </td>
  691. </tr>
  692. <tr>
  693. <td>
  694. <textarea id="req_body" name="req_body" style="width:100%" rows="35" wrap="on"/>
  695. </td>
  696. </tr>
  697. </table>
  698. </td>
  699. <td width="50%">
  700. <table width="100%" border="0" cellspacing="0" cellpadding="1">
  701. <xsl:if test="$showhttp">
  702. <tr>
  703. <td>
  704. <b>Headers:</b>
  705. </td>
  706. </tr>
  707. <tr>
  708. <td>
  709. <textarea id="resp_header" cols="10" style="width:100%" rows="4" readonly="true"></textarea>
  710. </td>
  711. </tr>
  712. </xsl:if>
  713. <tr>
  714. <td>
  715. <table width="100%">
  716. <tr>
  717. <!--td> <b>Response Body:</b> </td-->
  718. <td align="right"><input type="checkbox" id="prettify_resp" checked="true" onclick="onPrettifyXML('resp_body','prettify_resp')"/><label for='prettify_resp'>Prettify XML</label> </td>
  719. </tr>
  720. </table>
  721. </td>
  722. </tr>
  723. <tr>
  724. <td>
  725. <textarea id="resp_body" name="response" style="width:100%" rows="35" wrap="on" readonly="true"></textarea>
  726. </td>
  727. </tr>
  728. </table>
  729. </td>
  730. </tr>
  731. <tr>
  732. <td align="center" colspan="2">
  733. <input type="button" id="sendButton" value="Send Request" onclick="onSendRequest()"/> <input type="checkbox" checked="true" id="check_req"/><label for='check_req'>Check well-formness before send</label>
  734. </td>
  735. </tr>
  736. </table>
  737. <!-- </form> -->
  738. </body>
  739. </html>
  740. </xsl:template>
  741. </xsl:stylesheet>