2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The SystemFlavorMap is a configurable map between "natives" (Strings), which 0N/A * correspond to platform-specific data formats, and "flavors" (DataFlavors), 0N/A * which correspond to platform-independent MIME types. This mapping is used 0N/A * by the data transfer subsystem to transfer data between Java and native 0N/A * applications, and between Java applications in separate VMs. 0N/A * In the Sun reference implementation, the default SystemFlavorMap is 0N/A * contents of the URL referenced by the AWT property 0N/A * Constant prefix used to tag Java types converted to native platform 0N/A * System singleton which maps a thread's ClassLoader to a SystemFlavorMap. 0N/A * The list of valid, decoded text flavor representation classes, in order 0N/A * from best to worst. 0N/A "java.io.Reader",
"java.lang.String",
"java.nio.CharBuffer",
"\"[C\"" 0N/A * The list of valid, encoded text flavor representation classes, in order 0N/A * from best to worst. 0N/A "java.io.InputStream",
"java.nio.ByteBuffer",
"\"[B\"" 0N/A * This constant is passed to flavorToNativeLookup() to indicate that a 0N/A * a native should be synthesized, stored, and returned by encoding the 0N/A * DataFlavor's MIME type in case if the DataFlavor is not found in 0N/A * 'flavorToNative' map. 0N/A * Maps native Strings to Lists of DataFlavors (or base type Strings for 0N/A * text DataFlavors). 86N/A * Do not use the field directly, use getNativeToFlavor() instead. 86N/A * Accessor to nativeToFlavor map. Since we use lazy initialization we must 86N/A * use this accessor instead of direct access to the field which may not be 86N/A * initialized yet. This method will initialize the field if needed. 86N/A * @return nativeToFlavor 0N/A * Maps DataFlavors (or base type Strings for text DataFlavors) to Lists of 86N/A * Do not use the field directly, use getFlavorToNative() instead. 86N/A * Accessor to flavorToNative map. Since we use lazy initialization we must 86N/A * use this accessor instead of direct access to the field which may not be 86N/A * initialized yet. This method will initialize the field if needed. 86N/A * @return flavorToNative 86N/A * Shows if the object has been initialized. 0N/A * Caches the result of getNativesForFlavor(). Maps DataFlavors to 0N/A * SoftReferences which reference Lists of String natives. 0N/A * Caches the result getFlavorsForNative(). Maps String natives to 0N/A * SoftReferences which reference Lists of DataFlavors. 0N/A * Dynamic mapping generation used for text mappings should not be applied 0N/A * to the DataFlavors and String natives for which the mappings have been 0N/A * explicitly specified with setFlavorsForNative() or 0N/A * setNativesForFlavor(). This keeps all such keys. 0N/A * Returns the default FlavorMap for this thread's ClassLoader. 0N/A * AWT.DnD.flavorMapFileURL. 86N/A * For thread-safety must be called under lock on this. 0N/A * only way to handle duplicate keys and values. 0N/A // Continue lines that end in slashes if they are not comments 0N/A // Advance beyond whitespace on new line 0N/A // Find start of key 0N/A // Blank lines are ignored 0N/A // Find separation between key and value 0N/A // Skip over whitespace after key if any 0N/A // Skip over one non whitespace key value separators if any 0N/A // Skip over white space after other separators if any 0N/A // Convert then store key and value 0N/A // We need to store the charset and eoln 0N/A // parameters, if any, so that the 0N/A // DataTransferer will have this information 0N/A // for conversion into the native format. 0N/A // But don't store any of these parameters in the 0N/A // DataFlavor itself for any text natives (even 0N/A // non-charset ones). The SystemFlavorMap will 0N/A // synthesize the appropriate mappings later. 0N/A // For text/* flavors, store mappings in separate maps to 0N/A // enable dynamic mapping generation at a run-time. 0N/A for (
int i =
0; i <
4; i++) {
0N/A case '0':
case '1':
case '2':
case '3':
case '4':
0N/A case '5':
case '6':
case '7':
case '8':
case '9': {
0N/A case 'a':
case 'b':
case 'c':
0N/A case 'd':
case 'e':
case 'f': {
0N/A case 'A':
case 'B':
case 'C':
0N/A case 'D':
case 'E':
case 'F': {
0N/A "Malformed \\uxxxx encoding.");
0N/A * Stores the listed object under the specified hash key in map. Unlike a 0N/A * standard map, the listed object will not replace any object already at 0N/A * the appropriate Map location, but rather will be appended to a List 0N/A * stored in that location. 0N/A * Semantically equivalent to 'nativeToFlavor.get(nat)'. This method 0N/A * handles the case where 'nat' is not found in 'nativeToFlavor'. In that 0N/A * case, a new DataFlavor is synthesized, stored, and returned, if and 0N/A * only if the specified native is encoded as a Java MIME type. 0N/A // Prepending the platform-specific mappings ensures 0N/A // that the flavors added with 0N/A // addFlavorForUnencodedNative() are at the end of 0N/A "\"while constructing DataFlavor for: " +
0N/A * Semantically equivalent to 'flavorToNative.get(flav)'. This method 0N/A * handles the case where 'flav' is not found in 'flavorToNative' depending 0N/A * on the value of passes 'synthesize' parameter. If 'synthesize' is 0N/A * SYNTHESIZE_IF_NOT_FOUND a native is synthesized, stored, and returned by 0N/A * encoding the DataFlavor's MIME type. Otherwise an empty List is returned 0N/A * and 'flavorToNative' remains unaffected. 0N/A // Prepend the platform-specific mappings to ensure 0N/A // that the natives added with 0N/A // addUnencodedNativeForFlavor() are at the end of 0N/A * Returns a <code>List</code> of <code>String</code> natives to which the 0N/A * specified <code>DataFlavor</code> can be translated by the data transfer 0N/A * subsystem. The <code>List</code> will be sorted from best native to 0N/A * worst. That is, the first native will best reflect data in the specified 0N/A * flavor to the underlying native platform. 0N/A * If the specified <code>DataFlavor</code> is previously unknown to the 0N/A * data transfer subsystem and the data transfer subsystem is unable to 0N/A * translate this <code>DataFlavor</code> to any existing native, then 0N/A * invoking this method will establish a 0N/A * mapping in both directions between the specified <code>DataFlavor</code> 0N/A * and an encoded version of its MIME type as its native. 0N/A * @param flav the <code>DataFlavor</code> whose corresponding natives 0N/A * should be returned. If <code>null</code> is specified, all 0N/A * natives currently known to the data transfer subsystem are 0N/A * returned in a non-deterministic order. 0N/A * @return a <code>java.util.List</code> of <code>java.lang.String</code> 0N/A * objects which are platform-specific representations of platform- 0N/A * specific data formats 0N/A * @see #encodeDataFlavor 0N/A // Check cache, even for null flav 0N/A // Create a copy, because client code can modify the returned 0N/A // In this case we shouldn't synthesize a native for this flavor, 0N/A // since its mappings were explicitly specified. 0N/A // For text/* flavors, flavor-to-native mappings specified in 0N/A // To prevent the List stored in the map from modification. 0N/A // Also include text/plain natives, but don't duplicate Strings 0N/A // To prevent the List stored in the map from modification. 0N/A // This also guarantees that removeAll() is supported. 0N/A // Use HashSet to get constant-time performance for search. 0N/A // In this branch it is guaranteed that natives explicitly 0N/A // listed for flav's MIME type were added with 0N/A // addUnencodedNativeForFlavor(), so they have lower priority. 0N/A // flavorToNativeLookup() never returns null. 0N/A // It can return an empty List, however. 0N/A // To prevent the List stored in the map from modification. 0N/A // This also guarantees that removeAll() is supported. 0N/A // Use HashSet to get constant-time performance for search. 0N/A // In this branch it is guaranteed that natives explicitly 0N/A // listed for flav's MIME type were added with 0N/A // addUnencodedNativeForFlavor(), so they have lower priority. 0N/A // flavorToNativeLookup() never returns null. 0N/A // It can return an empty List, however. 0N/A // To prevent the List stored in the map from modification. 0N/A // Use HashSet to get constant-time performance for search. 0N/A // Create a copy, because client code can modify the returned list. 0N/A * Returns a <code>List</code> of <code>DataFlavor</code>s to which the 0N/A * specified <code>String</code> native can be translated by the data 0N/A * transfer subsystem. The <code>List</code> will be sorted from best 0N/A * <code>DataFlavor</code> to worst. That is, the first 0N/A * <code>DataFlavor</code> will best reflect data in the specified 0N/A * native to a Java application. 0N/A * If the specified native is previously unknown to the data transfer 0N/A * subsystem, and that native has been properly encoded, then invoking this 0N/A * method will establish a mapping in both directions between the specified 0N/A * native and a <code>DataFlavor</code> whose MIME type is a decoded 0N/A * version of the native. 0N/A * If the specified native is not a properly encoded native and the 0N/A * mappings for this native have not been altered with 0N/A * <code>setFlavorsForNative</code>, then the contents of the 0N/A * <code>List</code> is platform dependent, but <code>null</code> 0N/A * cannot be returned. 0N/A * @param nat the native whose corresponding <code>DataFlavor</code>s 0N/A * should be returned. If <code>null</code> is specified, all 0N/A * <code>DataFlavor</code>s currently known to the data transfer 0N/A * subsystem are returned in a non-deterministic order. 0N/A * @return a <code>java.util.List</code> of <code>DataFlavor</code> 0N/A * objects into which platform-specific data in the specified, 0N/A * platform-specific native can be translated 0N/A * @see #encodeJavaMIMEType 0N/A // Check cache, even for null nat 0N/A // Cannot happen, since we checked all mappings 0N/A // Check for equality to plainTextFlavor so 0N/A // that we can ensure that the exact charset of 0N/A // plainTextFlavor, not the canonical charset 0N/A // or another equivalent charset with a 0N/A // different name, is used. 0N/A // Non-charset text natives should be treated as 0N/A // opaque, 8-bit data in any of its various 0N/A * Returns a <code>Map</code> of the specified <code>DataFlavor</code>s to 0N/A * their most preferred <code>String</code> native. Each native value will 0N/A * be the same as the first native in the List returned by 0N/A * <code>getNativesForFlavor</code> for the specified flavor. 0N/A * If a specified <code>DataFlavor</code> is previously unknown to the 0N/A * data transfer subsystem, then invoking this method will establish a 0N/A * mapping in both directions between the specified <code>DataFlavor</code> 0N/A * and an encoded version of its MIME type as its native. 0N/A * @param flavors an array of <code>DataFlavor</code>s which will be the 0N/A * key set of the returned <code>Map</code>. If <code>null</code> is 0N/A * specified, a mapping of all <code>DataFlavor</code>s known to the 0N/A * data transfer subsystem to their most preferred 0N/A * <code>String</code> natives will be returned. 0N/A * @return a <code>java.util.Map</code> of <code>DataFlavor</code>s to 0N/A * <code>String</code> natives 0N/A * @see #getNativesForFlavor 0N/A * @see #encodeDataFlavor 0N/A // Use getNativesForFlavor to generate extra natives for text flavors 0N/A * Returns a <code>Map</code> of the specified <code>String</code> natives 0N/A * to their most preferred <code>DataFlavor</code>. Each 0N/A * <code>DataFlavor</code> value will be the same as the first 0N/A * <code>DataFlavor</code> in the List returned by 0N/A * <code>getFlavorsForNative</code> for the specified native. 0N/A * If a specified native is previously unknown to the data transfer 0N/A * subsystem, and that native has been properly encoded, then invoking this 0N/A * method will establish a mapping in both directions between the specified 0N/A * native and a <code>DataFlavor</code> whose MIME type is a decoded 0N/A * version of the native. 0N/A * @param natives an array of <code>String</code>s which will be the 0N/A * key set of the returned <code>Map</code>. If <code>null</code> is 0N/A * specified, a mapping of all supported <code>String</code> natives 0N/A * to their most preferred <code>DataFlavor</code>s will be 0N/A * @return a <code>java.util.Map</code> of <code>String</code> natives to 0N/A * <code>DataFlavor</code>s 0N/A * @see #getFlavorsForNative 0N/A * @see #encodeJavaMIMEType 0N/A // Use getFlavorsForNative to generate extra flavors for text natives 0N/A * Adds a mapping from the specified <code>DataFlavor</code> (and all 0N/A * <code>DataFlavor</code>s equal to the specified <code>DataFlavor</code>) 0N/A * to the specified <code>String</code> native. 0N/A * Unlike <code>getNativesForFlavor</code>, the mapping will only be 0N/A * established in one direction, and the native will not be encoded. To 0N/A * establish a two-way mapping, call 0N/A * <code>addFlavorForUnencodedNative</code> as well. The new mapping will 0N/A * be of lower priority than any existing mapping. 0N/A * This method has no effect if a mapping from the specified or equal 0N/A * <code>DataFlavor</code> to the specified <code>String</code> native 0N/A * @param flav the <code>DataFlavor</code> key for the mapping 0N/A * @param nat the <code>String</code> native value for the mapping 0N/A * @throws NullPointerException if flav or nat is <code>null</code> 0N/A * @see #addFlavorForUnencodedNative 0N/A * Discards the current mappings for the specified <code>DataFlavor</code> 0N/A * and all <code>DataFlavor</code>s equal to the specified 0N/A * <code>DataFlavor</code>, and creates new mappings to the 0N/A * specified <code>String</code> natives. 0N/A * Unlike <code>getNativesForFlavor</code>, the mappings will only be 0N/A * established in one direction, and the natives will not be encoded. To 0N/A * establish two-way mappings, call <code>setFlavorsForNative</code> 0N/A * as well. The first native in the array will represent the highest 0N/A * priority mapping. Subsequent natives will represent mappings of 0N/A * decreasing priority. 0N/A * If the array contains several elements that reference equal 0N/A * <code>String</code> natives, this method will establish new mappings 0N/A * for the first of those elements and ignore the rest of them. 0N/A * It is recommended that client code not reset mappings established by the 0N/A * data transfer subsystem. This method should only be used for 0N/A * application-level mappings. 0N/A * @param flav the <code>DataFlavor</code> key for the mappings 0N/A * @param natives the <code>String</code> native values for the mappings 0N/A * @throws NullPointerException if flav or natives is <code>null</code> 0N/A * or if natives contains <code>null</code> elements 0N/A * @see #setFlavorsForNative 0N/A // Clear the cache to handle the case of empty natives. 0N/A * Adds a mapping from a single <code>String</code> native to a single 0N/A * <code>DataFlavor</code>. Unlike <code>getFlavorsForNative</code>, the 0N/A * mapping will only be established in one direction, and the native will 0N/A * not be encoded. To establish a two-way mapping, call 0N/A * <code>addUnencodedNativeForFlavor</code> as well. The new mapping will 0N/A * be of lower priority than any existing mapping. 0N/A * This method has no effect if a mapping from the specified 0N/A * <code>String</code> native to the specified or equal 0N/A * <code>DataFlavor</code> already exists. 0N/A * @param nat the <code>String</code> native key for the mapping 0N/A * @param flav the <code>DataFlavor</code> value for the mapping 0N/A * @throws NullPointerException if nat or flav is <code>null</code> 0N/A * @see #addUnencodedNativeForFlavor 0N/A * Discards the current mappings for the specified <code>String</code> 0N/A * native, and creates new mappings to the specified 0N/A * <code>DataFlavor</code>s. Unlike <code>getFlavorsForNative</code>, the 0N/A * mappings will only be established in one direction, and the natives need 0N/A * not be encoded. To establish two-way mappings, call 0N/A * <code>setNativesForFlavor</code> as well. The first 0N/A * <code>DataFlavor</code> in the array will represent the highest priority 0N/A * mapping. Subsequent <code>DataFlavor</code>s will represent mappings of 0N/A * decreasing priority. 0N/A * If the array contains several elements that reference equal 0N/A * <code>DataFlavor</code>s, this method will establish new mappings 0N/A * for the first of those elements and ignore the rest of them. 0N/A * It is recommended that client code not reset mappings established by the 0N/A * data transfer subsystem. This method should only be used for 0N/A * application-level mappings. 0N/A * @param nat the <code>String</code> native key for the mappings 0N/A * @param flavors the <code>DataFlavor</code> values for the mappings 0N/A * @throws NullPointerException if nat or flavors is <code>null</code> 0N/A * or if flavors contains <code>null</code> elements 0N/A * @see #setNativesForFlavor 0N/A // Clear the cache to handle the case of empty flavors. 0N/A * Encodes a MIME type for use as a <code>String</code> native. The format 0N/A * of an encoded representation of a MIME type is implementation-dependent. 0N/A * The only restrictions are: 0N/A * <li>The encoded representation is <code>null</code> if and only if the 0N/A * MIME type <code>String</code> is <code>null</code>.</li> 0N/A * <li>The encoded representations for two non-<code>null</code> MIME type 0N/A * <code>String</code>s are equal if and only if these <code>String</code>s 0N/A * are equal according to <code>String.equals(Object)</code>.</li> 0N/A * Sun's reference implementation of this method returns the specified MIME 0N/A * type <code>String</code> prefixed with <code>JAVA_DATAFLAVOR:</code>. 0N/A * @param mimeType the MIME type to encode 0N/A * @return the encoded <code>String</code>, or <code>null</code> if 0N/A * mimeType is <code>null</code> 0N/A * Encodes a <code>DataFlavor</code> for use as a <code>String</code> 0N/A * native. The format of an encoded <code>DataFlavor</code> is 0N/A * implementation-dependent. The only restrictions are: 0N/A * <li>The encoded representation is <code>null</code> if and only if the 0N/A * specified <code>DataFlavor</code> is <code>null</code> or its MIME type 0N/A * <code>String</code> is <code>null</code>.</li> 0N/A * <li>The encoded representations for two non-<code>null</code> 0N/A * <code>DataFlavor</code>s with non-<code>null</code> MIME type 0N/A * <code>String</code>s are equal if and only if the MIME type 0N/A * <code>String</code>s of these <code>DataFlavor</code>s are equal 0N/A * according to <code>String.equals(Object)</code>.</li> 0N/A * Sun's reference implementation of this method returns the MIME type 0N/A * <code>String</code> of the specified <code>DataFlavor</code> prefixed 0N/A * with <code>JAVA_DATAFLAVOR:</code>. 0N/A * @param flav the <code>DataFlavor</code> to encode 0N/A * @return the encoded <code>String</code>, or <code>null</code> if 0N/A * flav is <code>null</code> or has a <code>null</code> MIME type 0N/A * Returns whether the specified <code>String</code> is an encoded Java 0N/A * @param str the <code>String</code> to test 0N/A * @return <code>true</code> if the <code>String</code> is encoded; 0N/A * <code>false</code> otherwise 0N/A * Decodes a <code>String</code> native for use as a Java MIME type. 0N/A * @param nat the <code>String</code> to decode 0N/A * @return the decoded Java MIME type, or <code>null</code> if nat is not 0N/A * an encoded <code>String</code> native 0N/A * Decodes a <code>String</code> native for use as a 0N/A * <code>DataFlavor</code>. 0N/A * @param nat the <code>String</code> to decode 0N/A * @return the decoded <code>DataFlavor</code>, or <code>null</code> if 0N/A * nat is not an encoded <code>String</code> native