dom/xslt/tests/buster/buster-files.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/tests/buster/buster-files.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +const kFileOutStreamCID = "@mozilla.org/network/file-output-stream;1";
    1.10 +const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;
    1.11 +
    1.12 +var cmdFileController = 
    1.13 +{
    1.14 +    supportsCommand: function(aCommand)
    1.15 +    {
    1.16 +        switch(aCommand) {
    1.17 +            case 'cmd_fl_save':
    1.18 +            case 'cmd_fl_import':
    1.19 +                return true;
    1.20 +            default:
    1.21 +        }
    1.22 +        return false;
    1.23 +    },
    1.24 +    isCommandEnabled: function(aCommand)
    1.25 +    {
    1.26 +        return this.supportsCommand(aCommand);
    1.27 +    },
    1.28 +    doCommand: function(aCommand)
    1.29 +    {
    1.30 +        switch(aCommand) {
    1.31 +            case 'cmd_fl_save':
    1.32 +                var sink = new Object;
    1.33 +                sink.write = function(aContent, aCount)
    1.34 +                {
    1.35 +                    // replace NC:succ with NC:orig_succ,
    1.36 +                    //  so the rdf stuff differs
    1.37 +                    var content = aContent.replace(/NC:succ/g,"NC:orig_succ");
    1.38 +                    content = content.replace(/NC:failCount/g,"NC:orig_failCount");
    1.39 +                    this.mSink.write(content, content.length);
    1.40 +                    return aCount;
    1.41 +                };
    1.42 +                var fp = doCreateRDFFP('Xalan results',
    1.43 +                                       nsIFilePicker.modeSave);
    1.44 +                var res = fp.show();
    1.45 +
    1.46 +                if (res == nsIFilePicker.returnOK ||
    1.47 +                    res == nsIFilePicker.returnReplace) {
    1.48 +                    var serial = doCreate(kRDFXMLSerializerID,
    1.49 +                                          nsIRDFXMLSerializer);
    1.50 +                    serial.init(view.mResultDS);
    1.51 +                    serial.QueryInterface(nsIRDFXMLSource);
    1.52 +                    var fl = fp.file;
    1.53 +                    var fstream = doCreate(kFileOutStreamCID,
    1.54 +                                           nsIFileOutputStream);
    1.55 +                    fstream.init(fl, 26, 420, 0);
    1.56 +                    sink.mSink = fstream;
    1.57 +                    serial.Serialize(sink);
    1.58 +                }
    1.59 +                break;
    1.60 +            case 'cmd_fl_import':
    1.61 +                var fp = doCreateRDFFP('Previous Xalan results',
    1.62 +                                       nsIFilePicker.modeLoad);
    1.63 +                var res = fp.show();
    1.64 +
    1.65 +                if (res == nsIFilePicker.returnOK) {
    1.66 +                    var fl = fp.file;
    1.67 +                    if (view.mPreviousResultDS) {
    1.68 +                        view.database.RemoveDataSource(view.mPreviousResultDS);
    1.69 +                        view.mPreviousResultDS = null;
    1.70 +                    }
    1.71 +                    view.mPreviousResultDS = kRDFSvc.GetDataSource(fp.fileURL.spec);
    1.72 +                    view.database.AddDataSource(view.mPreviousResultDS);
    1.73 +                }
    1.74 +
    1.75 +                document.getElementById('obs_orig_success')
    1.76 +                    .setAttribute('hidden','false');
    1.77 +                break;
    1.78 +            default:
    1.79 +                alert('Unknown Command'+aCommand);
    1.80 +        }
    1.81 +    }
    1.82 +};
    1.83 +
    1.84 +registerController(cmdFileController);

mercurial