Package com.zaranux.os.client.programs

Source Code of com.zaranux.os.client.programs.ZohoApplication

package com.zaranux.os.client.programs;
import com.google.gwt.http.client.URL;
import com.openmashupos.core.client.Mashlet;
import com.zaranux.client.api.AsyncCallback;
import com.zaranux.client.api.types.Access;
import com.zaranux.os.client.core.Program;
import com.zaranux.os.client.util.Log;

public class ZohoApplication extends Program {

  private String path;
 
  protected int width =  900;
  protected int height =  450;
 
  private String getExtension()
  {
    int i = path.lastIndexOf(".");
    return path.substring(i+1);
  }
 
  private String getFilename()
  {
    int i = path.lastIndexOf("/");
    return path.substring(i+1);
  }
 
  public ZohoApplication(String actionURL, String appTitle){
    this.actionURL = actionURL;
    this.appTitle = appTitle;
  }
 
  private String actionURL;
  private String appTitle;
 
 
  //@Override
  public void main(String[] args)
  {

    if(args.length <= 0)
    {
      //callback.onFailure(new Exception("Wrong parameters: path expected!"));
      return;
    }
 
   
    path = args[0];
    final String id = systemcall.userid();
   
    Access[] accesses;
   
    //if("zaranux".equals(id))
    // TODO: temp solution nos secure idAsser should be protected ..
    if(com.zaranux.client.app.core.Proxy.identityAssertion == null || "".equals(com.zaranux.client.app.core.Proxy.identityAssertion))
    {
      accesses = new Access[1];
      accesses[0] = Access.READ;
    }else
    {
      accesses = new Access[2];
      accesses[0] = Access.READ;
      accesses[1] = Access.WRITE;

    }
   
   
    systemcall.delegate(path, "zoho.com" ,accesses, 86400, new AsyncCallback<String>()
        {
        public void onSuccess(String accessAssertion)
        { 
          Log.debug("accessAssertion : " + accessAssertion);
          //accessAssertion="testAccess";
          String kernelBase = "http://zaranux.com/"; // temporarily; because zoho only accepts registered domains ...
          String authorizedURL = URL.encodeComponent(kernelBase +"@"+id + path + "?accessAssertion="+accessAssertion);
          String authorizedSaveURL = URL.encodeComponent(kernelBase +"@"+id + path + "?accessAssertion="+accessAssertion+"&systemcall=fileupload");

          systemcall.http("POST",actionURL,"apikey=5ed0930cc885a0b165dbaeed509a21cd&output=url&url=" + authorizedURL + "&saveurl=" + authorizedSaveURL + "&filename=" + getFilename() + "&id=0001&format=" + getExtension(), new AsyncCallback<String>()
          {
              public void onSuccess(String result)
              { 
                int urlIndex = result.indexOf("URL=");
               
                int warningIndex = result.indexOf("WARNING=");
                int rsltIndex = result.indexOf("RESULT=");

                if(urlIndex < 0) return;
                String url = null;
                if(warningIndex > urlIndex || rsltIndex > urlIndex)
                {
                url = result.substring(urlIndex+4, warningIndex < rsltIndex ? warningIndex : rsltIndex);
                Log.debug("case 1: url = " + url  );
                }
                else
                {
                url = result.substring(urlIndex+4);
                Log.debug("case 2: url = " + url  );
                }
                setWidget(new Mashlet(url),width,height);
              }
              public void onFailure(Throwable caught)
              {
                //callback.onFailure(caught);
              }
          }
          );
        }
        public void onFailure(Throwable caught)
        {
          //callback.onFailure(caught);
        }
    });
  }
}
TOP

Related Classes of com.zaranux.os.client.programs.ZohoApplication

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.