Author: reebalazs
Date: Sat Jan  3 02:47:25 2009
New Revision: 60769

Modified:
   kukit/kukit.js/branch/1.4/kukit/serveraction.js
Log:
Backport -r60768 from trunk: Clean up terrible mess in serveraction.js, left 
there by previous merge.
Also add a non-initializing ServerActionBase class, for reuse in plugins.

Modified: kukit/kukit.js/branch/1.4/kukit/serveraction.js
==============================================================================
--- kukit/kukit.js/branch/1.4/kukit/serveraction.js     (original)
+++ kukit/kukit.js/branch/1.4/kukit/serveraction.js     Sat Jan  3 02:47:25 2009
@@ -21,7 +21,9 @@
 
 var sa = this;
 
-sa.ServerAction = function() {
+// ServerActionBase is a non-initialize version of ServerAction
+// this enables to subclass it or reuse its methods
+sa.ServerActionBase = function() {
 
 this.initialize = function(name, oper) {
     this.oper = oper;
@@ -29,26 +31,6 @@
     if (typeof(this.url) == 'undefined') {
         this.url = name;
     }
-
-    this.calculateAbsoluteURL = function(url) {
-        //
-        // If the url is an absolute path, it is used
-        //
-        // If the url is not an absolute path, it is put at the end of the 
context
-        // url.
-        //
-        // example: url='@theview/getName',
-        //          context='http://your.site.com/portal/folder/object'
-        //
-        //     
result='http://your.site.com/portal/folder/object/@@theview/getName'
-        //
-        if (url.match(RegExp('/^https?:\/\//'))) {
-            return url;
-        } else {
-            var result = kukit.engine.baseUrl + '/' + url;
-            return result;
-        }
-    };
     this.url = this.calculateAbsoluteURL(this.url);
     this.notifyServer();
 };
@@ -200,86 +182,9 @@
             }
             commandstags = kukit.dom.getNsTags(dom, 'commands');
             if (commandstags.length != 1) {
-                // no good, maybe better luck with it as html payload
+                // no good
                 dom = null;
             }
-        }
-        // Check for html too, this enables setting the kss error command on 
the 
-        // error response.
-        if (dom == null) {
-            // Read the header and load it as xml, if defined.
-            var payload = domDoc.getResponseHeader('X-KSSCOMMANDS');
-            if (payload) {
-                try {
-                    dom = (new DOMParser()).parseFromString(payload, 
"text/xml");
-                } catch(e) {
-;;;                 kukit.E = 'Error parsing X-KSSCOMMANDS header.';
-                    throw kukit.err.responseParsingError(kukit.E);
-                }
-                commandstags = kukit.dom.getNsTags(dom, 'commands');
-                if (commandstags.length != 1) {
-                    // no good
-                    dom = null;
-                }
-            } else {
-                // Ok. we have not found it either in the headers.
-                // Check if there was a parsing error in the xml, 
-                // and log it as reported from the dom
-                // Opera <= 8.5 does not have the parseError attribute,
-                // so check for it first
-;;;             dom = domDoc.responseXML;
-;;;             kukit.E = 'Unknown server error (invalid KSS response, no 
error';
-;;;             kukit.E += ' info received)';
-;;;             if (dom && dom.parseError && (dom.parseError != 0)) {
-;;;                 kukit.E += ' : ' + Sarissa.getParseErrorText(dom);
-;;;                 }
-                throw kukit.err.responseParsingError(kukit.E);
-            }
-        }
-        if (dom == null) {
-            // this should not happen
-;;;         kukit.E = 'Neither xml nor html payload.';
-            throw kukit.err.responseParsingError(msg);
-        }
-        // find the commands (atm we don't limit ourselves inside the 
commandstag)
-        var commands = kukit.dom.getNsTags(dom, 'command');
-        // Warning, if there is a valid response containing 0 commands.
-        if (commands.length == 0) {
-;;;         kukit.log('No commands in kukit response');
-            return;
-        }
-        // One or more valid commands to parse
-        var command_processor = new kukit.cp.CommandProcessor();
-        command_processor.parseCommands(commands, domDoc);
-        kukit.engine.beginSetupEventsCollection();
-        command_processor.executeCommands(this.oper);
-        kukit.engine.finishSetupEventsCollection();
-    };
-
-    this.processError = function(errorcommand) {
-        var error_action = null;
-        if (this.oper.eventRule) {
-            var error_action = this.oper.eventRule.actions.getErrorActionFor(
-                this.oper.action);
-            }
-;;;     var reason = '';
-;;;     if (typeof(errorcommand) == 'string') {
-;;;         // not a command, just a string
-;;;         reason = ', client_reason="' + errorcommand + '" ';
-;;;     } else if (typeof(errorcommand) != 'undefined') {
-;;;         // a real error command, sent by the server
-;;;         // as kukit payload.
-;;;         // this way the server sends whatever message he wants as a 
parameter
-;;;         // to the error command.
-;;;         reason = ', server_reason="' + errorcommand.parms.message + '" ';
-;;;     }
-        if (error_action) {
-;;;         kukit.E = 'Request failed at url ' + this.oper.queueItem.url;
-;;;         kukit.E += ', rid=' + this.oper.queueItem.rid + reason;
-;;;         kukit.E += ', will be handled by action "' + error_action.name + 
'"';
-;;;         kukit.logWarning(kukit.E);
-            // Individual error handler was defined. Execute it!
-            error_action.execute(this.oper);
         } else {
             // Ok. we have not found it either in the headers.
             // Check if there was a parsing error in the xml, 
@@ -355,7 +260,12 @@
         // TODO figure out something?
     }
 };
-this.initialize.apply(this, arguments);
+
+};
+
+sa.ServerAction = function() {
+    this.initialize.apply(this, arguments);
 };
+sa.ServerAction.prototype = new sa.ServerActionBase();
 
 }();                              /// MODULE END
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to