2012-08-24 17:07 Europe/Helsinki: Robert Hanson:
> On Fri, Aug 24, 2012 at 3:26 AM, Mikko Rantalainen
> <[email protected]> wrote:
>> Is it possible to configure JmolApplet to fetch the required files
>> through the UA (web browser) instead of directly trying to connect the
>> server?
> 
> I believe so. If you can get it through AJAX, you are all set. Just
> use Jmol-JSO.
> You should create a new _Applet prototype function on your page:
> 
>   Jmol._Applet.prototype._getSecureFile = function(query, script){
>   this._script("zap;set echo middle center;echo Retrieving data...");
>   // script is necessary only if you need to do the post-load processing
>   var self = this;
>   Jmol._contactServer("?query=" + encodeURIComponent(query),
>    function(data){self._loadModel(data, ";" + script)},
> function(){alert("error...")}
>   );
>  }
> 
> and call that from your page link.

I didn't follow what you mean with "page link".

> Then be sure to set  Info.serverURL to your server, not mine!

Sure. In fact, I used _ajax() directly and never even use serverURL. See
below.

> Info.serverURL needs to point to a PHP document on your server to
> process your request for the "query" -- just deliver the file contents
> as is. In this way, the actual data files need never be exposed. Only
> your PHP file needs exposure.

I wonder what I did wrong. Here's the code I'm trying to use:


<script>
// We'll need to call Jmol._ajax() but it's an internal
// method. We workaround the issue by adding a new
// public method to Jmol object that calls the internal
// method for us.
Jmol._Applet.prototype._loadModelIndirect = function(url, script)
 {
  this._script("zap;\
   set echo middle center;\
   echo Loading model via user agent...");

  var self = this;
  var info =
  {
   dataType: "text",
   type: "GET",
   url: url,
   success: function(a)
   {
    Jmol._loadSuccess(a, function(data){
     self._loadModel(data, ";"+script);
    })
   },
   error: function()
   {
    Jmol._loadError(function(e){
     alert("error: "+e)
    })
   },
   async:Jmol._asynchronous
  }
  Jmol._ajax(info);
 };

var Info = {
 color: "#FFFFFF", // background color
 width: "100%",
 height: "100%",
 script: "language=\u0022fi\u0022;",
 use: "Java WebGL",
 jarPath: "/path/to/jmol/13.0.1",
 jarFile: "JmolApplet.jar",
 isSigned: false,
 //debug: true,
 };

myJmol = Jmol.getApplet("JmolView", Info);
myJmol._loadModelIndirect("http://path/to/molecule.jmol";, "");
</script>


The URL in _loadModelIndirect() will return the actual data only if
correct "session-id" is passed as a cookie.

I see that the browser is correctly downloading the molecule
and Jmol._loadModel() will be called with first parameter set
to the contents of the file and second parameter is set to
an empty string.

I can then trace the execution to Jmol._Applet.prototype._loadModel() in
 JmolApplet.js (from Jmol version 13.0.1) using Firefox 14 and
Firebug. The browser then executes

***
Jmol._Applet.prototype._loadModel = function(mol, params) {
var script = 'load DATA "model"\n' + mol + '\nEND "model" '
+ params;
this._applet.script(script);
}
***

Here the call 'this._applet.script()' will be passed a very long
 string (around 170 KB):

    'load DATA "model"\nMODEL_FILE_CONTENTS\nEND "model" ;'

where MODEL_FILE_CONTENTS is the actual file contents from correct .jmol
file (techically a ZIP archive).

Then nothing happens. The red message "Loading model via user
agent..." stays in the middle of the applet with zero CPU usage.

Do I need to do something else after calling Jmol._loadModel() inside
the ajax callback to get the model visible?

-- 
Mikko

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to