--- a/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java Tue Nov 24 18:46:17 2009 +0300
+++ b/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java Wed Nov 25 21:27:06 2009 +0300
@@ -28,14 +28,21 @@
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
+import java.io.BufferedReader;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -48,6 +55,8 @@
import sun.awt.datatransfer.DataTransferer;
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
+import java.io.ByteArrayOutputStream;
+
/**
* Platform-specific support for the data transfer subsystem.
*/
@@ -108,6 +117,22 @@
return super.getCharsetForTextFormat(lFormat);
}
+ protected boolean isURIListFormat(long format) {
+ String nat = getNativeForFormat(format);
+ if (nat == null) {
+ return false;
+ }
+ try {
+ DataFlavor df = new DataFlavor(nat);
+ if (df.getPrimaryType().equals("text") && df.getSubType().equals("uri-list")) {
+ return true;
+ }
+ } catch (Exception e) {
+ // Not a MIME format.
+ }
+ return false;
+ }
+
public boolean isFileFormat(long format) {
return format == FILE_NAME_ATOM.getAtom() ||
format == DT_NET_FILE_ATOM.getAtom();
@@ -170,6 +195,19 @@
}
}
+ protected ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList)
+ throws IOException
+ {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ for (int i = 0; i < fileList.size(); i++)
+ {
+ byte[] bytes = fileList.get(i).getBytes();
+ if (i != 0) bos.write(0);
+ bos.write(bytes, 0, bytes.length);
+ }
+ return bos;
+ }
+
/**
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
@@ -215,6 +253,52 @@
}
}
+ protected URI[] dragQueryURIs(InputStream stream,
+ byte[] bytes,
+ long format,
+ Transferable localeTransferable)
+ throws IOException {
+
+ String charset = null;
+ if (localeTransferable != null &&
+ isLocaleDependentTextFormat(format) &&
+ localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
+ try {
+ charset = new String(
+ (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor),
+ "UTF-8"
+ );
+ } catch (UnsupportedFlavorException cannotHappen) {
+ }
+ } else {
+ charset = getCharsetForTextFormat(format);
+ }
+ if (charset == null) {
+ // Only happens when we have a custom text type.
+ charset = getDefaultTextCharset();
+ }
+
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(stream, charset));
+ String line;
+ ArrayList<URI> uriList = new ArrayList<URI>();
+ URI uri;
+ while ((line = reader.readLine()) != null) {
+ try {
+ uri = new URI(line);
+ } catch (URISyntaxException uriSyntaxException) {
+ throw new IOException(uriSyntaxException);
+ }
+ uriList.add(uri);
+ }
+ return uriList.toArray(new URI[uriList.size()]);
+ } finally {
+ if (reader != null)
+ reader.close();
+ }
+ }
+
/**
* Returns true if and only if the name of the specified format Atom
* constitutes a valid MIME type with the specified primary type.