Cookbook > How to set up Processing to use the OwnCloud Core Processing Library

We will describe how to use the OwnCloud Core Processing Library within the Processing framework, starting from a blank sketch. Library’s functions will be refined and new ones may be developped, some additional libraries will be added as well in order to propose high level functions deeper linked to the IICloud(s) project.

 

own_processing_logo

 

1 OwnCloud server: your OwnCloud server should be reachable either via http, either via https, something like http://www.MyOwnCloudServer.org or https://www.AnotherOwnCloudServer.com etc… Another Cook Book has been written about how to install a personal OwnCloud server.

1 Processing: please refer to Processing installation guidelines in order to install properly the Processing framework if you do not have already one ready to be used.

1 OwnCloud Core Processing Library: download the current version of the library. Extract the zip file that includes the needed library file (.jar file) and some documentation files.

-

How To:

Launch Processing

Start a blank sketch via the menu File > New

Add the OwnCloud Core Processing Library to your Processing sketch via the menu Sketch > Add File… and point the jar file you just downloaded.

Insert the following line at the top of your sketch file:

—–

import ch.fabric.processing.owncloud.OCServer;

—–

This will make your Processing sketch aware of the OwnCloud Core Processing Library and its content.

Define a global variable to point your OwnCloud Core Processing Library object by adding:

—–

// My main access to the Owncloud server
OCServer _myOCServer;

—–

In the Processing sketch’s setup function, add the followings:

—–

 // —– Create a new access to an OwnCloud server
 _myOCServer = new OCServer();
    
 // —– Define the targeted OwnCloud server
boolean resB = _myOCServer.SetServer(“data.iiclouds.org”);

—–

The first line define a new OwnCloud object. This object will be used to access OwnCloud functions (copy, search and share files etc…).

The second line establishes a connection to your OwnCloud server by giving your OwnCloud server domain name or IP address. The returned value, a boolean (true/false) will indicate if the connection to your OwnCloud was established correctly (true) or not (false).

In the Processing sketch’s setup function, add the followings:

—–

if (resB) {
      // —– Define my Owncloud server login/password
      _myOCServer.SetAccess(“MyLoginHere”, “MyPasswordHere”);

      // —– Any additional actions here…

}

—–

You are done! You are now able to copy, transfer, search and share files from you OwnCloud server within the Processing framework. You can download files, copy them, move them etc… Add any actions you would like to perform, here are few examples:

—–

   // —– Get the content of my Owncloud’s account root directory…
   println(“———————–”);
   println(“[Processing - draw()] – Listing root directory content…”);
   String [] myContent = _myOCServer.getContentList();

   // —– …and loop on the result to display the root directory’s content      
    for(int i=0;i<myContent.length;i++) {
     println(“[Processing - draw()] – “+(i+1)+” – “+myContent[i]);
   }
   println(“———————–”);
      
   // —– Test if a directory exists in my Owncloud account with error returned value testing
   println(“———————–”);
   println(“[Processing - draw()] – Directory manipulation…”);
   resI = _myOCServer.fileExists(“/music/”);
   if (resI == OCServer.FILE_EXISTS)
     println(“[Processing - draw()] – Directory /music/ is existing.”);
   else if (resI == OCServer.FILE_DOES_NOT_EXIST)
     println(“[Processing - draw()] – Directory /music/ is NOT existing.”);
   else if (resI == OCServer.NETWORK_ERROR)
     println(“[Processing - draw()] – Network problem while accessing OwnCloud.”);

—–

Check the OwnCloud Core Processing Library documentation (included in the zip file you just downloaded) for an exhaustive list of possible actions/functions, their parameters and the returned values.

Have fun!

0 Comments