--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java 2015-09-21 16:51:52.000000000 +0300 +++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java 2015-09-21 16:51:52.000000000 +0300 @@ -1,3 +1,4 @@ + /* * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,12 +29,13 @@ import java.awt.*; import java.io.*; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.*; -import java.util.regex.*; import java.awt.datatransfer.*; import sun.awt.datatransfer.*; @@ -125,51 +127,30 @@ long format, Transferable transferable) throws IOException { if (format == CF_URL && URL.class.equals(flavor.getRepresentationClass())) { - String charset = Charset.defaultCharset().name(); - if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) { - try { - charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), "UTF-8"); - } catch (UnsupportedFlavorException cannotHappen) { - } + String[] strings = dragQueryFile(bytes); + if(strings.length == 0) { + return null; } - String xml = new String(bytes, charset); - // macosx pasteboard returns a property list that consists of one URL - // let's extract it. - return new URL(extractURL(xml)); - } - - if (format == CF_STRING) { + return new URL(strings[0]); + } else if(isUriListFlavor(flavor)) { + // dragQueryFile works fine with files and url, + // it parses and extracts values from property list. + // maxosx always returens property list for + // CF_URL and CF_FILE + String[] strings = dragQueryFile(bytes); + bytes = String.join(System.getProperty("line.separator"), + strings).getBytes(); + // now we extracted uri from xml, now we should treat it as + // regular string that allows to translate data to target represantation + // class by base method + format = CF_STRING; + } else if (format == CF_STRING) { bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8"); } return super.translateBytes(bytes, flavor, format, transferable); } - /** - * Macosx pasteboard returns xml document that contains one URL, for exmple: - *
- * {@code - * - * - *- */ - private String extractURL(String xml) { - Pattern urlExtractorPattern = Pattern.compile("- * - * } - *- * - *file:///path_to_file - *- *