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