src/share/classes/java/awt/datatransfer/SystemFlavorMap.java
Print this page
@@ -23,39 +23,29 @@
* questions.
*/
package java.awt.datatransfer;
-import java.awt.Toolkit;
-
-import java.io.BufferedInputStream;
-import java.io.InputStream;
-import java.lang.ref.SoftReference;
+import sun.datatransfer.DataFlavorUtil;
+import sun.datatransfer.DesktopDatatransferService;
import java.io.BufferedReader;
-import java.io.File;
-import java.io.InputStreamReader;
import java.io.IOException;
-
-import java.net.URL;
-import java.net.MalformedURLException;
-
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
import java.util.Set;
-import sun.awt.AppContext;
-import sun.awt.datatransfer.DataTransferer;
-
/**
* The SystemFlavorMap is a configurable map between "natives" (Strings), which
* correspond to platform-specific data formats, and "flavors" (DataFlavors),
* which correspond to platform-independent MIME types. This mapping is used
* by the data transfer subsystem to transfer data between Java and native
@@ -69,19 +59,10 @@
* Constant prefix used to tag Java types converted to native platform
* type.
*/
private static String JavaMIME = "JAVA_DATAFLAVOR:";
- private static final Object FLAVOR_MAP_KEY = new Object();
-
- /**
- * Copied from java.util.Properties.
- */
- private static final String keyValueSeparators = "=: \t\r\n\f";
- private static final String strictKeyValueSeparators = "=:";
- private static final String whiteSpaceChars = " \t\r\n\f";
-
/**
* The list of valid, decoded text flavor representation classes, in order
* from best to worst.
*/
private static final String[] UNICODE_TEXT_CLASSES = {
@@ -196,20 +177,15 @@
*/
private Set<Object> disabledMappingGenerationKeys = new HashSet<>();
/**
* Returns the default FlavorMap for this thread's ClassLoader.
+ *
* @return the default FlavorMap for this thread's ClassLoader
*/
public static FlavorMap getDefaultFlavorMap() {
- AppContext context = AppContext.getAppContext();
- FlavorMap fm = (FlavorMap) context.get(FLAVOR_MAP_KEY);
- if (fm == null) {
- fm = new SystemFlavorMap();
- context.put(FLAVOR_MAP_KEY, fm);
- }
- return fm;
+ return DataFlavorUtil.getDesktopService().getFlavorMap(SystemFlavorMap::new);
}
private SystemFlavorMap() {
}
@@ -237,25 +213,33 @@
while (line.endsWith("\\")) {
line = line.substring(0, line.length() - 1) + reader.readLine().trim();
}
int delimiterPosition = line.indexOf('=');
String key = line.substring(0, delimiterPosition).replace("\\ ", " ");
- String[] values = line.substring(delimiterPosition + 1, line.length()).split(",");
+ String[] values = line.substring(delimiterPosition + 1, line.length())
+ .replaceAll("\\\\n", "\n")
+ .replaceAll("\\\\r", "\r")
+ .split(",");
+
for (String value : values) {
try {
+ System.out.println(value + " " + Arrays.toString(value.getBytes()));
MimeType mime = new MimeType(value);
if ("text".equals(mime.getPrimaryType())) {
String charset = mime.getParameter("charset");
- if (DataTransferer.doesSubtypeSupportCharset(mime.getSubType(), charset))
+ if (DataFlavorUtil.doesSubtypeSupportCharset(mime.getSubType(), charset))
{
// We need to store the charset and eoln
// parameters, if any, so that the
// DataTransferer will have this information
// for conversion into the native format.
- DataTransferer transferer = DataTransferer.getInstance();
- if (transferer != null) {
- transferer.registerTextFlavorProperties(key, charset,
+ DesktopDatatransferService desktopService =
+ DataFlavorUtil.getDesktopService();
+ if (desktopService.isDesktopPresent()) {
+ System.out.println(mime.getParameter("eoln"));
+ desktopService.registerTextFlavorProperties(
+ key, charset,
mime.getParameter("eoln"),
mime.getParameter("terminators"));
}
}
@@ -330,14 +314,14 @@
*/
private LinkedHashSet<DataFlavor> nativeToFlavorLookup(String nat) {
LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(nat);
if (nat != null && !disabledMappingGenerationKeys.contains(nat)) {
- DataTransferer transferer = DataTransferer.getInstance();
- if (transferer != null) {
+ DesktopDatatransferService desktopService = DataFlavorUtil.getDesktopService();
+ if (desktopService.isDesktopPresent()) {
LinkedHashSet<DataFlavor> platformFlavors =
- transferer.getPlatformMappingsForNative(nat);
+ desktopService.getPlatformMappingsForNative(nat);
if (!platformFlavors.isEmpty()) {
if (flavors != null) {
// Prepending the platform-specific mappings ensures
// that the flavors added with
// addFlavorForUnencodedNative() are at the end of
@@ -393,14 +377,14 @@
final boolean synthesize) {
LinkedHashSet<String> natives = getFlavorToNative().get(flav);
if (flav != null && !disabledMappingGenerationKeys.contains(flav)) {
- DataTransferer transferer = DataTransferer.getInstance();
- if (transferer != null) {
+ DesktopDatatransferService desktopService = DataFlavorUtil.getDesktopService();
+ if (desktopService.isDesktopPresent()) {
LinkedHashSet<String> platformNatives =
- transferer.getPlatformMappingsForFlavor(flav);
+ desktopService.getPlatformMappingsForFlavor(flav);
if (!platformNatives.isEmpty()) {
if (natives != null) {
// Prepend the platform-specific mappings to ensure
// that the natives added with
// addUnencodedNativeForFlavor() are at the end of
@@ -472,11 +456,11 @@
retval = new LinkedHashSet<>(getNativeToFlavor().keySet());
} else if (disabledMappingGenerationKeys.contains(flav)) {
// In this case we shouldn't synthesize a native for this flavor,
// since its mappings were explicitly specified.
retval = flavorToNativeLookup(flav, false);
- } else if (DataTransferer.isFlavorCharsetTextType(flav)) {
+ } else if (DataFlavorUtil.isFlavorCharsetTextType(flav)) {
retval = new LinkedHashSet<>(0);
// For text/* flavors, flavor-to-native mappings specified in
// flavormap.properties are stored per flavor's base type.
if ("text".equals(flav.getPrimaryType())) {
@@ -500,11 +484,11 @@
// In this branch it is guaranteed that natives explicitly
// listed for flav's MIME type were added with
// addUnencodedNativeForFlavor(), so they have lower priority.
retval.addAll(flavorToNativeLookup(flav, false));
}
- } else if (DataTransferer.isFlavorNoncharsetTextType(flav)) {
+ } else if (DataFlavorUtil.isFlavorNoncharsetTextType(flav)) {
retval = getTextTypeToNative().get(flav.mimeType.getBaseType());
if (retval == null || retval.isEmpty()) {
retval = flavorToNativeLookup(flav, true);
} else {
@@ -600,11 +584,11 @@
} catch (MimeTypeParseException mtpe) {
// Cannot happen, since we checked all mappings
// on load from flavormap.properties.
}
- if (DataTransferer.doesSubtypeSupportCharset(subType, null)) {
+ if (DataFlavorUtil.doesSubtypeSupportCharset(subType, null)) {
if (TEXT_PLAIN_BASE_TYPE.equals(baseType))
{
returnValue.add(DataFlavor.stringFlavor);
}
@@ -622,11 +606,11 @@
}
returnValue.add(toAdd);
}
}
- for (String charset : DataTransferer.standardEncodings()) {
+ for (String charset : DataFlavorUtil.standardEncodings()) {
for (String encodedTextClass : ENCODED_TEXT_CLASSES) {
final String mimeType =
baseType + ";charset=" + charset +
";class=" + encodedTextClass;