chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1300830 - in /chemistry/playground/chemistry-opencmis-javascript-client/src: main/webapp/cmislib.js main/webapp/index.html test/resources/testcmislib.js
Date Thu, 15 Mar 2012 07:53:17 GMT
Author: jens
Date: Thu Mar 15 07:53:17 2012
New Revision: 1300830

URL: http://svn.apache.org/viewvc?rev=1300830&view=rev
Log:
add basic authentication, make JSONP optional

Modified:
    chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
    chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
    chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js?rev=1300830&r1=1300829&r2=1300830&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js (original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js Thu
Mar 15 07:53:17 2012
@@ -21,6 +21,7 @@ function trace(text) {
       window.console.log(text);  
     }  
 }
+
 function OperationContext() {
 	
     this.propertyFilter = "*";
@@ -41,20 +42,19 @@ function OperationContext() {
 function CmisSessionFactory (parameters) { 
     var PARAM_URL = "url";
     var PARAM_REPOSITORY_ID = "repositoryId";
-
+    var PARAM_JSONP = "jsonp";
+    var PARAM_USER = "user";
+    var PARAM_PWD = "password";
     this.params = parameters;
   
     this.createSession = function() {
-        return new CmisSession(this.params[PARAM_URL], this.params[PARAM_REPOSITORY_ID]);
+        return new CmisSession(this.params[PARAM_URL], this.params[PARAM_REPOSITORY_ID],
this.params[PARAM_JSONP],
+                this.params[PARAM_USER], this.params[PARAM_PWD]);
     };
         
     this.getRepositories = function(cbFct) {
         trace("getRepositories() for URL: " + this.params[PARAM_URL]);
-        $.ajax( { 
-                    url:this.params[PARAM_URL],
-                    dataType: "jsonp",
-                    success: cbFct
-        });
+        doJson(this.params[PARAM_URL], null, "GET", this.params[PARAM_USER], this.params[PARAM_PWD],
cbFct);
     };
 };
 
@@ -127,7 +127,7 @@ function TypeCache() {
     }
 };
 
-function CmisSession(urlPrefix, repositoryId) {
+function CmisSession(urlPrefix, repositoryId, jsonp, user, password) {
     this.repId = repositoryId;;
     this.urlPrefix = urlPrefix; // "/inmemory/browser/" + repId
     this.rootUrl = null;
@@ -135,6 +135,10 @@ function CmisSession(urlPrefix, reposito
     this.rootFolderId; // just use a place to store the id, must be filled by user of a CmisSession
     this.typeCache = new TypeCache();    
     this.pagingContext = {};
+    this.jsonp = jsonp;
+    this.user = user;
+    this.password = password;
+    
     
 	this.getUrl = function() {
 		return this.urlPrefix + "/" + this.repId;
@@ -193,7 +197,7 @@ function CmisSession(urlPrefix, reposito
             };
 
         trace("getRepositoryInfo(): " + url);
-        this.doJson(url, data, cbFct);
+        this.doJsonGet(url, data, cbFct);
     };
 
     this.getDocument = function(id, cbFct) {
@@ -210,7 +214,7 @@ function CmisSession(urlPrefix, reposito
         };
 
         trace("getDocument(): " + url);
-        this.doJson(url, data, cbFct);
+        this.doJsonGet(url, data, cbFct);
     };
 
     this.getChildren = function(id, cbFct) {
@@ -230,7 +234,7 @@ function CmisSession(urlPrefix, reposito
         };
 
         trace("getDocument(): " + url);
-        this.doJson(url, data, cbFct);
+        this.doJsonGet(url, data, cbFct);
     };
 
     this.deleteDocument = function(objectId, cbFct) {
@@ -243,12 +247,7 @@ function CmisSession(urlPrefix, reposito
         };
         
         trace("deleteDocument(): " + url);
-        $.ajax( { 
-            url: url,
-            data: properties,
-            type:  "POST",
-            success: cbFct
-        });
+        this.doJsonPost(url, properties, cbFct);
     };
     
     this.createDocument = function(name, typeId, folderId, customProperties, cbFct) {
@@ -283,12 +282,7 @@ function CmisSession(urlPrefix, reposito
             }
             }
         
-        $.ajax( { 
-            url: url,
-            data: properties,
-            type:  "POST",
-            success: cbFct        
-        });
+        this.doJsonPost(url, properties, cbFct);
     };
         
     this.getTypeDefinition = function(typeId, cbFct) {
@@ -305,7 +299,7 @@ function CmisSession(urlPrefix, reposito
         var cache = this.typeCache;
         var cachedTypeDef = this.typeCache.getType(typeId);
         if (null == cachedTypeDef) { // not found in cache get it from server
-            this.doJson(url, data, function(type) {
+            this.doJsonGet(url, data, function(type) {
                 cache.addType(type); // add found type to the cache
                 return cbFct.call(this, type);
             });
@@ -326,7 +320,7 @@ function CmisSession(urlPrefix, reposito
         };
 
         trace("getTypeDefinition() " + url);
-        this.doJson(url, data, cbFct);        
+        this.doJsonGet(url, data, cbFct);        
     };
     
     this.doQuery = function(queryString, cbFct) {
@@ -343,12 +337,7 @@ function CmisSession(urlPrefix, reposito
         };
 
         trace("doQuery() " + url);
-        $.ajax( { 
-            url: url,
-            data: properties,
-            type:  "POST",
-            success: cbFct        
-        });
+        this.doJsonPost(url, properties, cbFct);
     };
     
     this.doQueryPaged = function(queryString, elementId, cbFct) {
@@ -370,18 +359,14 @@ function CmisSession(urlPrefix, reposito
         };
 
         trace("doQuery() " + url);
-        $.ajax( { 
-            url: url,
-            data: properties,
-            type:  "POST",
-            success:  function (data) {
-                if (null == pgCtx) {
-                    session.addPagingContext(elementId, 0, data.numItems)
-                } else
-                    pgCtx.totalItems = data.numItems;
-                return cbFct.call(this, data);    
-            }        
-        });
+        this.doJsonPost(url, properties, function (data) {
+            if (null == pgCtx) 
+                session.addPagingContext(elementId, 0, data.numItems)
+            else
+                pgCtx.totalItems = data.numItems;
+            return cbFct.call(this, data);    
+            }      
+        );
     };
     
     
@@ -394,18 +379,17 @@ function CmisSession(urlPrefix, reposito
         };
 
         trace("getObjectFromTransaction(): " + url  + ", transaction-id: " + transId);
-        this.doJson(url, data, cbFct);
+        this.doJsonGet(url, data, cbFct);
+    };
+    
+    this.doJsonPost = function(url, params, cbFct) {
+        doJson(url, params, "POST", this.user, this.password, cbFct);
     };
     
-    this.doJson = function(urlPrefix, params, cbFct) {
-        $.ajax( { 
-            url: urlPrefix,
-            data: params,
-            dataType: "jsonp",
-            success: cbFct
-        });
+    this.doJsonGet = function(url, params, cbFct) {
+        doJson(url, params, "GET", this.user, this.password, cbFct);
 	};
-		
+	
 };
 
 CmisSession.defaultErrorHandler = function (event, jqXHR, settings, excep) {
@@ -432,3 +416,21 @@ CmisSession.defaultErrorHandler = functi
     return cmisError;
 };
 
+function doJson(url, params, method, username, password, cbFct) {
+    
+    if (username != null && username.length == 0)
+        username=null;
+    
+    if (password != null && password.length == 0)
+        password=null;
+
+    $.ajax( { 
+        url: url,
+        data: params,
+        dataType: (this.jsonp ? "jsonp" : "json"),
+        type:  method,
+        username: username,
+        password: password,
+        success: cbFct
+    });
+};

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html?rev=1300830&r1=1300829&r2=1300830&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html (original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html Thu
Mar 15 07:53:17 2012
@@ -36,18 +36,24 @@
     
 	var session = null;
 	  
-    function connectToRepo(connectionUrl, cbFct) {
+    function connectToRepo(connectionUrl, jsonp, user, password, cbFct) {
          var factory = new CmisSessionFactory({
-              url : connectionUrl
+              url : connectionUrl,
+              jsonp : jsonp,
+              user : user,
+              password: password
         	});
          factory.getRepositories(cbFct);
     }
  	            
-    function createSession(connectionUrl, repoId) {
+    function createSession(connectionUrl, repoId, jsonp, user, password) {
  	            trace("Initializing session to " + connectionUrl);
  	            var factory = new CmisSessionFactory({
  	                url : connectionUrl,
- 	                repositoryId : repoId
+ 	                repositoryId : repoId,
+ 	                jsonp : jsonp,
+ 	                user : user,
+ 	                password: password
  	          	});
  	              
  	            session = factory.createSession();
@@ -214,8 +220,9 @@
         } else
             return null;
     }
+    
     function createRandomString() {
-        return Math.round(Math.random()*100000).toString();
+        return Math.round(Math.random()*1000).toString();
     }
     
     function prepareCreate() {
@@ -318,7 +325,8 @@
 
         $('#repositories').click(function() {
             var firstRepoId;
-            connectToRepo($("#reposfield").val(), function(repoInfos) {
+            connectToRepo($("#reposfield").val(), $("#jsonpfield").attr("checked")=="checked",
$("#userfield").val(),
+        	        $("#pwdfield").val(), function(repoInfos) {
                 trace("getRepositories()");
                 var row;
                 var tbl = $('<table>').append($('<tr>').append($('<td>').text("Found
repositories:")))
@@ -333,7 +341,8 @@
             	$("#repoidfield").attr('value', firstRepoId);
             	$("#folderidfield").attr('value', repoInfos[firstRepoId].rootFolderId);
             	
-            	createSession($("#reposfield").val(), firstRepoId);
+            	createSession($("#reposfield").val(), firstRepoId, $("#jsonpfield").attr("checked")=="checked",
$("#userfield").val(),
+            	        $("#pwdfield").val());
             });
         });
         
@@ -450,6 +459,18 @@
 	        <td><label for="reposfield">URL:</label></td>
 	        <td><input type="text" id="reposfield" value="/inmemory/browser"/></td>
 	      </tr>
+	      <tr>
+	        <td><label for="userfield">User:</label></td>
+	        <td><input type="text" id="userfield" value="jsuser"/></td>
+	      </tr>
+	      <tr>
+	        <td><label for="pwdfield">Password:</label></td>
+	        <td><input type="password" id="pwdfield" value="pass"/></td>
+	      </tr>
+	      <tr>
+	        <td></td>
+	        <td><input type="checkbox" id="jsonpfield" name="jsonp" checked="checked"
value="jsonp"/>JSON-P</td>
+	      </tr>
 	    </table>
 	</form>
     <button id="repositories">Connect!</button> <br/>

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js?rev=1300830&r1=1300829&r2=1300830&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
(original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
Thu Mar 15 07:53:17 2012
@@ -56,6 +56,9 @@ module("Module CmisLib", {
         this.session = factory.createSession();
         this.session.rootFolderId = "100";
         this.session.rootUrl = "/inmemory/browser/A1/root";
+        this.session.jsonp = true;
+        this.session.user = "testuser";
+        this.session.password = "pass";
     },
     
     teardown: function() {
@@ -145,7 +148,7 @@ test("testCreateDeleteDocument", functio
             docId = data.properties["cmis:objectId"].value;
             trace("created docId " + docId);
             ctx.session.deleteDocument(docId, function(data) {
-                ok(data.exception == null, "DeleteDocument()");
+                ok(data == null || data.exception == null, "DeleteDocument()");
                 trace("testCreateDeleteDocument() done.");
                 start();
             });
@@ -164,7 +167,7 @@ test("testCreateDocumentMustFail()", fun
     $(document).ajaxError(function(event, jqXHR, settings, excep){
         ok(jqXHR.status == 409, "CreateDocument() failed as expected. ");
         ctx.session.deleteDocument(docId, function(data) {
-            ok(data.exception == null, "DeleteDocument()");
+            ok(data == null || data.exception == null, "DeleteDocument()");
             trace("testCreateDocumentMustFail() done.");
             start();
         });



Mime
View raw message