read data from a java applet (preferably with js) - java

Here's my problem. I have an application that shows some KPIs... the problem is that it displays those KPIs through a Java applet (and I don't have access to it's source). I need only a few data from that applet. Is there a way to parse data from a Java applet? I would like to parse it with Javascript. Would that be possible?

It's possible to call Java applet methods from JavaScript (read), but it would have to be set up like this already. If you don't have access to the source, perhaps inspect Java console output and/or use 'jar' and 'javap' commands to inspect the classes to see if there is something you can call.

Related

Parse JavaScript from html string in C#/Java

I am trying to do some WebScraping of a site and the data is in dynamically loaded containers. It appears that the loading is done via JavaScript. Therefore I would need to execute it, in order to get it. I have written 2 versions of the program, one in Java and one in C#, so helping me with one would be nice enough.
I am currently using WebResponse/WebRequest in C# and HttpURLConnection in Java. I have to login into the site first, which already works like a charm. Now I need to parse the content, so the data gets filled in and the containers loaded. Is there an easy way to run the html through a browser control or an already included library?
In C# you could just use a hidden WebControl. With that you could execute everything you need.

Run and Save output of JavaScript from Java

I'm trying to figure out how to run some JavaScript from my Java class. I know that javax.script can be used to do this, but here's the kicker:
The JavaScript I want to run returns and displays a PDF in the browser. I'd like to store the PDF that's generated in a byte array or something like that so my class can do something with it later such as save it to disk.
So I guess the best approach would be to take a String that I have that contains the HTML and JavaScript. Then emulate a browser page, run it, then store the source? I'm not sure what library I would use to do something like this. How might I achieve this?
Focusing on your problem with javascript and java you can you this lib called Direct Web Remoting:
DWR is a RPC library which makes it easy to call Java functions from
JavaScript and to call JavaScript functions from Java (a.k.a Reverse
Ajax).
http://directwebremoting.org/

How PHP script can be called using Java Applet

I want to access user's scanner using PHP script. I know this can be done by using PHP script on Linux based machine.
I want to put this script on the server and wanted to run it via Java Applet I don't know Java much also I am not sure if this task can be done by this way.
Please suggest if this is correct way and How to proceed on it.
Thanks for your time!
Can the scanner PHP code be operated purely via parameters in the URL? If so, then a Java applet could connect to those URLs passing parameters as necessary, and if the PHP script returns information in the HTML output stream (as if it were returning a web page), then the applet can parse the page it 'downloads' from that URL to get the information out. Not elegant, but do-able.

How can an Applet call a method in a different frame (from the same web site)?

Given an Applet in one frame in a multi-frame web application where all frames are loaded from the same web server, how can that Applet invoke JavaScript methods in other frames? I tried something like this:
jsobject.call("parent.otherFrame.methodToCall", new String[] {"argument"});
and I get a complaint that the function does not exist. However, if I invoke it like this:
jsobject.eval("parent.otherFrame.methodToCall('argument')");
then it works. I'm trying to avoid use of eval. Is calling code via call in a different frame from an Applet something that is likely to have different behavior in each browser and JVM combination? Is eval safer as it is evaluated in the JavaScript engine rather than partly on the Applet side?
My (limited) experience with a combination of Java applets, JavaScript and (the dreaded) frames, is that it is best to:
Include a script in the page/frame with the applet in it. Define a function intended to be called with 0 or more arguments (one of which might be the name of the target frame).
Call the function from the applet.
Let the JavaScript do the heavy lifting of finding the correct frame & doing whatever needs to be done.
This has a number of advantages.
It is easier to debug JS using the (for example) FF error console, than using the Java console.
JS can be updated more quickly and easily.
Each language encodes what it is good at doing. You can go into a Java editor to see the Java nicely formatted, and a JS editor to see the JS nicely formatted. As opposed to trying to read "JS written in Java" - a scarey experience.
When you ask for help on getting the script working, you have a neat example that the JS gurus can easily read!
The equivalent code without eval is probably something like this:
jsobject = (JSObject)jsobject.getMember("parent");
jsobject = (JSObject)jsobject.getMember("otherFrame");
jsobject.call("methodToCall", new String[] {"hello!"});

When JEditorPane will not do. JRex, JRex wherefore are thou JRex?

IDEA: Implement a recent web browser into a java application (for saved offline, non server content).
The question is this: can I have a java application implement a webbrowser with jquery / html / css support within a java program?
So I am asking anyone who has played with JRex for advice: I want to know how complicated will it be to integrate an open source webbrowser into java. I am not all that keen on the idea of compiling Mozilla from source build. Is there a ready made compiled version?
Is there a simplified method to have latest compiled version (most current in terms of support for HTML css & javascript), and integrate that into an application?
Also: I appreciate the amount of work required to support for HTML4 nevermind 5, and CSS2 compliance. How close is JRex to that?
Application: My intention with the webbrowser is to render a webpage from offline content. It will not need to be online content, and will simply be for file based displays = e.g. file:///C:...
Does the webbrowser have to be wrapped into a server to function, e.g. to pass files to the browser to render is how complicated? I am not keen to have to implement Jetty or another server type application just for this.
If JRex is not the solution... what then? Is it possible to start a browser implementation within Java and can Java interact with the information and traverse the Dom?
Or alternatively is there .hta equivalent in recent browsers like firefox?
If you need to have the embedded browser interact with your application code, you could try the SWT Browser control, it's actually maintained as opposed to JRex. Browser uses either WebKit or Gecko or embedded IE as appropriate, or lets you choose which one you want, so it should run jQuery and familiar Javascript. And since SWT is a JNI library to begin with they probably already have guidance on how to deploy an app that uses JNI.
You can feed HTML into the control from a string (example) or a java Url - which can point to local files or resource files in your JAR, which I assume will let you split your app into different files.
To call Java code, you need to expose it as Javascript functions. example
To manipulate the HTML from Java code, you need to call Javascript functions from Java. example
To make the previous two tasks easier, you might want to look into a JSON library to simplify passing around complex data.
Does it have to be implemented within a Java program? Could you let the user use the default browser on their machine (ie does it matter what browser)?
If not would use the Java Desktop API.
if (desktop.isSupported(Desktop.Action.BROWSE)) {
txtBrowserURI.setEnabled(true);
btnLaunchBrowser.setEnabled(true);
}
If you are using Java 1.5 try http://javadesktop.org/articles/jdic/

Categories

Resources