Getting the contents from client's clipboard like this website - java

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.

Related

Copy and Paste Between Applet and Other Applications

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.

Get source of data in clipboard

How can I know what is the source of data in clipboard?
For example when I copy something from Firefox to clipboard I want to get that the source is Firefox.
Is there any command to do that in Linux? Or is there a way to do that in Java?
Also, is there any way to track were the user pasted the data.
I want to detect if for example the user try to copy important data from organization's system, then s/he try to paste it some where else.
Thanks in advance for any help (:
It's not a language issue, it's an API issue. In Windows, the GetClipboardOwner() API call usually indicates the application that last updated the clipboard (via a handle). It's not 100% reliable. For example, if the application has terminated, then it will be null.
This function exists in Java but seems to be even less reliable, and may be mostly unused, according to this post:
Java clipboardOwner Purpose?
I think your best solution is to use the presence/absence of various clipboard formats to look for evidence. Simple formats like TEXT won't help, but complex formats like RTF and HTML will reveal clues. On Windows, there is a format for "html fragments" called CF_HTML, which has a header that looks different from one browser to the next. I would imagine that something similar exits with Java/Linux? Looking at the docs, there's something called a DataFlavor, that seems to have a very rich set of properties such as mimetype. It's possible that you could get a "fingerprint" of FireFox by looking at the attributes of each dataflavor present when copying.
There is no way to determine the source of the data in the clipboard in Java (for Linux I'm not sure but I doubt it).
To ensure that sensible Data does not leave your application do not allow the data to be copied or keep the data in an application internal clipboard and do not forward it to the system clipboard. In Java you have the control over your data being copied to the system clipboard or not.
If you use an application internal clipboard then be aware that a user could copy the sensible data first to a target that allows copying the content to the system clipboard and then copy it further out of your application.

Java Applet: Edit and upload changed documents

In a work-related project, we want users to be able to write a document (in say Word) then upload this to our central web server. When they want to make changes, they visit the website and downloads the document. When changes are registered, the document is uploaded automatically.
I have written a few Java classes that does the work for me (FTP upload/download, File monitoring etc), but I'd like some input on how to solve the practical part of it.
Should the web page include a Java Applet that contains a Download button? When clicked, the document is downloaded and the associated editor is opened.
If so, how should I proceed? If the user closes his browser, wont be applet be terminated as well?
I have never worked on a such project before, and since Stackoverflow is filled with incredible smart people, maybe some of you could come up with some ideas?
PS: I'm new to posting on Stack, so please let me know if I should be more specific / add more information etc. :)
Best regards!
EDIT:
The application is only going to be used internally in our offices. Sorry if I caused confusion. :)

"Inspect Element" tool for Java UI

I was looking for tool on Java that does the same (similar) functionality of "inspect element" of "Google Chrome". Does anyone has information whether this is available and how it can be implemented?
The question refers to cases when you have the Source code and you don't know the inside of it. Thus, the idea is to inspect elements (objects) on UI while running code!
Since you have access to the code you can use the Java Object Inspector.
Just add one line of code at the right place:
Inspector.inspect(objectToInspect);
Inspect Element in Chrome/Firefox and View Source in Safari are there because the internet is open sourced. The HTML code pushed to a user's machine is viewable by them (obviously not the spreadsheets or other static files held on a server.)
Compiled projects don't have this feature for practical reasons.
In many languages it is impossible to "decompile" an object into its source.
If you could go to Microsoft Word and Inspect any element, you could just copy and paste their application without paying.
So no, you cannot take a compiled Java object and click to see its source code.
I remember hearing about a project that did something like that a few years ago. I can't recall the name, but I ran across this while searching for it. https://github.com/cozycode/Swing-Inspector Based on the description, at least. it looks like it might be useful. If I remember what the original project was i'll post a follow up.
for you to find the java code, in the inspect element go to Sources. Look in the picture below. I inspected google and went to Sources this what i found. press on the files. that say js, and the java code will appear.
if you cant see the pic, tell me. or try to download it, and open it on paint.
enter image description here

Creating online help in Java Swing application - using pdf user docs

I am trying to link some user docs to my Java Swing application. The user docs are pdf and I would like to be able to click on a button in my application which opens up some sort of pdf renderer to display my userdoc.pdf.
I do not want to use the runtime exec command
I have tried the following with not much success --
pdfRenderer -- this seems to not work for the current version of pdfs (seems to want older pdfs)
acrobat viewer -- I keep getting font errors (the document is displayed but everytime I go to a new page, I get an error)
JPedal pdfHelp - This sounds cool and if it will work, it would be the best for me. But for some reason, I am unable to open any file here. No pdf file that I have loads in the window (The pdfHelp panel comes up with a list of pdfs as promised, but when I right click one of them and say "OpenPDF", I just get a progress bar and the file does not load, I have tried a few files on this and checked file permissions)
JPedal SimpleViewer -- So far this one seems to be the most promising. I would like to remove some of the functionality of this viewer though and am not able to edit the xml to do this. When I edit the xml, then I seem to get xml parsing errors.
Has anybody done anything similar that worked? Help please
PS. I need this to work on Linux machines (IcePDF seems to works only for Windows). I would very much prefer something that is free!
Would Java's Desktop API meet your requirements? It does launch another process, but it's not through you calling Runtime.exec().
The Desktop API uses your host operating system's file associations to launch applications associated with specific file types.
Update: pdfHelp from IDR solutions (creators of JPedal) works now. The latest version (4.0) has fixed the bug and it reads my pdf files (and I am sure more of the latest pdf files). Just playing around with the product today and it is great! There are few minor bugs but I really appreciate how quickly Mark Stephens(?) responded to the first bug. Good work guys!
I chose pdfbox for a similar use case - it's not perfect with every PDF, but works pretty well and is under active development. From the PDDocument you can get a list of PDPage objects, which have a convertToImage() method that gives you a BufferedImage you can draw on screen. I switched to this from pdf-renderer because I felt it gave better results in general.
PdfHelp has moved to its own domain at http://www.pdfhelp.org and have been updated to fix your issues and add some other improvements...

Categories

Resources