src/share/classes/java/awt/datatransfer/SystemFlavorMap.java
Print this page
*** 23,61 ****
* questions.
*/
package java.awt.datatransfer;
! import java.awt.Toolkit;
!
! import java.io.BufferedInputStream;
! import java.io.InputStream;
! import java.lang.ref.SoftReference;
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.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
--- 23,51 ----
* questions.
*/
package java.awt.datatransfer;
! import sun.datatransfer.DataFlavorUtil;
! import sun.datatransfer.DesktopDatatransferService;
import java.io.BufferedReader;
import java.io.IOException;
! 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.Set;
/**
* 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,87 ****
* 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 = {
--- 59,68 ----
*** 196,215 ****
*/
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;
}
private SystemFlavorMap() {
}
--- 177,191 ----
*/
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() {
! return DataFlavorUtil.getDesktopService().getFlavorMap(SystemFlavorMap::new);
}
private SystemFlavorMap() {
}
*** 237,261 ****
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(",");
for (String value : values) {
try {
MimeType mime = new MimeType(value);
if ("text".equals(mime.getPrimaryType())) {
String charset = mime.getParameter("charset");
! if (DataTransferer.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,
mime.getParameter("eoln"),
mime.getParameter("terminators"));
}
}
--- 213,245 ----
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())
! .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 (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.
! DesktopDatatransferService desktopService =
! DataFlavorUtil.getDesktopService();
! if (desktopService.isDesktopPresent()) {
! System.out.println(mime.getParameter("eoln"));
! desktopService.registerTextFlavorProperties(
! key, charset,
mime.getParameter("eoln"),
mime.getParameter("terminators"));
}
}
*** 330,343 ****
*/
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) {
LinkedHashSet<DataFlavor> platformFlavors =
! transferer.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
--- 314,327 ----
*/
private LinkedHashSet<DataFlavor> nativeToFlavorLookup(String nat) {
LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(nat);
if (nat != null && !disabledMappingGenerationKeys.contains(nat)) {
! DesktopDatatransferService desktopService = DataFlavorUtil.getDesktopService();
! if (desktopService.isDesktopPresent()) {
LinkedHashSet<DataFlavor> platformFlavors =
! 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,406 ****
final boolean synthesize) {
LinkedHashSet<String> natives = getFlavorToNative().get(flav);
if (flav != null && !disabledMappingGenerationKeys.contains(flav)) {
! DataTransferer transferer = DataTransferer.getInstance();
! if (transferer != null) {
LinkedHashSet<String> platformNatives =
! transferer.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
--- 377,390 ----
final boolean synthesize) {
LinkedHashSet<String> natives = getFlavorToNative().get(flav);
if (flav != null && !disabledMappingGenerationKeys.contains(flav)) {
! DesktopDatatransferService desktopService = DataFlavorUtil.getDesktopService();
! if (desktopService.isDesktopPresent()) {
LinkedHashSet<String> platformNatives =
! 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,482 ****
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)) {
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())) {
--- 456,466 ----
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 (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,510 ****
// 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)) {
retval = getTextTypeToNative().get(flav.mimeType.getBaseType());
if (retval == null || retval.isEmpty()) {
retval = flavorToNativeLookup(flav, true);
} else {
--- 484,494 ----
// 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 (DataFlavorUtil.isFlavorNoncharsetTextType(flav)) {
retval = getTextTypeToNative().get(flav.mimeType.getBaseType());
if (retval == null || retval.isEmpty()) {
retval = flavorToNativeLookup(flav, true);
} else {
*** 600,610 ****
} catch (MimeTypeParseException mtpe) {
// Cannot happen, since we checked all mappings
// on load from flavormap.properties.
}
! if (DataTransferer.doesSubtypeSupportCharset(subType, null)) {
if (TEXT_PLAIN_BASE_TYPE.equals(baseType))
{
returnValue.add(DataFlavor.stringFlavor);
}
--- 584,594 ----
} catch (MimeTypeParseException mtpe) {
// Cannot happen, since we checked all mappings
// on load from flavormap.properties.
}
! if (DataFlavorUtil.doesSubtypeSupportCharset(subType, null)) {
if (TEXT_PLAIN_BASE_TYPE.equals(baseType))
{
returnValue.add(DataFlavor.stringFlavor);
}
*** 622,632 ****
}
returnValue.add(toAdd);
}
}
! for (String charset : DataTransferer.standardEncodings()) {
for (String encodedTextClass : ENCODED_TEXT_CLASSES) {
final String mimeType =
baseType + ";charset=" + charset +
";class=" + encodedTextClass;
--- 606,616 ----
}
returnValue.add(toAdd);
}
}
! for (String charset : DataFlavorUtil.standardEncodings()) {
for (String encodedTextClass : ENCODED_TEXT_CLASSES) {
final String mimeType =
baseType + ";charset=" + charset +
";class=" + encodedTextClass;