PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/export/domit/testing_domit.php

https://github.com/adamfranco/segue-1.x
PHP | 320 lines | 294 code | 26 blank | 0 comment | 19 complexity | d102aa31dbc1d6e07e973ff902204ea4 MD5 | raw file
  1. <html>
  2. <!-- The DOMIT! XML Parser Testing Interface -->
  3. <head><title>DOMIT! Testing Interface</title>
  4. <link rel="stylesheet" href="testing_domit.css" />
  5. <script language="javascript">
  6. function showWindow(url) {
  7. window.open(url, "", "width=760,height=540,scrollbars,resizable,menubar");
  8. } //showWindow
  9. </script>
  10. </head>
  11. <body>
  12. <h2>DOMIT! Testing Interface</h2>
  13. <form action="testing_domit.php" method="POST">
  14. <?php
  15. class test_domit {
  16. var $xmldoc;
  17. var $xmlfile;
  18. var $xmlurl = "";
  19. var $xmltext = "";
  20. var $domparser = "domit";
  21. var $saxparser = "saxy";
  22. var $xmloutput = "tonormalizedstring";
  23. var $xmlaction = null;
  24. var $extension = "xml";
  25. function start() {
  26. $this->updateVars();
  27. $this->buildInterface();
  28. $this->parse();
  29. } //start
  30. function parse() {
  31. if ($this->xmlaction != null) {
  32. require_once("timer.php");
  33. $timer = new Timer();
  34. $success = false;
  35. ($this->saxparser == "saxy") ? ($parseSAXY = true) : ($parseSAXY = false);
  36. $timer->start();
  37. switch($this->domparser){
  38. case ("domit"):
  39. require_once('xml_domit_parser.php');
  40. $this->xmldoc =& new DOMIT_Document();
  41. break;
  42. case ("domitlite"):
  43. require_once('xml_domit_lite_parser.php');
  44. $this->xmldoc =& new DOMIT_Lite_Document();
  45. break;
  46. } // switch
  47. switch($this->xmlaction){
  48. case "parsefile":
  49. $success = $this->xmldoc->loadXML($this->xmlfile, $parseSAXY);
  50. break;
  51. case "parseurl":
  52. $success = $this->xmldoc->loadXML($this->xmlurl, $parseSAXY);
  53. break;
  54. case "parsetext":
  55. $success = $this->xmldoc->parseXML($this->xmltext, $parseSAXY);
  56. break;
  57. }
  58. $timer->stop();
  59. if ($success) {
  60. echo "<br /><br />Time elapsed: " . $timer->getTime() . "seconds<br /><br />\n";
  61. if ($this->xmloutput == "tostring") {
  62. echo $this->xmldoc->toString(true);
  63. }
  64. else if ($this->xmloutput == "tonormalizedstring") {
  65. echo $this->xmldoc->toNormalizedString(true);
  66. }
  67. else if ($this->xmloutput == "toarray") {
  68. echo "<pre>\n";
  69. print_r($this->xmldoc->toArray());
  70. echo "</pre>\n";
  71. }
  72. }
  73. else {
  74. echo "<br /><br />Parsing error: xml document may be invalid or malformed.\n";
  75. }
  76. }
  77. } //parse
  78. function updateVars() {
  79. global $HTTP_POST_VARS;
  80. if (isset($HTTP_POST_VARS['xmlaction'])) {
  81. $this->xmlaction = $HTTP_POST_VARS['xmlaction'];
  82. }
  83. if (isset($HTTP_POST_VARS['domparser'])) {
  84. $this->domparser = $HTTP_POST_VARS['domparser'];
  85. }
  86. if (isset($HTTP_POST_VARS['saxparser'])) {
  87. $this->saxparser = $HTTP_POST_VARS['saxparser'];
  88. }
  89. if (isset($HTTP_POST_VARS['xmloutput'])) {
  90. $this->xmloutput = $HTTP_POST_VARS['xmloutput'];
  91. }
  92. if (isset($HTTP_POST_VARS['xmlfile'])) {
  93. $this->xmlfile = $HTTP_POST_VARS['xmlfile'];
  94. }
  95. if (isset($HTTP_POST_VARS['xmltext'])) {
  96. $this->xmltext = $HTTP_POST_VARS['xmltext'];
  97. $this->xmltext = str_replace("\\\"", '"', $this->xmltext);
  98. $this->xmltext = str_replace("\\'", "'", $this->xmltext);
  99. }
  100. if (isset($HTTP_POST_VARS['xmlurl'])) {
  101. $this->xmlurl = $HTTP_POST_VARS['xmlurl'];
  102. }
  103. } //updateVars
  104. function buildInterface() {
  105. $files = $this->getFiles($this->extension);
  106. echo "<table width=\"760\" cellpadding=\"0\" cellspacing=\"0\"\n";
  107. //DOM TITLE
  108. echo "<tr class=\"row0\">\n";
  109. echo "<td><p>Choose a DOM Parser</p></td>\n";
  110. echo "<td>&nbsp;</td></tr>\n\n";
  111. //CHOOSE DOM PARSER
  112. echo "<tr class=\"row1\">\n";
  113. echo "<td><p>\n";
  114. echo "<select name=\"domparser\">\n";
  115. echo "<option value=\"domit\"" .
  116. (($this->domparser == "domit") ? "selected" : "") .
  117. ">DOMIT!</option>\n";
  118. echo "<option value=\"domitlite\"" .
  119. (($this->domparser == "domitlite") ? "selected" : "") .
  120. ">DOMIT! Lite</option>\n";
  121. echo "</select>\n";
  122. echo "</p></td><td>&nbsp;</td></tr>\n\n";
  123. //SPACER
  124. echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n\n";
  125. //SAX TITLE
  126. echo "<tr class=\"row0\">\n";
  127. echo "<td><p>Choose a SAX Parser</p></td>\n";
  128. echo "<td>&nbsp;</td></tr>\n\n";
  129. //CHOOSE SAX PARSER
  130. echo "<td><p>\n";
  131. echo "<select name=\"saxparser\">\n";
  132. echo "<option value=\"saxy\"" .
  133. (($this->saxparser == "saxy") ? "selected" : "") .
  134. ">SAXY</option>\n";
  135. echo "<option value=\"expat\"" .
  136. (($this->saxparser == "expat") ? "selected" : "") .
  137. ">Expat</option>\n";
  138. echo "</select>\n";
  139. echo "</p></td><td>&nbsp;</td></tr>\n\n";
  140. //SPACER
  141. echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n\n";
  142. //OUTPUT FORMAT TITLE
  143. echo "<tr class=\"row0\">\n";
  144. echo "<td><p>Choose an Output Format</p></td>\n";
  145. echo "<td>&nbsp;</td></tr>\n\n";
  146. //CHOOSE OUTPUT FORMAT
  147. echo "<td><p>\n";
  148. echo "<select name=\"xmloutput\">\n";
  149. echo "<option value=\"tonormalizedstring\"" .
  150. (($this->xmloutput == "tonormalizedstring") ? "selected" : "") .
  151. ">toNormalizedString()</option>\n";
  152. echo "<option value=\"tostring\"" .
  153. (($this->xmloutput == "tostring") ? "selected" : "") .
  154. ">toString()</option>\n";
  155. echo "<option value=\"toarray\"" .
  156. (($this->xmloutput == "toarray") ? "selected" : "") .
  157. ">toArray()</option>\n";
  158. echo "</select>\n";
  159. echo "</p></td><td>&nbsp;</td></tr>\n\n";
  160. //SPACER
  161. echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n\n";
  162. //PARSER SOURCE DATA TITLING
  163. echo "<tr class=\"row0\">\n";
  164. echo "<td><p>Choose an XML File and click \"Parse File\"</p></td>\n";
  165. echo "<td><p>Paste in some XML Text and click \"Parse Text\"</p></td>\n";
  166. echo "</tr>\n\n";
  167. //CHOOSE XML FILE
  168. echo "<tr class=\"row1\">\n";
  169. echo "<td><p>\n";
  170. echo "<select name=\"xmlfile\" size=\"5\">\n";
  171. echo "<option value=\"-1\">------------------------------Choose a File----------------------------</option>\n";
  172. $total = count($files);
  173. for ($i = 0; $i < $total; $i++) {
  174. $currFile = $files[$i];
  175. echo "<option value=\"" . $currFile . "\"" .
  176. (($this->xmlfile == $currFile) ? "selected" : "") .
  177. ">" . $currFile . "</option>\n";
  178. }
  179. echo "</select>\n";
  180. echo "</p>\n";
  181. echo "</td>\n\n";
  182. //PASTE XML TEXT
  183. echo "<td><p>\n";
  184. echo "<textarea name=\"xmltext\" cols=\"40\" rows=\"5\"></textarea>\n";
  185. echo "</p></td>\n";
  186. echo "</tr>\n\n";
  187. //SPACER AND HIDDEN TEXT FIELD
  188. echo "<tr><td>&nbsp;<input type=\"hidden\" name=\"xmlaction\"></td><td>&nbsp;</td></tr>\n\n";
  189. //PARSE FILE BUTTON
  190. echo "<tr class=\"row1\">\n";
  191. echo "<td><p>\n";
  192. echo "<input type=\"button\" name=\"parsefile\" value=\"Parse File\"" .
  193. "onclick=\"this.form.xmlaction.value='parsefile';this.form.submit();\">\n";
  194. echo "</p>\n";
  195. echo "</td>\n\n";
  196. //PARSE TEXT BUTTON
  197. echo "<td><p>\n";
  198. echo "<input type=\"button\" name=\"parsetext\" value=\"Parse Text\"" .
  199. "onclick=\"this.form.xmlaction.value='parsetext';this.form.submit();\" />\n";
  200. echo "</p></td>\n";
  201. echo "</tr>\n\n";
  202. //SPACER
  203. echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n\n";
  204. echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n\n";
  205. //PARSE URL TITLING
  206. echo "<tr class=\"row0\">\n";
  207. echo "<td><p>Enter the url of an XML file and click \"Parse URL\"</p></td>\n";
  208. echo "<td>&nbsp;</td></tr>\n\n";
  209. //PARSE URL FIELD
  210. echo "<td><p>\n";
  211. echo "<input type=\"text\" name=\"xmlurl\" size=\"53\" value=\"" . $this->xmlurl . "\" />\n";
  212. echo "</p></td><td>&nbsp;</td></tr>\n\n";
  213. //SPACER
  214. echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n\n";
  215. //PARSE URL BUTTON
  216. echo "<td><p>\n";
  217. echo "<input type=\"button\" name=\"parseurl\" value=\"Parse URL\"" .
  218. "onclick=\"this.form.xmlaction.value='parseurl';this.form.submit();\" />\n";
  219. echo "</p></td>\n";
  220. echo "</tr>\n\n";
  221. echo "</table>\n\n";
  222. } //buildInterface
  223. function getFiles($extension) {
  224. $arFiles = array();
  225. if ($handle = opendir('.')) {
  226. while (false !== ($file = readdir($handle))) {
  227. if ($file != "." && $file != "..") {
  228. if ($extension == $this->getExtension($file)) {
  229. $arFiles[] = $file;
  230. }
  231. }
  232. }
  233. }
  234. closedir($handle);
  235. return $arFiles;
  236. } //getFiles
  237. function getExtension($filename) {
  238. $extension = "";
  239. $dotPos = strpos($filename, ".");
  240. if ($dotPos !== false) {
  241. $extension = substr($filename, ($dotPos + 1));
  242. }
  243. return $extension;
  244. } //getExtension
  245. } //test_domit
  246. $testSuite = new test_domit();
  247. $testSuite->start();
  248. ?>
  249. </form>
  250. <br />
  251. <p><a href="http://www.engageinteractive.com/domit/"><img src='domitBanner.gif' width="120" height="60" /></a></p>
  252. </body>
  253. </html>