summaryrefslogtreecommitdiffstats
path: root/dom/xslt/tests/buster/buster-files.js
blob: cbdb8bdd2515a91d25593f71bdca8b6fb4ef55a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1";
const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;

var cmdFileController = 
{
    supportsCommand: function(aCommand)
    {
        switch(aCommand) {
            case 'cmd_fl_save':
            case 'cmd_fl_import':
                return true;
            default:
        }
        return false;
    },
    isCommandEnabled: function(aCommand)
    {
        return this.supportsCommand(aCommand);
    },
    doCommand: function(aCommand)
    {
        switch(aCommand) {
            case 'cmd_fl_save':
                var sink = new Object;
                sink.write = function(aContent, aCount)
                {
                    // replace NC:succ with NC:orig_succ,
                    //  so the rdf stuff differs
                    var content = aContent.replace(/NC:succ/g,"NC:orig_succ");
                    content = content.replace(/NC:failCount/g,"NC:orig_failCount");
                    this.mSink.write(content, content.length);
                    return aCount;
                };
                var fp = doCreateRDFFP('Xalan results',
                                       nsIFilePicker.modeSave);
                var res = fp.show();

                if (res == nsIFilePicker.returnOK ||
                    res == nsIFilePicker.returnReplace) {
                    var serial = doCreate(kRDFXMLSerializerID,
                                          nsIRDFXMLSerializer);
                    serial.init(view.mResultDS);
                    serial.QueryInterface(nsIRDFXMLSource);
                    var fl = fp.file;
                    var fstream = doCreate(kFileOutStreamCID,
                                           nsIFileOutputStream);
                    fstream.init(fl, 26, 420, 0);
                    sink.mSink = fstream;
                    serial.Serialize(sink);
                }
                break;
            case 'cmd_fl_import':
                var fp = doCreateRDFFP('Previous Xalan results',
                                       nsIFilePicker.modeLoad);
                var res = fp.show();

                if (res == nsIFilePicker.returnOK) {
                    var fl = fp.file;
                    if (view.mPreviousResultDS) {
                        view.database.RemoveDataSource(view.mPreviousResultDS);
                        view.mPreviousResultDS = null;
                    }
                    view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec);
                    view.database.AddDataSource(view.mPreviousResultDS);
                }

                document.getElementById('obs_orig_success')
                    .setAttribute('hidden','false');
                break;
            default:
                alert('Unknown Command'+aCommand);
        }
    }
};

registerController(cmdFileController);