jdk/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java
author serb
Thu, 05 Feb 2015 16:16:46 +0300
changeset 29010 10d6c5d5ebcf
parent 28987 a389d5a5bc45
child 31898 6890dfde0ed1
permissions -rw-r--r--
8062738: Test java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug fails in Windows Reviewed-by: azvegint, ant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29010
10d6c5d5ebcf 8062738: Test java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug fails in Windows
serb
parents: 28987
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 438
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 438
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 438
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 438
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 438
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.datatransfer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
    28
import sun.datatransfer.DataFlavorUtil;
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
    29
import sun.datatransfer.DesktopDatatransferService;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.BufferedReader;
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
    32
import java.io.IOException;
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
    33
import java.io.InputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.InputStreamReader;
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
    35
import java.lang.ref.SoftReference;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
    37
import java.util.Collections;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashSet;
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
    40
import java.util.LinkedHashSet;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Map;
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
    43
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The SystemFlavorMap is a configurable map between "natives" (Strings), which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * correspond to platform-specific data formats, and "flavors" (DataFlavors),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * which correspond to platform-independent MIME types. This mapping is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * by the data transfer subsystem to transfer data between Java and native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * applications, and between Java applications in separate VMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public final class SystemFlavorMap implements FlavorMap, FlavorTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Constant prefix used to tag Java types converted to native platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static String JavaMIME = "JAVA_DATAFLAVOR:";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
23905
51af43e32270 8026797: Enhance data transfers
malenkov
parents: 23588
diff changeset
    63
    private static final Object FLAVOR_MAP_KEY = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The list of valid, decoded text flavor representation classes, in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * from best to worst.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final String[] UNICODE_TEXT_CLASSES = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        "java.io.Reader", "java.lang.String", "java.nio.CharBuffer", "\"[C\""
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * The list of valid, encoded text flavor representation classes, in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * from best to worst.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final String[] ENCODED_TEXT_CLASSES = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        "java.io.InputStream", "java.nio.ByteBuffer", "\"[B\""
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * A String representing text/plain MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final String TEXT_PLAIN_BASE_TYPE = "text/plain";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
    87
     * A String representing text/html MIME type.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
    88
     */
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
    89
    private static final String HTML_TEXT_BASE_TYPE = "text/html";
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
    90
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
    91
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Maps native Strings to Lists of DataFlavors (or base type Strings for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * text DataFlavors).
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
    94
     * Do not use the field directly, use getNativeToFlavor() instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
    96
    private final Map<String, LinkedHashSet<DataFlavor>> nativeToFlavor = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
    99
     * Accessor to nativeToFlavor map.  Since we use lazy initialization we must
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   100
     * use this accessor instead of direct access to the field which may not be
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   101
     * initialized yet.  This method will initialize the field if needed.
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   102
     *
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   103
     * @return nativeToFlavor
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   104
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   105
    private Map<String, LinkedHashSet<DataFlavor>> getNativeToFlavor() {
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   106
        if (!isMapInitialized) {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   107
            initSystemFlavorMap();
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   108
        }
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   109
        return nativeToFlavor;
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   110
    }
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   111
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   112
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Maps DataFlavors (or base type Strings for text DataFlavors) to Lists of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * native Strings.
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   115
     * Do not use the field directly, use getFlavorToNative() instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   117
    private final Map<DataFlavor, LinkedHashSet<String>> flavorToNative = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   120
     * Accessor to flavorToNative map.  Since we use lazy initialization we must
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   121
     * use this accessor instead of direct access to the field which may not be
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   122
     * initialized yet.  This method will initialize the field if needed.
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   123
     *
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   124
     * @return flavorToNative
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   125
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   126
    private synchronized Map<DataFlavor, LinkedHashSet<String>> getFlavorToNative() {
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   127
        if (!isMapInitialized) {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   128
            initSystemFlavorMap();
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   129
        }
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   130
        return flavorToNative;
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   131
    }
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   132
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   133
    /**
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   134
     * Maps a text DataFlavor primary mime-type to the native. Used only to store
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   135
     * standard mappings registered in the flavormap.properties
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   136
     * Do not use this field directly, use getTextTypeToNative() instead.
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   137
     */
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   138
    private Map<String, LinkedHashSet<String>> textTypeToNative = new HashMap<>();
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   139
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   140
    /**
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   141
     * Shows if the object has been initialized.
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   142
     */
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   143
    private boolean isMapInitialized = false;
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   144
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   145
    /**
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   146
     * An accessor to textTypeToNative map.  Since we use lazy initialization we
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   147
     * must use this accessor instead of direct access to the field which may not
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   148
     * be initialized yet. This method will initialize the field if needed.
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   149
     *
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   150
     * @return textTypeToNative
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   151
     */
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   152
    private synchronized Map<String, LinkedHashSet<String>> getTextTypeToNative() {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   153
        if (!isMapInitialized) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   154
            initSystemFlavorMap();
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   155
            // From this point the map should not be modified
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   156
            textTypeToNative = Collections.unmodifiableMap(textTypeToNative);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   157
        }
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   158
        return textTypeToNative;
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   159
    }
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   160
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   161
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Caches the result of getNativesForFlavor(). Maps DataFlavors to
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   163
     * SoftReferences which reference LinkedHashSet of String natives.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   165
    private final SoftCache<DataFlavor, String> nativesForFlavorCache = new SoftCache<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Caches the result getFlavorsForNative(). Maps String natives to
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   169
     * SoftReferences which reference LinkedHashSet of DataFlavors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   171
    private final SoftCache<String, DataFlavor> flavorsForNativeCache = new SoftCache<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Dynamic mapping generation used for text mappings should not be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * to the DataFlavors and String natives for which the mappings have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * explicitly specified with setFlavorsForNative() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * setNativesForFlavor(). This keeps all such keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   179
    private Set<Object> disabledMappingGenerationKeys = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Returns the default FlavorMap for this thread's ClassLoader.
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   183
     *
22281
830790e8640d 8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents: 21598
diff changeset
   184
     * @return the default FlavorMap for this thread's ClassLoader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public static FlavorMap getDefaultFlavorMap() {
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   187
        return DataFlavorUtil.getDesktopService().getFlavorMap(SystemFlavorMap::new);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   190
    private SystemFlavorMap() {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   191
    }
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
25782
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   194
     * Initializes a SystemFlavorMap by reading flavormap.properties
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   195
     * For thread-safety must be called under lock on this.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   197
    private void initSystemFlavorMap() {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   198
        if (isMapInitialized) {
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   199
            return;
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   200
        }
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   201
        isMapInitialized = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
26009
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   203
        InputStream is = SystemFlavorMap.class.getResourceAsStream("/sun/datatransfer/resources/flavormap.properties");
25782
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   204
        if (is == null) {
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   205
            throw new InternalError("Default flavor mapping not found");
23905
51af43e32270 8026797: Enhance data transfers
malenkov
parents: 23588
diff changeset
   206
        }
51af43e32270 8026797: Enhance data transfers
malenkov
parents: 23588
diff changeset
   207
25782
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   208
        try (InputStreamReader isr = new InputStreamReader(is);
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   209
             BufferedReader reader = new BufferedReader(isr)) {
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   210
            String line;
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   211
            while ((line = reader.readLine()) != null) {
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   212
                line = line.trim();
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   213
                if (line.startsWith("#") || line.isEmpty()) continue;
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   214
                while (line.endsWith("\\")) {
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   215
                    line = line.substring(0, line.length() - 1) + reader.readLine().trim();
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   216
                }
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   217
                int delimiterPosition = line.indexOf('=');
29010
10d6c5d5ebcf 8062738: Test java/awt/datatransfer/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug fails in Windows
serb
parents: 28987
diff changeset
   218
                String key = line.substring(0, delimiterPosition).replace("\\ ", " ");
25782
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   219
                String[] values = line.substring(delimiterPosition + 1, line.length()).split(",");
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   220
                for (String value : values) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    try {
26009
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   222
                        value = loadConvert(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        MimeType mime = new MimeType(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        if ("text".equals(mime.getPrimaryType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                            String charset = mime.getParameter("charset");
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   226
                            if (DataFlavorUtil.doesSubtypeSupportCharset(mime.getSubType(), charset))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                // We need to store the charset and eoln
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                // parameters, if any, so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                // DataTransferer will have this information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                // for conversion into the native format.
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   232
                                DesktopDatatransferService desktopService =
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   233
                                        DataFlavorUtil.getDesktopService();
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   234
                                if (desktopService.isDesktopPresent()) {
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   235
                                    desktopService.registerTextFlavorProperties(
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   236
                                            key, charset,
25782
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   237
                                            mime.getParameter("eoln"),
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   238
                                            mime.getParameter("terminators"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                            // But don't store any of these parameters in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            // DataFlavor itself for any text natives (even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            // non-charset ones). The SystemFlavorMap will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            // synthesize the appropriate mappings later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            mime.removeParameter("charset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            mime.removeParameter("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            mime.removeParameter("eoln");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            mime.removeParameter("terminators");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            value = mime.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    } catch (MimeTypeParseException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    DataFlavor flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                        flavor = new DataFlavor(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        try {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   262
                            flavor = new DataFlavor(value, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        } catch (Exception ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                            ee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   269
                    final LinkedHashSet<DataFlavor> dfs = new LinkedHashSet<>();
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   270
                    dfs.add(flavor);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   271
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    if ("text".equals(flavor.getPrimaryType())) {
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   273
                        dfs.addAll(convertMimeTypeToDataFlavors(value));
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   274
                        store(flavor.mimeType.getBaseType(), key, getTextTypeToNative());
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   275
                    }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   276
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   277
                    for (DataFlavor df : dfs) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   278
                        store(df, key, getFlavorToNative());
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   279
                        store(key, df, getNativeToFlavor());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
25782
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   283
        } catch (IOException e) {
5a832643a534 8047336: Read flavormap.properties as resource
pchelko
parents: 24529
diff changeset
   284
            throw new InternalError("Error reading default flavor mapping", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
26009
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   288
    // Copied from java.util.Properties
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   289
    private static String loadConvert(String theString) {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   290
        char aChar;
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   291
        int len = theString.length();
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   292
        StringBuilder outBuffer = new StringBuilder(len);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   293
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   294
        for (int x = 0; x < len; ) {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   295
            aChar = theString.charAt(x++);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   296
            if (aChar == '\\') {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   297
                aChar = theString.charAt(x++);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   298
                if (aChar == 'u') {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   299
                    // Read the xxxx
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   300
                    int value = 0;
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   301
                    for (int i = 0; i < 4; i++) {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   302
                        aChar = theString.charAt(x++);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   303
                        switch (aChar) {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   304
                            case '0': case '1': case '2': case '3': case '4':
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   305
                            case '5': case '6': case '7': case '8': case '9': {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   306
                                value = (value << 4) + aChar - '0';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   307
                                break;
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   308
                            }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   309
                            case 'a': case 'b': case 'c':
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   310
                            case 'd': case 'e': case 'f': {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   311
                                value = (value << 4) + 10 + aChar - 'a';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   312
                                break;
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   313
                            }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   314
                            case 'A': case 'B': case 'C':
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   315
                            case 'D': case 'E': case 'F': {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   316
                                value = (value << 4) + 10 + aChar - 'A';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   317
                                break;
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   318
                            }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   319
                            default: {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   320
                                throw new IllegalArgumentException(
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   321
                                        "Malformed \\uxxxx encoding.");
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   322
                            }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   323
                        }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   324
                    }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   325
                    outBuffer.append((char)value);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   326
                } else {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   327
                    if (aChar == 't') {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   328
                        aChar = '\t';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   329
                    } else if (aChar == 'r') {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   330
                        aChar = '\r';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   331
                    } else if (aChar == 'n') {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   332
                        aChar = '\n';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   333
                    } else if (aChar == 'f') {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   334
                        aChar = '\f';
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   335
                    }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   336
                    outBuffer.append(aChar);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   337
                }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   338
            } else {
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   339
                outBuffer.append(aChar);
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   340
            }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   341
        }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   342
        return outBuffer.toString();
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   343
    }
682a3a6d43a7 8051449: Incorrect parsing of the default flavor mapping
pchelko
parents: 25782
diff changeset
   344
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Stores the listed object under the specified hash key in map. Unlike a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * standard map, the listed object will not replace any object already at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * the appropriate Map location, but rather will be appended to a List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * stored in that location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   351
    private <H, L> void store(H hashed, L listed, Map<H, LinkedHashSet<L>> map) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   352
        LinkedHashSet<L> list = map.get(hashed);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (list == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   354
            list = new LinkedHashSet<>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            map.put(hashed, list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (!list.contains(listed)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            list.add(listed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Semantically equivalent to 'nativeToFlavor.get(nat)'. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * handles the case where 'nat' is not found in 'nativeToFlavor'. In that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * case, a new DataFlavor is synthesized, stored, and returned, if and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * only if the specified native is encoded as a Java MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   368
    private LinkedHashSet<DataFlavor> nativeToFlavorLookup(String nat) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   369
        LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (nat != null && !disabledMappingGenerationKeys.contains(nat)) {
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   372
            DesktopDatatransferService desktopService = DataFlavorUtil.getDesktopService();
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   373
            if (desktopService.isDesktopPresent()) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   374
                LinkedHashSet<DataFlavor> platformFlavors =
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   375
                        desktopService.getPlatformMappingsForNative(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                if (!platformFlavors.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    if (flavors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        // Prepending the platform-specific mappings ensures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                        // that the flavors added with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        // addFlavorForUnencodedNative() are at the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        // list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                        platformFlavors.addAll(flavors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    flavors = platformFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (flavors == null && isJavaMIMEType(nat)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            String decoded = decodeJavaMIMEType(nat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            DataFlavor flavor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                flavor = new DataFlavor(decoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                System.err.println("Exception \"" + e.getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                   ": " + e.getMessage()  +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                   "\"while constructing DataFlavor for: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                   decoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (flavor != null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   403
                flavors = new LinkedHashSet<>(1);
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   404
                getNativeToFlavor().put(nat, flavors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                flavors.add(flavor);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   406
                flavorsForNativeCache.remove(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   408
                LinkedHashSet<String> natives = getFlavorToNative().get(flavor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                if (natives == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   410
                    natives = new LinkedHashSet<>(1);
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   411
                    getFlavorToNative().put(flavor, natives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                natives.add(nat);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   414
                nativesForFlavorCache.remove(flavor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   418
        return (flavors != null) ? flavors : new LinkedHashSet<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Semantically equivalent to 'flavorToNative.get(flav)'. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * handles the case where 'flav' is not found in 'flavorToNative' depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * on the value of passes 'synthesize' parameter. If 'synthesize' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * SYNTHESIZE_IF_NOT_FOUND a native is synthesized, stored, and returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * encoding the DataFlavor's MIME type. Otherwise an empty List is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * and 'flavorToNative' remains unaffected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   429
    private LinkedHashSet<String> flavorToNativeLookup(final DataFlavor flav,
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   430
                                                       final boolean synthesize) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   431
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   432
        LinkedHashSet<String> natives = getFlavorToNative().get(flav);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (flav != null && !disabledMappingGenerationKeys.contains(flav)) {
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   435
            DesktopDatatransferService desktopService = DataFlavorUtil.getDesktopService();
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   436
            if (desktopService.isDesktopPresent()) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   437
                LinkedHashSet<String> platformNatives =
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   438
                        desktopService.getPlatformMappingsForFlavor(flav);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                if (!platformNatives.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    if (natives != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        // Prepend the platform-specific mappings to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        // that the natives added with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        // addUnencodedNativeForFlavor() are at the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        // list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        platformNatives.addAll(natives);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    natives = platformNatives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (natives == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (synthesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                String encoded = encodeDataFlavor(flav);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   455
                natives = new LinkedHashSet<>(1);
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   456
                getFlavorToNative().put(flav, natives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                natives.add(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   459
                LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(encoded);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                if (flavors == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   461
                    flavors = new LinkedHashSet<>(1);
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   462
                    getNativeToFlavor().put(encoded, flavors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                flavors.add(flav);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   465
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   466
                nativesForFlavorCache.remove(flav);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   467
                flavorsForNativeCache.remove(encoded);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            } else {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   469
                natives = new LinkedHashSet<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   473
        return new LinkedHashSet<>(natives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Returns a <code>List</code> of <code>String</code> natives to which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * specified <code>DataFlavor</code> can be translated by the data transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * subsystem. The <code>List</code> will be sorted from best native to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * worst. That is, the first native will best reflect data in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * flavor to the underlying native platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * If the specified <code>DataFlavor</code> is previously unknown to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * data transfer subsystem and the data transfer subsystem is unable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * translate this <code>DataFlavor</code> to any existing native, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * invoking this method will establish a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * mapping in both directions between the specified <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * and an encoded version of its MIME type as its native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param flav the <code>DataFlavor</code> whose corresponding natives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *        should be returned. If <code>null</code> is specified, all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *        natives currently known to the data transfer subsystem are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *        returned in a non-deterministic order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @return a <code>java.util.List</code> of <code>java.lang.String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *         objects which are platform-specific representations of platform-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *         specific data formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @see #encodeDataFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   501
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public synchronized List<String> getNativesForFlavor(DataFlavor flav) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   503
        LinkedHashSet<String> retval = nativesForFlavorCache.check(flav);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   504
        if (retval != null) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   505
            return new ArrayList<>(retval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (flav == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   509
            retval = new LinkedHashSet<>(getNativeToFlavor().keySet());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } else if (disabledMappingGenerationKeys.contains(flav)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // In this case we shouldn't synthesize a native for this flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // since its mappings were explicitly specified.
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   513
            retval = flavorToNativeLookup(flav, false);
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   514
        } else if (DataFlavorUtil.isFlavorCharsetTextType(flav)) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   515
            retval = new LinkedHashSet<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // For text/* flavors, flavor-to-native mappings specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            // flavormap.properties are stored per flavor's base type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if ("text".equals(flav.getPrimaryType())) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   520
                LinkedHashSet<String> textTypeNatives =
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   521
                        getTextTypeToNative().get(flav.mimeType.getBaseType());
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   522
                if (textTypeNatives != null) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   523
                    retval.addAll(textTypeNatives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            // Also include text/plain natives, but don't duplicate Strings
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   528
            LinkedHashSet<String> textTypeNatives =
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   529
                    getTextTypeToNative().get(TEXT_PLAIN_BASE_TYPE);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   530
            if (textTypeNatives != null) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   531
                retval.addAll(textTypeNatives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   534
            if (retval.isEmpty()) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   535
                retval = flavorToNativeLookup(flav, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                // In this branch it is guaranteed that natives explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                // listed for flav's MIME type were added with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                // addUnencodedNativeForFlavor(), so they have lower priority.
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   540
                retval.addAll(flavorToNativeLookup(flav, false));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   542
        } else if (DataFlavorUtil.isFlavorNoncharsetTextType(flav)) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   543
            retval = getTextTypeToNative().get(flav.mimeType.getBaseType());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            if (retval == null || retval.isEmpty()) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   546
                retval = flavorToNativeLookup(flav, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                // In this branch it is guaranteed that natives explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                // listed for flav's MIME type were added with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                // addUnencodedNativeForFlavor(), so they have lower priority.
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   551
                retval.addAll(flavorToNativeLookup(flav, false));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        } else {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   554
            retval = flavorToNativeLookup(flav, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   557
        nativesForFlavorCache.put(flav, retval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        // Create a copy, because client code can modify the returned list.
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   559
        return new ArrayList<>(retval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Returns a <code>List</code> of <code>DataFlavor</code>s to which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * specified <code>String</code> native can be translated by the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * transfer subsystem. The <code>List</code> will be sorted from best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * <code>DataFlavor</code> to worst. That is, the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <code>DataFlavor</code> will best reflect data in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * native to a Java application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * If the specified native is previously unknown to the data transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * subsystem, and that native has been properly encoded, then invoking this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * method will establish a mapping in both directions between the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * native and a <code>DataFlavor</code> whose MIME type is a decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * version of the native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * If the specified native is not a properly encoded native and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * mappings for this native have not been altered with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * <code>setFlavorsForNative</code>, then the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <code>List</code> is platform dependent, but <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * cannot be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @param nat the native whose corresponding <code>DataFlavor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *        should be returned. If <code>null</code> is specified, all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *        <code>DataFlavor</code>s currently known to the data transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *        subsystem are returned in a non-deterministic order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @return a <code>java.util.List</code> of <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *         objects into which platform-specific data in the specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *         platform-specific native can be translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @see #encodeJavaMIMEType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   593
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public synchronized List<DataFlavor> getFlavorsForNative(String nat) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   595
        LinkedHashSet<DataFlavor> returnValue = flavorsForNativeCache.check(nat);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   596
        if (returnValue != null) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   597
            return new ArrayList<>(returnValue);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   598
        } else {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   599
            returnValue = new LinkedHashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (nat == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   603
            for (String n : getNativesForFlavor(null)) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   604
                returnValue.addAll(getFlavorsForNative(n));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        } else {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   607
            final LinkedHashSet<DataFlavor> flavors = nativeToFlavorLookup(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (disabledMappingGenerationKeys.contains(nat)) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   609
                return new ArrayList<>(flavors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   612
            final LinkedHashSet<DataFlavor> flavorsWithSynthesized =
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   613
                    nativeToFlavorLookup(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   615
            for (DataFlavor df : flavorsWithSynthesized) {
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   616
                returnValue.add(df);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   617
                if ("text".equals(df.getPrimaryType())) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   618
                    String baseType = df.mimeType.getBaseType();
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   619
                    returnValue.addAll(convertMimeTypeToDataFlavors(baseType));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   622
        }
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   623
        flavorsForNativeCache.put(nat, returnValue);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   624
        return new ArrayList<>(returnValue);
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   625
    }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   626
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 26749
diff changeset
   627
    @SuppressWarnings("deprecation")
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   628
    private static Set<DataFlavor> convertMimeTypeToDataFlavors(
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   629
        final String baseType) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   630
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   631
        final Set<DataFlavor> returnValue = new LinkedHashSet<>();
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   632
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   633
        String subType = null;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   634
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   635
        try {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   636
            final MimeType mimeType = new MimeType(baseType);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   637
            subType = mimeType.getSubType();
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   638
        } catch (MimeTypeParseException mtpe) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   639
            // Cannot happen, since we checked all mappings
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   640
            // on load from flavormap.properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   643
        if (DataFlavorUtil.doesSubtypeSupportCharset(subType, null)) {
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   644
            if (TEXT_PLAIN_BASE_TYPE.equals(baseType))
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   645
            {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   646
                returnValue.add(DataFlavor.stringFlavor);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   647
            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   648
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   649
            for (String unicodeClassName : UNICODE_TEXT_CLASSES) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   650
                final String mimeType = baseType + ";charset=Unicode;class=" +
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   651
                                            unicodeClassName;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   652
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   653
                final LinkedHashSet<String> mimeTypes =
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   654
                    handleHtmlMimeTypes(baseType, mimeType);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   655
                for (String mt : mimeTypes) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   656
                    DataFlavor toAdd = null;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   657
                    try {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   658
                        toAdd = new DataFlavor(mt);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   659
                    } catch (ClassNotFoundException cannotHappen) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   660
                    }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   661
                    returnValue.add(toAdd);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   662
                }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   663
            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   664
26010
9a3cf8ee0776 8037485: Refactor java.awt.datatransfer to eliminate dependency on AWT
pchelko
parents: 26009
diff changeset
   665
            for (String charset : DataFlavorUtil.standardEncodings()) {
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   666
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   667
                for (String encodedTextClass : ENCODED_TEXT_CLASSES) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   668
                    final String mimeType =
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   669
                            baseType + ";charset=" + charset +
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   670
                            ";class=" + encodedTextClass;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   671
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   672
                    final LinkedHashSet<String> mimeTypes =
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   673
                        handleHtmlMimeTypes(baseType, mimeType);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   674
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   675
                    for (String mt : mimeTypes) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   676
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   677
                        DataFlavor df = null;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   678
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   679
                        try {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   680
                            df = new DataFlavor(mt);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   681
                            // Check for equality to plainTextFlavor so
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   682
                            // that we can ensure that the exact charset of
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   683
                            // plainTextFlavor, not the canonical charset
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   684
                            // or another equivalent charset with a
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   685
                            // different name, is used.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   686
                            if (df.equals(DataFlavor.plainTextFlavor)) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   687
                                df = DataFlavor.plainTextFlavor;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   688
                            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   689
                        } catch (ClassNotFoundException cannotHappen) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   690
                        }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   691
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   692
                        returnValue.add(df);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   693
                    }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   694
                }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   695
            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   696
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   697
            if (TEXT_PLAIN_BASE_TYPE.equals(baseType))
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   698
            {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   699
                returnValue.add(DataFlavor.plainTextFlavor);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   700
            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   701
        } else {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   702
            // Non-charset text natives should be treated as
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   703
            // opaque, 8-bit data in any of its various
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   704
            // representations.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   705
            for (String encodedTextClassName : ENCODED_TEXT_CLASSES) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   706
                DataFlavor toAdd = null;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   707
                try {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   708
                    toAdd = new DataFlavor(baseType +
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   709
                         ";class=" + encodedTextClassName);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   710
                } catch (ClassNotFoundException cannotHappen) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   711
                }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   712
                returnValue.add(toAdd);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   713
            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   714
        }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   715
        return returnValue;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   716
    }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   717
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 26037
diff changeset
   718
    private static final String [] htmlDocumentTypes =
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   719
            new String [] {"all", "selection", "fragment"};
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   720
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   721
    private static LinkedHashSet<String> handleHtmlMimeTypes(String baseType,
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   722
                                                             String mimeType) {
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   723
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   724
        LinkedHashSet<String> returnValues = new LinkedHashSet<>();
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   725
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   726
        if (HTML_TEXT_BASE_TYPE.equals(baseType)) {
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 26037
diff changeset
   727
            for (String documentType : htmlDocumentTypes) {
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   728
                returnValues.add(mimeType + ";document=" + documentType);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   729
            }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   730
        } else {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   731
            returnValues.add(mimeType);
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   732
        }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   733
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 15263
diff changeset
   734
        return returnValues;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Returns a <code>Map</code> of the specified <code>DataFlavor</code>s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * their most preferred <code>String</code> native. Each native value will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * be the same as the first native in the List returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * <code>getNativesForFlavor</code> for the specified flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * If a specified <code>DataFlavor</code> is previously unknown to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * data transfer subsystem, then invoking this method will establish a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * mapping in both directions between the specified <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * and an encoded version of its MIME type as its native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @param flavors an array of <code>DataFlavor</code>s which will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     *        key set of the returned <code>Map</code>. If <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *        specified, a mapping of all <code>DataFlavor</code>s known to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *        data transfer subsystem to their most preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *        <code>String</code> natives will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @return a <code>java.util.Map</code> of <code>DataFlavor</code>s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *         <code>String</code> natives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @see #getNativesForFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @see #encodeDataFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   759
    @Override
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   760
    public synchronized Map<DataFlavor,String> getNativesForFlavors(DataFlavor[] flavors)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        // Use getNativesForFlavor to generate extra natives for text flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        // and stringFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        if (flavors == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   766
            List<DataFlavor> flavor_list = getFlavorsForNative(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            flavors = new DataFlavor[flavor_list.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            flavor_list.toArray(flavors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   771
        Map<DataFlavor, String> retval = new HashMap<>(flavors.length, 1.0f);
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   772
        for (DataFlavor flavor : flavors) {
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   773
            List<String> natives = getNativesForFlavor(flavor);
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   774
            String nat = (natives.isEmpty()) ? null : natives.get(0);
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   775
            retval.put(flavor, nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Returns a <code>Map</code> of the specified <code>String</code> natives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * to their most preferred <code>DataFlavor</code>. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * <code>DataFlavor</code> value will be the same as the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * <code>DataFlavor</code> in the List returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * <code>getFlavorsForNative</code> for the specified native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * If a specified native is previously unknown to the data transfer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * subsystem, and that native has been properly encoded, then invoking this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * method will establish a mapping in both directions between the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * native and a <code>DataFlavor</code> whose MIME type is a decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * version of the native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @param natives an array of <code>String</code>s which will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *        key set of the returned <code>Map</code>. If <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *        specified, a mapping of all supported <code>String</code> natives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *        to their most preferred <code>DataFlavor</code>s will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     *        returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @return a <code>java.util.Map</code> of <code>String</code> natives to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     *         <code>DataFlavor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see #getFlavorsForNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @see #encodeJavaMIMEType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   805
    @Override
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   806
    public synchronized Map<String,DataFlavor> getFlavorsForNatives(String[] natives)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // Use getFlavorsForNative to generate extra flavors for text natives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        if (natives == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   810
            List<String> nativesList = getNativesForFlavor(null);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   811
            natives = new String[nativesList.size()];
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   812
            nativesList.toArray(natives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   815
        Map<String, DataFlavor> retval = new HashMap<>(natives.length, 1.0f);
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   816
        for (String aNative : natives) {
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   817
            List<DataFlavor> flavors = getFlavorsForNative(aNative);
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   818
            DataFlavor flav = (flavors.isEmpty())? null : flavors.get(0);
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   819
            retval.put(aNative, flav);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Adds a mapping from the specified <code>DataFlavor</code> (and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * <code>DataFlavor</code>s equal to the specified <code>DataFlavor</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * to the specified <code>String</code> native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * Unlike <code>getNativesForFlavor</code>, the mapping will only be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * established in one direction, and the native will not be encoded. To
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * establish a two-way mapping, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * <code>addFlavorForUnencodedNative</code> as well. The new mapping will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * be of lower priority than any existing mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * This method has no effect if a mapping from the specified or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <code>DataFlavor</code> to the specified <code>String</code> native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * already exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @param flav the <code>DataFlavor</code> key for the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @param nat the <code>String</code> native value for the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @throws NullPointerException if flav or nat is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @see #addFlavorForUnencodedNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    public synchronized void addUnencodedNativeForFlavor(DataFlavor flav,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                                                         String nat) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   846
        Objects.requireNonNull(nat, "Null native not permitted");
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   847
        Objects.requireNonNull(flav, "Null flavor not permitted");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   849
        LinkedHashSet<String> natives = getFlavorToNative().get(flav);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        if (natives == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   851
            natives = new LinkedHashSet<>(1);
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   852
            getFlavorToNative().put(flav, natives);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        natives.add(nat);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   855
        nativesForFlavorCache.remove(flav);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Discards the current mappings for the specified <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * and all <code>DataFlavor</code>s equal to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * <code>DataFlavor</code>, and creates new mappings to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * specified <code>String</code> natives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * Unlike <code>getNativesForFlavor</code>, the mappings will only be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * established in one direction, and the natives will not be encoded. To
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * establish two-way mappings, call <code>setFlavorsForNative</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * as well. The first native in the array will represent the highest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * priority mapping. Subsequent natives will represent mappings of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * decreasing priority.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * If the array contains several elements that reference equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * <code>String</code> natives, this method will establish new mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * for the first of those elements and ignore the rest of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * It is recommended that client code not reset mappings established by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * data transfer subsystem. This method should only be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * application-level mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @param flav the <code>DataFlavor</code> key for the mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @param natives the <code>String</code> native values for the mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @throws NullPointerException if flav or natives is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *         or if natives contains <code>null</code> elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @see #setFlavorsForNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    public synchronized void setNativesForFlavor(DataFlavor flav,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                                 String[] natives) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   888
        Objects.requireNonNull(natives, "Null natives not permitted");
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   889
        Objects.requireNonNull(flav, "Null flavors not permitted");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   891
        getFlavorToNative().remove(flav);
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   892
        for (String aNative : natives) {
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   893
            addUnencodedNativeForFlavor(flav, aNative);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        disabledMappingGenerationKeys.add(flav);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   896
        nativesForFlavorCache.remove(flav);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * Adds a mapping from a single <code>String</code> native to a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * <code>DataFlavor</code>. Unlike <code>getFlavorsForNative</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * mapping will only be established in one direction, and the native will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * not be encoded. To establish a two-way mapping, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * <code>addUnencodedNativeForFlavor</code> as well. The new mapping will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * be of lower priority than any existing mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * This method has no effect if a mapping from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * <code>String</code> native to the specified or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * <code>DataFlavor</code> already exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @param nat the <code>String</code> native key for the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @param flav the <code>DataFlavor</code> value for the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @throws NullPointerException if nat or flav is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @see #addUnencodedNativeForFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public synchronized void addFlavorForUnencodedNative(String nat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                                                         DataFlavor flav) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   919
        Objects.requireNonNull(nat, "Null native not permitted");
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   920
        Objects.requireNonNull(flav, "Null flavor not permitted");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   922
        LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        if (flavors == null) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   924
            flavors = new LinkedHashSet<>(1);
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   925
            getNativeToFlavor().put(nat, flavors);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        flavors.add(flav);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   928
        flavorsForNativeCache.remove(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Discards the current mappings for the specified <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * native, and creates new mappings to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * <code>DataFlavor</code>s. Unlike <code>getFlavorsForNative</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * mappings will only be established in one direction, and the natives need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * not be encoded. To establish two-way mappings, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * <code>setNativesForFlavor</code> as well. The first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * <code>DataFlavor</code> in the array will represent the highest priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * mapping. Subsequent <code>DataFlavor</code>s will represent mappings of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * decreasing priority.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * If the array contains several elements that reference equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * <code>DataFlavor</code>s, this method will establish new mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * for the first of those elements and ignore the rest of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * It is recommended that client code not reset mappings established by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * data transfer subsystem. This method should only be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * application-level mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @param nat the <code>String</code> native key for the mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @param flavors the <code>DataFlavor</code> values for the mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @throws NullPointerException if nat or flavors is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     *         or if flavors contains <code>null</code> elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * @see #setNativesForFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    public synchronized void setFlavorsForNative(String nat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                                                 DataFlavor[] flavors) {
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   960
        Objects.requireNonNull(nat, "Null native not permitted");
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   961
        Objects.requireNonNull(flavors, "Null flavors not permitted");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
109
ddfda358e547 6603256: Startup: Defer initialization of DropTarget's flavorMap
son
parents: 2
diff changeset
   963
        getNativeToFlavor().remove(nat);
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   964
        for (DataFlavor flavor : flavors) {
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
   965
            addFlavorForUnencodedNative(nat, flavor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        disabledMappingGenerationKeys.add(nat);
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
   968
        flavorsForNativeCache.remove(nat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Encodes a MIME type for use as a <code>String</code> native. The format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * of an encoded representation of a MIME type is implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * The only restrictions are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * <li>The encoded representation is <code>null</code> if and only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * MIME type <code>String</code> is <code>null</code>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * <li>The encoded representations for two non-<code>null</code> MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * <code>String</code>s are equal if and only if these <code>String</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * are equal according to <code>String.equals(Object)</code>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * <p>
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
   983
     * The reference implementation of this method returns the specified MIME
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * type <code>String</code> prefixed with <code>JAVA_DATAFLAVOR:</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @param mimeType the MIME type to encode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @return the encoded <code>String</code>, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     *         mimeType is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    public static String encodeJavaMIMEType(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        return (mimeType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            ? JavaMIME + mimeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Encodes a <code>DataFlavor</code> for use as a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * native. The format of an encoded <code>DataFlavor</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * implementation-dependent. The only restrictions are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * <li>The encoded representation is <code>null</code> if and only if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * specified <code>DataFlavor</code> is <code>null</code> or its MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * <code>String</code> is <code>null</code>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * <li>The encoded representations for two non-<code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * <code>DataFlavor</code>s with non-<code>null</code> MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * <code>String</code>s are equal if and only if the MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * <code>String</code>s of these <code>DataFlavor</code>s are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * according to <code>String.equals(Object)</code>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * <p>
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
  1011
     * The reference implementation of this method returns the MIME type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * <code>String</code> of the specified <code>DataFlavor</code> prefixed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * with <code>JAVA_DATAFLAVOR:</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * @param flav the <code>DataFlavor</code> to encode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * @return the encoded <code>String</code>, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     *         flav is <code>null</code> or has a <code>null</code> MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    public static String encodeDataFlavor(DataFlavor flav) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        return (flav != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            ? SystemFlavorMap.encodeJavaMIMEType(flav.getMimeType())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Returns whether the specified <code>String</code> is an encoded Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * @param str the <code>String</code> to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @return <code>true</code> if the <code>String</code> is encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    public static boolean isJavaMIMEType(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        return (str != null && str.startsWith(JavaMIME, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Decodes a <code>String</code> native for use as a Java MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * @param nat the <code>String</code> to decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * @return the decoded Java MIME type, or <code>null</code> if nat is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *         an encoded <code>String</code> native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    public static String decodeJavaMIMEType(String nat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        return (isJavaMIMEType(nat))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            ? nat.substring(JavaMIME.length(), nat.length()).trim()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * Decodes a <code>String</code> native for use as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @param nat the <code>String</code> to decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * @return the decoded <code>DataFlavor</code>, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     *         nat is not an encoded <code>String</code> native
22281
830790e8640d 8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents: 21598
diff changeset
  1057
     * @throws ClassNotFoundException if the class of the data flavor
830790e8640d 8031467: Fix doclint missing issues in java.awt.{dnd[.peer], datatransfer}
darcy
parents: 21598
diff changeset
  1058
     * is not loaded
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    public static DataFlavor decodeDataFlavor(String nat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        String retval_str = SystemFlavorMap.decodeJavaMIMEType(nat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        return (retval_str != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            ? new DataFlavor(retval_str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    }
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
  1068
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1069
    private static final class SoftCache<K, V> {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1070
        Map<K, SoftReference<LinkedHashSet<V>>> cache;
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1071
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1072
        public void put(K key, LinkedHashSet<V> value) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1073
            if (cache == null) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1074
                cache = new HashMap<>(1);
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
  1075
            }
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1076
            cache.put(key, new SoftReference<>(value));
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
  1077
        }
24529
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1078
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1079
        public void remove(K key) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1080
            if (cache == null) return;
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1081
            cache.remove(null);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1082
            cache.remove(key);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1083
        }
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1084
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1085
        public LinkedHashSet<V> check(K key) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1086
            if (cache == null) return null;
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1087
            SoftReference<LinkedHashSet<V>> ref = cache.get(key);
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1088
            if (ref != null) {
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1089
                return ref.get();
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1090
            }
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1091
            return null;
c580bcb3aabc 8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order
pchelko
parents: 23905
diff changeset
  1092
        }
20166
77e3750a0df9 8024987: Copy/paste regression since JDK8 b86
pchelko
parents: 16705
diff changeset
  1093
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
}