!import
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is TransforMiiX XSLT processor code.
16 *
17 * The Initial Developer of the Original Code is
18 * Axel Hecht.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Axel Hecht <axel@pike.org>
24 * Peter Van der Beken <peterv@propagandism.org>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1";
41 const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;
42
43 var cmdFileController =
44 {
supportsCommand
45 supportsCommand: function(aCommand)
46 {
47 switch(aCommand) {
48 case 'cmd_fl_save':
49 case 'cmd_fl_import':
50 return true;
51 default:
52 }
53 return false;
54 },
isCommandEnabled
55 isCommandEnabled: function(aCommand)
56 {
57 return this.supportsCommand(aCommand);
58 },
doCommand
59 doCommand: function(aCommand)
60 {
61 switch(aCommand) {
62 case 'cmd_fl_save':
63 var sink = new Object;
anon:64:29
64 sink.write = function(aContent, aCount)
65 {
66 // replace NC:succ with NC:orig_succ,
67 // so the rdf stuff differs
68 var content = aContent.replace(/NC:succ/g,"NC:orig_succ");
69 content = content.replace(/NC:failCount/g,"NC:orig_failCount");
70 this.mSink.write(content, content.length);
71 return aCount;
72 };
73 var fp = doCreateRDFFP('Xalan results',
74 nsIFilePicker.modeSave);
75 var res = fp.show();
76
77 if (res == nsIFilePicker.returnOK ||
78 res == nsIFilePicker.returnReplace) {
79 var serial = doCreate(kRDFXMLSerializerID,
80 nsIRDFXMLSerializer);
81 serial.init(view.mResultDS);
82 serial.QueryInterface(nsIRDFXMLSource);
83 var fl = fp.file;
84 var fstream = doCreate(kFileOutStreamCID,
85 nsIFileOutputStream);
86 fstream.init(fl, 26, 420, 0);
87 sink.mSink = fstream;
88 serial.Serialize(sink);
89 }
90 break;
91 case 'cmd_fl_import':
92 var fp = doCreateRDFFP('Previous Xalan results',
93 nsIFilePicker.modeLoad);
94 var res = fp.show();
95
96 if (res == nsIFilePicker.returnOK) {
97 var fl = fp.file;
98 if (view.mPreviousResultDS) {
99 view.database.RemoveDataSource(view.mPreviousResultDS);
100 view.mPreviousResultDS = null;
101 }
102 view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec);
103 view.database.AddDataSource(view.mPreviousResultDS);
104 }
105
106 document.getElementById('obs_orig_success')
107 .setAttribute('hidden','false');
108 break;
109 default:
110 alert('Unknown Command'+aCommand);
111 }
112 }
113 };
114
115 registerController(cmdFileController);