Author: xlawrence
Date: Tue Jan 10 15:15:53 2006
New Revision: 12735

URL: https://jahia.mine.nu/websvn/listing.php?sc=1&rev=12735&repname=jahia
Log:
include Jahia Transport Layer and utility JS classes to use with Zimbra ajaxTK

Added:
    trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/
    trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/AsynchCommand.js
    trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/ClientException.js
    trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/XmlUtils.js

Added: trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/AsynchCommand.js
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/AsynchCommand.js&rev=12735&repname=jahia
==============================================================================
--- trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/AsynchCommand.js 
(added)
+++ trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/AsynchCommand.js 
Tue Jan 10 15:15:53 2006
@@ -0,0 +1,227 @@
+/*
+ *                                   ____.
+ *                       __/\ ______|    |__/\.     _______
+ *            __   .____|    |       \   |    +----+       \
+ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+ *   \\______: :---|    :    :           |    :    |         \________>
+ *           |__\---\_____________:______:    :____|____:_____\
+ *                                      /_____|
+ *
+ *              . . . i n   j a h i a   w e   t r u s t . . .
+ *
+ *
+ *
+ * ----- BEGIN LICENSE BLOCK -----
+ * Version: JCSL 1.0
+ *
+ * The contents of this file are subject to the Jahia Community Source License
+ * 1.0 or later (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.jahia.org/license
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the rights, obligations and limitations governing use of the contents
+ * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
+ * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
+ * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
+ *
+ * The Shared Modifications are Jahia View Helper.
+ *
+ * The Developer of the Shared Modifications is Jahia Solution S�rl.
+ * Portions created by the Initial Developer are Copyright (C) 2002 by the
+ * Initial Developer. All Rights Reserved.
+ *
+ * ----- END LICENSE BLOCK -----
+ */
+
+/**
+* @class AsynchCommand
+* This class executes AJAX commands asynchronously.
+* When command is executed (Rpc call returns) all invokeListeners are notified.
+* @ constructor
+**/
+function AsynchCommand() {
+    this.invokeListeners = new Array();
+    this.commandXmlDoc = "";
+    this._responseXmlDoc = null;
+    this._st = null;
+    //start time (call sent)
+    this._en = null;
+    //end time (call returned)
+}
+
+AsynchCommand.prototype.toString =
+function () {
+    return "AsynchCommand";
+}
+
+/**
+* @method addInvokeListener
+* @param obj : AjxCallback
+* use this method to be notified when rpc call returns.
+* Callback receives an argument that is either responseXmlDocBody or 
exceptionObject
+* -    _responseXmlDoc:AjxXmlDoc is a resonse Xml document
+**/
+AsynchCommand.prototype.addInvokeListener =
+function (obj) {
+    this.invokeListeners.push(obj);
+}
+
+/**
+* @method removeInvokeListener
+* @param obj
+* use this method to unsubscribe obj from events of this command object
+**/
+AsynchCommand.prototype.removeInvokeListener =
+function (obj) {
+    var cnt = this.invokeListeners.length;
+    var ix = 0;
+    for (; ix < cnt; ix++) {
+        if (this.invokeListeners[ix] == obj) {
+            this.invokeListeners[ix] = null;
+            break;
+        }
+    }
+}
+
+/**
+* @method _fireInvokeEvent
+* @param exceptionObject
+**/
+AsynchCommand.prototype._fireInvokeEvent =
+function (exceptionObject) {
+    var cnt = this.invokeListeners.length;
+    for (var ix = 0; ix < cnt; ix++) {
+        if (this.invokeListeners[ix] != null) {
+            if (exceptionObject) {
+                this.invokeListeners[ix].run(exceptionObject);
+            } else {
+                if (this._responseXmlDoc) {
+                    this.invokeListeners[ix].run(this._responseXmlDoc);
+                } else {
+                    this.invokeListeners[ix].run(new AjxException("Service 
error", AjxException.UNKNOWN_ERROR, "AsynchCommand.prototype._fireInvokeEvent", 
"Service returned empty document"));
+                }
+            }
+        }
+    }
+}
+
+/**
+* @method rpcCallback
+* @param response
+* this method is called by XMLHttpRequest object's event handler.
+response obejct contains the following properties
+text, xml, success, status
+**/
+AsynchCommand.prototype.rpcCallback =
+function (response) {
+    this._en = new Date();
+    DBG.println(AjxDebug.DBG1, "<H4>ASYNCHRONOUS REQUEST RETURNED</H4>");
+    DBG.println(AjxDebug.DBG1, "ASYNCHRONOUS ROUND TRIP TIME: " + 
(this._en.getTime() - this._st.getTime()));
+    var newEx = null;
+    if (! response.success) {
+        // Safari may produces some response with null response body before 
the real response is received
+        if (response.text == null) return;
+
+        try {
+            var respDoc = AjxEnv.isIE || response.xml == null
+                    ? AjxXmlDoc.createFromXml(response.text)
+                    : AjxXmlDoc.createFromDom(response.xml);
+            if (respDoc.getBody()) {
+                DBG.println(AjxDebug.DBG1, "<H4>RESPONSE</H4>");
+                DBG.printXML(AjxDebug.DBG1, respDoc.getDocXml());
+            }
+        } catch (ex) {
+            newEx = new AjxException();
+            newEx.method = "AsynchCommand.prototype.rpcCallback";
+            newEx.detail = "Unknown problem ecnountered while communicating 
with the server. ";
+            newEx.detail += "text: ";
+            newEx.detail += response.text;
+            newEx.detail += "\n";
+            newEx.detail += "xml: ";
+            newEx.detail += response.xml;
+            newEx.detail += "\n";
+            newEx.detail += "status: ";
+            newEx.detail += response.status;
+            newEx.detail += "\n";
+            newEx.code = AjxException.UNKNOWN_ERROR;
+            newEx.msg = "Unknown Error";
+        }
+    } else {
+        try {
+            // responseXML is empty under IE and FF doesnt seem to populate 
xml if faulted
+            var respDoc = AjxEnv.isIE || response.xml == null
+                    ? AjxXmlDoc.createFromXml(response.text)
+                    : AjxXmlDoc.createFromDom(response.xml);
+            this._responseXmlDoc = respDoc;
+            DBG.println(AjxDebug.DBG1, "<H4>RESPONSE</H4>");
+            DBG.printXML(AjxDebug.DBG1, respDoc.getDocXml());
+        } catch (ex) {
+            if (ex instanceof AjxException) {
+                newEx = ex;
+            } else {
+                newEx = new AjxException();
+                newEx.method = "AsynchCommand.prototype.rpcCallback";
+                newEx.detail = ex.toString();
+                newEx.code = AjxException.UNKNOWN_ERROR;
+                newEx.msg = "Unknown Error";
+            }
+            this._fireInvokeEvent(newEx);
+            return;
+        }
+    }
+    //call event listeners
+    this._fireInvokeEvent(newEx);
+}
+
+/**
+* Cancels this request (which must be async).
+*/
+AsynchCommand.prototype.cancel =
+function() {
+    if (!this._rpcId) return;
+
+    var rpcRequestObj = AjxRpc.getRpcCtxt(this._rpcId);
+    if (rpcRequestObj)
+        rpcRequestObj.cancel();
+}
+
+/**
+* @method invoke
+* @param xmlDoc     The XML document containing the data to send to the server
+* @param serverUri  The server's URL
+* Use this method to send a command to the server
+**/
+AsynchCommand.prototype.invoke =
+function (xmlDoc, serverUri) {
+    if (arguments.length < 2) {
+        DBG.println(AjxDebug.DBG1, "AsynchCommand.prototype.invoke requires 2 
arguments");
+        return;
+    }
+
+    try {
+        DBG.println(AjxDebug.DBG1, "<H4>ASYNCHRONOUS REQUEST</H4>");
+        DBG.printXML(AjxDebug.DBG1, xmlDoc.getDocXml());
+        var requestStr = xmlDoc.getDocXml();
+
+        this._st = new Date();
+        this._rpcId = AjxRpc.invoke(requestStr, serverUri, {"Content-Type": 
"text/xml; charset=utf-8"},
+                new AjxCallback(this, AsynchCommand.prototype.rpcCallback));
+    } catch (ex) {
+        //JavaScript error, network error or unknown error may happen
+        var newEx = new AjxException();
+        newEx.method = "AsynchCommand.invoke";
+        if (ex instanceof AjxException) {
+            newEx.detail = ex.msg + ": " + ex.code + " (" + ex.mteethod + ")";
+            newEx.msg = "Network Error";
+            newEx.code = ex.code;
+        } else {
+            newEx.detail = ex.toString();
+            newEx.code = AjxException.UNKNOWN_ERROR;
+            newEx.msg = "Unknown Error";
+        }
+        //notify listeners
+        this._fireInvokeEvent(newEx);
+    }
+}
\ No newline at end of file

Added: 
trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/ClientException.js
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/ClientException.js&rev=12735&repname=jahia
==============================================================================
--- trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/ClientException.js 
(added)
+++ trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/ClientException.js 
Tue Jan 10 15:15:53 2006
@@ -0,0 +1,90 @@
+/*
+ *                                   ____.
+ *                       __/\ ______|    |__/\.     _______
+ *            __   .____|    |       \   |    +----+       \
+ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+ *   \\______: :---|    :    :           |    :    |         \________>
+ *           |__\---\_____________:______:    :____|____:_____\
+ *                                      /_____|
+ *
+ *              . . . i n   j a h i a   w e   t r u s t . . .
+ *
+ *
+ *
+ * ----- BEGIN LICENSE BLOCK -----
+ * Version: JCSL 1.0
+ *
+ * The contents of this file are subject to the Jahia Community Source License
+ * 1.0 or later (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.jahia.org/license
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the rights, obligations and limitations governing use of the contents
+ * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
+ * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
+ * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
+ *
+ * The Shared Modifications are Jahia View Helper.
+ *
+ * The Developer of the Shared Modifications is Jahia Solution S�rl.
+ * Portions created by the Initial Developer are Copyright (C) 2002 by the
+ * Initial Developer. All Rights Reserved.
+ *
+ * ----- END LICENSE BLOCK -----
+ */
+
+function ClientException(msg, code, method, detail) {
+       if (arguments.length == 0) return;
+       AjxException.call(this, msg, code, method, detail);
+}
+
+ClientException.prototype = new AjxException;
+ClientException.prototype.constructor = ClientException;
+
+ClientException.prototype.toString =
+function() {
+       return "ClientException";
+}
+
+ClientException.CSFE_SVC_ERROR                                 = 
"CSFE_SVC_ERROR";
+ClientException.NETWORK_ERROR                          = "NETWORK_ERROR";
+ClientException.NO_AUTH_TOKEN                          = "NO_AUTH_TOKEN";
+ClientException.SOAP_ERROR                                     = "SOAP_ERROR";
+
+// CSFE Exceptions
+ClientException.SVC_AUTH_EXPIRED                       = 
"service.AUTH_EXPIRED";
+ClientException.SVC_AUTH_REQUIRED                      = 
"service.AUTH_REQUIRED";
+ClientException.SVC_FAILURE                            = "service.FAILURE";
+ClientException.SVC_INVALID_REQUEST            = "service.INVALID_REQUEST";
+ClientException.SVC_PARSE_ERROR                        = "service.PARSE_ERROR";
+ClientException.SVC_PERM_DENIED                        = "service.PERM_DENIED";
+ClientException.SVC_UNKNOWN_DOCUMENT           = "service.UNKNOWN_DOCUMENT";
+ClientException.SVC_WRONG_HOST                                 = 
"service.WRONG_HOST";
+
+ClientException.ACCT_AUTH_FAILED                       = "account.AUTH_FAILED";
+ClientException.ACCT_EXISTS                            = 
"account.ACCOUNT_EXISTS";
+ClientException.ACCT_INVALID_PASSWORD          = "account.INVALID_PASSWORD";
+ClientException.ACCT_INVALID_PREF_NAME                 = 
"account.INVALID_PREF_NAME";
+ClientException.ACCT_INVALID_PREF_VALUE        = "account.INVALID_PREF_VALUE";
+ClientException.ACCT_NO_SUCH_ACCOUNT           = "account.NO_SUCH_ACCOUNT";
+ClientException.ACCT_NO_SUCH_SAVED_SEARCH      = 
"account.NO_SUCH_SAVED_SEARCH";
+ClientException.ACCT_NO_SUCH_TAG                       = 
"account.ACCT_NO_SUCH_TAG";
+ClientException.ACCT_PASS_RECENTLY_USED        = 
"account.PASSWORD_RECENTLY_USED";
+ClientException.ACCT_PASS_CHANGE_TOO_SOON      = 
"account.PASSWORD_CHANGE_TOO_SOON";
+ClientException.DOMAIN_NOT_EMPTY                       = 
"account.DOMAIN_NOT_EMPTY";
+
+ClientException.COS_EXISTS                                     = 
"account.COS_EXISTS";
+
+ClientException.DOMAIN_EXISTS                          = 
"account.DOMAIN_EXISTS";
+
+ClientException.MAIL_INVALID_NAME                      = "mail.INVALID_NAME";
+ClientException.MAIL_NO_SUCH_FOLDER            = "mail.NO_SUCH_FOLDER";
+ClientException.MAIL_NO_SUCH_TAG                       = "mail.NO_SUCH_TAG";
+ClientException.MAIL_NO_SUCH_CONV                      = "mail.NO_SUCH_CONV";
+ClientException.MAIL_NO_SUCH_MSG                       = "mail.NO_SUCH_MSG";
+ClientException.MAIL_NO_SUCH_PART                      = "mail.NO_SUCH_PART";
+ClientException.MAIL_QUOTA_EXCEEDED            = "mail.QUOTA_EXCEEDED";
+ClientException.MAIL_QUERY_PARSE_ERROR                 = 
"mail.QUERY_PARSE_ERROR";
+ClientException.MAIL_SEND_FAILURE           = "mail.SEND_FAILURE";
\ No newline at end of file

Added: trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/XmlUtils.js
URL: 
https://jahia.mine.nu/websvn/filedetails.php?path=/trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/XmlUtils.js&rev=12735&repname=jahia
==============================================================================
--- trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/XmlUtils.js (added)
+++ trunk/core/src/webapp/jsp/jahia/javascript/zimbra/jahia/XmlUtils.js Tue Jan 
10 15:15:53 2006
@@ -0,0 +1,70 @@
+/**
+ * Utility class to manage XML documents given as String
+ */
+function XmlUtils() {
+}
+
+/**
+ * Returns the value of an XML tag
+ */
+XmlUtils.getNodeValue =
+function (content, nodeName) {
+    var tmp = content;
+    var tag = "<" + nodeName;
+    var start = tmp.indexOf(tag);
+    if (start > -1) {
+        tmp = tmp.substring(start + tag.length);
+        start = tmp.indexOf(">") + 1;
+    }
+
+    var end = tmp.indexOf("</" + nodeName + ">");
+
+    if (start != -1 && start < end) {
+        return tmp.substring(start, end);
+    } else {
+        return null;
+    }
+}
+
+/**
+ * Returns the value of an XML attribute
+ */
+XmlUtils.getAttrValue =
+function (content, nodeName, attribute) {
+    var tmp = content;
+    var tag = "<" + nodeName;
+    var start = tmp.indexOf(tag);
+    if (start > -1) {
+        tmp = tmp.substring(start);
+    } else {
+        return null;
+    }
+    var end = tmp.indexOf(">");
+    tmp = tmp.substring(start, end);
+    start = tmp.indexOf(attribute);
+
+    if (start > -1) {
+        var value = tmp.substring(start + attribute.length + 2);
+        return value.substring(0, value.indexOf("\""));
+    } else {
+        return null;
+    }
+}
+
+/**
+ * Splits the Xml string into substrings. Each substring will be the what is 
betwwen the opening and closing
+ * tagName given in parameter.
+ */
+XmlUtils.splitXml =
+function (xmlString, tagName) {
+    var result = new Array();
+    for (var i = 0; ; i++) {
+        var start = xmlString.indexOf("<" + tagName);
+        if (start < 0) {
+            return result;
+        }
+        var end = xmlString.indexOf("</" + tagName + ">");
+        result[i] = xmlString.substring(start, end + tagName.length + 3);
+        xmlString = xmlString.substring(end + tagName.length + 3);
+    }
+}
\ No newline at end of file

Reply via email to