michael@0: /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1"; michael@0: const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream; michael@0: michael@0: var cmdFileController = michael@0: { michael@0: supportsCommand: function(aCommand) michael@0: { michael@0: switch(aCommand) { michael@0: case 'cmd_fl_save': michael@0: case 'cmd_fl_import': michael@0: return true; michael@0: default: michael@0: } michael@0: return false; michael@0: }, michael@0: isCommandEnabled: function(aCommand) michael@0: { michael@0: return this.supportsCommand(aCommand); michael@0: }, michael@0: doCommand: function(aCommand) michael@0: { michael@0: switch(aCommand) { michael@0: case 'cmd_fl_save': michael@0: var sink = new Object; michael@0: sink.write = function(aContent, aCount) michael@0: { michael@0: // replace NC:succ with NC:orig_succ, michael@0: // so the rdf stuff differs michael@0: var content = aContent.replace(/NC:succ/g,"NC:orig_succ"); michael@0: content = content.replace(/NC:failCount/g,"NC:orig_failCount"); michael@0: this.mSink.write(content, content.length); michael@0: return aCount; michael@0: }; michael@0: var fp = doCreateRDFFP('Xalan results', michael@0: nsIFilePicker.modeSave); michael@0: var res = fp.show(); michael@0: michael@0: if (res == nsIFilePicker.returnOK || michael@0: res == nsIFilePicker.returnReplace) { michael@0: var serial = doCreate(kRDFXMLSerializerID, michael@0: nsIRDFXMLSerializer); michael@0: serial.init(view.mResultDS); michael@0: serial.QueryInterface(nsIRDFXMLSource); michael@0: var fl = fp.file; michael@0: var fstream = doCreate(kFileOutStreamCID, michael@0: nsIFileOutputStream); michael@0: fstream.init(fl, 26, 420, 0); michael@0: sink.mSink = fstream; michael@0: serial.Serialize(sink); michael@0: } michael@0: break; michael@0: case 'cmd_fl_import': michael@0: var fp = doCreateRDFFP('Previous Xalan results', michael@0: nsIFilePicker.modeLoad); michael@0: var res = fp.show(); michael@0: michael@0: if (res == nsIFilePicker.returnOK) { michael@0: var fl = fp.file; michael@0: if (view.mPreviousResultDS) { michael@0: view.database.RemoveDataSource(view.mPreviousResultDS); michael@0: view.mPreviousResultDS = null; michael@0: } michael@0: view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec); michael@0: view.database.AddDataSource(view.mPreviousResultDS); michael@0: } michael@0: michael@0: document.getElementById('obs_orig_success') michael@0: .setAttribute('hidden','false'); michael@0: break; michael@0: default: michael@0: alert('Unknown Command'+aCommand); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: registerController(cmdFileController);