[Phoenix-commits] rev 14765 - public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content

andi at wyona.com andi at wyona.com
Wed Jun 28 18:09:39 CEST 2006


Author: andi
Date: 2006-06-28 18:09:37 +0200 (Wed, 28 Jun 2006)
New Revision: 14765

Added:
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/document.js
Modified:
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/editor.xul
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/model.js
   public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/networkservice.js
Log:
Splitted the model into document and model. Last checkin before transition.


Added: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/document.js
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/document.js	2006-06-28 15:21:25 UTC (rev 14764)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/document.js	2006-06-28 16:09:37 UTC (rev 14765)
@@ -0,0 +1,232 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ * Copyright 2006 Wyona AG Zurich
+ *
+ * This file is part of Phoenix.
+ *
+ * Phoenix is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Phoenix is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Phoenix; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+/**
+ * @author Andreas Wuest
+ *
+ */
+
+function Document(aLoadURI, aScreenName) {
+    var loadURL = null;
+
+    /* DEBUG */ dump("Phoenix:document.js:Document(\"" + aLoadURI + "\", \"" + aScreenName + "\") invoked\n");
+
+    this.loadURI = aLoadURI;
+
+    loadURL = this.loadURI;
+    loadURL.QueryInterface(Components.interfaces.nsIURL);
+    this.documentBaseName  = loadURL.fileBaseName;
+    this.documentExtension = loadURL.fileExtension;
+
+    if (aScreenName) {
+        this.screenName = aScreenName;
+    } else {
+        this.screenName = this.documentBaseName + this.documentExtension;
+    }
+}
+
+Document.prototype = {
+    loadURI          : null,
+    documentBaseName : null,
+    documentExtension: null,
+    screenName       : null,
+    localSavePath    : null,
+    contentType      : null,
+    data             : null,
+
+    getLoadURI: function () {
+        return this.loadURI;
+    },
+
+    getDocumentBaseName: function () {
+        /* DEBUG */ dump("Phoenix:document.js:Document.getDocumentBaseName() invoked\n");
+        return this.documentBaseName;
+    },
+
+    getDocumentExtension: function () {
+        /* DEBUG */ dump("Phoenix:document.js:Document.getDocumentExtension() invoked\n");
+        return this.documentExtension;
+    },
+
+    setLocalSavePath: function (aLocalPath) {
+        /* DEBUG */ dump("Phoenix:document.js:Document.setLocalSavePath(\"" + aLocalPath + "\") invoked\n");
+        this.localSavePath = aLocalPath;
+    },
+
+    getLocalSavePath: function () {
+        /* DEBUG */ dump("Phoenix:document.js:Document.getLocalSavePath() invoked\n");
+        return this.localSavePath;
+    },
+
+    getContentType: function () {
+        /* DEBUG */ dump("Phoenix:document.js:Document.getContentType() invoked\n");
+        return this.contentType;
+    },
+
+    getData: function () {
+        /* DEBUG */ dump("Phoenix:document.js:Document.getData() invoked\n");
+        return this.document;
+    },
+
+    isSaveable: function () {
+        /* DEBUG */ dump("Phoenix:document.js:Document.isSaveable() invoked\n");
+        return (this.localSavePath ? true : false);
+    },
+
+    loadDocument: function (aLoadFinishedCallback) {
+        /* DEBUG */ dump("Phoenix:document.js:Document.loadDocument() invoked\n");
+
+        NetworkService.httpRequestGET(this.loadURI.spec, null, aLoadFinishedCallback);
+    },
+
+    createFromTemplate: function (aTemplateString) {
+        /* DEBUG */ dump("Phoenix:document.js:Document.createFromTemplate() invoked\n");
+
+        // TODO: parse template into DOM, so we can setDocumentDOM()
+        this.setDocument(aTemplateString);
+
+        /* DEBUG */ dump("Phoenix:document.js:Document.createFromTemplate: dump of set document:\n" + this.document + "\n");
+    }
+};
+
+
+function NeutronDocument(aLoadURI, aLoadMethod, aUploadURI, aUploadMethod, aFragmentName) {
+    /* DEBUG */ dump("Phoenix:document.js:NeutronDocument(\"" + aLoadURI + "\", \"" + aLoadMethod + "\", \"" + aUploadURI + "\", \"" + aUploadMethod + "\", \"" + aFragmentName + "\") invoked\n");
+
+    this.__proto__.__proto__.constructor.call(this, aLoadURI, aFragmentName);
+
+    this.loadMethod   = aLoadMethod;
+    this.uploadURI    = aUploadURI;
+    this.uploadMethod = aUploadMethod;
+}
+
+NeutronDocument.prototype = {
+    __proto__: Document.prototype,
+
+    loadMethod: null,
+
+    uploadURI   : null,
+    uploadMethod: null,
+
+    acquiredLock: false,
+
+    getLoadMethod: function () {
+        return this.loadMethod;
+    },
+
+    getUploadURI: function () {
+        return this.saveURI;
+    },
+
+    getUploadMethod: function () {
+        return this.saveMethod;
+    },
+
+    getAcquiredLock: function () {
+        return this.acquiredLock;
+    },
+
+    loadDocument: function (aLoadFinishedCallback) {
+        /* DEBUG */ dump("Phoenix:document.js:NeutronDocument.loadDocument() invoked\n");
+
+        if (this.loadMethod == "GET") {
+            NetworkService.httpRequestGET(this.loadURI.spec, null, NeutronDocument.loadFinishedHandler, aLoadFinishedCallback);
+        } else {
+            // unknown request method
+            throw new PhoenixEditorException("Phoenix:document.js:NeutronDocument.loadDocument: request method \"" + this.uploadMethod + "\" unknown.");
+        }
+    },
+
+    loadFinishedHandler: function (aDocumentData, aResponseStatusCode, aLoadFinishedCallback) {
+        /* DEBUG */ dump("Phoenix:document.js:NeutronDocument.loadFinishedHandler(\"" + aDocumentData + "\", \"" + aResponseStatusCode + "\") invoked\n");
+
+        if (aResponseStatusCode == 200) {
+            // success, call back to original caller
+            aLoadFinishedCallback(aDocumentData);
+        } else {
+            try {
+                // parse error message
+                Neutron.response(aDocumentData);
+            } catch (exception) {
+                if (exception instanceof NeutronProtocolException) {
+                    // report error message retrieved from response
+                    alert("Opening file did not succeed.\n\n" + exception.message);
+                } else {
+                    dump("Phoenix:document.js:NeutronDocument.loadFinishedHandler: an error occurred during parsing the response message: " + exception.toString() + "\n");
+                    /* DEBUG */ PhoenixDebug.dumpExceptionToConsole("Phoenix:document.js:NeutronDocument.loadFinishedHandler", exception);
+                    Components.utils.reportError(exception);
+
+                    // report generic error
+                    alert("Document could not be opened.");
+                }
+            }
+
+            // call back to original caller
+            aLoadFinishedCallback(null);
+        }
+    },
+
+    uploadDocument: function (aLoadFinishedCallback) {
+        /* DEBUG */ dump("Phoenix:document.js:NeutronDocument.uploadDocument() invoked\n");
+
+        switch (this.uploadMethod) {
+            case "PUT":
+                NetworkService.httpRequestPUT(this.uploadURI.spec, null, this.data, this.contentType, NeutronDocument.uploadFinishedHandler, aLoadFinishedCallback);
+                break;
+            case "POST":
+                NetworkService.httpRequestPOST(this.uploadURI.spec, null, this.data, this.contentType, NeutronDocument.uploadFinishedHandler, aLoadFinishedCallback);
+                break;
+            default:
+                // unknown request method
+                throw new PhoenixEditorException("Phoenix:document.js:NeutronDocument.uploadDocument: request method \"" + this.uploadMethod + "\" unknown.");
+        }
+    },
+
+    uploadFinishedHandler: function (aDocumentData, aResponseStatusCode, aLoadFinishedCallback) {
+        /* DEBUG */ dump("Phoenix:document.js:NeutronDocument.uploadFinishedHandler(\"" + aDocumentData + "\", \"" + aResponseStatusCode + "\") invoked\n");
+
+        if (aResponseStatusCode == 200) {
+            // success, call back to original caller
+            aLoadFinishedCallback(aDocumentData);
+        } else {
+            try {
+            // parse error message
+                Neutron.response(aDocumentData);
+            } catch (exception) {
+                if (exception instanceof NeutronProtocolException) {
+                    // report error message retrieved from response
+                    alert("Saving file did not succeed.\n\n" + exception.message);
+                } else {
+                    dump("Phoenix:document.js:NeutronDocument.uploadFinishedHandler: an error occurred during parsing the response message: " + exception.toString() + "\n");
+                    /* DEBUG */ PhoenixDebug.dumpExceptionToConsole("Phoenix:document.js:NeutronDocument.uploadFinishedHandler", exception);
+
+                    // report generic error
+                    alert("Document could not be saved.");
+                }
+            }
+
+            // call back to original caller
+            aLoadFinishedCallback(null);
+        }
+    }
+};

Modified: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/editor.xul
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/editor.xul	2006-06-28 15:21:25 UTC (rev 14764)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/editor.xul	2006-06-28 16:09:37 UTC (rev 14765)
@@ -50,6 +50,8 @@
   <script type="application/x-javascript"
           src="chrome://phoenix/content/neutronparser10.js"/>
   <script type="application/x-javascript"
+          src="chrome://phoenix/content/document.js"/>
+  <script type="application/x-javascript"
           src="chrome://phoenix/content/model.js"/>
   <script type="application/x-javascript"
           src="chrome://phoenix/content/view.js"/>

Modified: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/model.js
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/model.js	2006-06-28 15:21:25 UTC (rev 14764)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/model.js	2006-06-28 16:09:37 UTC (rev 14765)
@@ -189,6 +189,7 @@
         this.setDocument(aDocumentData);
     },
 
+    // TODO: not being used anymore -> remove
     loadDocument: function () {
         /* DEBUG */ dump("Phoenix:model.js:loadDocument() invoked\n");
 /*

Modified: public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/networkservice.js
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/networkservice.js	2006-06-28 15:21:25 UTC (rev 14764)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/src/chrome/content/networkservice.js	2006-06-28 16:09:37 UTC (rev 14765)
@@ -27,7 +27,7 @@
  */
 
 var NetworkService = {
-    httpRequestGET: function (aURI, aHeaderArray, aCallbackFunction) {
+    httpRequestGET: function (aURI, aHeaderArray, aCallbackFunction, aContext) {
         var ioService             = null;
         var channel               = null;
         var streamListener        = null;
@@ -52,7 +52,7 @@
             // don't notify nsIProgressEventSink listeners (keeps the throbber from turning)
             channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BACKGROUND;
 
-            streamListener = new StreamListener(aCallbackFunction, channel);
+            streamListener = new StreamListener(aCallbackFunction, channel, aContext);
 
             channel.asyncOpen(streamListener, null);
         } catch (exception) {
@@ -124,16 +124,18 @@
     }
 };
 
-function StreamListener(aLoadFinishedCallback, aChannel) {
-    /* DEBUG */ dump("Phoenix:networkservice.js:StreamListener(\"" + aLoadFinishedCallback + "\", \"" + aChannel + "\") invoked\n");
+function StreamListener(aLoadFinishedCallback, aChannel, aContext) {
+    /* DEBUG */ dump("Phoenix:networkservice.js:StreamListener(\"" + aLoadFinishedCallback + "\", \"" + aChannel + "\", \"" + aContext + "\") invoked\n");
 
     this.loadFinishedCallback = aLoadFinishedCallback;
     this.channel              = aChannel;
+    this.context              = aContext;
 }
 
 StreamListener.prototype = {
     channel             : null,
     loadFinishedCallback: null,
+    context             : null,
     documentData        : null,
 
     QueryInterface: function (aUUID) {
@@ -184,13 +186,13 @@
 
             /* DEBUG */ dump("Phoenix:networkservice.js:StreamListener.onStopRequest: document data =\n" + unicodeDoc + "\n");
 
-            this.loadFinishedCallback(unicodeDoc, responseStatusCode);
+            this.loadFinishedCallback(unicodeDoc, responseStatusCode, this.context);
         } else {
             // request failed
 
             /* DEBUG */ dump("Phoenix:networkservice.js:StreamListener.onStopRequest: load failed\n");
 
-            this.loadFinishedCallback(null, responseStatusCode);
+            this.loadFinishedCallback(null, responseStatusCode, this.context);
         }
     },
 




More information about the Phoenix-commits mailing list