From: Pinelle, D. <dav...@us...> - 2010-02-03 20:07:18
|
I am using ImageJA as a viewer for a radiological teaching file system. So far, so good, but I have a question about passing arguments (using the HTML PARAM tag) to the applet. I am able to pass the URLs for images to the applet without any problem, and people are able to interactively select images in my system, and then the images are displayed in the ImageJA viewer. My goal now is to be able to pass several variables to the applet and then to be able to write an ImageJ macro or plug-in that can manipulate the variables. I noticed that the ImageJApplet class has been modified in ImageJA, and it accepts macro expressions or macros posted in URLs. It seems like this should solve my problem, but I have not been able to get this feature to work properly. I have passed in my variables as macro expressions, and I have also passed in a short macro as an expression. I have tried several variations on this: I have passed in the variables as separate eval parameters, and I have tried interacting with the variables in macros launched through StartupMacros.txt, etc., but without much luck. Nothing seems to happen when I run my code, and when I try to access the variables in other macros, they are not recognized. This code runs in a Java servlet that is deployed in Tomcat. Everything works and has been tested extensively...except the arguments that are being passed in using the eval1 parameter. The part that is included in the eval1 PARAM is a simple test macro that is supposed to print the variables to the screen so that I can make sure they reach the applet okay. When I run this code, the ImageJA applet does not acknowledge the eval1 PARAM. My main question is whether this functionality is fully implemented at this point (passing in macros) and whether I am doing this correctly. I also would like to know how the variables passed in through the eval parameter are scoped. If, for example, I pass in a variable like this: applet.append("<PARAM NAME=eval1 VALUE=\"var host=\""+req.getHeader("host")+"\";\" >"); How/where can I access it once it reaches the applet (using macros or plugins)? Thanks and regards, David String reqURL = req.getRequestURL().toString(); int k = reqURL.indexOf("://") + 3; //get past the protocol k = reqURL.indexOf("/",k) + 1; //get to the beginning of the servlet name k = reqURL.indexOf("/",k) + 1; //get to the end of the servlet name, plus the slash StringBuffer applet = new StringBuffer(); applet.append("<HTML><BODY>"); applet.append("<APPLET "); String codebase = reqURL.substring(0,k) + "dicomviewer/imagej"; applet.append("CODEBASE=\""+codebase+"\" "); applet.append("ARCHIVE=\"ij.jar\" "); applet.append("CODE=\"ij.ImageJApplet.class\" "); applet.append("NAME=\"Viewer.java\" "); applet.append("WIDTH=\"100% \" "); applet.append("HEIGHT=\"100%\" "); applet.append("HSPACE=\"0\" "); applet.append("VSPACE=\"0\" "); applet.append("ALIGN=\"top\" "); applet.append(">"); applet.append("<PARAM name=\"java_arguments\" value=\"-Xmx256m\">"); applet.append("<PARAM NAME=url1 VALUE=\""+reqURL+"\">"); //THIS IS WHERE I AM HAVING PROBLEMS applet.append("<PARAM NAME=eval1 VALUE=\""+ "var host=\""+req.getHeader("host")+"\";"+System.getProperty("line.separator")+ "var authorization=\""+req.getHeader("authorization")+"\";"+System.getProperty("line.separator")+ "var useragent=\""+req.getHeader("user-agent")+"\";"+System.getProperty("line.separator")+ "var accept=\""+req.getHeader("accept")+"\";"+System.getProperty("line.separator")+ "var keepalive=\""+req.getHeader("keep-alive")+"\";"+System.getProperty("line.separator")+ "var referer=\""+req.getHeader("referer")+"\";"+System.getProperty("line.separator")+ "print (\"The arguments are:\");"+System.getProperty("line.separator")+ "print (\"host \" + host);"+System.getProperty("line.separator")+ "print (\"authorization \" + authorization);"+System.getProperty("line.separator")+ "print (\"useragent \" + useragent);"+System.getProperty("line.separator")+ "print (\"accept \" + accept);"+System.getProperty("line.separator")+ "print (\"keepalive \" + keepalive);"+System.getProperty("line.separator")+ "print (\"referer \" + referer);"+System.getProperty("line.separator")+ "print (\"--\"); \" >"); applet.append("</APPLET>"); applet.append("</BODY></HTML>"); |