APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt.datatransfer

public final Class SystemFlavorMap

extends Object
implements FlavorMap, FlavorTable
Class Inheritance
All Implemented Interfaces
java.awt.datatransfer.FlavorTable, java.awt.datatransfer.FlavorMap
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, java.lang.ref.SoftReference, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashSet, .List, .Map, .Objects, .Set, sun.datatransfer.DataFlavorUtil, .DesktopDatatransferService

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 applications, and between Java applications in separate VMs.
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private Set<Object>
disabledMappingGenerationKeys

Dynamic mapping generation used for text mappings should not be applied to the DataFlavors and String natives for which the mappings have been explicitly specified with setFlavorsForNative or setNativesForFlavor.

private static final String[]
ENCODED_TEXT_CLASSES

The list of valid, encoded text flavor representation classes, in order from best to worst.

private final SystemFlavorMap.SoftCache<String, DataFlavor>
flavorsForNativeCache

Caches the result getFlavorsForNative().

private final Map<DataFlavor, LinkedHashSet<String>>
flavorToNative

Maps DataFlavors (or base type Strings for text DataFlavors) to Lists of native Strings.

private static final String
HTML_TEXT_BASE_TYPE

A String representing text/html MIME type.

private static final String[]
private boolean
isMapInitialized

Shows if the object has been initialized.

private static String
JavaMIME

Constant prefix used to tag Java types converted to native platform type.

private final SystemFlavorMap.SoftCache<DataFlavor, String>
nativesForFlavorCache

Caches the result of getNativesForFlavor().

private final Map<String, LinkedHashSet<DataFlavor>>
nativeToFlavor

Maps native Strings to Lists of DataFlavors (or base type Strings for text DataFlavors).

private static final String
TEXT_PLAIN_BASE_TYPE

A String representing text/plain MIME type.

private Map<String, LinkedHashSet<String>>
textTypeToNative

Maps a text DataFlavor primary mime-type to the native.

private static final String[]
UNICODE_TEXT_CLASSES

The list of valid, decoded text flavor representation classes, in order from best to worst.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addFlavorForUnencodedNative(String
the String native key for the mapping
nat
,
DataFlavor
the DataFlavor value for the mapping
flav
)

Adds a mapping from a single String native to a single DataFlavor.

public synchronized void
addUnencodedNativeForFlavor(DataFlavor
the DataFlavor key for the mapping
flav
,
String
the String native value for the mapping
nat
)

Adds a mapping from the specified DataFlavor (and all DataFlavors equal to the specified DataFlavor) to the specified String native.

private static Set<DataFlavor>
public static DataFlavor

Returns:

the decoded DataFlavor, or null if nat is not an encoded String native
decodeDataFlavor
(String
the String to decode
nat
)

Decodes a String native for use as a DataFlavor.

public static String

Returns:

the decoded Java MIME type, or null if nat is not an encoded String native
decodeJavaMIMEType
(String
the String to decode
nat
)

Decodes a String native for use as a Java MIME type.

public static String

Returns:

the encoded String, or null if flav is null or has a null MIME type
encodeDataFlavor
(DataFlavor
the DataFlavor to encode
flav
)

Encodes a DataFlavor for use as a String native.

public static String

Returns:

the encoded String, or null if mimeType is null
encodeJavaMIMEType
(String
the MIME type to encode
mimeType
)

Encodes a MIME type for use as a String native.

private LinkedHashSet<String>
flavorToNativeLookup(final DataFlavor flav, final boolean synthesize)

Semantically equivalent to 'flavorToNative.get(flav)'.

public static FlavorMap

Returns:

the default FlavorMap for this thread's ClassLoader
getDefaultFlavorMap
()

Returns the default FlavorMap for this thread's ClassLoader.

public synchronized List<DataFlavor>

Returns:

a java.util.List of DataFlavor objects into which platform-specific data in the specified, platform-specific native can be translated
getFlavorsForNative
(String
the native whose corresponding DataFlavors should be returned. If null is specified, all DataFlavors currently known to the data transfer subsystem are returned in a non-deterministic order.
nat
)

Implements java.awt.datatransfer.FlavorTable.getFlavorsForNative.

Returns a List of DataFlavors to which the specified String native can be translated by the data transfer subsystem.

public synchronized Map<String, DataFlavor>

Returns:

a java.util.Map of String natives to DataFlavors
getFlavorsForNatives
(String[]
an array of Strings which will be the key set of the returned Map. If null is specified, a mapping of all supported String natives to their most preferred DataFlavors will be returned.
natives
)

Implements java.awt.datatransfer.FlavorMap.getFlavorsForNatives.

Returns a Map of the specified String natives to their most preferred DataFlavor.

private synchronized Map<DataFlavor, LinkedHashSet<String>>

Returns:

flavorToNative
getFlavorToNative
()

Accessor to flavorToNative map.

public synchronized List<String>

Returns:

a java.util.List of java.lang.String objects which are platform-specific representations of platform-specific data formats
getNativesForFlavor
(DataFlavor
the DataFlavor whose corresponding natives should be returned. If null is specified, all natives currently known to the data transfer subsystem are returned in a non-deterministic order.
flav
)

Implements java.awt.datatransfer.FlavorTable.getNativesForFlavor.

Returns a List of String natives to which the specified DataFlavor can be translated by the data transfer subsystem.

public synchronized Map<DataFlavor, String>

Returns:

a java.util.Map of DataFlavors to String natives
getNativesForFlavors
(DataFlavor[]
an array of DataFlavors which will be the key set of the returned Map. If null is specified, a mapping of all DataFlavors known to the data transfer subsystem to their most preferred String natives will be returned.
flavors
)

Implements java.awt.datatransfer.FlavorMap.getNativesForFlavors.

Returns a Map of the specified DataFlavors to their most preferred String native.

private Map<String, LinkedHashSet<DataFlavor>>

Returns:

nativeToFlavor
getNativeToFlavor
()

Accessor to nativeToFlavor map.

private synchronized Map<String, LinkedHashSet<String>>

Returns:

textTypeToNative
getTextTypeToNative
()

An accessor to textTypeToNative map.

private static LinkedHashSet<String>
handleHtmlMimeTypes(String baseType, String mimeType)

private void
initSystemFlavorMap()

Initializes a SystemFlavorMap by reading flavormap.properties.

public static boolean

Returns:

true if the String is encoded; false otherwise
isJavaMIMEType
(String
the String to test
str
)

Returns whether the specified String is an encoded Java MIME type.

private static String
loadConvert(String theString)

private LinkedHashSet<DataFlavor>
nativeToFlavorLookup(String nat)

Semantically equivalent to 'nativeToFlavor.get(nat)'.

public synchronized void
setFlavorsForNative(String
the String native key for the mappings
nat
,
DataFlavor[]
the DataFlavor values for the mappings
flavors
)

Discards the current mappings for the specified String native, and creates new mappings to the specified DataFlavors.

public synchronized void
setNativesForFlavor(DataFlavor
the DataFlavor key for the mappings
flav
,
String[]
the String native values for the mappings
natives
)

Discards the current mappings for the specified DataFlavor and all DataFlavors equal to the specified DataFlavor, and creates new mappings to the specified String natives.

private <H, L> void
store(H hashed, L listed, Map<H, LinkedHashSet<L>> map)

Stores the listed object under the specified hash key in map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

disabledMappingGenerationKeysback to summary
private Set<Object> disabledMappingGenerationKeys

Dynamic mapping generation used for text mappings should not be applied to the DataFlavors and String natives for which the mappings have been explicitly specified with setFlavorsForNative or setNativesForFlavor. This keeps all such keys.

ENCODED_TEXT_CLASSESback to summary
private static final String[] ENCODED_TEXT_CLASSES

The list of valid, encoded text flavor representation classes, in order from best to worst.

flavorsForNativeCacheback to summary
private final SystemFlavorMap.SoftCache<String, DataFlavor> flavorsForNativeCache

Caches the result getFlavorsForNative(). Maps String natives to SoftReferences which reference LinkedHashSet of DataFlavors.

flavorToNativeback to summary
private final Map<DataFlavor, LinkedHashSet<String>> flavorToNative

Maps DataFlavors (or base type Strings for text DataFlavors) to Lists of native Strings.

Do not use the field directly, use getFlavorToNative instead.

HTML_TEXT_BASE_TYPEback to summary
private static final String HTML_TEXT_BASE_TYPE

A String representing text/html MIME type.

htmlDocumentTypesback to summary
private static final String[] htmlDocumentTypes
isMapInitializedback to summary
private boolean isMapInitialized

Shows if the object has been initialized.

JavaMIMEback to summary
private static String JavaMIME

Constant prefix used to tag Java types converted to native platform type.

nativesForFlavorCacheback to summary
private final SystemFlavorMap.SoftCache<DataFlavor, String> nativesForFlavorCache

Caches the result of getNativesForFlavor(). Maps DataFlavors to SoftReferences which reference LinkedHashSet of String natives.

nativeToFlavorback to summary
private final Map<String, LinkedHashSet<DataFlavor>> nativeToFlavor

Maps native Strings to Lists of DataFlavors (or base type Strings for text DataFlavors).

Do not use the field directly, use getNativeToFlavor instead.

TEXT_PLAIN_BASE_TYPEback to summary
private static final String TEXT_PLAIN_BASE_TYPE

A String representing text/plain MIME type.

textTypeToNativeback to summary
private Map<String, LinkedHashSet<String>> textTypeToNative

Maps a text DataFlavor primary mime-type to the native. Used only to store standard mappings registered in the flavormap.properties.

Do not use this field directly, use getTextTypeToNative instead.

UNICODE_TEXT_CLASSESback to summary
private static final String[] UNICODE_TEXT_CLASSES

The list of valid, decoded text flavor representation classes, in order from best to worst.

Constructor Detail

SystemFlavorMapback to summary
private SystemFlavorMap()

Method Detail

addFlavorForUnencodedNativeback to summary
public synchronized void addFlavorForUnencodedNative(String nat, DataFlavor flav)

Adds a mapping from a single String native to a single DataFlavor. Unlike getFlavorsForNative, the mapping will only be established in one direction, and the native will not be encoded. To establish a two-way mapping, call addUnencodedNativeForFlavor as well. The new mapping will be of lower priority than any existing mapping. This method has no effect if a mapping from the specified String native to the specified or equal DataFlavor already exists.

Parameters
nat:String

the String native key for the mapping

flav:DataFlavor

the DataFlavor value for the mapping

Exceptions
NullPointerException:
if nat or flav is null
Since
1.4
See Also
addUnencodedNativeForFlavor
addUnencodedNativeForFlavorback to summary
public synchronized void addUnencodedNativeForFlavor(DataFlavor flav, String nat)

Adds a mapping from the specified DataFlavor (and all DataFlavors equal to the specified DataFlavor) to the specified String native. Unlike getNativesForFlavor, the mapping will only be established in one direction, and the native will not be encoded. To establish a two-way mapping, call addFlavorForUnencodedNative as well. The new mapping will be of lower priority than any existing mapping. This method has no effect if a mapping from the specified or equal DataFlavor to the specified String native already exists.

Parameters
flav:DataFlavor

the DataFlavor key for the mapping

nat:String

the String native value for the mapping

Exceptions
NullPointerException:
if flav or nat is null
Since
1.4
See Also
addFlavorForUnencodedNative
convertMimeTypeToDataFlavorsback to summary
private static Set<DataFlavor> convertMimeTypeToDataFlavors(final String baseType)
Annotations
@SuppressWarnings:deprecation
decodeDataFlavorback to summary
public static DataFlavor decodeDataFlavor(String nat) throws ClassNotFoundException

Decodes a String native for use as a DataFlavor.

Parameters
nat:String

the String to decode

Returns:DataFlavor

the decoded DataFlavor, or null if nat is not an encoded String native

Exceptions
ClassNotFoundException:
if the class of the data flavor is not loaded
decodeJavaMIMETypeback to summary
public static String decodeJavaMIMEType(String nat)

Decodes a String native for use as a Java MIME type.

Parameters
nat:String

the String to decode

Returns:String

the decoded Java MIME type, or null if nat is not an encoded String native

encodeDataFlavorback to summary
public static String encodeDataFlavor(DataFlavor flav)

Encodes a DataFlavor for use as a String native. The format of an encoded DataFlavor is implementation-dependent. The only restrictions are:

  • The encoded representation is null if and only if the specified DataFlavor is null or its MIME type String is null
  • The encoded representations for two non-null DataFlavors with non-null MIME type Strings are equal if and only if the MIME type Strings of these DataFlavors are equal according to String.equals(Object)
The reference implementation of this method returns the MIME type String of the specified DataFlavor prefixed with JAVA_DATAFLAVOR:.
Parameters
flav:DataFlavor

the DataFlavor to encode

Returns:String

the encoded String, or null if flav is null or has a null MIME type

encodeJavaMIMETypeback to summary
public static String encodeJavaMIMEType(String mimeType)

Encodes a MIME type for use as a String native. The format of an encoded representation of a MIME type is implementation-dependent. The only restrictions are:

  • The encoded representation is null if and only if the MIME type String is null
  • The encoded representations for two non-null MIME type Strings are equal if and only if these Strings are equal according to String.equals(Object)
The reference implementation of this method returns the specified MIME type String prefixed with JAVA_DATAFLAVOR:.
Parameters
mimeType:String

the MIME type to encode

Returns:String

the encoded String, or null if mimeType is null

flavorToNativeLookupback to summary
private LinkedHashSet<String> flavorToNativeLookup(final DataFlavor flav, final boolean synthesize)

Semantically equivalent to 'flavorToNative.get(flav)'. This method handles the case where 'flav' is not found in 'flavorToNative' depending on the value of passes 'synthesize' parameter. If 'synthesize' is SYNTHESIZE_IF_NOT_FOUND a native is synthesized, stored, and returned by encoding the DataFlavor's MIME type. Otherwise an empty List is returned and 'flavorToNative' remains unaffected.

getDefaultFlavorMapback to summary
public static FlavorMap getDefaultFlavorMap()

Returns the default FlavorMap for this thread's ClassLoader.

Returns:FlavorMap

the default FlavorMap for this thread's ClassLoader

getFlavorsForNativeback to summary
public synchronized List<DataFlavor> getFlavorsForNative(String nat)

Implements java.awt.datatransfer.FlavorTable.getFlavorsForNative.

Returns a List of DataFlavors to which the specified String native can be translated by the data transfer subsystem. The List will be sorted from best DataFlavor to worst. That is, the first DataFlavor will best reflect data in the specified native to a Java application.

If the specified native is previously unknown to the data transfer subsystem, and that native has been properly encoded, then invoking this method will establish a mapping in both directions between the specified native and a DataFlavor whose MIME type is a decoded version of the native.

If the specified native is not a properly encoded native and the mappings for this native have not been altered with setFlavorsForNative, then the contents of the List is platform dependent, but null cannot be returned.

Parameters
nat:String

the native whose corresponding DataFlavors should be returned. If null is specified, all DataFlavors currently known to the data transfer subsystem are returned in a non-deterministic order.

Returns:List<DataFlavor>

a java.util.List of DataFlavor objects into which platform-specific data in the specified, platform-specific native can be translated

Annotations
@Override
Since
1.4
See Also
encodeJavaMIMEType
getFlavorsForNativesback to summary
public synchronized Map<String, DataFlavor> getFlavorsForNatives(String[] natives)

Implements java.awt.datatransfer.FlavorMap.getFlavorsForNatives.

Returns a Map of the specified String natives to their most preferred DataFlavor. Each DataFlavor value will be the same as the first DataFlavor in the List returned by getFlavorsForNative for the specified native.

If a specified native is previously unknown to the data transfer subsystem, and that native has been properly encoded, then invoking this method will establish a mapping in both directions between the specified native and a DataFlavor whose MIME type is a decoded version of the native.

Parameters
natives:String[]

an array of Strings which will be the key set of the returned Map. If null is specified, a mapping of all supported String natives to their most preferred DataFlavors will be returned.

Returns:Map<String, DataFlavor>

a java.util.Map of String natives to DataFlavors

Annotations
@Override
See Also
getFlavorsForNative, encodeJavaMIMEType
getFlavorToNativeback to summary
private synchronized Map<DataFlavor, LinkedHashSet<String>> getFlavorToNative()

Accessor to flavorToNative map. Since we use lazy initialization we must use this accessor instead of direct access to the field which may not be initialized yet. This method will initialize the field if needed.

Returns:Map<DataFlavor, LinkedHashSet<String>>

flavorToNative

getNativesForFlavorback to summary
public synchronized List<String> getNativesForFlavor(DataFlavor flav)

Implements java.awt.datatransfer.FlavorTable.getNativesForFlavor.

Returns a List of String natives to which the specified DataFlavor can be translated by the data transfer subsystem. The List will be sorted from best native to worst. That is, the first native will best reflect data in the specified flavor to the underlying native platform.

If the specified DataFlavor is previously unknown to the data transfer subsystem and the data transfer subsystem is unable to translate this DataFlavor to any existing native, then invoking this method will establish a mapping in both directions between the specified DataFlavor and an encoded version of its MIME type as its native.

Parameters
flav:DataFlavor

the DataFlavor whose corresponding natives should be returned. If null is specified, all natives currently known to the data transfer subsystem are returned in a non-deterministic order.

Returns:List<String>

a java.util.List of java.lang.String objects which are platform-specific representations of platform-specific data formats

Annotations
@Override
Since
1.4
See Also
encodeDataFlavor
getNativesForFlavorsback to summary
public synchronized Map<DataFlavor, String> getNativesForFlavors(DataFlavor[] flavors)

Implements java.awt.datatransfer.FlavorMap.getNativesForFlavors.

Returns a Map of the specified DataFlavors to their most preferred String native. Each native value will be the same as the first native in the List returned by getNativesForFlavor for the specified flavor.

If a specified DataFlavor is previously unknown to the data transfer subsystem, then invoking this method will establish a mapping in both directions between the specified DataFlavor and an encoded version of its MIME type as its native.

Parameters
flavors:DataFlavor[]

an array of DataFlavors which will be the key set of the returned Map. If null is specified, a mapping of all DataFlavors known to the data transfer subsystem to their most preferred String natives will be returned.

Returns:Map<DataFlavor, String>

a java.util.Map of DataFlavors to String natives

Annotations
@Override
See Also
getNativesForFlavor, encodeDataFlavor
getNativeToFlavorback to summary
private Map<String, LinkedHashSet<DataFlavor>> getNativeToFlavor()

Accessor to nativeToFlavor map. Since we use lazy initialization we must use this accessor instead of direct access to the field which may not be initialized yet. This method will initialize the field if needed.

Returns:Map<String, LinkedHashSet<DataFlavor>>

nativeToFlavor

getTextTypeToNativeback to summary
private synchronized Map<String, LinkedHashSet<String>> getTextTypeToNative()

An accessor to textTypeToNative map. Since we use lazy initialization we must use this accessor instead of direct access to the field which may not be initialized yet. This method will initialize the field if needed.

Returns:Map<String, LinkedHashSet<String>>

textTypeToNative

handleHtmlMimeTypesback to summary
private static LinkedHashSet<String> handleHtmlMimeTypes(String baseType, String mimeType)
initSystemFlavorMapback to summary
private void initSystemFlavorMap()

Initializes a SystemFlavorMap by reading flavormap.properties. For thread-safety must be called under lock on this.

isJavaMIMETypeback to summary
public static boolean isJavaMIMEType(String str)

Returns whether the specified String is an encoded Java MIME type.

Parameters
str:String

the String to test

Returns:boolean

true if the String is encoded; false otherwise

loadConvertback to summary
private static String loadConvert(String theString)
nativeToFlavorLookupback to summary
private LinkedHashSet<DataFlavor> nativeToFlavorLookup(String nat)

Semantically equivalent to 'nativeToFlavor.get(nat)'. This method handles the case where 'nat' is not found in 'nativeToFlavor'. In that case, a new DataFlavor is synthesized, stored, and returned, if and only if the specified native is encoded as a Java MIME type.

setFlavorsForNativeback to summary
public synchronized void setFlavorsForNative(String nat, DataFlavor[] flavors)

Discards the current mappings for the specified String native, and creates new mappings to the specified DataFlavors. Unlike getFlavorsForNative, the mappings will only be established in one direction, and the natives need not be encoded. To establish two-way mappings, call setNativesForFlavor as well. The first DataFlavor in the array will represent the highest priority mapping. Subsequent DataFlavors will represent mappings of decreasing priority.

If the array contains several elements that reference equal DataFlavors, this method will establish new mappings for the first of those elements and ignore the rest of them.

It is recommended that client code not reset mappings established by the data transfer subsystem. This method should only be used for application-level mappings.

Parameters
nat:String

the String native key for the mappings

flavors:DataFlavor[]

the DataFlavor values for the mappings

Exceptions
NullPointerException:
if nat or flavors is null or if flavors contains null elements
Since
1.4
See Also
setNativesForFlavor
setNativesForFlavorback to summary
public synchronized void setNativesForFlavor(DataFlavor flav, String[] natives)

Discards the current mappings for the specified DataFlavor and all DataFlavors equal to the specified DataFlavor, and creates new mappings to the specified String natives. Unlike getNativesForFlavor, the mappings will only be established in one direction, and the natives will not be encoded. To establish two-way mappings, call setFlavorsForNative as well. The first native in the array will represent the highest priority mapping. Subsequent natives will represent mappings of decreasing priority.

If the array contains several elements that reference equal String natives, this method will establish new mappings for the first of those elements and ignore the rest of them.

It is recommended that client code not reset mappings established by the data transfer subsystem. This method should only be used for application-level mappings.

Parameters
flav:DataFlavor

the DataFlavor key for the mappings

natives:String[]

the String native values for the mappings

Exceptions
NullPointerException:
if flav or natives is null or if natives contains null elements
Since
1.4
See Also
setFlavorsForNative
storeback to summary
private <H, L> void store(H hashed, L listed, Map<H, LinkedHashSet<L>> map)

Stores the listed object under the specified hash key in map. Unlike a standard map, the listed object will not replace any object already at the appropriate Map location, but rather will be appended to a List stored in that location.

java.awt.datatransfer back to summary

private final Class SystemFlavorMap.SoftCache<K, V>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Map<K, SoftReference<LinkedHashSet<V>>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public LinkedHashSet<V>
check(K key)

public void
put(K key, LinkedHashSet<V> value)

public void
remove(K key)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
pack-priv Map<K, SoftReference<LinkedHashSet<V>>> cache

Constructor Detail

SoftCacheback to summary
private SoftCache()

Method Detail

checkback to summary
public LinkedHashSet<V> check(K key)
putback to summary
public void put(K key, LinkedHashSet<V> value)
removeback to summary
public void remove(K key)