8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.lwawt.macosx; 27 28 import java.awt.*; 29 import java.awt.datatransfer.*; 30 import java.io.IOException; 31 import java.io.NotSerializableException; 32 import java.util.*; 33 34 import sun.awt.datatransfer.*; 35 36 37 /** 38 * A class which interfaces with Cocoa's pasteboard in order to support 39 * data transfer via Clipboard operations. Most of the work is provided by 40 * sun.awt.datatransfer.DataTransferer. 41 */ 42 43 final class CClipboard extends SunClipboard { 44 45 public CClipboard(String name) { 46 super(name); 47 } 48 49 @Override 50 public long getID() { 51 return 0; 52 } 53 54 @Override 55 protected void clearNativeContext() { 56 // Leaving Empty, as WClipboard.clearNativeContext is empty as well. 57 } 58 59 @Override 60 protected void setContentsNative(Transferable contents) { 61 FlavorTable flavorMap = getDefaultFlavorTable(); 62 // Don't use delayed Clipboard rendering for the Transferable's data. 63 // If we did that, we would call Transferable.getTransferData on 64 // the Toolkit thread, which is a security hole. 65 // 66 // Get all of the target formats into which the Transferable can be 67 // translated. Then, for each format, translate the data and post 68 // it to the Clipboard. 69 DataTransferer dataTransferer = DataTransferer.getInstance(); 70 long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap); 71 declareTypes(formatArray, this); 72 73 Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap); 74 for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) { 75 long format = entry.getKey(); 76 DataFlavor flavor = entry.getValue(); 77 78 try { 79 byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format); 80 setData(bytes, format); 81 } catch (IOException e) { 82 // Fix 4696186: don't print exception if data with 83 // javaJVMLocalObjectMimeType failed to serialize. 84 // May remove this if-check when 5078787 is fixed. 85 if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) && 86 e instanceof NotSerializableException)) { 87 e.printStackTrace(); 88 } 89 } 90 } 91 92 notifyChanged(); 93 } 94 95 @Override 96 protected native long[] getClipboardFormats(); 97 @Override 98 protected native byte[] getClipboardData(long format) throws IOException; 99 | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.lwawt.macosx; 27 28 import sun.awt.datatransfer.desktop.DataTransferer; 29 import sun.awt.datatransfer.desktop.SunClipboard; 30 31 import java.awt.*; 32 import java.awt.datatransfer.*; 33 import java.io.IOException; 34 import java.io.NotSerializableException; 35 import java.util.*; 36 37 38 /** 39 * A class which interfaces with Cocoa's pasteboard in order to support 40 * data transfer via Clipboard operations. Most of the work is provided by 41 * {@link sun.awt.datatransfer.desktop.DataTransferer}. 42 */ 43 44 final class CClipboard extends SunClipboard { 45 46 public CClipboard(String name) { 47 super(name); 48 } 49 50 @Override 51 public long getID() { 52 return 0; 53 } 54 55 @Override 56 protected void clearNativeContext() { 57 // Leaving Empty, as WClipboard.clearNativeContext is empty as well. 58 } 59 60 @Override 61 protected void setContentsNative(Transferable contents) { 62 FlavorTable flavorMap = getDefaultFlavorTable(); 63 // Don't use delayed Clipboard rendering for the Transferable's data. 64 // If we did that, we would call Transferable.getTransferData on 65 // the Toolkit thread, which is a security hole. 66 // 67 // Get all of the target formats into which the Transferable can be 68 // translated. Then, for each format, translate the data and post 69 // it to the Clipboard. 70 DataTransferer dataTransferer = DataTransferer.getInstance(); 71 long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap); 72 declareTypes(formatArray, this); 73 74 Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap); 75 for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) { 76 long format = entry.getKey(); 77 DataFlavor flavor = entry.getValue(); 78 79 try { 80 byte[] bytes = dataTransferer.translateTransferable(contents, flavor, format); 81 setData(bytes, format); 82 } catch (IOException e) { 83 // Fix 4696186: don't print exception if data with 84 // javaJVMLocalObjectMimeType failed to serialize. 85 // May remove this if-check when 5078787 is fixed. 86 if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) && 87 e instanceof NotSerializableException)) { 88 e.printStackTrace(); 89 } 90 } 91 } 92 93 notifyChanged(); 94 } 95 96 @Override 97 protected native long[] getClipboardFormats(); 98 @Override 99 protected native byte[] getClipboardData(long format) throws IOException; 100 |