src/share/classes/java/awt/datatransfer/SystemFlavorMap.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


 164      * SoftReferences which reference Lists of String natives.
 165      */
 166     private Map<DataFlavor, SoftReference<List<String>>> getNativesForFlavorCache = new HashMap<>();
 167 
 168     /**
 169      * Caches the result getFlavorsForNative(). Maps String natives to
 170      * SoftReferences which reference Lists of DataFlavors.
 171      */
 172     private Map<String, SoftReference<List<DataFlavor>>> getFlavorsForNativeCache = new HashMap<>();
 173 
 174     /**
 175      * Dynamic mapping generation used for text mappings should not be applied
 176      * to the DataFlavors and String natives for which the mappings have been
 177      * explicitly specified with setFlavorsForNative() or
 178      * setNativesForFlavor(). This keeps all such keys.
 179      */
 180     private Set disabledMappingGenerationKeys = new HashSet();
 181 
 182     /**
 183      * Returns the default FlavorMap for this thread's ClassLoader.

 184      */
 185     public static FlavorMap getDefaultFlavorMap() {
 186         ClassLoader contextClassLoader =
 187             Thread.currentThread().getContextClassLoader();
 188         if (contextClassLoader == null) {
 189             contextClassLoader = ClassLoader.getSystemClassLoader();
 190         }
 191 
 192         FlavorMap fm;
 193 
 194         synchronized(flavorMaps) {
 195             fm = flavorMaps.get(contextClassLoader);
 196             if (fm == null) {
 197                 fm = new SystemFlavorMap();
 198                 flavorMaps.put(contextClassLoader, fm);
 199             }
 200         }
 201 
 202         return fm;
 203     }


1292     /**
1293      * Decodes a <code>String</code> native for use as a Java MIME type.
1294      *
1295      * @param nat the <code>String</code> to decode
1296      * @return the decoded Java MIME type, or <code>null</code> if nat is not
1297      *         an encoded <code>String</code> native
1298      */
1299     public static String decodeJavaMIMEType(String nat) {
1300         return (isJavaMIMEType(nat))
1301             ? nat.substring(JavaMIME.length(), nat.length()).trim()
1302             : null;
1303     }
1304 
1305     /**
1306      * Decodes a <code>String</code> native for use as a
1307      * <code>DataFlavor</code>.
1308      *
1309      * @param nat the <code>String</code> to decode
1310      * @return the decoded <code>DataFlavor</code>, or <code>null</code> if
1311      *         nat is not an encoded <code>String</code> native


1312      */
1313     public static DataFlavor decodeDataFlavor(String nat)
1314         throws ClassNotFoundException
1315     {
1316         String retval_str = SystemFlavorMap.decodeJavaMIMEType(nat);
1317         return (retval_str != null)
1318             ? new DataFlavor(retval_str)
1319             : null;
1320     }
1321 
1322     private List<String> getAllNativesForType(String type) {
1323         Set<String> retval = null;
1324         for (DataFlavor dataFlavor : convertMimeTypeToDataFlavors(type)) {
1325             List<String> natives = getFlavorToNative().get(dataFlavor);
1326             if (natives != null && !natives.isEmpty()) {
1327                 if (retval == null) {
1328                     retval = new LinkedHashSet<>();
1329                 }
1330                 retval.addAll(natives);
1331             }
   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


 164      * SoftReferences which reference Lists of String natives.
 165      */
 166     private Map<DataFlavor, SoftReference<List<String>>> getNativesForFlavorCache = new HashMap<>();
 167 
 168     /**
 169      * Caches the result getFlavorsForNative(). Maps String natives to
 170      * SoftReferences which reference Lists of DataFlavors.
 171      */
 172     private Map<String, SoftReference<List<DataFlavor>>> getFlavorsForNativeCache = new HashMap<>();
 173 
 174     /**
 175      * Dynamic mapping generation used for text mappings should not be applied
 176      * to the DataFlavors and String natives for which the mappings have been
 177      * explicitly specified with setFlavorsForNative() or
 178      * setNativesForFlavor(). This keeps all such keys.
 179      */
 180     private Set disabledMappingGenerationKeys = new HashSet();
 181 
 182     /**
 183      * Returns the default FlavorMap for this thread's ClassLoader.
 184      * @return the default FlavorMap for this thread's ClassLoader
 185      */
 186     public static FlavorMap getDefaultFlavorMap() {
 187         ClassLoader contextClassLoader =
 188             Thread.currentThread().getContextClassLoader();
 189         if (contextClassLoader == null) {
 190             contextClassLoader = ClassLoader.getSystemClassLoader();
 191         }
 192 
 193         FlavorMap fm;
 194 
 195         synchronized(flavorMaps) {
 196             fm = flavorMaps.get(contextClassLoader);
 197             if (fm == null) {
 198                 fm = new SystemFlavorMap();
 199                 flavorMaps.put(contextClassLoader, fm);
 200             }
 201         }
 202 
 203         return fm;
 204     }


1293     /**
1294      * Decodes a <code>String</code> native for use as a Java MIME type.
1295      *
1296      * @param nat the <code>String</code> to decode
1297      * @return the decoded Java MIME type, or <code>null</code> if nat is not
1298      *         an encoded <code>String</code> native
1299      */
1300     public static String decodeJavaMIMEType(String nat) {
1301         return (isJavaMIMEType(nat))
1302             ? nat.substring(JavaMIME.length(), nat.length()).trim()
1303             : null;
1304     }
1305 
1306     /**
1307      * Decodes a <code>String</code> native for use as a
1308      * <code>DataFlavor</code>.
1309      *
1310      * @param nat the <code>String</code> to decode
1311      * @return the decoded <code>DataFlavor</code>, or <code>null</code> if
1312      *         nat is not an encoded <code>String</code> native
1313      * @throws ClassNotFoundException if the class of the data flavor
1314      * is not loaded
1315      */
1316     public static DataFlavor decodeDataFlavor(String nat)
1317         throws ClassNotFoundException
1318     {
1319         String retval_str = SystemFlavorMap.decodeJavaMIMEType(nat);
1320         return (retval_str != null)
1321             ? new DataFlavor(retval_str)
1322             : null;
1323     }
1324 
1325     private List<String> getAllNativesForType(String type) {
1326         Set<String> retval = null;
1327         for (DataFlavor dataFlavor : convertMimeTypeToDataFlavors(type)) {
1328             List<String> natives = getFlavorToNative().get(dataFlavor);
1329             if (natives != null && !natives.isEmpty()) {
1330                 if (retval == null) {
1331                     retval = new LinkedHashSet<>();
1332                 }
1333                 retval.addAll(natives);
1334             }