I know there is a security policy restriction that does not allow cutting, copying, and pasting between an applet and some other application in the more recent versions of Java. However, my users need this functionality. Changing the java security policy file as defined here:
https://blogs.oracle.com/kyle/entry/copy_and_paste_in_java
is impractical when dealing with a distributed application that is used by 100's of users. So are there other alternatives that can be done in code? This is a signed applet.
From within a Java applet, even a signed one, I could not figure out how to access the system clipboard. Statements like this:
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Actually freeze the applet making it impossible to continue. This is using Java 1.8.
I read something here:
https://brooknovak.wordpress.com/2009/07/28/accessing-the-system-clipboard-with-javascript/
That provided the basis for a work around. Basically, you capture the selected text (assuming it is text that you want to move to the system clipboard) in java then make a call from within the applet to a Javascript method with the selected text as a parameter. Javascript has built in methods that allow population of the system clipboard. The details are in the link above. Note, this was only tested with Internet Explorer 11.
Related
This might sound like a ridiculous question, but I have to ask it because I have a working product which is doing this.
I have an applet running inside a browser. This applet is just not just any applet, but a fairly complex package application for CRM/ERP. I was told by a vendor company that they are able to monitor what a user does inside the applet, by replacing applet's main class at runtime before launch with their own. The term used was "endorsing".
I am a bit clueless now. How can you look inside an applet and listen on user clicks and keyboard events, even if you could somehow hack into it? I can tell you that this is a true story, because I have seen this vendor company's applicaiton and it just sits in the background and records all the contextual information (for instance, user filled which textbox in the applet, the name of the textbox and etc).
Are they any hacks at classloading level (I feel stupid asking this), or something else that I have not come across in java that would let you do something 'urban legendary' like this?
Java Applets are loaded using a HTML tags like this:
<applet archive="ApplicationSP1.jar,Application.jar" code="Main.class" name="myApp" width="800" height="600"></applet>
As you can see, the "archive" attribute supports several .jar files.
You could use this technique to load your own versions of the Java Classes of the application by putting them in the ApplicationSP1.jar file. They will be loaded before those classes stored in the second Application.jar.
Obviously, you would need to do some reverse engineering to understand which classes from the original application to override or wrap. Then you have to create new ones named exactly (same package and class name) as those you want to override.
Other option would be developing Aspects to capture events in the application and load these aspects using same technique of multiple .jar in the archive attribute of the HTML applet tag.
The solution for capturing Swing/AWT event can be found in
Want javax.swing hook that tells me WHICH component in the hierarchy is executing an action
It is difficult for overwriting Swing/AWT class used by applet which launching from browser.
They have to breaking the protection of Java security manager and get writing permission of JRE endorsed library folder.
For this case, Java Endorsed Standards Override Mechanism is hard to implement without manually operation of end user.
Can someone explain how does this website accesses the contents of the clipboard and displays it?
http://snag.gy
I am working on a similar project and need to make use of this functionality where users can ctrl+v paste an image. Also, if the site is using Java plug-in, why doesn't my chrome pop up out-of-date warning?
Any help is appreciated!
Thank you.
You should be able to tell that by looking at the source (http://snag.gy/assets/js/index.min.js). The code will be unreadable since it's minified, but you can make it readable with a code beautifier (such as http://jsbeautifier.org/).
It uses a java applet to read your clipboard (it's adding it to the page dynamically). It also contains a reference to http://code.google.com/p/zeroclipboard/ which is a flash-based solution mentioned here . I saw that it also makes use of the clipboardData object.
Looks like there are several fallbacks depending on the browser, and also it uses different mechanisms based on the origin of the copied data. You could start with How does the paste image from clipboard functionality work in Gmail and Google Chrome 12+? and fallback to a java applet if the browser is older.
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 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).
I need assistance finding a delivery method that best fulfills the following requirements:
We wish to deliver a single file to my clients.
Clients should be able to launch this file from the operating system shell - much like running an '.exe' on Windows.
After being launched, the program/script should be able to display a window with HTML content. this may be done using a stand alone program, a runtime or by running within a browser.
We need the ability to embed a resource within the delivered file, such as an mp3 file, which i can later extract programmatically.
Optimally, the solution should run on Windows, Mac and Linux machines. Less than perfect cross-platform interoperability is acceptable, but we want as broad a penetration as possible.
Clients should not need to pre-install anything (unless it is done transparently), pre-configure anything, or approve any thing for this to happen.
For example:
We could use a regular executable file, written in C++ to do this, but it will not be cross-platform.
We could use a sliverlight XAP file, an adobe Flex file or a Java JAR, but internet explorer warns users when local content is launched. In addition these approaches mean that we have less than perfect penetration, even though it is acceptable in these cases.
We could use a python (or equivalent) script, but the installed-base (penetration) of the python interpreter is not good enough.
Using a standard HTML is not enough because of the difficulty of embedding resources in it. Embedding Silverlight XAML or uuencoded content in HTML causes IE to display a warning.
Using something along the lines of a jpeg as a delivery method is not rich enough since we need to display HTML.
..but internet explorer warns users when local content is launched..
I don't get it, what's the problem with IE saying "Hey this app is trying to run your files!"
I don't mean you don't have a good reason for this, it is just, I don't get it.
IE will only warn the user if the app has not been downloaded and try to access local resources, for instance if running from an applet or a JNLP like this one:(click on the first orange button you see )
But if the users download the jar and run it from the computer ( double click on it ) the app is local and can run without problems.
The jar file is a zip file after all, so you can attach your mp3 file with it. Double click is supported in the desired platform, and the HTML content could be either a local file ( un-packed along with the mp3 file ) or an internet web page.
Java is preinstalled on those OS already.
"internet explorer warns users when local content is launched"
There's a reason for this. How can they distinguish your excellent, well-behaved, polite application from a virus?
Since the line between your app and a virus is very, very blurry, go with any of Silverlight XAP file, an adobe Flex file or a Java JAR.
The IE business is a good thing, not a bad thing.
You could try using the 'Jetty' application server.
This supposes there is a working java environment on the target machine.
Jetty is java servlet container but it is possible to configure
everything (web server, html templates, applications, etc.) in a
single executable jar, which launches the web server and opens a default page.
Exactly how the jar file is launched will vary from platform to platform
but otherwise the user interface will be identicle, and, as its a java application
you can do pretty much anything one it has started.
Sounds like MIME HTML does exactly what you want - unfortunately, it is not supported by many browsers other than IE.
I'd investigate Adobe AIR. It can display both HTML and Flex content in a desktop application without using a web browser. However this will require installation of the AIR runtime, also I'm not sure if the Linux version is out of the beta stage.
http://www.adobe.com/products/air/
You can also use a binary for each platform.
As per your description the app is very simple, and porting from one platf to another sounds like just matter of re-compile and offer binary based on the dist.
Is this an option?