I changed the order of attributes and methods to the order mentioned
below and moved the assignment of static variables from static{} block
to variable declaration.
2005-11-21 Jan Roehrich <[EMAIL PROTECTED]>
* java/awt/datatransfer/DataFlavor.java: more code style
fixes. Changed order to static attributes, attributes, static
methods, constructors, methods. Moved static part into static
attribute declaration.
Index: DataFlavor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/datatransfer/DataFlavor.java,v
retrieving revision 1.26
diff -u -r1.26 DataFlavor.java
--- DataFlavor.java 21 Nov 2005 01:58:27 -0000 1.26
+++ DataFlavor.java 21 Nov 2005 22:06:36 -0000
@@ -71,27 +71,35 @@
* @deprecated The charset unicode is platform specific and InputStream
* deals with bytes not chars. Use <code>getRederForText()</code>.
*/
- public static final DataFlavor plainTextFlavor;
+ public static final DataFlavor plainTextFlavor =
+ new DataFlavor(java.io.InputStream.class,
+ "text/plain; charset=unicode",
+ "plain unicode text");
/**
* This is the data flavor used for transferring Java strings. The
* MIME type is "application/x-java-serialized-object" and the
* representation class is <code>java.lang.String</code>.
*/
- public static final DataFlavor stringFlavor;
+ public static final DataFlavor stringFlavor =
+ new DataFlavor(java.lang.String.class, "Java Unicode String");
/**
* This is a data flavor used for transferring lists of files. The
* representation type is a <code>java.util.List</code>, with each
* element of the list being a <code>java.io.File</code>.
*/
- public static final DataFlavor javaFileListFlavor;
+ public static final DataFlavor javaFileListFlavor =
+ new DataFlavor(java.util.List.class,
+ "application/x-java-file-list; class=java.util.List",
+ "Java File List");
/**
* This is an image flavor used for transferring images. The
* representation type is a <code>java.awt.Image</code>.
*/
- public static final DataFlavor imageFlavor;
+ public static final DataFlavor imageFlavor =
+ new DataFlavor(java.awt.Image.class, "Java Image");
/**
* This is the MIME type used for transferring a serialized object.
@@ -115,27 +123,6 @@
public static final String javaRemoteObjectMimeType =
"application/x-java-remote-object";
- static
- {
- plainTextFlavor
- = new DataFlavor(java.io.InputStream.class,
- "text/plain; charset=unicode",
- "plain unicode text");
-
- stringFlavor
- = new DataFlavor(java.lang.String.class,
- "Java Unicode String");
-
- javaFileListFlavor
- = new DataFlavor(java.util.List.class,
- "application/x-java-file-list; class=java.util.List",
- "Java File List");
-
- imageFlavor
- = new DataFlavor(java.awt.Image.class,
- "Java Image");
- }
-
/*
* Instance Variables
*/
@@ -202,6 +189,107 @@
else
throw new ClassNotFoundException(className);
}
+
+ private static Class getRepresentationClassFromMime(String mimeString,
+ ClassLoader classLoader)
+ {
+ String classname = getParameter("class", mimeString);
+ if (classname != null)
+ {
+ try
+ {
+ return tryToLoadClass(classname, classLoader);
+ }
+ catch(Exception e)
+ {
+ throw new IllegalArgumentException("classname: " + e.getMessage());
+ }
+ }
+ else
+ return java.io.InputStream.class;
+ }
+
+ /**
+ * Returns the value of the named MIME type parameter, or <code>null</code>
+ * if the parameter does not exist. Given the parameter name and the mime
+ * string.
+ *
+ * @param paramName The name of the parameter.
+ * @param mimeString The mime string from where the name should be found.
+ *
+ * @return The value of the parameter or null.
+ */
+ private static String getParameter(String paramName, String mimeString)
+ {
+ int idx = mimeString.indexOf(paramName + "=");
+ if (idx == -1)
+ return(null);
+
+ String value = mimeString.substring(idx + paramName.length() + 1);
+
+ idx = value.indexOf(" ");
+ if (idx == -1)
+ return(value);
+ else
+ return(value.substring(0, idx));
+ }
+
+ /**
+ * XXX - Currently returns <code>plainTextFlavor</code>.
+ */
+ public static final DataFlavor getTextPlainUnicodeFlavor()
+ {
+ return plainTextFlavor;
+ }
+
+ /**
+ * Selects the best supported text flavor on this implementation.
+ * Returns <code>null</code> when none of the given flavors is liked.
+ *
+ * The <code>DataFlavor</code> returned the first data flavor in the
+ * array that has either a representation class which is (a subclass of)
+ * <code>Reader</code> or <code>String</code>, or has a representation
+ * class which is (a subclass of) <code>InputStream</code> and has a
+ * primary MIME type of "text" and has an supported encoding.
+ */
+ public static final DataFlavor
+ selectBestTextFlavor(DataFlavor[] availableFlavors)
+ {
+ for(int i = 0; i < availableFlavors.length; i++)
+ {
+ DataFlavor df = availableFlavors[i];
+ Class c = df.representationClass;
+
+ // A Reader or String is good.
+ if ((Reader.class.isAssignableFrom(c))
+ || (String.class.isAssignableFrom(c)))
+ return df;
+
+ // A InputStream is good if the mime primary type is "text"
+ if ((InputStream.class.isAssignableFrom(c))
+ && ("text".equals(df.getPrimaryType())))
+ {
+ String encoding = availableFlavors[i].getParameter("charset");
+ if (encoding == null)
+ encoding = "us-ascii";
+ Reader r = null;
+ try
+ {
+ // Try to construct a dummy reader with the found encoding
+ r = new InputStreamReader
+ (new ByteArrayInputStream(new byte[0]), encoding);
+ }
+ catch(UnsupportedEncodingException uee) { /* ignore */ }
+
+ if (r != null)
+ return df;
+ }
+ }
+
+ // Nothing found
+ return null;
+ }
+
/*
* Constructors
@@ -278,25 +366,6 @@
mimeType, humanPresentableName);
}
- private static Class getRepresentationClassFromMime(String mimeString,
- ClassLoader classLoader)
- {
- String classname = getParameter("class", mimeString);
- if (classname != null)
- {
- try
- {
- return tryToLoadClass(classname, classLoader);
- }
- catch(Exception e)
- {
- throw new IllegalArgumentException("classname: " + e.getMessage());
- }
- }
- else
- return java.io.InputStream.class;
- }
-
/**
* Initializes a new instance of <code>DataFlavor</code> with the
* specified MIME type and description. If the MIME type has a
@@ -402,31 +471,6 @@
/**
* Returns the value of the named MIME type parameter, or <code>null</code>
- * if the parameter does not exist. Given the parameter name and the mime
- * string.
- *
- * @param paramName The name of the parameter.
- * @param mimeString The mime string from where the name should be found.
- *
- * @return The value of the parameter or null.
- */
- private static String getParameter(String paramName, String mimeString)
- {
- int idx = mimeString.indexOf(paramName + "=");
- if (idx == -1)
- return(null);
-
- String value = mimeString.substring(idx + paramName.length() + 1);
-
- idx = value.indexOf(" ");
- if (idx == -1)
- return(value);
- else
- return(value.substring(0, idx));
- }
-
- /**
- * Returns the value of the named MIME type parameter, or <code>null</code>
* if the parameter does not exist.
*
* @param paramName The name of the paramter.
@@ -765,14 +809,6 @@
}
/**
- * XXX - Currently returns <code>plainTextFlavor</code>.
- */
- public static final DataFlavor getTextPlainUnicodeFlavor()
- {
- return plainTextFlavor;
- }
-
- /**
* XXX - Currently returns <code>java.io.InputStream</code>.
*
* @since 1.3
@@ -788,54 +824,6 @@
public final String getDefaultRepresentationClassAsString()
{
return getDefaultRepresentationClass().getName();
- }
-
- /**
- * Selects the best supported text flavor on this implementation.
- * Returns <code>null</code> when none of the given flavors is liked.
- *
- * The <code>DataFlavor</code> returned the first data flavor in the
- * array that has either a representation class which is (a subclass of)
- * <code>Reader</code> or <code>String</code>, or has a representation
- * class which is (a subclass of) <code>InputStream</code> and has a
- * primary MIME type of "text" and has an supported encoding.
- */
- public static final DataFlavor
- selectBestTextFlavor(DataFlavor[] availableFlavors)
- {
- for(int i = 0; i < availableFlavors.length; i++)
- {
- DataFlavor df = availableFlavors[i];
- Class c = df.representationClass;
-
- // A Reader or String is good.
- if ((Reader.class.isAssignableFrom(c))
- || (String.class.isAssignableFrom(c)))
- return df;
-
- // A InputStream is good if the mime primary type is "text"
- if ((InputStream.class.isAssignableFrom(c))
- && ("text".equals(df.getPrimaryType())))
- {
- String encoding = availableFlavors[i].getParameter("charset");
- if (encoding == null)
- encoding = "us-ascii";
- Reader r = null;
- try
- {
- // Try to construct a dummy reader with the found encoding
- r = new InputStreamReader
- (new ByteArrayInputStream(new byte[0]), encoding);
- }
- catch(UnsupportedEncodingException uee) { /* ignore */ }
-
- if (r != null)
- return df;
- }
- }
-
- // Nothing found
- return null;
}
/**
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
_______________________________________________ Classpath-patches mailing list [email protected] http://lists.gnu.org/mailman/listinfo/classpath-patches
