diff --git a/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java b/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java index 26d2347ff15bae39c7cca16f282e6e6fc184812a..f82d5930a630e983f863526b01147fe90d02ac4f 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java +++ b/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java @@ -27,13 +27,13 @@ package sun.lwawt.macosx; import java.awt.*; import java.awt.image.*; -import sun.awt.image.ImageRepresentation; import java.io.*; import java.net.URL; import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.*; +import java.util.regex.*; import java.awt.datatransfer.*; import sun.awt.datatransfer.*; @@ -122,26 +122,52 @@ public class CDataTransferer extends DataTransferer { @Override public Object translateBytes(byte[] bytes, DataFlavor flavor, - long format, Transferable transferable) throws IOException { - - if (format == CF_URL && URL.class.equals(flavor.getRepresentationClass())) - { - String charset = getDefaultTextCharset(); - if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) { - try { - charset = new String((byte[])transferable.getTransferData(javaTextEncodingFlavor), "UTF-8"); - } catch (UnsupportedFlavorException cannotHappen) { - } - } + long format, Transferable transferable) throws IOException { - return new URL(new String(bytes, charset)); - } - if (format == CF_STRING) { - bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8"); + if (format == CF_URL && URL.class.equals(flavor.getRepresentationClass())) { + String charset = getDefaultTextCharset(); + if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) { + try { + charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), "UTF-8"); + } catch (UnsupportedFlavorException cannotHappen) { + } } - return super.translateBytes(bytes, flavor, format, transferable); + String xml = new String(bytes, charset); + // macosx pastboard returns a propery list that contins of one URL + // let's extract it. + return new URL(extractURL(xml)); + } else if (format == CF_STRING) { + bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8"); + } + + return super.translateBytes(bytes, flavor, format, transferable); + } + + /** + * Macosx pastboard returns xml document that contains one URL, for exmple: + *
+ * {@code + * + * + *+ */ + private String extractURL(String xml) { + Pattern urlExtractorPattern = Pattern.compile("+ * + * } + *+ * + *file:///Users/mcherkas/Downloads/Version.jpg + *+ *