Index: SystemFlavorMap.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/datatransfer/SystemFlavorMap.java,v
retrieving revision 1.9
diff -u -r1.9 SystemFlavorMap.java
--- SystemFlavorMap.java 30 Nov 2005 00:59:57 -0000 1.9
+++ SystemFlavorMap.java 30 Nov 2005 01:44:52 -0000
@@ -62,6 +62,11 @@
private static final Map systemFlavorMaps = new WeakHashMap();
/**
+ * Constant which is used to prefix encode Java MIME types.
+ */
+ private static final String GNU_JAVA_MIME_PREFIX = "gnu.java:";
+
+ /**
* This map maps native String
s to lists of
* DataFlavor
s
*/
@@ -72,7 +77,7 @@
* String
s
*/
private HashMap flavorToNativeMap = new HashMap();
-
+
/**
* Private constructor.
*/
@@ -141,36 +146,90 @@
}
/**
- * Returns the native type name for the given java mime type.
+ * 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:
+ *
null
if and only if the
+ * MIME type String
is null
.null
MIME type
+ * String
s are equal if and only if these String
s
+ * are equal according to String.equals(Object)
.
+ * The present implementation of this method returns the specified MIME
+ * type String
prefixed with gnu.java:
.
+ *
+ * @param mime the MIME type to encode
+ * @return the encoded String
, or null
if
+ * mimeType is null
*/
public static String encodeJavaMIMEType (String mime)
{
- return null;
+ if (mime != null)
+ return GNU_JAVA_MIME_PREFIX + mime;
+ else
+ return null;
}
/**
- * Returns the native type name for the given data flavor.
+ * Encodes a DataFlavor
for use as a String
+ * native. The format of an encoded DataFlavor
is
+ * implementation-dependent. The only restrictions are:
+ *
null
if and only if the
+ * specified DataFlavor
is null
or its MIME type
+ * String
is null
.null
+ * DataFlavor
s with non-null
MIME type
+ * String
s are equal if and only if the MIME type
+ * String
s of these DataFlavor
s are equal
+ * according to String.equals(Object)
.
+ * The present implementation of this method returns the MIME type
+ * String
of the specified DataFlavor
prefixed
+ * with gnu.java:
.
+ *
+ * @param df the DataFlavor
to encode
+ * @return the encoded String
, or null
if
+ * flav is null
or has a null
MIME type
*/
public static String encodeDataFlavor (DataFlavor df)
{
- return null;
+ if (df != null)
+ {
+ return encodeJavaMIMEType(df.getMimeType());
+ }
+ else
+ return null;
}
/**
* Returns true if the native type name can be represented as
- * a java mime type.
+ * a java mime type. Returns false
if parameter is
+ * null
.
*/
public static boolean isJavaMIMEType (String name)
{
- return false;
+ return (name != null && name.startsWith(GNU_JAVA_MIME_PREFIX));
}
/**
- * Returns the java mime type for the given the native type name.
+ * Decodes a String
native for use as a Java MIME type.
+ *
+ * @param name the String
to decode
+ * @return the decoded Java MIME type, or null
if nat
+ * is not an encoded String
native
*/
public static String decodeJavaMIMEType (String name)
{
- return null;
+ if (isJavaMIMEType(name))
+ {
+ return name.substring(GNU_JAVA_MIME_PREFIX.length());
+ }
+ else
+ return null;
}
/**
@@ -188,6 +247,20 @@
return null;
}
+ /**
+ * 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. + */ public List getFlavorsForNative (String nat) { throw new Error ("Not implemented");