fp.init(window,  getCalStringBundle().GetStringFromName("SaveAs"), nsIFilePicker.modeSave); 
fp.init(window, calGetString("calendar", "SaveAs"), nsIFilePicker.modeSave); 
function saveEventsToFile(calendarEventArray, aDefaultFileName){   if (!calendarEventArray)       return;   if (!calendarEventArray.length)   {      alert(getCalStringBundle().GetStringFromName("noEventsToSave"));      return;   }   // Show the 'Save As' dialog and ask for a filename to save to   const nsIFilePicker = Components.interfaces.nsIFilePicker;   var fp = Components.classes["@mozilla.org/filepicker;1"]                      .createInstance(nsIFilePicker);   fp.init(window,  getCalStringBundle().GetStringFromName("SaveAs"),           nsIFilePicker.modeSave);   if (aDefaultFileName && aDefaultFileName.length && aDefaultFileName.length > 0) {      fp.defaultString = aDefaultFileName;   } else if (calendarEventArray.length == 1 && calendarEventArray[0].title) {      fp.defaultString = calendarEventArray[0].title;   } else {      fp.defaultString = getCalStringBundle().GetStringFromName("defaultFileName");   }   fp.defaultExtension = "ics";   // Get a list of exporters   var contractids = new Array();   var catman = Components.classes["@mozilla.org/categorymanager;1"]                          .getService(Components.interfaces.nsICategoryManager);   var catenum = catman.enumerateCategory('cal-exporters');   while (catenum.hasMoreElements()) {       var entry = catenum.getNext();       entry = entry.QueryInterface(Components.interfaces.nsISupportsCString);       var contractid = catman.getCategoryEntry('cal-exporters', entry);       var exporter = Components.classes[contractid]                                .getService(Components.interfaces.calIExporter);       var types = exporter.getFileTypes({});       var type;       for each (type in types) {           fp.appendFilter(type.description, type.extensionFilter);           contractids.push(contractid);       }   }   fp.show();   // Now find out as what to save, convert the events and save to file.   if (fp.file && fp.file.path.length > 0)    {      const UTF8 = "UTF-8";      var aDataStream;      var extension;      var charset;      var exporter = Components.classes[contractids[fp.filterIndex]]                               .getService(Components.interfaces.calIExporter);      var filePath = fp.file.path;      if(filePath.indexOf(".") == -1 )          filePath += "."+exporter.getFileTypes({})[0].defaultExtension;      const LOCALFILE_CTRID = "@mozilla.org/file/local;1";      const FILEOUT_CTRID = "@mozilla.org/network/file-output-stream;1";      const nsILocalFile = Components.interfaces.nsILocalFile;      const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;      var outputStream;      var localFileInstance = Components.classes[LOCALFILE_CTRID]                                        .createInstance(nsILocalFile);      localFileInstance.initWithPath(filePath);      outputStream = Components.classes[FILEOUT_CTRID]                               .createInstance(nsIFileOutputStream);      try      {         outputStream.init(localFileInstance, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, 0664, 0);         // XXX Do the right thing with unicode and stuff. Or, again, should the         //     exporter handle that?         exporter.exportToStream(outputStream, calendarEventArray.length, calendarEventArray, null);         outputStream.close();      }      catch(ex)      {         showError(getCalStringBundle().GetStringFromName("unableToWrite") + filePath );      }   }}
5872	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/5872/89dd51a153f57c2abc01787b4781afb3fc7a572d/import-export.js/clean/calendar/base/content/import-export.js