|
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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 |
|
6 const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1"; |
|
7 const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream; |
|
8 |
|
9 var cmdFileController = |
|
10 { |
|
11 supportsCommand: function(aCommand) |
|
12 { |
|
13 switch(aCommand) { |
|
14 case 'cmd_fl_save': |
|
15 case 'cmd_fl_import': |
|
16 return true; |
|
17 default: |
|
18 } |
|
19 return false; |
|
20 }, |
|
21 isCommandEnabled: function(aCommand) |
|
22 { |
|
23 return this.supportsCommand(aCommand); |
|
24 }, |
|
25 doCommand: function(aCommand) |
|
26 { |
|
27 switch(aCommand) { |
|
28 case 'cmd_fl_save': |
|
29 var sink = new Object; |
|
30 sink.write = function(aContent, aCount) |
|
31 { |
|
32 // replace NC:succ with NC:orig_succ, |
|
33 // so the rdf stuff differs |
|
34 var content = aContent.replace(/NC:succ/g,"NC:orig_succ"); |
|
35 content = content.replace(/NC:failCount/g,"NC:orig_failCount"); |
|
36 this.mSink.write(content, content.length); |
|
37 return aCount; |
|
38 }; |
|
39 var fp = doCreateRDFFP('Xalan results', |
|
40 nsIFilePicker.modeSave); |
|
41 var res = fp.show(); |
|
42 |
|
43 if (res == nsIFilePicker.returnOK || |
|
44 res == nsIFilePicker.returnReplace) { |
|
45 var serial = doCreate(kRDFXMLSerializerID, |
|
46 nsIRDFXMLSerializer); |
|
47 serial.init(view.mResultDS); |
|
48 serial.QueryInterface(nsIRDFXMLSource); |
|
49 var fl = fp.file; |
|
50 var fstream = doCreate(kFileOutStreamCID, |
|
51 nsIFileOutputStream); |
|
52 fstream.init(fl, 26, 420, 0); |
|
53 sink.mSink = fstream; |
|
54 serial.Serialize(sink); |
|
55 } |
|
56 break; |
|
57 case 'cmd_fl_import': |
|
58 var fp = doCreateRDFFP('Previous Xalan results', |
|
59 nsIFilePicker.modeLoad); |
|
60 var res = fp.show(); |
|
61 |
|
62 if (res == nsIFilePicker.returnOK) { |
|
63 var fl = fp.file; |
|
64 if (view.mPreviousResultDS) { |
|
65 view.database.RemoveDataSource(view.mPreviousResultDS); |
|
66 view.mPreviousResultDS = null; |
|
67 } |
|
68 view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec); |
|
69 view.database.AddDataSource(view.mPreviousResultDS); |
|
70 } |
|
71 |
|
72 document.getElementById('obs_orig_success') |
|
73 .setAttribute('hidden','false'); |
|
74 break; |
|
75 default: |
|
76 alert('Unknown Command'+aCommand); |
|
77 } |
|
78 } |
|
79 }; |
|
80 |
|
81 registerController(cmdFileController); |