From a20c9a0845bc0c6a7ef447a38d8f37587bc979f4 Mon Sep 17 00:00:00 2001 From: "mikep%oeone.com" Date: Thu, 6 Feb 2003 18:06:18 +0000 Subject: [PATCH] Fixing publishing so that you can now publish an entire calendar or just the selected events. git-svn-id: svn://10.0.0.236/trunk@137485 18797224-902f-48f8-a5cc-f745e15eee43 --- .../calendar/resources/content/calendar.js | 19 ++++++ .../calendar/resources/content/calendar.xul | 2 +- .../resources/content/importExport.js | 7 +- .../resources/content/jslib/io/file.js | 65 ++++++++----------- mozilla/calendar/resources/content/publish.js | 8 +-- .../resources/content/publishDialog.js | 22 +++++-- .../resources/locale/en-US/menuOverlay.dtd | 2 +- 7 files changed, 69 insertions(+), 56 deletions(-) diff --git a/mozilla/calendar/resources/content/calendar.js b/mozilla/calendar/resources/content/calendar.js index 9f5345892ee..b36d69c189e 100644 --- a/mozilla/calendar/resources/content/calendar.js +++ b/mozilla/calendar/resources/content/calendar.js @@ -1038,6 +1038,25 @@ function publishEntireCalendar() var args = new Object(); args.onOk = self.publishEntireCalendarDialogResponse; + var name = gCalendarWindow.calendarManager.getSelectedCalendarId(); + var node = gCalendarWindow.calendarManager.rdf.getNode( name ); + + var remotePath = node.getAttribute( "http://home.netscape.com/NC-rdf#remotePath" ); + + if( remotePath != "" ) + { + var publishObject = new Object( ); + publishObject.username = node.getAttribute( "http://home.netscape.com/NC-rdf#username" ); + + //get the url and the filename from the remotePath + var arrayOfPath = remotePath.split( "/" ); + publishObject.filename = arrayOfPath.pop(); + + publishObject.url = remotePath.substr( 0, ( remotePath.length - publishObject.filename.length) ); + + publishObject.password = node.getAttribute( "http://home.netscape.com/NC-rdf#password" ); + args.publishObject = publishObject; + } openDialog("chrome://calendar/content/publishDialog.xul", "caPublishEvents", "chrome,modal", args ); } diff --git a/mozilla/calendar/resources/content/calendar.xul b/mozilla/calendar/resources/content/calendar.xul index 533e41dc416..8ae067c5011 100644 --- a/mozilla/calendar/resources/content/calendar.xul +++ b/mozilla/calendar/resources/content/calendar.xul @@ -121,7 +121,7 @@ - + diff --git a/mozilla/calendar/resources/content/importExport.js b/mozilla/calendar/resources/content/importExport.js index a611bbd60be..e2c31e9c879 100644 --- a/mozilla/calendar/resources/content/importExport.js +++ b/mozilla/calendar/resources/content/importExport.js @@ -667,11 +667,10 @@ function eventArrayToICalString( calendarEventArray, doPatchForExport ) for( var eventArrayIndex = 0; eventArrayIndex < calendarEventArray.length; ++eventArrayIndex ) { var calendarEvent = calendarEventArray[ eventArrayIndex ].clone(); - // convert time to represent local to produce correct DTSTART and DTEND if(calendarEvent.allDay != true) - convertLocalToZulu( calendarEvent ); - + convertLocalToZulu( calendarEvent ); + // check if all required properties are available if( calendarEvent.method == 0 ) calendarEvent.method = calendarEvent.ICAL_METHOD_PUBLISH; @@ -683,7 +682,7 @@ function eventArrayToICalString( calendarEventArray, doPatchForExport ) else sTextiCalendar += calendarEvent.getIcalString() ; } - + return sTextiCalendar; } diff --git a/mozilla/calendar/resources/content/jslib/io/file.js b/mozilla/calendar/resources/content/jslib/io/file.js index d095757c480..bc96ef476d5 100644 --- a/mozilla/calendar/resources/content/jslib/io/file.js +++ b/mozilla/calendar/resources/content/jslib/io/file.js @@ -9,7 +9,7 @@ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. -The Original Code is Collabnet code. +The Original Code is jslib code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are @@ -128,12 +128,14 @@ const JS_FILE_FILE = "file.js"; const JS_FILE_F_CHANNEL_CID = "@mozilla.org/network/local-file-channel;1"; const JS_FILE_IOSERVICE_CID = "@mozilla.org/network/io-service;1"; const JS_FILE_I_STREAM_CID = "@mozilla.org/scriptableinputstream;1"; +const JS_FILE_OUTSTREAM_CID = "@mozilla.org/network/file-output-stream;1"; const JS_FILE_F_TRANSPORT_SERVICE_CID = "@mozilla.org/network/file-transport-service;1"; const JS_FILE_I_FILE_CHANNEL = "nsIFileChannel"; const JS_FILE_I_IOSERVICE = C.interfaces.nsIIOService; const JS_FILE_I_SCRIPTABLE_IN_STREAM = "nsIScriptableInputStream"; +const JS_FILE_I_FILE_OUT_STREAM = C.interfaces.nsIFileOutputStream; const JS_FILE_READ = 0x01; // 1 const JS_FILE_WRITE = 0x08; // 8 @@ -160,15 +162,6 @@ try { const JS_FILE_IOSERVICE = C.classes[JS_FILE_IOSERVICE_CID]. getService(JS_FILE_I_IOSERVICE); - - /*** - * The File Transport Service provides nsITransport objects - * which can supply nsIOutputStream objects for writing to files. - */ - const JS_FILE_FileTransportService = - C.classes[JS_FILE_F_TRANSPORT_SERVICE_CID]. - getService(C.interfaces.nsIFileTransportService); - } catch (e) { jslibError (e, "open("+this.mMode+") (unable to get nsIFileChannel)", "NS_ERROR_FAILURE", @@ -176,11 +169,7 @@ try { } /*** - * Possible values for the ioFlags parameter to - * FileTransportService.createTransport. - */ - -/*** + * Possible values for the ioFlags parameter * From: * http://lxr.mozilla.org/seamonkey/source/nsprpub/pr/include/prio.h#601 */ @@ -325,35 +314,35 @@ File.prototype.open = function(aMode, aPerms) var offSet=0; if (aMode == JS_FILE_WRITE_MODE) { this.mMode=JS_FILE_WRITE_MODE; - // Create a file transport in write mode - if (!this.mTransport) { - this.mTransport = JS_FILE_FileTransportService.createTransport - (this.mFileInst, - JS_FILE_NS_WRONLY | JS_FILE_NS_CREATE_FILE | - JS_FILE_NS_TRUNCATE, aPerms, true); - } + // create a filestream + var fs = C.classes[JS_FILE_OUTSTREAM_CID]. + createInstance(JS_FILE_I_FILE_OUT_STREAM); + + fs.init(this.mFileInst, JS_FILE_NS_TRUNCATE | + JS_FILE_NS_WRONLY, 00004, null); + this.mOutStream = fs; } else { this.mMode=JS_FILE_APPEND_MODE; - if (!this.mTransport) { - this.mTransport = JS_FILE_FileTransportService.createTransport( - this.mFileInst, - JS_FILE_NS_CREATE_FILE | JS_FILE_NS_WRONLY - | JS_FILE_NS_APPEND, - aPerms, true); - } - jslib_debug("this.mTransport: "+this.mTransport); + // create a filestream + var fs = C.classes[JS_FILE_OUTSTREAM_CID]. + createInstance(JS_FILE_I_FILE_OUT_STREAM); + + fs.init(this.mFileInst, JS_FILE_NS_RDWR | + JS_FILE_NS_APPEND, 00004, null); + this.mOutStream = fs; } } catch(e) { - jslibError(e, "open("+this.mMode+") (unable to get transport)", - "NS_ERROR_FAILURE", - JS_FILE_FILE+":open"); + jslibError(e, "open("+this.mMode+") (unable to get file stream)", + "NS_ERROR_FAILURE", + JS_FILE_FILE+":open"); return null; } try { // Use the previously created file transport to open an output // stream for writing to the file if (!this.mOutStream) { - this.mOutStream = this.mTransport.openOutputStream(offSet, -1, 0); + // this.mOutStream = this.mTransport.openOutputStream(offSet, -1, 0); + // this.mOutStream = } } catch(e) { jslibError(e, "open("+this.mMode+") (unable to get outputstream)", @@ -378,15 +367,13 @@ File.prototype.open = function(aMode, aPerms) try { this.mFileChannel = JS_FILE_IOSERVICE.newChannelFromURI(this.mURI); this.mInputStream = new JS_FILE_InputStream(); - this.mLineBuffer = new Array(); - this.mFileChannel.init(this.mFileInst, JS_FILE_READ, this.permissions); this.mInputStream.init(this.mFileChannel.open()); this.mLineBuffer = new Array(); rv=true; } catch (e) { jslibError(e, "open(r) (error setting permissions)", "NS_ERROR_FAILURE", - JS_FILE_FILE+":open"); + JS_FILE_FILE+":open\n"+e); return null; } break; @@ -571,14 +558,14 @@ File.prototype.write = function(aBuffer, aPerms) "NS_ERROR_FAILURE", JS_FILE_FILE+":write"); this.close(); - return false; + return null; } if (!this.mFileInst) { jslibError(null, "(no file instance)", "NS_ERROR_NOT_INITIALIZED", JS_FILE_FILE+":write"); - return false; + return null; } if (!aBuffer) diff --git a/mozilla/calendar/resources/content/publish.js b/mozilla/calendar/resources/content/publish.js index d8da93da147..7f42da39874 100644 --- a/mozilla/calendar/resources/content/publish.js +++ b/mozilla/calendar/resources/content/publish.js @@ -78,14 +78,12 @@ function calendarPublish(aDataString, newLocation, fileName, login, password, co dump("failed to get a destination channel\n"); return; } - output_string_to_channel(protocolChannel, aDataString, contentType); protocolChannel.asyncOpen(gPublishingListener, null); - dump("done\n"); - } + } catch (e) { - alert("an error occurred: " + e + "\n"); + alert("an error occurred in calendarPublish: " + e + "\n"); } } @@ -107,7 +105,7 @@ function calendarUploadFile(aSourceFilename, newLocation, fileName, login, passw } catch (e) { - alert("an error occurred: " + e + "\n"); + alert("an error occurred in calendarUploadFile: " + e + "\n"); } } diff --git a/mozilla/calendar/resources/content/publishDialog.js b/mozilla/calendar/resources/content/publishDialog.js index cdc92582380..36ff75c66b2 100644 --- a/mozilla/calendar/resources/content/publishDialog.js +++ b/mozilla/calendar/resources/content/publishDialog.js @@ -97,12 +97,22 @@ function loadCalendarPublishDialog() gOnOkFunction = args.onOk; - //get default values from the prefs - document.getElementById( "publish-url-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.path", "" ); - document.getElementById( "publish-remotefilename-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.filename", "" ); - document.getElementById( "publish-username-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.username", "" ); - document.getElementById( "publish-password-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.password", "" ); - + if( args.publishObject ) + { + document.getElementById( "publish-url-textbox" ).value = args.publishObject.url; + document.getElementById( "publish-remotefilename-textbox" ).value = args.publishObject.filename; + document.getElementById( "publish-username-textbox" ).value = args.publishObject.username; + document.getElementById( "publish-password-textbox" ).value = args.publishObject.password; + } + else + { + //get default values from the prefs + document.getElementById( "publish-url-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.path", "" ); + document.getElementById( "publish-remotefilename-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.filename", "" ); + document.getElementById( "publish-username-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.username", "" ); + document.getElementById( "publish-password-textbox" ).value = opener.getCharPref( opener.gCalendarWindow.calendarPreferences.calendarPref, "publish.password", "" ); + } + var firstFocus = document.getElementById( "publish-url-textbox" ); firstFocus.focus(); } diff --git a/mozilla/calendar/resources/locale/en-US/menuOverlay.dtd b/mozilla/calendar/resources/locale/en-US/menuOverlay.dtd index fb97ed41ee6..e3c795144b4 100644 --- a/mozilla/calendar/resources/locale/en-US/menuOverlay.dtd +++ b/mozilla/calendar/resources/locale/en-US/menuOverlay.dtd @@ -76,7 +76,7 @@ - +