Changeset 42


Ignore:
Timestamp:
Nov 10, 2010, 6:56:18 AM (14 years ago)
Author:
djay
Message:

Enhance the JavaScript? support by automatically load the ZOO-api.js and ZOO-proj4js.js file before loading the JavaScript? service. This way no more need to integrate the whole ZOO-api.js and proj4js.js files into the JavaScript? service provider code.

Location:
trunk/zoo-kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/service_internal_js.c

    r34 r42  
    7777    return 1;
    7878
     79  map* tmpm1=getMap(request,"metapath");
     80  char ntmp[1024];
     81  getcwd(ntmp,1024);
     82
     83  /**
     84   * Load the first part of the ZOO-API
     85   */
     86  char api0[strlen(tmpm1->value)+strlen(ntmp)+15];
     87  sprintf(api0,"%s/%sZOO-proj4js.js",ntmp,tmpm1->value);
     88  fprintf(stderr,"Trying to load %s\n",api0);
     89  JSScript *api_script1=loadZooApiFile(cx,global,api0);
     90  fflush(stderr);
     91
     92  char api1[strlen(tmpm1->value)+strlen(ntmp)+11];
     93  sprintf(api1,"%s/%sZOO-api.js",ntmp,tmpm1->value);
     94  fprintf(stderr,"Trying to load %s\n",api1);
     95  JSScript *api_script2=loadZooApiFile(cx,global,api1);
     96  fflush(stderr);
     97
    7998  /* Your application code here. This may include JSAPI calls
    8099     to create your own custom JS objects and run scripts. */
     
    82101  int res=SERVICE_FAILED;
    83102  maps* mc=*main_conf;
    84   map* tmpm1=getMap(request,"metapath");
    85103  map* tmpm2=getMap(s->content,"serviceProvider");
    86   char ntmp[1024];
    87   getcwd(ntmp,1024);
     104
    88105  char filename[strlen(tmpm1->value)+strlen(tmpm2->value)+strlen(ntmp)+2];
    89106  sprintf(filename,"%s/%s%s",ntmp,tmpm1->value,tmpm2->value);
     
    208225  /* Cleanup. */
    209226  JS_DestroyScript(cx, script);
     227  JS_DestroyScript(cx, api_script1);
     228  JS_DestroyScript(cx, api_script2);
    210229  //JS_MaybeGC(cx);
    211230  // If we use the DestroyContext as requested to release memory then we get
     
    219238#endif
    220239  return res;
     240}
     241
     242JSScript * loadZooApiFile(JSContext *cx,JSObject  *global, char* filename){
     243  struct stat api_status;
     244  int s=stat(filename, &api_status);
     245  if(s==0){
     246    jsval rval;
     247    FILE *jsfile=fopen(filename,"r");
     248    JSBool ok ;
     249    JSScript *script = JS_CompileFileHandle(cx, global, filename,jsfile);
     250    if(script!=NULL){
     251      (void)JS_ExecuteScript(cx, global, script, &rval);
     252      fprintf(stderr,"**************\n%s correctly loaded\n**************\n",filename);
     253      return script;
     254    }
     255    else
     256      fprintf(stderr,"\n**************\nUnable to run %s\n**************\n",filename);
     257  }
     258  else
     259    fprintf(stderr,"\n**************\nUnable to load %s\n**************\n",filename);
     260  return NULL;
    221261}
    222262
  • trunk/zoo-kernel/service_internal_js.h

    r1 r42  
    5252  int zoo_js_support(maps**,map*,service*,maps **,maps **);
    5353
     54  JSScript *loadZooApiFile(JSContext*,JSObject*,char*);
     55
    5456#ifdef __cplusplus
    5557}
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png