I am working on a swing application with javafx control (WebView). In which I have to browse HTML files either in JEditorPane or WebView.
But the problem in my project is that I am trying to view HTML files which are encrypted with the help of a software htmlprotecter . It is encrypting the files by invoking the a prompt for entering a password after that the files can be opened in browser. Is there any procedure in Java in which I can pass the password to HTML file to disable javascript and file could be opened in Java programs?
two real possibilities that i see here...
1) the javascript "encryption" (are you sure you are not confusing this with some sort of encoding?) is extremely simplistic and you can emulate the "decryption" routine yourself by operating on the HTML content within java.
2) the "encryption" is very complex and your only option is to parse and run the javascript - which means utilizing some java-based javascript engine (which i have no knowledge of)
case 2 is probably more effort than it is worth.
in short, there is no simple way to pass the password to HTML file to disable javascript. you'll either have to decrypt/decode it yourself or actually run the javascript within java.
Related
The program I am writing is in Java.
I am writing a little program that will download the html of webpages and save them. It works easily for basic pages that don't use JavaScript. But how can I download the page if I want it after a script has updated it? The page I am dealing with is actually updated by Ajax which might be one step harder.
I understand that this is probably a difficult problem that involves setting up a JavaScript run time environment of some kind. I am prepared for a solution of any level of difficulty, I just don't know exactly how to approach it or where to get started.
You can't do that alone with Java only. As the page that you want to download is rendered with javascript, then you must be able to execute the javascript to get the whole rendered page.
Because of this situation, you need to use a headless browser which is a web browser that can access to web pages but can’t show the output within a GUI, aims to provide the content of web pages as fully rendered to serve to the programs or scripts.
You can start with the most famous ones which are Selenium, HtmlUnit and PhantomJS
I'm developing a console Java application(Not swing) using java.awt.Desktop class, which will launch the browser with something like this;
Desktop.getDesktop().browse(URI.create("http://www.google.com"));
This works, but actually what i want is not to give an absolute URL but to display a string with HTML content which I have builded in the code. Can I directly do do this without saving my content as a html page and then calling again?
String myHtmlstring="<body>.."
For this to work, you would need an browser, which can be started with the html-content as parameter.
firefox -code "<html><head><title>demo</title></head><body>..."
If you look at the manpages for firefox, lynx and opera, you won't find such an option (I didn't). But theoretically, it would be possible.
Since html-pages are normally some kb big, using the parameters would be very unhandy, because html often contains quotes and apostrophes, which would need masking. Therefore, if a passing of content would be possible, I would expect it as reading from stdin like so:
cat demo.html | browser
However, I don't know a browser which supports this.
Summary: No, it's not possible with today browsers, but in principle it would be possible. Going with temporary files would be the solution, you're already aware off.
Its not particularly clear what you're asking for though, what do you mean when you say, "display my own html string?" Do you want to generate html and then have the browser display that?
JavaFX 2.0 comes with a webkit component, and you can embed that in your swing application and do with it what you will. Its officially released for Windows and in [beta|preview|alpha] for max/linux. So if you don't require support for multiple platforms right now, its probably a good choice.
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/
I have exported some Processing code (outputs sensor data to a textbox) to an
applet that includes the .jar and .html files. I have tried to insert this html on a
simple website that I created and the java applet doesn't work. Do I have to somehow
modify the html? I know that the .jar files are already in the same directory and
are referenced appropriately in the exported html code. Is there a better approach
to posting to a website? Thank you
I don't think that it is possible, due to security restrictions on applet communication.
More than likely you will have to write a small client/server program using sockets.
The idea would be to transmit the the output from your locally running client application to your applet(server) which would receive and display the data.
You could use any language with socket support obviously(Flash, PHP, etc.), but I assume you will want to stick with Java.
I am looking for a way to save a couple of files created with JavaScript on the clients computer. I want him to be able to choose a folder (similar to open/save folder dialog), and then write the files there. This obviously requires three things:
Ability to popup such a dialog.
Ability to write on the client's computer (signed applets?)
Some way to interact with JavaScript because it knows the filenames and contents to write.
Is this possible or should I just stop dreaming?
It sure is possible.
One way is to use a signed applet, but if your users are willing to upgrade to Java 1.6.0_10+, a signed applet is not needed. Since 1.6.0_10 (the Next Generation Java Plug-In), JNLP API services are available to embedded applets. Here is a demo. of the JNLP file services.
I see the other reply has already covered the applet/JS interaction.
It is possible with a signed applet.
I'd probably do it the other way around, let the javascript code pass all the data to the applet and the applet should open a FileDialog and write the file.
Calling javascript from java can be achieved via `JSObject, calling Java from Javascript is explained here
If your applet is signed you can do everything that you can do in regular application. You can open "File dialog" but it will be the Java's dialog, not the same that is opened when user pushes "browse" button of tag <intput type"file"/>. Obviously signed applet can perform read and write operations with user's disk.
All applets (either signed or unsigned) may call javascript using JSObject. You just have to say MAYSCRIPT="true" into applet tag.
I think that you cannot open the browser's "file open" dialog applet. Actually you even cannot open it using regular javascript. (I'd be happy to know that I am wrong at this point but I spent some time trying to do this and failed).