buster-files.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1";
  6. const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;
  7. var cmdFileController =
  8. {
  9. supportsCommand: function(aCommand)
  10. {
  11. switch(aCommand) {
  12. case 'cmd_fl_save':
  13. case 'cmd_fl_import':
  14. return true;
  15. default:
  16. }
  17. return false;
  18. },
  19. isCommandEnabled: function(aCommand)
  20. {
  21. return this.supportsCommand(aCommand);
  22. },
  23. doCommand: function(aCommand)
  24. {
  25. switch(aCommand) {
  26. case 'cmd_fl_save':
  27. var sink = new Object;
  28. sink.write = function(aContent, aCount)
  29. {
  30. // replace NC:succ with NC:orig_succ,
  31. // so the rdf stuff differs
  32. var content = aContent.replace(/NC:succ/g,"NC:orig_succ");
  33. content = content.replace(/NC:failCount/g,"NC:orig_failCount");
  34. this.mSink.write(content, content.length);
  35. return aCount;
  36. };
  37. var fp = doCreateRDFFP('Xalan results',
  38. nsIFilePicker.modeSave);
  39. var res = fp.show();
  40. if (res == nsIFilePicker.returnOK ||
  41. res == nsIFilePicker.returnReplace) {
  42. var serial = doCreate(kRDFXMLSerializerID,
  43. nsIRDFXMLSerializer);
  44. serial.init(view.mResultDS);
  45. serial.QueryInterface(nsIRDFXMLSource);
  46. var fl = fp.file;
  47. var fstream = doCreate(kFileOutStreamCID,
  48. nsIFileOutputStream);
  49. fstream.init(fl, 26, 420, 0);
  50. sink.mSink = fstream;
  51. serial.Serialize(sink);
  52. }
  53. break;
  54. case 'cmd_fl_import':
  55. var fp = doCreateRDFFP('Previous Xalan results',
  56. nsIFilePicker.modeLoad);
  57. var res = fp.show();
  58. if (res == nsIFilePicker.returnOK) {
  59. var fl = fp.file;
  60. if (view.mPreviousResultDS) {
  61. view.database.RemoveDataSource(view.mPreviousResultDS);
  62. view.mPreviousResultDS = null;
  63. }
  64. view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec);
  65. view.database.AddDataSource(view.mPreviousResultDS);
  66. }
  67. document.getElementById('obs_orig_success')
  68. .setAttribute('hidden','false');
  69. break;
  70. default:
  71. alert('Unknown Command'+aCommand);
  72. }
  73. }
  74. };
  75. registerController(cmdFileController);