jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java
author mcherkas
Fri, 04 Oct 2013 20:13:32 +0400
changeset 20455 f6f9a0c2796b
parent 20172 f48935a247ec
child 20854 242194ae1563
child 21250 12f343590d5a
permissions -rw-r--r--
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index. Reviewed-by: anthony, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
     2
 * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4267
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.datatransfer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.datatransfer.DataTransferer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A {@code DataFlavor} provides meta information about data. {@code DataFlavor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * is typically used to access data on the clipboard, or during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * a drag and drop operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * An instance of {@code DataFlavor} encapsulates a content type as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * defined in <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * and <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * A content type is typically referred to as a MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A content type consists of a media type (referred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * to as the primary type), a subtype, and optional parameters. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * for details on the syntax of a MIME type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The JRE data transfer implementation interprets the parameter &quot;class&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * of a MIME type as <B>a representation class</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The representation class reflects the class of the object being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * transferred. In other words, the representation class is the type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * object returned by {@link Transferable#getTransferData}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * For example, the MIME type of {@link #imageFlavor} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * {@code "image/x-java-image;class=java.awt.Image"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the primary type is {@code image}, the subtype is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * {@code x-java-image}, and the representation class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * {@code java.awt.Image}. When {@code getTransferData} is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * with a {@code DataFlavor} of {@code imageFlavor}, an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * {@code java.awt.Image} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * It's important to note that {@code DataFlavor} does no error checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * against the representation class. It is up to consumers of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * {@code DataFlavor}, such as {@code Transferable}, to honor the representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Note, if you do not specify a representation class when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * creating a {@code DataFlavor}, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * representation class is used. See appropriate documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * {@code DataFlavor}'s constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Also, {@code DataFlavor} instances with the &quot;text&quot; primary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * MIME type may have a &quot;charset&quot; parameter. Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * {@link #selectBestTextFlavor} for details on &quot;text&quot; MIME types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * and the &quot;charset&quot; parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Equality of {@code DataFlavors} is determined by the primary type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * subtype, and representation class. Refer to {@link #equals(DataFlavor)} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * details. When determining equality, any optional parameters are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * For example, the following produces two {@code DataFlavors} that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * are considered identical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   DataFlavor flavor1 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; foo=bar&quot;);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *   DataFlavor flavor2 = new DataFlavor(Object.class, &quot;X-test/test; class=&lt;java.lang.Object&gt;; x=y&quot;);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   // The following returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *   flavor1.equals(flavor2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * As mentioned, {@code flavor1} and {@code flavor2} are considered identical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * As such, asking a {@code Transferable} for either {@code DataFlavor} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * the same results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * For more information on the using data transfer with Swing see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20172
diff changeset
    93
 * the <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * How to Use Drag and Drop and Data Transfer</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * section in <em>Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @author      Blake Sullivan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @author      Laurence P. G. Cable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @author      Jeff Dunn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
public class DataFlavor implements Externalizable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final long serialVersionUID = 8367026044764648243L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final Class ioInputStreamClass = java.io.InputStream.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Tries to load a class from: the bootstrap loader, the system loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * the context loader (if one is present) and finally the loader specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param className the name of the class to be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param fallback the fallback loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return the class loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @exception ClassNotFoundException if class is not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected final static Class<?> tryToLoadClass(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                   ClassLoader fallback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        ClassLoader systemClassLoader = (ClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        ClassLoader cl = Thread.currentThread().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                            getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        return (cl != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                            ? cl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                            : ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return Class.forName(className, true, systemClassLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } catch (ClassNotFoundException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            if (fallback != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                return Class.forName(className, true, fallback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                throw new ClassNotFoundException(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * private initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static private DataFlavor createConstant(Class rc, String prn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return new DataFlavor(rc, prn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * private initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    static private DataFlavor createConstant(String mt, String prn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return new DataFlavor(mt, prn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   164
    /*
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   165
     * private initializer
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   166
     */
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   167
    static private DataFlavor initHtmlDataFlavor(String htmlFlavorType) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   168
        try {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   169
            return new DataFlavor ("text/html; class=java.lang.String;document=" +
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   170
                                       htmlFlavorType + ";charset=Unicode");
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   171
        } catch (Exception e) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   172
            return null;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   173
        }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   174
    }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   175
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * The <code>DataFlavor</code> representing a Java Unicode String class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *     representationClass = java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *     mimeType           = "application/x-java-serialized-object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public static final DataFlavor stringFlavor = createConstant(java.lang.String.class, "Unicode String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * The <code>DataFlavor</code> representing a Java Image class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *     representationClass = java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *     mimeType            = "image/x-java-image"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static final DataFlavor imageFlavor = createConstant("image/x-java-image; class=java.awt.Image", "Image");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The <code>DataFlavor</code> representing plain text with Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * encoding, where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *     representationClass = InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *     mimeType            = "text/plain; charset=unicode"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * This <code>DataFlavor</code> has been <b>deprecated</b> because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * (1) Its representation is an InputStream, an 8-bit based representation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * while Unicode is a 16-bit character set; and (2) The charset "unicode"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * is not well-defined. "unicode" implies a particular platform's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * implementation of Unicode, not a cross-platform implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @deprecated as of 1.3. Use <code>DataFlavor.getReaderForText(Transferable)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *             instead of <code>Transferable.getTransferData(DataFlavor.plainTextFlavor)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public static final DataFlavor plainTextFlavor = createConstant("text/plain; charset=unicode; class=java.io.InputStream", "Plain Text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * A MIME Content-Type of application/x-java-serialized-object represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * a graph of Java object(s) that have been made persistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * The representation class associated with this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * identifies the Java type of an object returned as a reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * from an invocation <code>java.awt.datatransfer.getTransferData</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public static final String javaSerializedObjectMimeType = "application/x-java-serialized-object";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * To transfer a list of files to/from Java (and the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * platform) a <code>DataFlavor</code> of this type/subtype and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * representation class of <code>java.util.List</code> is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Each element of the list is required/guaranteed to be of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <code>java.io.File</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public static final DataFlavor javaFileListFlavor = createConstant("application/x-java-file-list;class=java.util.List", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * To transfer a reference to an arbitrary Java object reference that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * has no associated MIME Content-type, across a <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * interface WITHIN THE SAME JVM, a <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * with this type/subtype is used, with a <code>representationClass</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * equal to the type of the class/interface being passed across the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <code>Transferable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * The object reference returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <code>Transferable.getTransferData</code> for a <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * with this MIME Content-Type is required to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * an instance of the representation Class of the <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static final String javaJVMLocalObjectMimeType = "application/x-java-jvm-local-objectref";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * In order to pass a live link to a Remote object via a Drag and Drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <code>ACTION_LINK</code> operation a Mime Content Type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * application/x-java-remote-object should be used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * where the representation class of the <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * represents the type of the <code>Remote</code> interface to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * transferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public static final String javaRemoteObjectMimeType = "application/x-java-remote-object";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   260
     * Represents a piece of an HTML markup. The markup consists of the part
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   261
     * selected on the source side. Therefore some tags in the markup may be
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   262
     * unpaired. If the flavor is used to represent the data in
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   263
     * a {@link Transferable} instance, no additional changes will be made.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   264
     * This DataFlavor instance represents the same HTML markup as DataFlavor
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   265
     * instances which content MIME type does not contain document parameter
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   266
     * and representation class is the String class.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   267
     * <pre>
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   268
     *     representationClass = String
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   269
     *     mimeType           = "text/html"
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   270
     * </pre>
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   271
     */
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   272
    public static DataFlavor selectionHtmlFlavor = initHtmlDataFlavor("selection");
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   273
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   274
    /**
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   275
     * Represents a piece of an HTML markup. If possible, the markup received
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   276
     * from a native system is supplemented with pair tags to be
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   277
     * a well-formed HTML markup. If the flavor is used to represent the data in
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   278
     * a {@link Transferable} instance, no additional changes will be made.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   279
     * <pre>
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   280
     *     representationClass = String
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   281
     *     mimeType           = "text/html"
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   282
     * </pre>
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   283
     */
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   284
    public static DataFlavor fragmentHtmlFlavor = initHtmlDataFlavor("fragment");
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   285
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   286
    /**
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   287
     * Represents a piece of an HTML markup. If possible, the markup
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   288
     * received from a native system is supplemented with additional
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   289
     * tags to make up a well-formed HTML document. If the flavor is used to
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   290
     * represent the data in a {@link Transferable} instance,
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   291
     * no additional changes will be made.
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   292
     * <pre>
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   293
     *     representationClass = String
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   294
     *     mimeType           = "text/html"
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   295
     * </pre>
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   296
     */
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   297
    public static  DataFlavor allHtmlFlavor = initHtmlDataFlavor("all");
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   298
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
   299
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Constructs a new <code>DataFlavor</code>.  This constructor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * provided only for the purpose of supporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <code>Externalizable</code> interface.  It is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * intended for public (client) use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public DataFlavor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Constructs a fully specified <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @exception NullPointerException if either <code>primaryType</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *            <code>subType</code> or <code>representationClass</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class representationClass, String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (primaryType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            throw new NullPointerException("primaryType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (subType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            throw new NullPointerException("subType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            throw new NullPointerException("representationClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (params == null) params = new MimeTypeParameterList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        params.set("class", representationClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (humanPresentableName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            humanPresentableName = (String)params.get("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            if (humanPresentableName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                humanPresentableName = primaryType + "/" + subType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            mimeType = new MimeType(primaryType, subType, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            throw new IllegalArgumentException("MimeType Parse Exception: " + mtpe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        this.representationClass  = representationClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        this.humanPresentableName = humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        mimeType.removeParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Constructs a <code>DataFlavor</code> that represents a Java class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * The returned <code>DataFlavor</code> will have the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *    representationClass = representationClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *    mimeType            = application/x-java-serialized-object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param representationClass the class used to transfer data in this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param humanPresentableName the human-readable string used to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *                 this flavor; if this parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *                 then the value of the the MIME Content Type is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @exception NullPointerException if <code>representationClass</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public DataFlavor(Class<?> representationClass, String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        this("application", "x-java-serialized-object", null, representationClass, humanPresentableName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw new NullPointerException("representationClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Constructs a <code>DataFlavor</code> that represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * <code>MimeType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * The returned <code>DataFlavor</code> will have the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * If the <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * "application/x-java-serialized-object; class=&lt;representation class&gt;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * the result is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Otherwise:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *     representationClass = InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *     mimeType            = mimeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param mimeType the string used to identify the MIME type for this flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *                 if the the <code>mimeType</code> does not specify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *                 "class=" parameter, or if the class is not successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *                 loaded, then an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *                 is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param humanPresentableName the human-readable string used to identify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *                 this flavor; if this parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *                 then the value of the the MIME Content Type is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @exception IllegalArgumentException if <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *                 invalid or if the class is not successfully loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @exception NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public DataFlavor(String mimeType, String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            initialize(mimeType, humanPresentableName, this.getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            throw new IllegalArgumentException("failed to parse:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        } catch (ClassNotFoundException cnfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            throw new IllegalArgumentException("can't find specified class: " + cnfe.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Constructs a <code>DataFlavor</code> that represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <code>MimeType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * The returned <code>DataFlavor</code> will have the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * If the mimeType is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * "application/x-java-serialized-object; class=&lt;representation class&gt;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * the result is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Otherwise:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *     representationClass = InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *     mimeType            = mimeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @param mimeType the string used to identify the MIME type for this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @param humanPresentableName the human-readable string used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *          identify this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param classLoader the class loader to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception ClassNotFoundException if the class is not loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @exception IllegalArgumentException if <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *                 invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @exception NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            initialize(mimeType, humanPresentableName, classLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            throw new IllegalArgumentException("failed to parse:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Constructs a <code>DataFlavor</code> from a <code>mimeType</code> string.
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 16705
diff changeset
   457
     * The string can specify a "class=&lt;fully specified Java class name&gt;"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * parameter to create a <code>DataFlavor</code> with the desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * representation class. If the string does not contain "class=" parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * <code>java.io.InputStream</code> is used as default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param mimeType the string used to identify the MIME type for this flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *                 if the class specified by "class=" parameter is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *                 successfully loaded, then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *                 <code>ClassNotFoundException</code> is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @exception ClassNotFoundException if the class is not loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @exception IllegalArgumentException if <code>mimeType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *                 invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @exception NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public DataFlavor(String mimeType) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            initialize(mimeType, null, this.getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            throw new IllegalArgumentException("failed to parse:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    * Common initialization code called from various constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    * @param mimeType the MIME Content Type (must have a class= param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    * @param humanPresentableName the human Presentable Name or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    *                 <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    * @param classLoader the fallback class loader to resolve against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    * @throws MimeTypeParseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    * @throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    * @throws  NullPointerException if <code>mimeType</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    * @see tryToLoadClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        this.mimeType = new MimeType(mimeType); // throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        String rcn = getParameter("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (rcn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if ("application/x-java-serialized-object".equals(this.mimeType.getBaseType()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                throw new IllegalArgumentException("no representation class specified for:" + mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                representationClass = java.io.InputStream.class; // default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        } else { // got a class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            representationClass = DataFlavor.tryToLoadClass(rcn, classLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        this.mimeType.setParameter("class", representationClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (humanPresentableName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            humanPresentableName = this.mimeType.getParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (humanPresentableName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                humanPresentableName = this.mimeType.getPrimaryType() + "/" + this.mimeType.getSubType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        this.humanPresentableName = humanPresentableName; // set it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        this.mimeType.removeParameter("humanPresentableName"); // just in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * String representation of this <code>DataFlavor</code> and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * parameters. The resulting <code>String</code> contains the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * the <code>DataFlavor</code> class, this flavor's MIME type, and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * representation class. If this flavor has a primary MIME type of "text",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * supports the charset parameter, and has an encoded representation, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * flavor's charset is also included. See <code>selectBestTextFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * for a list of text flavors which support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @return  string representation of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        String string = getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        string += "["+paramString()+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    private String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        String params = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        params += "mimetype=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            params += "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            params += mimeType.getBaseType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        params += ";representationclass=";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
           params += "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
           params += representationClass.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (DataTransferer.isFlavorCharsetTextType(this) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            (isRepresentationClassInputStream() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
             isRepresentationClassByteBuffer() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
             DataTransferer.byteArrayClass.equals(representationClass)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            params += ";charset=" + DataTransferer.getTextCharset(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns a <code>DataFlavor</code> representing plain text with Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * encoding, where:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *     representationClass = java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *     mimeType            = "text/plain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *                            charset=&lt;platform default Unicode encoding&gt;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Sun's implementation for Microsoft Windows uses the encoding <code>utf-16le</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Sun's implementation for Solaris and Linux uses the encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <code>iso-10646-ucs-2</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @return a <code>DataFlavor</code> representing plain text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *    with Unicode encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public static final DataFlavor getTextPlainUnicodeFlavor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        String encoding = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        DataTransferer transferer = DataTransferer.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (transferer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            encoding = transferer.getDefaultUnicodeEncoding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return new DataFlavor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            "text/plain;charset="+encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            +";class=java.io.InputStream", "Plain Text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Selects the best text <code>DataFlavor</code> from an array of <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * DataFlavor</code>s. Only <code>DataFlavor.stringFlavor</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * equivalent flavors, and flavors that have a primary MIME type of "text",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * are considered for selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Flavors are first sorted by their MIME types in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <li>"text/sgml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <li>"text/xml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <li>"text/html"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <li>"text/rtf"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <li>"text/enriched"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <li>"text/richtext"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * <li>"text/uri-list"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * <li>"text/tab-separated-values"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <li>"text/t140"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * <li>"text/rfc822-headers"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <li>"text/parityfec"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <li>"text/directory"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <li>"text/css"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <li>"text/calendar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * <li>"application/x-java-serialized-object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * <li>"text/plain"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * <li>"text/&lt;other&gt;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <p>For example, "text/sgml" will be selected over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * "text/html", and <code>DataFlavor.stringFlavor</code> will be chosen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * over <code>DataFlavor.plainTextFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * If two or more flavors share the best MIME type in the array, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * MIME type will be checked to see if it supports the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * The following MIME types support, or are treated as though they support,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * the charset parameter:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <li>"text/sgml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * <li>"text/xml"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * <li>"text/html"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * <li>"text/enriched"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * <li>"text/richtext"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <li>"text/uri-list"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * <li>"text/directory"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <li>"text/css"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * <li>"text/calendar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <li>"application/x-java-serialized-object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <li>"text/plain"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * The following MIME types do not support, or are treated as though they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * do not support, the charset parameter:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * <li>"text/rtf"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * <li>"text/tab-separated-values"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * <li>"text/t140"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * <li>"text/rfc822-headers"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * <li>"text/parityfec"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * For "text/&lt;other&gt;" MIME types, the first time the JRE needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * determine whether the MIME type supports the charset parameter, it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * check whether the parameter is explicitly listed in an arbitrarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * chosen <code>DataFlavor</code> which uses that MIME type. If so, the JRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * will assume from that point on that the MIME type supports the charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * parameter and will not check again. If the parameter is not explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * listed, the JRE will assume from that point on that the MIME type does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * not support the charset parameter and will not check again. Because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * this check is performed on an arbitrarily chosen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <code>DataFlavor</code>, developers must ensure that all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <code>DataFlavor</code>s with a "text/&lt;other&gt;" MIME type specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * the charset parameter if it is supported by that MIME type. Developers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * should never rely on the JRE to substitute the platform's default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * charset for a "text/&lt;other&gt;" DataFlavor. Failure to adhere to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * restriction will lead to undefined behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * If the best MIME type in the array does not support the charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * parameter, the flavors which share that MIME type will then be sorted by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * their representation classes in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * <code>[B</code>, &lt;all others&gt;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * If two or more flavors share the best representation class, or if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * flavor has one of the three specified representations, then one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * flavors will be chosen non-deterministically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * If the best MIME type in the array does support the charset parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * the flavors which share that MIME type will then be sorted by their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * representation classes in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <code>java.nio.CharBuffer</code>, <code>[C</code>, &lt;all others&gt;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * If two or more flavors share the best representation class, and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * representation is one of the four explicitly listed, then one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * flavors will be chosen non-deterministically. If, however, no flavor has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * one of the four specified representations, the flavors will then be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * sorted by their charsets. Unicode charsets, such as "UTF-16", "UTF-8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * "UTF-16BE", "UTF-16LE", and their aliases, are considered best. After
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * them, the platform default charset and its aliases are selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * "US-ASCII" and its aliases are worst. All other charsets are chosen in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * alphabetical order, but only charsets supported by this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * of the Java platform will be considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * If two or more flavors share the best charset, the flavors will then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * again be sorted by their representation classes in the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * <code>[B</code>, &lt;all others&gt;.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * If two or more flavors share the best representation class, or if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * flavor has one of the three specified representations, then one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * flavors will be chosen non-deterministically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @param availableFlavors an array of available <code>DataFlavor</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @return the best (highest fidelity) flavor according to the rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *         specified above, or <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *         if <code>availableFlavors</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *         has zero length, or contains no text flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    public static final DataFlavor selectBestTextFlavor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                                       DataFlavor[] availableFlavors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        if (availableFlavors == null || availableFlavors.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        if (textFlavorComparator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            textFlavorComparator = new TextFlavorComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        DataFlavor bestFlavor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            (DataFlavor)Collections.max(Arrays.asList(availableFlavors),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                                        textFlavorComparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (!bestFlavor.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        return bestFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    private static Comparator textFlavorComparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    static class TextFlavorComparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        extends DataTransferer.DataFlavorComparator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         * Compares two <code>DataFlavor</code> objects. Returns a negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         * integer, zero, or a positive integer as the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * <code>DataFlavor</code> is worse than, equal to, or better than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         * <code>DataFlavor</code>s are ordered according to the rules outlined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         * for <code>selectBestTextFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         * @param obj1 the first <code>DataFlavor</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         * @param obj2 the second <code>DataFlavor</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         * @return a negative integer, zero, or a positive integer as the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
         *         argument is worse, equal to, or better than the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
         * @throws ClassCastException if either of the arguments is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
         *         instance of <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
         * @throws NullPointerException if either of the arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
         *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        public int compare(Object obj1, Object obj2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            DataFlavor flavor1 = (DataFlavor)obj1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            DataFlavor flavor2 = (DataFlavor)obj2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if (flavor1.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                if (flavor2.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    return super.compare(obj1, obj2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            } else if (flavor2.isFlavorTextType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Gets a Reader for a text flavor, decoded, if necessary, for the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * charset (encoding). The supported representation classes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * <code>java.nio.CharBuffer</code>, <code>[C</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * and <code>[B</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * Because text flavors which do not support the charset parameter are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * encoded in a non-standard format, this method should not be called for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * such flavors. However, in order to maintain backward-compatibility,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * if this method is called for such a flavor, this method will treat the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * flavor as though it supports the charset parameter and attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * decode it accordingly. See <code>selectBestTextFlavor</code> for a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * of text flavors which do not support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @param transferable the <code>Transferable</code> whose data will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *        requested in this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @return a <code>Reader</code> to read the <code>Transferable</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     *         data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @exception IllegalArgumentException if the representation class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *            is not one of the seven listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @exception IllegalArgumentException if the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *            has <code>null</code> data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @exception NullPointerException if the <code>Transferable</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *            <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @exception UnsupportedEncodingException if this flavor's representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *            is <code>java.io.InputStream</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *            <code>java.nio.ByteBuffer</code>, or <code>[B</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *            this flavor's encoding is not supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *            implementation of the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @exception UnsupportedFlavorException if the <code>Transferable</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     *            does not support this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @exception IOException if the data cannot be read because of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *            I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    public Reader getReaderForText(Transferable transferable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        throws UnsupportedFlavorException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        Object transferObject = transferable.getTransferData(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        if (transferObject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                ("getTransferData() returned null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        if (transferObject instanceof Reader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            return (Reader)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        } else if (transferObject instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            return new StringReader((String)transferObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        } else if (transferObject instanceof CharBuffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            CharBuffer buffer = (CharBuffer)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            int size = buffer.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            char[] chars = new char[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            buffer.get(chars, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            return new CharArrayReader(chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        } else if (transferObject instanceof char[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            return new CharArrayReader((char[])transferObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        InputStream stream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        if (transferObject instanceof InputStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            stream = (InputStream)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        } else if (transferObject instanceof ByteBuffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            ByteBuffer buffer = (ByteBuffer)transferObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            int size = buffer.remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            byte[] bytes = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            buffer.get(bytes, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            stream = new ByteArrayInputStream(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        } else if (transferObject instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            stream = new ByteArrayInputStream((byte[])transferObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        if (stream == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            throw new IllegalArgumentException("transfer data is not Reader, String, CharBuffer, char array, InputStream, ByteBuffer, or byte array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        String encoding = getParameter("charset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        return (encoding == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            ? new InputStreamReader(stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            : new InputStreamReader(stream, encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * Returns the MIME type string for this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @return the MIME type string for this flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    public String getMimeType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        return (mimeType != null) ? mimeType.toString() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Returns the <code>Class</code> which objects supporting this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * <code>DataFlavor</code> will return when this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * is requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @return the <code>Class</code> which objects supporting this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * <code>DataFlavor</code> will return when this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * is requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    public Class<?> getRepresentationClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        return representationClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * Returns the human presentable name for the data format that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * <code>DataFlavor</code> represents.  This name would be localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * for different countries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @return the human presentable name for the data format that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *    <code>DataFlavor</code> represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public String getHumanPresentableName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        return humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * Returns the primary MIME type for this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @return the primary MIME type of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public String getPrimaryType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        return (mimeType != null) ? mimeType.getPrimaryType() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * Returns the sub MIME type of this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @return the Sub MIME type of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public String getSubType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        return (mimeType != null) ? mimeType.getSubType() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Returns the human presentable name for this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * if <code>paramName</code> equals "humanPresentableName".  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * returns the MIME type value associated with <code>paramName</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @param paramName the parameter name requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @return the value of the name parameter, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     *  if there is no associated value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    public String getParameter(String paramName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        if (paramName.equals("humanPresentableName")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            return humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            return (mimeType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                ? mimeType.getParameter(paramName) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * Sets the human presentable name for the data format that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * <code>DataFlavor</code> represents. This name would be localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * for different countries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @param humanPresentableName the new human presentable name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    public void setHumanPresentableName(String humanPresentableName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        this.humanPresentableName = humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * The equals comparison for the {@code DataFlavor} class is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * as follows: Two <code>DataFlavor</code>s are considered equal if and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * only if their MIME primary type and subtype and representation class are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * equal. Additionally, if the primary type is "text", the subtype denotes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * a text flavor which supports the charset parameter, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * representation class is not <code>java.io.Reader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * <code>java.lang.String</code>, <code>java.nio.CharBuffer</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * <code>[C</code>, the <code>charset</code> parameter must also be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * If a charset is not explicitly specified for one or both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * <code>DataFlavor</code>s, the platform default encoding is assumed. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * <code>selectBestTextFlavor</code> for a list of text flavors which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * @param o the <code>Object</code> to compare with <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * @return <code>true</code> if <code>that</code> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *         <code>DataFlavor</code>; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        return ((o instanceof DataFlavor) && equals((DataFlavor)o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * This method has the same behavior as {@link #equals(Object)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * The only difference being that it takes a {@code DataFlavor} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * as a parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * @param that the <code>DataFlavor</code> to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     *        <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * @return <code>true</code> if <code>that</code> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *         <code>DataFlavor</code>; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    public boolean equals(DataFlavor that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (that == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        if (this == that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        if (representationClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            if (that.getRepresentationClass() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            if (!representationClass.equals(that.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            if (that.mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            if (!mimeType.match(that.mimeType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1003
            if ("text".equals(getPrimaryType())) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1004
                if (DataTransferer.doesSubtypeSupportCharset(this) &&
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1005
                    representationClass != null &&
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1006
                    !(isRepresentationClassReader() ||
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1007
                        String.class.equals(representationClass) ||
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1008
                        isRepresentationClassCharBuffer() ||
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1009
                        DataTransferer.charArrayClass.equals(representationClass)))
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1010
                {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1011
                    String thisCharset =
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1012
                        DataTransferer.canonicalName(getParameter("charset"));
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1013
                    String thatCharset =
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1014
                        DataTransferer.canonicalName(that.getParameter("charset"));
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1015
                    if (thisCharset == null) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1016
                        if (thatCharset != null) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1017
                            return false;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1018
                        }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1019
                    } else {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1020
                        if (!thisCharset.equals(thatCharset)) {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1021
                            return false;
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1022
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    }
16705
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1024
                }
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1025
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1026
                if ("html".equals(getSubType()) &&
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1027
                        this.getParameter("document") != null )
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1028
                {
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1029
                   if (!this.getParameter("document").
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1030
                            equals(that.getParameter("document")))
1caaa379eded 7075105: WIN: Provide a way to format HTML on drop
denis
parents: 5506
diff changeset
  1031
                    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * Compares only the <code>mimeType</code> against the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * <code>String</code> and <code>representationClass</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * not considered in the comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * If <code>representationClass</code> needs to be compared, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * <code>equals(new DataFlavor(s))</code> may be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @deprecated As inconsistent with <code>hashCode()</code> contract,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *             use <code>isMimeTypeEqual(String)</code> instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * @param s the {@code mimeType} to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * @return true if the String (MimeType) is equal; false otherwise or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     *         {@code s} is {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    public boolean equals(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        if (s == null || mimeType == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        return isMimeTypeEqual(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * Returns hash code for this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * For two equal <code>DataFlavor</code>s, hash codes are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * For the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * that matches <code>DataFlavor.equals(String)</code>, it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * guaranteed that <code>DataFlavor</code>'s hash code is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * to the hash code of the <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @return a hash code for this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        if (representationClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            total += representationClass.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            String primaryType = mimeType.getPrimaryType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            if (primaryType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                total += primaryType.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            // Do not add subType.hashCode() to the total. equals uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            // MimeType.match which reports a match if one or both of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            // subTypes is '*', regardless of the other subType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            if ("text".equals(primaryType) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                DataTransferer.doesSubtypeSupportCharset(this) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                representationClass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                !(isRepresentationClassReader() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                  String.class.equals(representationClass) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                  isRepresentationClassCharBuffer() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                  DataTransferer.charArrayClass.equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                  (representationClass)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                String charset =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                    DataTransferer.canonicalName(getParameter("charset"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                if (charset != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                    total += charset.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        return total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * Identical to {@link #equals(DataFlavor)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @param that the <code>DataFlavor</code> to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *        <code>this</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @return <code>true</code> if <code>that</code> is equivalent to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     *         <code>DataFlavor</code>; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    public boolean match(DataFlavor that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        return equals(that);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * Returns whether the string representation of the MIME type passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * is equivalent to the MIME type of this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * Parameters are not included in the comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @param mimeType the string representation of the MIME type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * @return true if the string representation of the MIME type passed in is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     *         equivalent to the MIME type of this <code>DataFlavor</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     *         false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * @throws NullPointerException if mimeType is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    public boolean isMimeTypeEqual(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        // JCK Test DataFlavor0117: if 'mimeType' is null, throw NPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        if (mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            throw new NullPointerException("mimeType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        if (this.mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            return this.mimeType.match(new MimeType(mimeType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        } catch (MimeTypeParseException mtpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * Compares the <code>mimeType</code> of two <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * objects. No parameters are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @param dataFlavor the <code>DataFlavor</code> to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @return true if the <code>MimeType</code>s are equal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     *  otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    public final boolean isMimeTypeEqual(DataFlavor dataFlavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        return isMimeTypeEqual(dataFlavor.mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * Compares the <code>mimeType</code> of two <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * objects.  No parameters are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * @return true if the <code>MimeType</code>s are equal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     *  otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    private boolean isMimeTypeEqual(MimeType mtype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        if (this.mimeType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            return (mtype == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        return mimeType.match(mtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    * Does the <code>DataFlavor</code> represent a serialized object?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    public boolean isMimeTypeSerializedObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        return isMimeTypeEqual(javaSerializedObjectMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    public final Class<?> getDefaultRepresentationClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        return ioInputStreamClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    public final String getDefaultRepresentationClassAsString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        return getDefaultRepresentationClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    * Does the <code>DataFlavor</code> represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    * <code>java.io.InputStream</code>?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public boolean isRepresentationClassInputStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        return ioInputStreamClass.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * Returns whether the representation class for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * <code>DataFlavor</code> is <code>java.io.Reader</code> or a subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * thereof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    public boolean isRepresentationClassReader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        return java.io.Reader.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * Returns whether the representation class for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * <code>DataFlavor</code> is <code>java.nio.CharBuffer</code> or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * subclass thereof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    public boolean isRepresentationClassCharBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        return java.nio.CharBuffer.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * Returns whether the representation class for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * <code>DataFlavor</code> is <code>java.nio.ByteBuffer</code> or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * subclass thereof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    public boolean isRepresentationClassByteBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        return java.nio.ByteBuffer.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    * Returns true if the representation class can be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    * @return true if the representation class can be serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    public boolean isRepresentationClassSerializable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        return java.io.Serializable.class.isAssignableFrom(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    * Returns true if the representation class is <code>Remote</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    * @return true if the representation class is <code>Remote</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    public boolean isRepresentationClassRemote() {
4267
3dee4217d3dc 6890458: Datatransfer API should not require RMI to be present
alanb
parents: 2
diff changeset
  1249
        return DataTransferer.isRemote(representationClass);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    * Returns true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    * a serialized object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    * @return true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    *   a Serialized Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    public boolean isFlavorSerializedObjectType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        return isRepresentationClassSerializable() && isMimeTypeEqual(javaSerializedObjectMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Returns true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * a remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * @return true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     *  a Remote Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    public boolean isFlavorRemoteObjectType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        return isRepresentationClassRemote()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            && isRepresentationClassSerializable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            && isMimeTypeEqual(javaRemoteObjectMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    * Returns true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    * a list of file objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    * @return true if the <code>DataFlavor</code> specified represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    *   a List of File objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
   public boolean isFlavorJavaFileListType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        if (mimeType == null || representationClass == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        return java.util.List.class.isAssignableFrom(representationClass) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
               mimeType.match(javaFileListFlavor.mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * Returns whether this <code>DataFlavor</code> is a valid text flavor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * this implementation of the Java platform. Only flavors equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * <code>DataFlavor.stringFlavor</code> and <code>DataFlavor</code>s with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * a primary MIME type of "text" can be valid text flavors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * If this flavor supports the charset parameter, it must be equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * <code>DataFlavor.stringFlavor</code>, or its representation must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * <code>java.nio.CharBuffer</code>, <code>[C</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * <code>[B</code>. If the representation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * <code>[B</code>, then this flavor's <code>charset</code> parameter must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * be supported by this implementation of the Java platform. If a charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * is not specified, then the platform default charset, which is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * supported, is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * If this flavor does not support the charset parameter, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * representation must be <code>java.io.InputStream</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     * <code>java.nio.ByteBuffer</code>, or <code>[B</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * See <code>selectBestTextFlavor</code> for a list of text flavors which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * support the charset parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * @return <code>true</code> if this <code>DataFlavor</code> is a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     *         text flavor as described above; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * @see #selectBestTextFlavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    public boolean isFlavorTextType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        return (DataTransferer.isFlavorCharsetTextType(this) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                DataTransferer.isFlavorNoncharsetTextType(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    * Serializes this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
   public synchronized void writeExternal(ObjectOutput os) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
       if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
           mimeType.setParameter("humanPresentableName", humanPresentableName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
           os.writeObject(mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
           mimeType.removeParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
       } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
           os.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
       os.writeObject(representationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    * Restores this <code>DataFlavor</code> from a Serialized state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
   public synchronized void readExternal(ObjectInput is) throws IOException , ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
       String rcn = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        mimeType = (MimeType)is.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            humanPresentableName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                mimeType.getParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            mimeType.removeParameter("humanPresentableName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            rcn = mimeType.getParameter("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            if (rcn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                throw new IOException("no class parameter specified in: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                                      mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            representationClass = (Class)is.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        } catch (OptionalDataException ode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            if (!ode.eof || ode.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                throw ode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            // Ensure backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            // Old versions didn't write the representation class to the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            if (rcn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                representationClass =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                    DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    * Returns a clone of this <code>DataFlavor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    * @return a clone of this <code>DataFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    public Object clone() throws CloneNotSupportedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        Object newObj = super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        if (mimeType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            ((DataFlavor)newObj).mimeType = (MimeType)mimeType.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        return newObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    } // clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    * Called on <code>DataFlavor</code> for every MIME Type parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    * to allow <code>DataFlavor</code> subclasses to handle special
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    * parameters like the text/plain <code>charset</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    * parameters, whose values are case insensitive.  (MIME type parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    * values are supposed to be case sensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    * This method is called for each parameter name/value pair and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    * return the normalized representation of the <code>parameterValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    * This method is never invoked by this implementation from 1.1 onwards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        return parameterValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    * Called for each MIME type string to give <code>DataFlavor</code> subtypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    * the opportunity to change how the normalization of MIME types is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    * accomplished.  One possible use would be to add default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    * parameter/value pairs in cases where none are present in the MIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    * type string passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    * This method is never invoked by this implementation from 1.1 onwards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    protected String normalizeMimeType(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        return mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /* placeholder for caching any platform-specific data for flavor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    transient int       atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    /* Mime Type of DataFlavor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    MimeType            mimeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    private String      humanPresentableName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    /** Java class of objects this DataFlavor represents **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    private Class       representationClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
} // class DataFlavor