mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8187443: Forest Consolidation: Move files to unified layout
Reviewed-by: darcy, ihse
This commit is contained in:
parent
270fe13182
commit
3789983e89
56923 changed files with 3 additions and 15727 deletions
|
@ -0,0 +1,78 @@
|
|||
#
|
||||
# This properties file is used to initialize the default
|
||||
# java.awt.datatransfer.SystemFlavorMap. It contains the Mac OS X platform-specific,
|
||||
# default mappings between common Mac OS X selection atoms and platform-independent
|
||||
# MIME type strings, which will be converted into
|
||||
# java.awt.datatransfer.DataFlavors.
|
||||
#
|
||||
# The standard format is:
|
||||
#
|
||||
# <native>=<MIME type>,<MIME type>, ...
|
||||
#
|
||||
# <native> should be a string identifier that the native platform will
|
||||
# recognize as a valid data format. <MIME type> should specify both a MIME
|
||||
# primary type and a MIME subtype separated by a '/'. The MIME type may include
|
||||
# parameters, where each parameter is a key/value pair separated by '=', and
|
||||
# where each parameter to the MIME type is separated by a ';'.
|
||||
#
|
||||
# Because SystemFlavorMap implements FlavorTable, developers are free to
|
||||
# duplicate DataFlavor values and set multiple values for a single native by
|
||||
# separating them with ",". If a mapping contains a duplicate key or value,
|
||||
# earlier mappings which included this key or value will be preferred.
|
||||
#
|
||||
# Mappings whose values specify DataFlavors with primary MIME types of
|
||||
# "text", and which support the charset parameter, should specify the exact
|
||||
# format in which the native platform expects the data. The "charset"
|
||||
# parameter specifies the char to byte encoding, the "eoln" parameter
|
||||
# specifies the end-of-line marker, and the "terminators" parameter specifies
|
||||
# the number of terminating NUL bytes. Note that "eoln" and "terminators"
|
||||
# are not standardized MIME type parameters. They are specific to this file
|
||||
# format ONLY. They will not appear in any of the DataFlavors returned by the
|
||||
# SystemFlavorMap at the Java level.
|
||||
#
|
||||
# If the "charset" parameter is omitted, or has zero length, the platform
|
||||
# default encoding is assumed. If the "eoln" parameter is omitted, or has
|
||||
# zero length, "\n" is assumed. If the "terminators" parameter is omitted,
|
||||
# or has a value less than zero, zero is assumed.
|
||||
#
|
||||
# Upon initialization, the data transfer subsystem will record the specified
|
||||
# details of the native text format, but the default SystemFlavorMap will
|
||||
# present a large set of synthesized DataFlavors which map, in both
|
||||
# directions, to the native. After receiving data from the application in one
|
||||
# of the synthetic DataFlavors, the data transfer subsystem will transform
|
||||
# the data stream into the format specified in this file before passing the
|
||||
# transformed stream to the native system.
|
||||
#
|
||||
# Mappings whose values specify DataFlavors with primary MIME types of
|
||||
# "text", but which do not support the charset parameter, will be treated as
|
||||
# opaque, 8-bit data. They will not undergo any transformation process, and
|
||||
# any "charset", "eoln", or "terminators" parameters specified in this file
|
||||
# will be ignored.
|
||||
#
|
||||
# See java.awt.datatransfer.DataFlavor.selectBestTextFlavor for a list of
|
||||
# text flavors which support the charset parameter.
|
||||
|
||||
UTF8_STRING=text/plain;charset=UTF-8;eoln="\n";terminators=0
|
||||
|
||||
# The COMPOUND_TEXT support for inter-client text transfer is disabled by
|
||||
# default. The reason is that many native applications prefer this format over
|
||||
# other native text formats, but are unable to decode the textual data in this
|
||||
# format properly. This results in java-to-native text transfer failures.
|
||||
# To enable the COMPOUND_TEXT support for this JRE installation uncomment
|
||||
# the line below.
|
||||
|
||||
# COMPOUND_TEXT=text/plain;charset=x-compound-text;eoln="\n";terminators=0
|
||||
|
||||
TEXT=text/plain;eoln="\n";terminators=0
|
||||
STRING=text/plain;charset=UTF-8;eoln="\n";terminators=0
|
||||
FILE_NAME=application/x-java-file-list;class=java.util.List
|
||||
text/uri-list=application/x-java-file-list;class=java.util.List
|
||||
PNG=image/x-java-image;class=java.awt.Image
|
||||
JFIF=image/x-java-image;class=java.awt.Image
|
||||
TIFF=image/x-java-image;class=java.awt.Image
|
||||
RICH_TEXT=text/rtf
|
||||
HTML=text/html;charset=utf-8;eoln="\r\n";terminators=1
|
||||
URL=application/x-java-url;class=java.net.URL
|
||||
FILE_NAME=text/uri-list;eoln="\r\n";terminators=1
|
||||
URL=text/uri-list;eoln="\r\n";terminators=1
|
||||
XPICT=image/x-pict;class=java.io.InputStream
|
|
@ -0,0 +1,331 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.datatransfer.DataFlavorUtil;
|
||||
|
||||
/**
|
||||
* A class that implements a mechanism to transfer data using cut/copy/paste
|
||||
* operations.
|
||||
* <p>
|
||||
* {@link FlavorListener}s may be registered on an instance of the Clipboard
|
||||
* class to be notified about changes to the set of {@link DataFlavor}s
|
||||
* available on this clipboard (see {@link #addFlavorListener}).
|
||||
*
|
||||
* @author Amy Fowler
|
||||
* @author Alexander Gerasimov
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
* @see java.awt.Toolkit#getSystemSelection
|
||||
* @since 1.1
|
||||
*/
|
||||
public class Clipboard {
|
||||
|
||||
String name;
|
||||
|
||||
/**
|
||||
* The owner of the clipboard.
|
||||
*/
|
||||
protected ClipboardOwner owner;
|
||||
|
||||
/**
|
||||
* Contents of the clipboard.
|
||||
*/
|
||||
protected Transferable contents;
|
||||
|
||||
/**
|
||||
* An aggregate of flavor listeners registered on this local clipboard.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private Set<FlavorListener> flavorListeners;
|
||||
|
||||
/**
|
||||
* A set of {@code DataFlavor}s that is available on this local clipboard.
|
||||
* It is used for tracking changes of {@code DataFlavor}s available on this
|
||||
* clipboard.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private Set<DataFlavor> currentDataFlavors;
|
||||
|
||||
/**
|
||||
* Creates a clipboard object.
|
||||
*
|
||||
* @param name for the clipboard
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public Clipboard(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this clipboard object.
|
||||
*
|
||||
* @return the name of this clipboard object
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current contents of the clipboard to the specified transferable
|
||||
* object and registers the specified clipboard owner as the owner of the
|
||||
* new contents.
|
||||
* <p>
|
||||
* If there is an existing owner different from the argument {@code owner},
|
||||
* that owner is notified that it no longer holds ownership of the clipboard
|
||||
* contents via an invocation of {@code ClipboardOwner.lostOwnership()} on
|
||||
* that owner. An implementation of {@code setContents()} is free not to
|
||||
* invoke {@code lostOwnership()} directly from this method. For example,
|
||||
* {@code lostOwnership()} may be invoked later on a different thread. The
|
||||
* same applies to {@code FlavorListener}s registered on this clipboard.
|
||||
* <p>
|
||||
* The method throws {@code IllegalStateException} if the clipboard is
|
||||
* currently unavailable. For example, on some platforms, the system
|
||||
* clipboard is unavailable while it is accessed by another application.
|
||||
*
|
||||
* @param contents the transferable object representing the clipboard
|
||||
* content
|
||||
* @param owner the object which owns the clipboard content
|
||||
* @throws IllegalStateException if the clipboard is currently unavailable
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public synchronized void setContents(Transferable contents, ClipboardOwner owner) {
|
||||
final ClipboardOwner oldOwner = this.owner;
|
||||
final Transferable oldContents = this.contents;
|
||||
|
||||
this.owner = owner;
|
||||
this.contents = contents;
|
||||
|
||||
if (oldOwner != null && oldOwner != owner) {
|
||||
DataFlavorUtil.getDesktopService().invokeOnEventThread(() ->
|
||||
oldOwner.lostOwnership(Clipboard.this, oldContents));
|
||||
}
|
||||
fireFlavorsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a transferable object representing the current contents of the
|
||||
* clipboard. If the clipboard currently has no contents, it returns
|
||||
* {@code null}. The parameter Object requestor is not currently used. The
|
||||
* method throws {@code IllegalStateException} if the clipboard is currently
|
||||
* unavailable. For example, on some platforms, the system clipboard is
|
||||
* unavailable while it is accessed by another application.
|
||||
*
|
||||
* @param requestor the object requesting the clip data (not used)
|
||||
* @return the current transferable object on the clipboard
|
||||
* @throws IllegalStateException if the clipboard is currently unavailable
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public synchronized Transferable getContents(Object requestor) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of {@code DataFlavor}s in which the current contents of
|
||||
* this clipboard can be provided. If there are no {@code DataFlavor}s
|
||||
* available, this method returns a zero-length array.
|
||||
*
|
||||
* @return an array of {@code DataFlavor}s in which the current contents of
|
||||
* this clipboard can be provided
|
||||
* @throws IllegalStateException if this clipboard is currently unavailable
|
||||
* @since 1.5
|
||||
*/
|
||||
public DataFlavor[] getAvailableDataFlavors() {
|
||||
Transferable cntnts = getContents(null);
|
||||
if (cntnts == null) {
|
||||
return new DataFlavor[0];
|
||||
}
|
||||
return cntnts.getTransferDataFlavors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the current contents of this clipboard can be
|
||||
* provided in the specified {@code DataFlavor}.
|
||||
*
|
||||
* @param flavor the requested {@code DataFlavor} for the contents
|
||||
* @return {@code true} if the current contents of this clipboard can be
|
||||
* provided in the specified {@code DataFlavor}; {@code false}
|
||||
* otherwise
|
||||
* @throws NullPointerException if {@code flavor} is {@code null}
|
||||
* @throws IllegalStateException if this clipboard is currently unavailable
|
||||
* @since 1.5
|
||||
*/
|
||||
public boolean isDataFlavorAvailable(DataFlavor flavor) {
|
||||
if (flavor == null) {
|
||||
throw new NullPointerException("flavor");
|
||||
}
|
||||
|
||||
Transferable cntnts = getContents(null);
|
||||
if (cntnts == null) {
|
||||
return false;
|
||||
}
|
||||
return cntnts.isDataFlavorSupported(flavor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object representing the current contents of this clipboard in
|
||||
* the specified {@code DataFlavor}. The class of the object returned is
|
||||
* defined by the representation class of {@code flavor}.
|
||||
*
|
||||
* @param flavor the requested {@code DataFlavor} for the contents
|
||||
* @return an object representing the current contents of this clipboard in
|
||||
* the specified {@code DataFlavor}
|
||||
* @throws NullPointerException if {@code flavor} is {@code null}
|
||||
* @throws IllegalStateException if this clipboard is currently unavailable
|
||||
* @throws UnsupportedFlavorException if the requested {@code DataFlavor} is
|
||||
* not available
|
||||
* @throws IOException if the data in the requested {@code DataFlavor} can
|
||||
* not be retrieved
|
||||
* @see DataFlavor#getRepresentationClass
|
||||
* @since 1.5
|
||||
*/
|
||||
public Object getData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException, IOException {
|
||||
if (flavor == null) {
|
||||
throw new NullPointerException("flavor");
|
||||
}
|
||||
|
||||
Transferable cntnts = getContents(null);
|
||||
if (cntnts == null) {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
return cntnts.getTransferData(flavor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the specified {@code FlavorListener} to receive
|
||||
* {@code FlavorEvent}s from this clipboard. If {@code listener} is
|
||||
* {@code null}, no exception is thrown and no action is performed.
|
||||
*
|
||||
* @param listener the listener to be added
|
||||
* @see #removeFlavorListener
|
||||
* @see #getFlavorListeners
|
||||
* @see FlavorListener
|
||||
* @see FlavorEvent
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized void addFlavorListener(FlavorListener listener) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flavorListeners == null) {
|
||||
flavorListeners = new HashSet<>();
|
||||
currentDataFlavors = getAvailableDataFlavorSet();
|
||||
}
|
||||
|
||||
flavorListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified {@code FlavorListener} so that it no longer
|
||||
* receives {@code FlavorEvent}s from this {@code Clipboard}. This method
|
||||
* performs no function, nor does it throw an exception, if the listener
|
||||
* specified by the argument was not previously added to this
|
||||
* {@code Clipboard}. If {@code listener} is {@code null}, no exception is
|
||||
* thrown and no action is performed.
|
||||
*
|
||||
* @param listener the listener to be removed
|
||||
* @see #addFlavorListener
|
||||
* @see #getFlavorListeners
|
||||
* @see FlavorListener
|
||||
* @see FlavorEvent
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized void removeFlavorListener(FlavorListener listener) {
|
||||
if (listener == null || flavorListeners == null) {
|
||||
return;
|
||||
}
|
||||
flavorListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the {@code FlavorListener}s currently registered
|
||||
* on this {@code Clipboard}.
|
||||
*
|
||||
* @return all of this clipboard's {@code FlavorListener}s or an empty array
|
||||
* if no listeners are currently registered
|
||||
* @see #addFlavorListener
|
||||
* @see #removeFlavorListener
|
||||
* @see FlavorListener
|
||||
* @see FlavorEvent
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized FlavorListener[] getFlavorListeners() {
|
||||
return flavorListeners == null ? new FlavorListener[0] :
|
||||
flavorListeners.toArray(new FlavorListener[flavorListeners.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks change of the {@code DataFlavor}s and, if necessary, notifies all
|
||||
* listeners that have registered interest for notification on
|
||||
* {@code FlavorEvent}s.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private void fireFlavorsChanged() {
|
||||
if (flavorListeners == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<DataFlavor> prevDataFlavors = currentDataFlavors;
|
||||
currentDataFlavors = getAvailableDataFlavorSet();
|
||||
if (Objects.equals(prevDataFlavors, currentDataFlavors)) {
|
||||
return;
|
||||
}
|
||||
flavorListeners.forEach(listener ->
|
||||
DataFlavorUtil.getDesktopService().invokeOnEventThread(() ->
|
||||
listener.flavorsChanged(new FlavorEvent(Clipboard.this))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of {@code DataFlavor}s currently available on this
|
||||
* clipboard.
|
||||
*
|
||||
* @return a set of {@code DataFlavor}s currently available on this
|
||||
* clipboard
|
||||
* @since 1.5
|
||||
*/
|
||||
private Set<DataFlavor> getAvailableDataFlavorSet() {
|
||||
Set<DataFlavor> set = new HashSet<>();
|
||||
Transferable contents = getContents(null);
|
||||
if (contents != null) {
|
||||
DataFlavor[] flavors = contents.getTransferDataFlavors();
|
||||
if (flavors != null) {
|
||||
set.addAll(Arrays.asList(flavors));
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
/**
|
||||
* Defines the interface for classes that will provide data to a clipboard. An
|
||||
* instance of this interface becomes the owner of the contents of a clipboard
|
||||
* (clipboard owner) if it is passed as an argument to
|
||||
* {@link Clipboard#setContents} method of the clipboard and this method returns
|
||||
* successfully. The instance remains the clipboard owner until another
|
||||
* application or another object within this application asserts ownership of
|
||||
* this clipboard.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
* @see Clipboard
|
||||
* @since 1.1
|
||||
*/
|
||||
public interface ClipboardOwner {
|
||||
|
||||
/**
|
||||
* Notifies this object that it is no longer the clipboard owner. This
|
||||
* method will be called when another application or another object within
|
||||
* this application asserts ownership of the clipboard.
|
||||
*
|
||||
* @param clipboard the clipboard that is no longer owned
|
||||
* @param contents the contents which this owner had placed on the
|
||||
* {@code clipboard}
|
||||
*/
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents);
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
* {@code FlavorEvent} is used to notify interested parties that available
|
||||
* {@link DataFlavor}s have changed in the {@link Clipboard} (the event source).
|
||||
*
|
||||
* @author Alexander Gerasimov
|
||||
* @see FlavorListener
|
||||
* @since 1.5
|
||||
*/
|
||||
public class FlavorEvent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = -5842664112252414548L;
|
||||
|
||||
/**
|
||||
* Constructs a {@code FlavorEvent} object.
|
||||
*
|
||||
* @param source the {@code Clipboard} that is the source of the event
|
||||
* @throws IllegalArgumentException if the {@code source} is {@code null}
|
||||
*/
|
||||
public FlavorEvent(Clipboard source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* Defines an object which listens for {@link FlavorEvent}s.
|
||||
*
|
||||
* @author Alexander Gerasimov
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface FlavorListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Invoked when the target {@link Clipboard} of the listener has changed its
|
||||
* available {@link DataFlavor}s.
|
||||
* <p>
|
||||
* Some notifications may be redundant — they are not caused by a
|
||||
* change of the set of DataFlavors available on the clipboard. For example,
|
||||
* if the clipboard subsystem supposes that the system clipboard's contents
|
||||
* has been changed but it can't ascertain whether its DataFlavors have been
|
||||
* changed because of some exceptional condition when accessing the
|
||||
* clipboard, the notification is sent to ensure from omitting a significant
|
||||
* notification. Ordinarily, those redundant notifications should be
|
||||
* occasional.
|
||||
*
|
||||
* @param e a {@code FlavorEvent} object
|
||||
*/
|
||||
void flavorsChanged(FlavorEvent e);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A two-way Map between "natives" (Strings), which correspond to
|
||||
* platform-specific data formats, and "flavors" (DataFlavors), which correspond
|
||||
* to platform-independent MIME types. FlavorMaps need not be symmetric, but
|
||||
* typically are.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public interface FlavorMap {
|
||||
|
||||
/**
|
||||
* Returns a {@code Map} of the specified {@code DataFlavor}s to their
|
||||
* corresponding {@code String} native. The returned {@code Map} is a
|
||||
* modifiable copy of this {@code FlavorMap}'s internal data. Client code is
|
||||
* free to modify the {@code Map} without affecting this object.
|
||||
*
|
||||
* @param flavors an array of {@code DataFlavor}s which will be the key set
|
||||
* of the returned {@code Map}. If {@code null} is specified, a
|
||||
* mapping of all {@code DataFlavor}s currently known to this
|
||||
* {@code FlavorMap} to their corresponding {@code String} natives
|
||||
* will be returned.
|
||||
* @return a {@code java.util.Map} of {@code DataFlavor}s to {@code String}
|
||||
* natives
|
||||
*/
|
||||
Map<DataFlavor, String> getNativesForFlavors(DataFlavor[] flavors);
|
||||
|
||||
/**
|
||||
* Returns a {@code Map} of the specified {@code String} natives to their
|
||||
* corresponding {@code DataFlavor}. The returned {@code Map} is a
|
||||
* modifiable copy of this {@code FlavorMap}'s internal data. Client code is
|
||||
* free to modify the {@code Map} without affecting this object.
|
||||
*
|
||||
* @param natives an array of {@code String}s which will be the key set of
|
||||
* the returned {@code Map}. If {@code null} is specified, a mapping
|
||||
* of all {@code String} natives currently known to this
|
||||
* {@code FlavorMap} to their corresponding {@code DataFlavor}s will
|
||||
* be returned.
|
||||
* @return a {@code java.util.Map} of {@code String} natives to
|
||||
* {@code DataFlavor}s
|
||||
*/
|
||||
Map<String, DataFlavor> getFlavorsForNatives(String[] natives);
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A FlavorMap which relaxes the traditional 1-to-1 restriction of a Map. A
|
||||
* flavor is permitted to map to any number of natives, and likewise a native is
|
||||
* permitted to map to any number of flavors. FlavorTables need not be
|
||||
* symmetric, but typically are.
|
||||
*
|
||||
* @author David Mendenhall
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface FlavorTable extends FlavorMap {
|
||||
|
||||
/**
|
||||
* Returns a {@code List} of {@code String} natives to which the specified
|
||||
* {@code DataFlavor} corresponds. The {@code List} will be sorted from best
|
||||
* native to worst. That is, the first native will best reflect data in the
|
||||
* specified flavor to the underlying native platform. The returned
|
||||
* {@code List} is a modifiable copy of this {@code FlavorTable}'s internal
|
||||
* data. Client code is free to modify the {@code List} without affecting
|
||||
* this object.
|
||||
*
|
||||
* @param flav the {@code DataFlavor} whose corresponding natives should be
|
||||
* returned. If {@code null} is specified, all natives currently
|
||||
* known to this {@code FlavorTable} are returned in a
|
||||
* non-deterministic order.
|
||||
* @return a {@code java.util.List} of {@code java.lang.String} objects
|
||||
* which are platform-specific representations of platform-specific
|
||||
* data formats
|
||||
*/
|
||||
List<String> getNativesForFlavor(DataFlavor flav);
|
||||
|
||||
/**
|
||||
* Returns a {@code List} of {@code DataFlavor}s to which the specified
|
||||
* {@code String} corresponds. The {@code List} will be sorted from best
|
||||
* {@code DataFlavor} to worst. That is, the first {@code DataFlavor} will
|
||||
* best reflect data in the specified native to a Java application. The
|
||||
* returned {@code List} is a modifiable copy of this {@code FlavorTable}'s
|
||||
* internal data. Client code is free to modify the {@code List} without
|
||||
* affecting this object.
|
||||
*
|
||||
* @param nat the native whose corresponding {@code DataFlavor}s should be
|
||||
* returned. If {@code null} is specified, all {@code DataFlavor}s
|
||||
* currently known to this {@code FlavorTable} are returned in a
|
||||
* non-deterministic order.
|
||||
* @return a {@code java.util.List} of {@code DataFlavor} objects into which
|
||||
* platform-specific data in the specified, platform-specific native
|
||||
* can be translated
|
||||
*/
|
||||
List<DataFlavor> getFlavorsForNative(String nat);
|
||||
}
|
|
@ -0,0 +1,386 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045
|
||||
* and 2046.
|
||||
* <p>
|
||||
* THIS IS *NOT* - REPEAT *NOT* - A PUBLIC CLASS! DataFlavor IS THE PUBLIC
|
||||
* INTERFACE, AND THIS IS PROVIDED AS A ***PRIVATE*** (THAT IS AS IN *NOT*
|
||||
* PUBLIC) HELPER CLASS!
|
||||
*/
|
||||
class MimeType implements Externalizable, Cloneable {
|
||||
|
||||
/*
|
||||
* serialization support
|
||||
*/
|
||||
|
||||
static final long serialVersionUID = -6568722458793895906L;
|
||||
|
||||
/**
|
||||
* Constructor for externalization; this constructor should not be called
|
||||
* directly by an application, since the result will be an uninitialized,
|
||||
* immutable {@code MimeType} object.
|
||||
*/
|
||||
public MimeType() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@code MimeType} from a {@code String}.
|
||||
*
|
||||
* @param rawdata text used to initialize the {@code MimeType}
|
||||
* @throws NullPointerException if {@code rawdata} is {@code null}
|
||||
*/
|
||||
public MimeType(String rawdata) throws MimeTypeParseException {
|
||||
parse(rawdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@code MimeType} with the given primary and sub type but has an
|
||||
* empty parameter list.
|
||||
*
|
||||
* @param primary the primary type of this {@code MimeType}
|
||||
* @param sub the subtype of this {@code MimeType}
|
||||
* @throws NullPointerException if either {@code primary} or {@code sub} is
|
||||
* {@code null}
|
||||
*/
|
||||
public MimeType(String primary, String sub) throws MimeTypeParseException {
|
||||
this(primary, sub, new MimeTypeParameterList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@code MimeType} with a pre-defined and valid (or empty)
|
||||
* parameter list.
|
||||
*
|
||||
* @param primary the primary type of this {@code MimeType}
|
||||
* @param sub the subtype of this {@code MimeType}
|
||||
* @param mtpl the requested parameter list
|
||||
* @throws NullPointerException if either {@code primary}, {@code sub} or
|
||||
* {@code mtpl} is {@code null}
|
||||
*/
|
||||
public MimeType(String primary, String sub, MimeTypeParameterList mtpl) throws
|
||||
MimeTypeParseException {
|
||||
// check to see if primary is valid
|
||||
if(isValidToken(primary)) {
|
||||
primaryType = primary.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
}
|
||||
|
||||
// check to see if sub is valid
|
||||
if(isValidToken(sub)) {
|
||||
subType = sub.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
}
|
||||
|
||||
parameters = (MimeTypeParameterList)mtpl.clone();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
||||
// We sum up the hash codes for all of the strings. This
|
||||
// way, the order of the strings is irrelevant
|
||||
int code = 0;
|
||||
code += primaryType.hashCode();
|
||||
code += subType.hashCode();
|
||||
code += parameters.hashCode();
|
||||
return code;
|
||||
} // hashCode()
|
||||
|
||||
/**
|
||||
* {@code MimeType}s are equal if their primary types, subtypes, and
|
||||
* parameters are all equal. No default values are taken into account.
|
||||
*
|
||||
* @param thatObject the object to be evaluated as a {@code MimeType}
|
||||
* @return {@code true} if {@code thatObject} is a {@code MimeType};
|
||||
* otherwise returns {@code false}
|
||||
*/
|
||||
public boolean equals(Object thatObject) {
|
||||
if (!(thatObject instanceof MimeType)) {
|
||||
return false;
|
||||
}
|
||||
MimeType that = (MimeType)thatObject;
|
||||
boolean isIt =
|
||||
((this.primaryType.equals(that.primaryType)) &&
|
||||
(this.subType.equals(that.subType)) &&
|
||||
(this.parameters.equals(that.parameters)));
|
||||
return isIt;
|
||||
} // equals()
|
||||
|
||||
/**
|
||||
* A routine for parsing the MIME type out of a String.
|
||||
*
|
||||
* @throws NullPointerException if {@code rawdata} is {@code null}
|
||||
*/
|
||||
private void parse(String rawdata) throws MimeTypeParseException {
|
||||
int slashIndex = rawdata.indexOf('/');
|
||||
int semIndex = rawdata.indexOf(';');
|
||||
if((slashIndex < 0) && (semIndex < 0)) {
|
||||
// neither character is present, so treat it
|
||||
// as an error
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
} else if((slashIndex < 0) && (semIndex >= 0)) {
|
||||
// we have a ';' (and therefore a parameter list),
|
||||
// but no '/' indicating a sub type is present
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
} else if((slashIndex >= 0) && (semIndex < 0)) {
|
||||
// we have a primary and sub type but no parameter list
|
||||
primaryType = rawdata.substring(0,slashIndex).
|
||||
trim().toLowerCase(Locale.ENGLISH);
|
||||
subType = rawdata.substring(slashIndex + 1).
|
||||
trim().toLowerCase(Locale.ENGLISH);
|
||||
parameters = new MimeTypeParameterList();
|
||||
} else if (slashIndex < semIndex) {
|
||||
// we have all three items in the proper sequence
|
||||
primaryType = rawdata.substring(0, slashIndex).
|
||||
trim().toLowerCase(Locale.ENGLISH);
|
||||
subType = rawdata.substring(slashIndex + 1,
|
||||
semIndex).trim().toLowerCase(Locale.ENGLISH);
|
||||
parameters = new
|
||||
MimeTypeParameterList(rawdata.substring(semIndex));
|
||||
} else {
|
||||
// we have a ';' lexically before a '/' which means we have a primary type
|
||||
// & a parameter list but no sub type
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
}
|
||||
|
||||
// now validate the primary and sub types
|
||||
|
||||
// check to see if primary is valid
|
||||
if(!isValidToken(primaryType)) {
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
}
|
||||
|
||||
// check to see if sub is valid
|
||||
if(!isValidToken(subType)) {
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the primary type of this object.
|
||||
*/
|
||||
public String getPrimaryType() {
|
||||
return primaryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the sub type of this object.
|
||||
*/
|
||||
public String getSubType() {
|
||||
return subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a copy of this object's parameter list.
|
||||
*/
|
||||
public MimeTypeParameterList getParameters() {
|
||||
return (MimeTypeParameterList)parameters.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value associated with the given name, or {@code null} if
|
||||
* there is no current association.
|
||||
*/
|
||||
public String getParameter(String name) {
|
||||
return parameters.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to be associated with the given name, replacing
|
||||
* any previous association.
|
||||
*
|
||||
* @throws IllegalArgumentException if parameter or value is illegal
|
||||
*/
|
||||
public void setParameter(String name, String value) {
|
||||
parameters.set(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any value associated with the given name.
|
||||
*
|
||||
* @throws IllegalArgumentException if parameter may not be deleted
|
||||
*/
|
||||
public void removeParameter(String name) {
|
||||
parameters.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String representation of this object.
|
||||
*/
|
||||
public String toString() {
|
||||
return getBaseType() + parameters.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a String representation of this object without the parameter list.
|
||||
*/
|
||||
public String getBaseType() {
|
||||
return primaryType + "/" + subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the primary type and the subtype of this object
|
||||
* are the same as the specified {@code type}; otherwise returns
|
||||
* {@code false}.
|
||||
*
|
||||
* @param type the type to compare to {@code this}'s type
|
||||
* @return {@code true} if the primary type and the subtype of this object
|
||||
* are the same as the specified {@code type}; otherwise returns
|
||||
* {@code false}
|
||||
*/
|
||||
public boolean match(MimeType type) {
|
||||
if (type == null)
|
||||
return false;
|
||||
return primaryType.equals(type.getPrimaryType())
|
||||
&& (subType.equals("*")
|
||||
|| type.getSubType().equals("*")
|
||||
|| (subType.equals(type.getSubType())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the primary type and the subtype of this object
|
||||
* are the same as the content type described in {@code rawdata}; otherwise
|
||||
* returns {@code false}.
|
||||
*
|
||||
* @param rawdata the raw data to be examined
|
||||
* @return {@code true} if the primary type and the subtype of this object
|
||||
* are the same as the content type described in {@code rawdata};
|
||||
* otherwise returns {@code false}; if {@code rawdata} is
|
||||
* {@code null}, returns {@code false}
|
||||
*/
|
||||
public boolean match(String rawdata) throws MimeTypeParseException {
|
||||
if (rawdata == null)
|
||||
return false;
|
||||
return match(new MimeType(rawdata));
|
||||
}
|
||||
|
||||
/**
|
||||
* The object implements the writeExternal method to save its contents by
|
||||
* calling the methods of DataOutput for its primitive values or calling the
|
||||
* writeObject method of ObjectOutput for objects, strings and arrays.
|
||||
*
|
||||
* @throws IOException Includes any I/O exceptions that may occur
|
||||
*/
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
String s = toString(); // contains ASCII chars only
|
||||
// one-to-one correspondence between ASCII char and byte in UTF string
|
||||
if (s.length() <= 65535) { // 65535 is max length of UTF string
|
||||
out.writeUTF(s);
|
||||
} else {
|
||||
out.writeByte(0);
|
||||
out.writeByte(0);
|
||||
out.writeInt(s.length());
|
||||
out.write(s.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The object implements the readExternal method to restore its contents by
|
||||
* calling the methods of DataInput for primitive types and readObject for
|
||||
* objects, strings and arrays. The readExternal method must read the values
|
||||
* in the same sequence and with the same types as were written by
|
||||
* writeExternal.
|
||||
*
|
||||
* @throws ClassNotFoundException If the class for an object being restored
|
||||
* cannot be found
|
||||
*/
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
String s = in.readUTF();
|
||||
if (s == null || s.length() == 0) { // long mime type
|
||||
byte[] ba = new byte[in.readInt()];
|
||||
in.readFully(ba);
|
||||
s = new String(ba);
|
||||
}
|
||||
try {
|
||||
parse(s);
|
||||
} catch(MimeTypeParseException e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone of this object.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*/
|
||||
public Object clone() {
|
||||
MimeType newObj = null;
|
||||
try {
|
||||
newObj = (MimeType)super.clone();
|
||||
} catch (CloneNotSupportedException cannotHappen) {
|
||||
}
|
||||
newObj.parameters = (MimeTypeParameterList)parameters.clone();
|
||||
return newObj;
|
||||
}
|
||||
|
||||
private String primaryType;
|
||||
private String subType;
|
||||
private MimeTypeParameterList parameters;
|
||||
|
||||
// below here be scary parsing related things
|
||||
|
||||
/**
|
||||
* Determines whether or not a given character belongs to a legal token.
|
||||
*/
|
||||
private static boolean isTokenChar(char c) {
|
||||
return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not a given string is a legal token.
|
||||
*
|
||||
* @throws NullPointerException if {@code s} is {@code null}
|
||||
*/
|
||||
private boolean isValidToken(String s) {
|
||||
int len = s.length();
|
||||
if(len > 0) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char c = s.charAt(i);
|
||||
if (!isTokenChar(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A string that holds all the special chars.
|
||||
*/
|
||||
private static final String TSPECIALS = "()<>@,;:\\\"/[]?=";
|
||||
} // class MimeType
|
|
@ -0,0 +1,405 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An object that encapsulates the parameter list of a MimeType as defined in
|
||||
* RFC 2045 and 2046.
|
||||
*
|
||||
* @author jeff.dunn@eng.sun.com
|
||||
*/
|
||||
class MimeTypeParameterList implements Cloneable {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public MimeTypeParameterList() {
|
||||
parameters = new Hashtable<>();
|
||||
}
|
||||
|
||||
public MimeTypeParameterList(String rawdata)
|
||||
throws MimeTypeParseException
|
||||
{
|
||||
parameters = new Hashtable<>();
|
||||
|
||||
// now parse rawdata
|
||||
parse(rawdata);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int code = Integer.MAX_VALUE/45; // "random" value for empty lists
|
||||
String paramName = null;
|
||||
Enumeration<String> enum_ = this.getNames();
|
||||
|
||||
while (enum_.hasMoreElements()) {
|
||||
paramName = enum_.nextElement();
|
||||
code += paramName.hashCode();
|
||||
code += this.get(paramName).hashCode();
|
||||
}
|
||||
|
||||
return code;
|
||||
} // hashCode()
|
||||
|
||||
/**
|
||||
* Two parameter lists are considered equal if they have exactly the same
|
||||
* set of parameter names and associated values. The order of the parameters
|
||||
* is not considered.
|
||||
*/
|
||||
public boolean equals(Object thatObject) {
|
||||
//System.out.println("MimeTypeParameterList.equals("+this+","+thatObject+")");
|
||||
if (!(thatObject instanceof MimeTypeParameterList)) {
|
||||
return false;
|
||||
}
|
||||
MimeTypeParameterList that = (MimeTypeParameterList)thatObject;
|
||||
if (this.size() != that.size()) {
|
||||
return false;
|
||||
}
|
||||
String name = null;
|
||||
String thisValue = null;
|
||||
String thatValue = null;
|
||||
Set<Map.Entry<String, String>> entries = parameters.entrySet();
|
||||
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
|
||||
Map.Entry<String, String> entry = null;
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
name = entry.getKey();
|
||||
thisValue = entry.getValue();
|
||||
thatValue = that.parameters.get(name);
|
||||
if ((thisValue == null) || (thatValue == null)) {
|
||||
// both null -> equal, only one null -> not equal
|
||||
if (thisValue != thatValue) {
|
||||
return false;
|
||||
}
|
||||
} else if (!thisValue.equals(thatValue)) {
|
||||
return false;
|
||||
}
|
||||
} // while iterator
|
||||
|
||||
return true;
|
||||
} // equals()
|
||||
|
||||
/**
|
||||
* A routine for parsing the parameter list out of a String.
|
||||
*/
|
||||
protected void parse(String rawdata) throws MimeTypeParseException {
|
||||
int length = rawdata.length();
|
||||
if(length > 0) {
|
||||
int currentIndex = skipWhiteSpace(rawdata, 0);
|
||||
int lastIndex = 0;
|
||||
|
||||
if(currentIndex < length) {
|
||||
char currentChar = rawdata.charAt(currentIndex);
|
||||
while ((currentIndex < length) && (currentChar == ';')) {
|
||||
String name;
|
||||
String value;
|
||||
boolean foundit;
|
||||
|
||||
// eat the ';'
|
||||
++currentIndex;
|
||||
|
||||
// now parse the parameter name
|
||||
|
||||
// skip whitespace
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
|
||||
if(currentIndex < length) {
|
||||
// find the end of the token char run
|
||||
lastIndex = currentIndex;
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
while((currentIndex < length) && isTokenChar(currentChar)) {
|
||||
++currentIndex;
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
}
|
||||
name = rawdata.substring(lastIndex, currentIndex).toLowerCase();
|
||||
|
||||
// now parse the '=' that separates the name from the value
|
||||
|
||||
// skip whitespace
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
|
||||
if((currentIndex < length) && (rawdata.charAt(currentIndex) == '=')) {
|
||||
// eat it and parse the parameter value
|
||||
++currentIndex;
|
||||
|
||||
// skip whitespace
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
|
||||
if(currentIndex < length) {
|
||||
// now find out whether or not we have a quoted value
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
if(currentChar == '"') {
|
||||
// yup it's quoted so eat it and capture the quoted string
|
||||
++currentIndex;
|
||||
lastIndex = currentIndex;
|
||||
|
||||
if(currentIndex < length) {
|
||||
// find the next unescaped quote
|
||||
foundit = false;
|
||||
while((currentIndex < length) && !foundit) {
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
if(currentChar == '\\') {
|
||||
// found an escape sequence so pass this and the next character
|
||||
currentIndex += 2;
|
||||
} else if(currentChar == '"') {
|
||||
// found it!
|
||||
foundit = true;
|
||||
} else {
|
||||
++currentIndex;
|
||||
}
|
||||
}
|
||||
if(currentChar == '"') {
|
||||
value = unquote(rawdata.substring(lastIndex, currentIndex));
|
||||
// eat the quote
|
||||
++currentIndex;
|
||||
} else {
|
||||
throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
|
||||
}
|
||||
} else {
|
||||
throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
|
||||
}
|
||||
} else if(isTokenChar(currentChar)) {
|
||||
// nope it's an ordinary token so it ends with a non-token char
|
||||
lastIndex = currentIndex;
|
||||
foundit = false;
|
||||
while((currentIndex < length) && !foundit) {
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
|
||||
if(isTokenChar(currentChar)) {
|
||||
++currentIndex;
|
||||
} else {
|
||||
foundit = true;
|
||||
}
|
||||
}
|
||||
value = rawdata.substring(lastIndex, currentIndex);
|
||||
} else {
|
||||
// it ain't a value
|
||||
throw new MimeTypeParseException("Unexpected character encountered at index " + currentIndex);
|
||||
}
|
||||
|
||||
// now put the data into the hashtable
|
||||
parameters.put(name, value);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Couldn't find a value for parameter named " + name);
|
||||
}
|
||||
} else {
|
||||
throw new MimeTypeParseException("Couldn't find the '=' that separates a parameter name from its value.");
|
||||
}
|
||||
} else {
|
||||
throw new MimeTypeParseException("Couldn't find parameter name");
|
||||
}
|
||||
|
||||
// setup the next iteration
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
if(currentIndex < length) {
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
}
|
||||
}
|
||||
if(currentIndex < length) {
|
||||
throw new MimeTypeParseException("More characters encountered in input than expected.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the number of name-value pairs in this list.
|
||||
*/
|
||||
public int size() {
|
||||
return parameters.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this list is empty.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return parameters.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value associated with the given name, or {@code null} if
|
||||
* there is no current association.
|
||||
*/
|
||||
public String get(String name) {
|
||||
return parameters.get(name.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to be associated with the given name, replacing any
|
||||
* previous association.
|
||||
*/
|
||||
public void set(String name, String value) {
|
||||
parameters.put(name.trim().toLowerCase(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any value associated with the given name.
|
||||
*/
|
||||
public void remove(String name) {
|
||||
parameters.remove(name.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an enumeration of all the names in this list.
|
||||
*/
|
||||
public Enumeration<String> getNames() {
|
||||
return parameters.keys();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
// Heuristic: 8 characters per field
|
||||
StringBuilder buffer = new StringBuilder(parameters.size() * 16);
|
||||
|
||||
Enumeration<String> keys = parameters.keys();
|
||||
while(keys.hasMoreElements())
|
||||
{
|
||||
buffer.append("; ");
|
||||
|
||||
String key = keys.nextElement();
|
||||
buffer.append(key);
|
||||
buffer.append('=');
|
||||
buffer.append(quote(parameters.get(key)));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone of this object.
|
||||
*
|
||||
* @return a clone of this object
|
||||
*/
|
||||
@SuppressWarnings("unchecked") // Cast from clone
|
||||
public Object clone() {
|
||||
MimeTypeParameterList newObj = null;
|
||||
try {
|
||||
newObj = (MimeTypeParameterList)super.clone();
|
||||
} catch (CloneNotSupportedException cannotHappen) {
|
||||
}
|
||||
newObj.parameters = (Hashtable<String, String>)parameters.clone();
|
||||
return newObj;
|
||||
}
|
||||
|
||||
private Hashtable<String, String> parameters;
|
||||
|
||||
// below here be scary parsing related things
|
||||
|
||||
/**
|
||||
* Determine whether or not a given character belongs to a legal token.
|
||||
*/
|
||||
private static boolean isTokenChar(char c) {
|
||||
return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first non white space character in
|
||||
* {@code rawdata} at or after index {@code i}.
|
||||
*/
|
||||
private static int skipWhiteSpace(String rawdata, int i) {
|
||||
int length = rawdata.length();
|
||||
if (i < length) {
|
||||
char c = rawdata.charAt(i);
|
||||
while ((i < length) && Character.isWhitespace(c)) {
|
||||
++i;
|
||||
c = rawdata.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* A routine that knows how and when to quote and escape the given value.
|
||||
*/
|
||||
private static String quote(String value) {
|
||||
boolean needsQuotes = false;
|
||||
|
||||
// check to see if we actually have to quote this thing
|
||||
int length = value.length();
|
||||
for(int i = 0; (i < length) && !needsQuotes; ++i) {
|
||||
needsQuotes = !isTokenChar(value.charAt(i));
|
||||
}
|
||||
|
||||
if(needsQuotes) {
|
||||
StringBuilder buffer = new StringBuilder((int)(length * 1.5));
|
||||
|
||||
// add the initial quote
|
||||
buffer.append('"');
|
||||
|
||||
// add the properly escaped text
|
||||
for(int i = 0; i < length; ++i) {
|
||||
char c = value.charAt(i);
|
||||
if((c == '\\') || (c == '"')) {
|
||||
buffer.append('\\');
|
||||
}
|
||||
buffer.append(c);
|
||||
}
|
||||
|
||||
// add the closing quote
|
||||
buffer.append('"');
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A routine that knows how to strip the quotes and escape sequences from
|
||||
* the given value.
|
||||
*/
|
||||
private static String unquote(String value) {
|
||||
int valueLength = value.length();
|
||||
StringBuilder buffer = new StringBuilder(valueLength);
|
||||
|
||||
boolean escaped = false;
|
||||
for(int i = 0; i < valueLength; ++i) {
|
||||
char currentChar = value.charAt(i);
|
||||
if(!escaped && (currentChar != '\\')) {
|
||||
buffer.append(currentChar);
|
||||
} else if(escaped) {
|
||||
buffer.append(currentChar);
|
||||
escaped = false;
|
||||
} else {
|
||||
escaped = true;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A string that holds all the special chars.
|
||||
*/
|
||||
private static final String TSPECIALS = "()<>@,;:\\\"/[]?=";
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
/**
|
||||
* A class to encapsulate MimeType parsing related exceptions.
|
||||
*
|
||||
* @since 1.3
|
||||
* @serial exclude
|
||||
*/
|
||||
public class MimeTypeParseException extends Exception {
|
||||
|
||||
// use serialVersionUID from JDK 1.2.2 for interoperability
|
||||
private static final long serialVersionUID = -5604407764691570741L;
|
||||
|
||||
/**
|
||||
* Constructs a MimeTypeParseException with no specified detail message.
|
||||
*/
|
||||
public MimeTypeParseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a MimeTypeParseException with the specified detail message.
|
||||
*
|
||||
* @param s the detail message
|
||||
*/
|
||||
public MimeTypeParseException(String s) {
|
||||
super(s);
|
||||
}
|
||||
} // class MimeTypeParseException
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* A {@code Transferable} which implements the capability required to transfer a
|
||||
* {@code String}.
|
||||
* <p>
|
||||
* This {@code Transferable} properly supports {@code DataFlavor.stringFlavor}
|
||||
* and all equivalent flavors. Support for {@code DataFlavor.plainTextFlavor}
|
||||
* and all equivalent flavors is <b>deprecated</b>. No other {@code DataFlavor}s
|
||||
* are supported.
|
||||
*
|
||||
* @see DataFlavor#stringFlavor
|
||||
* @see DataFlavor#plainTextFlavor
|
||||
* @since 1.1
|
||||
*/
|
||||
public class StringSelection implements Transferable, ClipboardOwner {
|
||||
|
||||
private static final int STRING = 0;
|
||||
private static final int PLAIN_TEXT = 1;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static final DataFlavor[] flavors = {
|
||||
DataFlavor.stringFlavor,
|
||||
DataFlavor.plainTextFlavor // deprecated
|
||||
};
|
||||
|
||||
private String data;
|
||||
|
||||
/**
|
||||
* Creates a {@code Transferable} capable of transferring the specified
|
||||
* {@code String}.
|
||||
*
|
||||
* @param data the string to be transferred
|
||||
*/
|
||||
public StringSelection(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of flavors in which this {@code Transferable} can
|
||||
* provide the data. {@code DataFlavor.stringFlavor} is properly supported.
|
||||
* Support for {@code DataFlavor.plainTextFlavor} is <b>deprecated</b>.
|
||||
*
|
||||
* @return an array of length two, whose elements are
|
||||
* {@code DataFlavor.stringFlavor} and
|
||||
* {@code DataFlavor.plainTextFlavor}
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
// returning flavors itself would allow client code to modify
|
||||
// our internal behavior
|
||||
return flavors.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the requested flavor is supported by this
|
||||
* {@code Transferable}.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return {@code true} if {@code flavor} is equal to
|
||||
* {@code DataFlavor.stringFlavor} or
|
||||
* {@code DataFlavor.plainTextFlavor}; {@code false} if
|
||||
* {@code flavor} is not one of the above flavors
|
||||
* @throws NullPointerException if {@code flavor} is {@code null}
|
||||
*/
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
// JCK Test StringSelection0003: if 'flavor' is null, throw NPE
|
||||
for (int i = 0; i < flavors.length; i++) {
|
||||
if (flavor.equals(flavors[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code Transferable}'s data in the requested
|
||||
* {@code DataFlavor} if possible. If the desired flavor is
|
||||
* {@code DataFlavor.stringFlavor}, or an equivalent flavor, the
|
||||
* {@code String} representing the selection is returned. If the desired
|
||||
* flavor is {@code DataFlavor.plainTextFlavor}, or an equivalent flavor, a
|
||||
* {@code Reader} is returned.
|
||||
* <br>
|
||||
* <b>Note:</b> The behavior of this method for
|
||||
* {@code DataFlavor.plainTextFlavor}
|
||||
* and equivalent {@code DataFlavor}s is inconsistent with the definition of
|
||||
* {@code DataFlavor.plainTextFlavor}.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return the data in the requested flavor, as outlined above
|
||||
* @throws UnsupportedFlavorException if the requested data flavor is not
|
||||
* equivalent to either {@code DataFlavor.stringFlavor} or
|
||||
* {@code DataFlavor.plainTextFlavor}
|
||||
* @throws IOException if an IOException occurs while retrieving the data.
|
||||
* By default, StringSelection never throws this exception, but a
|
||||
* subclass may.
|
||||
* @throws NullPointerException if {@code flavor} is {@code null}
|
||||
* @see java.io.Reader
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException, IOException
|
||||
{
|
||||
// JCK Test StringSelection0007: if 'flavor' is null, throw NPE
|
||||
if (flavor.equals(flavors[STRING])) {
|
||||
return (Object)data;
|
||||
} else if (flavor.equals(flavors[PLAIN_TEXT])) {
|
||||
return new StringReader(data == null ? "" : data);
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Defines the interface for classes that can be used to provide data for a
|
||||
* transfer operation.
|
||||
* <p>
|
||||
* For information on using data transfer with Swing, see
|
||||
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
|
||||
* How to Use Drag and Drop and Data Transfer</a>, a section in
|
||||
* <em>The Java Tutorial</em>, for more information.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
* @since 1.1
|
||||
*/
|
||||
public interface Transferable {
|
||||
|
||||
/**
|
||||
* Returns an array of DataFlavor objects indicating the flavors the data
|
||||
* can be provided in. The array should be ordered according to preference
|
||||
* for providing the data (from most richly descriptive to least
|
||||
* descriptive).
|
||||
*
|
||||
* @return an array of data flavors in which this data can be transferred
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors();
|
||||
|
||||
/**
|
||||
* Returns whether or not the specified data flavor is supported for this
|
||||
* object.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return boolean indicating whether or not the data flavor is supported
|
||||
*/
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor);
|
||||
|
||||
/**
|
||||
* Returns an object which represents the data to be transferred. The class
|
||||
* of the object returned is defined by the representation class of the
|
||||
* flavor.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return an object which represents the data to be transferred
|
||||
* @throws IOException if the data is no longer available in the requested
|
||||
* flavor
|
||||
* @throws UnsupportedFlavorException if the requested data flavor is not
|
||||
* supported
|
||||
* @see DataFlavor#getRepresentationClass
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
/**
|
||||
* Signals that the requested data is not supported in this flavor.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
* @see Transferable#getTransferData
|
||||
* @since 1.1
|
||||
*/
|
||||
public class UnsupportedFlavorException extends Exception {
|
||||
|
||||
/*
|
||||
* JDK 1.1 serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = 5383814944251665601L;
|
||||
|
||||
/**
|
||||
* Constructs an UnsupportedFlavorException.
|
||||
*
|
||||
* @param flavor the flavor object which caused the exception. May be
|
||||
* {@code null}.
|
||||
*/
|
||||
public UnsupportedFlavorException(DataFlavor flavor) {
|
||||
super((flavor != null) ? flavor.getHumanPresentableName() : null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides interfaces and classes for transferring data between and within
|
||||
* applications. It defines the notion of a "transferable" object, which is an
|
||||
* object capable of being transferred between or within applications. An object
|
||||
* identifies itself as being transferable by implementing the Transferable
|
||||
* interface.
|
||||
* <p>
|
||||
* It also provides a clipboard mechanism, which is an object that temporarily
|
||||
* holds a transferable object that can be transferred between or within an
|
||||
* application. The clipboard is typically used for copy and paste operations.
|
||||
* Although it is possible to create a clipboard to use within an application,
|
||||
* most applications will use the system clipboard to ensure the data can be
|
||||
* transferred across applications running on the platform.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
package java.awt.datatransfer;
|
38
src/java.datatransfer/share/classes/module-info.java
Normal file
38
src/java.datatransfer/share/classes/module-info.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the API for transferring data between and within applications.
|
||||
*
|
||||
* @moduleGraph
|
||||
* @since 9
|
||||
*/
|
||||
module java.datatransfer {
|
||||
exports java.awt.datatransfer;
|
||||
|
||||
exports sun.datatransfer to java.desktop;
|
||||
|
||||
uses sun.datatransfer.DesktopDatatransferService;
|
||||
}
|
|
@ -0,0 +1,837 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.datatransfer;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.FlavorMap;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.IllegalCharsetNameException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Utility class with different datatransfer helper functions.
|
||||
*
|
||||
* @since 9
|
||||
*/
|
||||
public class DataFlavorUtil {
|
||||
|
||||
private DataFlavorUtil() {
|
||||
// Avoid instantiation
|
||||
}
|
||||
|
||||
private static Comparator<String> getCharsetComparator() {
|
||||
return CharsetComparator.INSTANCE;
|
||||
}
|
||||
|
||||
public static Comparator<DataFlavor> getDataFlavorComparator() {
|
||||
return DataFlavorComparator.INSTANCE;
|
||||
}
|
||||
|
||||
public static Comparator<Long> getIndexOrderComparator(Map<Long, Integer> indexMap) {
|
||||
return new IndexOrderComparator(indexMap);
|
||||
}
|
||||
|
||||
public static Comparator<DataFlavor> getTextFlavorComparator() {
|
||||
return TextFlavorComparator.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks whether a particular text/* MIME type supports the charset
|
||||
* parameter. The Map is initialized with all of the standard MIME types
|
||||
* listed in the DataFlavor.selectBestTextFlavor method comment. Additional
|
||||
* entries may be added during the life of the JRE for text/<other>
|
||||
* types.
|
||||
*/
|
||||
private static final Map<String, Boolean> textMIMESubtypeCharsetSupport;
|
||||
|
||||
static {
|
||||
Map<String, Boolean> tempMap = new HashMap<>(17);
|
||||
tempMap.put("sgml", Boolean.TRUE);
|
||||
tempMap.put("xml", Boolean.TRUE);
|
||||
tempMap.put("html", Boolean.TRUE);
|
||||
tempMap.put("enriched", Boolean.TRUE);
|
||||
tempMap.put("richtext", Boolean.TRUE);
|
||||
tempMap.put("uri-list", Boolean.TRUE);
|
||||
tempMap.put("directory", Boolean.TRUE);
|
||||
tempMap.put("css", Boolean.TRUE);
|
||||
tempMap.put("calendar", Boolean.TRUE);
|
||||
tempMap.put("plain", Boolean.TRUE);
|
||||
tempMap.put("rtf", Boolean.FALSE);
|
||||
tempMap.put("tab-separated-values", Boolean.FALSE);
|
||||
tempMap.put("t140", Boolean.FALSE);
|
||||
tempMap.put("rfc822-headers", Boolean.FALSE);
|
||||
tempMap.put("parityfec", Boolean.FALSE);
|
||||
textMIMESubtypeCharsetSupport = Collections.synchronizedMap(tempMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy initialization of Standard Encodings.
|
||||
*/
|
||||
private static class StandardEncodingsHolder {
|
||||
private static final SortedSet<String> standardEncodings = load();
|
||||
|
||||
private static SortedSet<String> load() {
|
||||
final SortedSet<String> tempSet = new TreeSet<>(getCharsetComparator().reversed());
|
||||
tempSet.add("US-ASCII");
|
||||
tempSet.add("ISO-8859-1");
|
||||
tempSet.add("UTF-8");
|
||||
tempSet.add("UTF-16BE");
|
||||
tempSet.add("UTF-16LE");
|
||||
tempSet.add("UTF-16");
|
||||
tempSet.add(Charset.defaultCharset().name());
|
||||
return Collections.unmodifiableSortedSet(tempSet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code SortedSet} of Strings which are a total order of the
|
||||
* standard character sets supported by the JRE. The ordering follows the
|
||||
* same principles as {@link DataFlavor#selectBestTextFlavor(DataFlavor[])}.
|
||||
* So as to avoid loading all available character converters, optional,
|
||||
* non-standard, character sets are not included.
|
||||
*/
|
||||
public static Set<String> standardEncodings() {
|
||||
return StandardEncodingsHolder.standardEncodings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an arbitrary text encoding to its canonical name.
|
||||
*/
|
||||
public static String canonicalName(String encoding) {
|
||||
if (encoding == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Charset.forName(encoding).name();
|
||||
} catch (IllegalCharsetNameException icne) {
|
||||
return encoding;
|
||||
} catch (UnsupportedCharsetException uce) {
|
||||
return encoding;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests only whether the flavor's MIME type supports the charset parameter.
|
||||
* Must only be called for flavors with a primary type of "text".
|
||||
*/
|
||||
public static boolean doesSubtypeSupportCharset(DataFlavor flavor) {
|
||||
String subType = flavor.getSubType();
|
||||
if (subType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean support = textMIMESubtypeCharsetSupport.get(subType);
|
||||
|
||||
if (support != null) {
|
||||
return support;
|
||||
}
|
||||
|
||||
boolean ret_val = (flavor.getParameter("charset") != null);
|
||||
textMIMESubtypeCharsetSupport.put(subType, ret_val);
|
||||
return ret_val;
|
||||
}
|
||||
public static boolean doesSubtypeSupportCharset(String subType,
|
||||
String charset)
|
||||
{
|
||||
Boolean support = textMIMESubtypeCharsetSupport.get(subType);
|
||||
|
||||
if (support != null) {
|
||||
return support;
|
||||
}
|
||||
|
||||
boolean ret_val = (charset != null);
|
||||
textMIMESubtypeCharsetSupport.put(subType, ret_val);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this flavor is a text type which supports the 'charset'
|
||||
* parameter.
|
||||
*/
|
||||
public static boolean isFlavorCharsetTextType(DataFlavor flavor) {
|
||||
// Although stringFlavor doesn't actually support the charset
|
||||
// parameter (because its primary MIME type is not "text"), it should
|
||||
// be treated as though it does. stringFlavor is semantically
|
||||
// equivalent to "text/plain" data.
|
||||
if (DataFlavor.stringFlavor.equals(flavor)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!"text".equals(flavor.getPrimaryType()) ||
|
||||
!doesSubtypeSupportCharset(flavor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?> rep_class = flavor.getRepresentationClass();
|
||||
|
||||
if (flavor.isRepresentationClassReader() ||
|
||||
String.class.equals(rep_class) ||
|
||||
flavor.isRepresentationClassCharBuffer() ||
|
||||
char[].class.equals(rep_class))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(flavor.isRepresentationClassInputStream() ||
|
||||
flavor.isRepresentationClassByteBuffer() ||
|
||||
byte[].class.equals(rep_class))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String charset = flavor.getParameter("charset");
|
||||
|
||||
// null equals default encoding which is always supported
|
||||
return (charset == null) || isEncodingSupported(charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this flavor is a text type which does not support the
|
||||
* 'charset' parameter.
|
||||
*/
|
||||
public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) {
|
||||
if (!"text".equals(flavor.getPrimaryType()) || doesSubtypeSupportCharset(flavor)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (flavor.isRepresentationClassInputStream() ||
|
||||
flavor.isRepresentationClassByteBuffer() ||
|
||||
byte[].class.equals(flavor.getRepresentationClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the specified flavor is a text flavor which supports the "charset"
|
||||
* parameter, then this method returns that parameter, or the default
|
||||
* charset if no such parameter was specified at construction. For non-text
|
||||
* DataFlavors, and for non-charset text flavors, this method returns
|
||||
* {@code null}.
|
||||
*/
|
||||
public static String getTextCharset(DataFlavor flavor) {
|
||||
if (!isFlavorCharsetTextType(flavor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String encoding = flavor.getParameter("charset");
|
||||
|
||||
return (encoding != null) ? encoding : Charset.defaultCharset().name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this JRE can both encode and decode text in the
|
||||
* specified encoding.
|
||||
*/
|
||||
private static boolean isEncodingSupported(String encoding) {
|
||||
if (encoding == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return Charset.isSupported(encoding);
|
||||
} catch (IllegalCharsetNameException icne) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to compare two objects by their Integer indices in the
|
||||
* given map. If the map doesn't contain an entry for either of the objects,
|
||||
* the fallback index will be used for the object instead.
|
||||
*
|
||||
* @param indexMap the map which maps objects into Integer indexes
|
||||
* @param obj1 the first object to be compared
|
||||
* @param obj2 the second object to be compared
|
||||
* @param fallbackIndex the Integer to be used as a fallback index
|
||||
* @return a negative integer, zero, or a positive integer as the first
|
||||
* object is mapped to a less, equal to, or greater index than the
|
||||
* second
|
||||
*/
|
||||
static <T> int compareIndices(Map<T, Integer> indexMap,
|
||||
T obj1, T obj2,
|
||||
Integer fallbackIndex) {
|
||||
Integer index1 = indexMap.getOrDefault(obj1, fallbackIndex);
|
||||
Integer index2 = indexMap.getOrDefault(obj2, fallbackIndex);
|
||||
return index1.compareTo(index2);
|
||||
}
|
||||
|
||||
/**
|
||||
* An IndexedComparator which compares two String charsets. The comparison
|
||||
* follows the rules outlined in DataFlavor.selectBestTextFlavor. In order
|
||||
* to ensure that non-Unicode, non-ASCII, non-default charsets are sorted
|
||||
* in alphabetical order, charsets are not automatically converted to their
|
||||
* canonical forms.
|
||||
*/
|
||||
private static class CharsetComparator implements Comparator<String> {
|
||||
static final CharsetComparator INSTANCE = new CharsetComparator();
|
||||
|
||||
private static final Map<String, Integer> charsets;
|
||||
|
||||
private static final Integer DEFAULT_CHARSET_INDEX = 2;
|
||||
private static final Integer OTHER_CHARSET_INDEX = 1;
|
||||
private static final Integer WORST_CHARSET_INDEX = 0;
|
||||
private static final Integer UNSUPPORTED_CHARSET_INDEX = Integer.MIN_VALUE;
|
||||
|
||||
private static final String UNSUPPORTED_CHARSET = "UNSUPPORTED";
|
||||
|
||||
static {
|
||||
Map<String, Integer> charsetsMap = new HashMap<>(8, 1.0f);
|
||||
|
||||
// we prefer Unicode charsets
|
||||
charsetsMap.put(canonicalName("UTF-16LE"), 4);
|
||||
charsetsMap.put(canonicalName("UTF-16BE"), 5);
|
||||
charsetsMap.put(canonicalName("UTF-8"), 6);
|
||||
charsetsMap.put(canonicalName("UTF-16"), 7);
|
||||
|
||||
// US-ASCII is the worst charset supported
|
||||
charsetsMap.put(canonicalName("US-ASCII"), WORST_CHARSET_INDEX);
|
||||
|
||||
charsetsMap.putIfAbsent(Charset.defaultCharset().name(), DEFAULT_CHARSET_INDEX);
|
||||
|
||||
charsetsMap.put(UNSUPPORTED_CHARSET, UNSUPPORTED_CHARSET_INDEX);
|
||||
|
||||
charsets = Collections.unmodifiableMap(charsetsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares charsets. Returns a negative integer, zero, or a positive
|
||||
* integer as the first charset is worse than, equal to, or better than
|
||||
* the second.
|
||||
* <p>
|
||||
* Charsets are ordered according to the following rules:
|
||||
* <ul>
|
||||
* <li>All unsupported charsets are equal</li>
|
||||
* <li>Any unsupported charset is worse than any supported charset.
|
||||
* <li>Unicode charsets, such as "UTF-16", "UTF-8", "UTF-16BE" and
|
||||
* "UTF-16LE", are considered best</li>
|
||||
* <li>After them, platform default charset is selected</li>
|
||||
* <li>"US-ASCII" is the worst of supported charsets</li>
|
||||
* <li>For all other supported charsets, the lexicographically less one
|
||||
* is considered the better</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param charset1 the first charset to be compared
|
||||
* @param charset2 the second charset to be compared
|
||||
* @return a negative integer, zero, or a positive integer as the first
|
||||
* argument is worse, equal to, or better than the second
|
||||
*/
|
||||
public int compare(String charset1, String charset2) {
|
||||
charset1 = getEncoding(charset1);
|
||||
charset2 = getEncoding(charset2);
|
||||
|
||||
int comp = compareIndices(charsets, charset1, charset2, OTHER_CHARSET_INDEX);
|
||||
|
||||
if (comp == 0) {
|
||||
return charset2.compareTo(charset1);
|
||||
}
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns encoding for the specified charset according to the following
|
||||
* rules:
|
||||
* <ul>
|
||||
* <li>If the charset is {@code null}, then {@code null} will be
|
||||
* returned</li>
|
||||
* <li>Iff the charset specifies an encoding unsupported by this JRE,
|
||||
* {@code UNSUPPORTED_CHARSET} will be returned</li>
|
||||
* <li>If the charset specifies an alias name, the corresponding
|
||||
* canonical name will be returned iff the charset is a known
|
||||
* Unicode, ASCII, or default charset</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param charset the charset
|
||||
* @return an encoding for this charset
|
||||
*/
|
||||
static String getEncoding(String charset) {
|
||||
if (charset == null) {
|
||||
return null;
|
||||
} else if (!isEncodingSupported(charset)) {
|
||||
return UNSUPPORTED_CHARSET;
|
||||
} else {
|
||||
// Only convert to canonical form if the charset is one
|
||||
// of the charsets explicitly listed in the known charsets
|
||||
// map. This will happen only for Unicode, ASCII, or default
|
||||
// charsets.
|
||||
String canonicalName = canonicalName(charset);
|
||||
return (charsets.containsKey(canonicalName))
|
||||
? canonicalName
|
||||
: charset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An IndexedComparator which compares two DataFlavors. For text flavors,
|
||||
* the comparison follows the rules outlined in
|
||||
* {@link DataFlavor#selectBestTextFlavor selectBestTextFlavor}. For
|
||||
* non-text flavors, unknown application MIME types are preferred, followed
|
||||
* by known application/x-java-* MIME types. Unknown application types are
|
||||
* preferred because if the user provides his own data flavor, it will
|
||||
* likely be the most descriptive one. For flavors which are otherwise
|
||||
* equal, the flavors' string representation are compared in the
|
||||
* alphabetical order.
|
||||
*/
|
||||
private static class DataFlavorComparator implements Comparator<DataFlavor> {
|
||||
|
||||
static final DataFlavorComparator INSTANCE = new DataFlavorComparator();
|
||||
|
||||
private static final Map<String, Integer> exactTypes;
|
||||
private static final Map<String, Integer> primaryTypes;
|
||||
private static final Map<Class<?>, Integer> nonTextRepresentations;
|
||||
private static final Map<String, Integer> textTypes;
|
||||
private static final Map<Class<?>, Integer> decodedTextRepresentations;
|
||||
private static final Map<Class<?>, Integer> encodedTextRepresentations;
|
||||
|
||||
private static final Integer UNKNOWN_OBJECT_LOSES = Integer.MIN_VALUE;
|
||||
private static final Integer UNKNOWN_OBJECT_WINS = Integer.MAX_VALUE;
|
||||
|
||||
static {
|
||||
{
|
||||
Map<String, Integer> exactTypesMap = new HashMap<>(4, 1.0f);
|
||||
|
||||
// application/x-java-* MIME types
|
||||
exactTypesMap.put("application/x-java-file-list", 0);
|
||||
exactTypesMap.put("application/x-java-serialized-object", 1);
|
||||
exactTypesMap.put("application/x-java-jvm-local-objectref", 2);
|
||||
exactTypesMap.put("application/x-java-remote-object", 3);
|
||||
|
||||
exactTypes = Collections.unmodifiableMap(exactTypesMap);
|
||||
}
|
||||
|
||||
{
|
||||
Map<String, Integer> primaryTypesMap = new HashMap<>(1, 1.0f);
|
||||
|
||||
primaryTypesMap.put("application", 0);
|
||||
|
||||
primaryTypes = Collections.unmodifiableMap(primaryTypesMap);
|
||||
}
|
||||
|
||||
{
|
||||
Map<Class<?>, Integer> nonTextRepresentationsMap = new HashMap<>(3, 1.0f);
|
||||
|
||||
nonTextRepresentationsMap.put(java.io.InputStream.class, 0);
|
||||
nonTextRepresentationsMap.put(java.io.Serializable.class, 1);
|
||||
|
||||
nonTextRepresentationsMap.put(RMI.remoteClass(), 2);
|
||||
|
||||
nonTextRepresentations = Collections.unmodifiableMap(nonTextRepresentationsMap);
|
||||
}
|
||||
|
||||
{
|
||||
Map<String, Integer> textTypesMap = new HashMap<>(16, 1.0f);
|
||||
|
||||
// plain text
|
||||
textTypesMap.put("text/plain", 0);
|
||||
|
||||
// stringFlavor
|
||||
textTypesMap.put("application/x-java-serialized-object", 1);
|
||||
|
||||
// misc
|
||||
textTypesMap.put("text/calendar", 2);
|
||||
textTypesMap.put("text/css", 3);
|
||||
textTypesMap.put("text/directory", 4);
|
||||
textTypesMap.put("text/parityfec", 5);
|
||||
textTypesMap.put("text/rfc822-headers", 6);
|
||||
textTypesMap.put("text/t140", 7);
|
||||
textTypesMap.put("text/tab-separated-values", 8);
|
||||
textTypesMap.put("text/uri-list", 9);
|
||||
|
||||
// enriched
|
||||
textTypesMap.put("text/richtext", 10);
|
||||
textTypesMap.put("text/enriched", 11);
|
||||
textTypesMap.put("text/rtf", 12);
|
||||
|
||||
// markup
|
||||
textTypesMap.put("text/html", 13);
|
||||
textTypesMap.put("text/xml", 14);
|
||||
textTypesMap.put("text/sgml", 15);
|
||||
|
||||
textTypes = Collections.unmodifiableMap(textTypesMap);
|
||||
}
|
||||
|
||||
{
|
||||
Map<Class<?>, Integer> decodedTextRepresentationsMap = new HashMap<>(4, 1.0f);
|
||||
|
||||
decodedTextRepresentationsMap.put(char[].class, 0);
|
||||
decodedTextRepresentationsMap.put(CharBuffer.class, 1);
|
||||
decodedTextRepresentationsMap.put(String.class, 2);
|
||||
decodedTextRepresentationsMap.put(Reader.class, 3);
|
||||
|
||||
decodedTextRepresentations =
|
||||
Collections.unmodifiableMap(decodedTextRepresentationsMap);
|
||||
}
|
||||
|
||||
{
|
||||
Map<Class<?>, Integer> encodedTextRepresentationsMap = new HashMap<>(3, 1.0f);
|
||||
|
||||
encodedTextRepresentationsMap.put(byte[].class, 0);
|
||||
encodedTextRepresentationsMap.put(ByteBuffer.class, 1);
|
||||
encodedTextRepresentationsMap.put(InputStream.class, 2);
|
||||
|
||||
encodedTextRepresentations =
|
||||
Collections.unmodifiableMap(encodedTextRepresentationsMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int compare(DataFlavor flavor1, DataFlavor flavor2) {
|
||||
if (flavor1.equals(flavor2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int comp;
|
||||
|
||||
String primaryType1 = flavor1.getPrimaryType();
|
||||
String subType1 = flavor1.getSubType();
|
||||
String mimeType1 = primaryType1 + "/" + subType1;
|
||||
Class<?> class1 = flavor1.getRepresentationClass();
|
||||
|
||||
String primaryType2 = flavor2.getPrimaryType();
|
||||
String subType2 = flavor2.getSubType();
|
||||
String mimeType2 = primaryType2 + "/" + subType2;
|
||||
Class<?> class2 = flavor2.getRepresentationClass();
|
||||
|
||||
if (flavor1.isFlavorTextType() && flavor2.isFlavorTextType()) {
|
||||
// First, compare MIME types
|
||||
comp = compareIndices(textTypes, mimeType1, mimeType2, UNKNOWN_OBJECT_LOSES);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// Only need to test one flavor because they both have the
|
||||
// same MIME type. Also don't need to worry about accidentally
|
||||
// passing stringFlavor because either
|
||||
// 1. Both flavors are stringFlavor, in which case the
|
||||
// equality test at the top of the function succeeded.
|
||||
// 2. Only one flavor is stringFlavor, in which case the MIME
|
||||
// type comparison returned a non-zero value.
|
||||
if (doesSubtypeSupportCharset(flavor1)) {
|
||||
// Next, prefer the decoded text representations of Reader,
|
||||
// String, CharBuffer, and [C, in that order.
|
||||
comp = compareIndices(decodedTextRepresentations, class1,
|
||||
class2, UNKNOWN_OBJECT_LOSES);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// Next, compare charsets
|
||||
comp = CharsetComparator.INSTANCE.compare(getTextCharset(flavor1),
|
||||
getTextCharset(flavor2));
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, prefer the encoded text representations of
|
||||
// InputStream, ByteBuffer, and [B, in that order.
|
||||
comp = compareIndices(encodedTextRepresentations, class1,
|
||||
class2, UNKNOWN_OBJECT_LOSES);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
} else {
|
||||
// First, prefer text types
|
||||
if (flavor1.isFlavorTextType()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (flavor2.isFlavorTextType()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Next, prefer application types.
|
||||
comp = compareIndices(primaryTypes, primaryType1, primaryType2,
|
||||
UNKNOWN_OBJECT_LOSES);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// Next, look for application/x-java-* types. Prefer unknown
|
||||
// MIME types because if the user provides his own data flavor,
|
||||
// it will likely be the most descriptive one.
|
||||
comp = compareIndices(exactTypes, mimeType1, mimeType2,
|
||||
UNKNOWN_OBJECT_WINS);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// Finally, prefer the representation classes of Remote,
|
||||
// Serializable, and InputStream, in that order.
|
||||
comp = compareIndices(nonTextRepresentations, class1, class2,
|
||||
UNKNOWN_OBJECT_LOSES);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
// The flavours are not equal but still not distinguishable.
|
||||
// Compare String representations in alphabetical order
|
||||
return flavor1.getMimeType().compareTo(flavor2.getMimeType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the Map that maps objects to Integer indices and a boolean value,
|
||||
* this Comparator imposes a direct or reverse order on set of objects.
|
||||
* <p>
|
||||
* If the specified boolean value is SELECT_BEST, the Comparator imposes the
|
||||
* direct index-based order: an object A is greater than an object B if and
|
||||
* only if the index of A is greater than the index of B. An object that
|
||||
* doesn't have an associated index is less or equal than any other object.
|
||||
* <p>
|
||||
* If the specified boolean value is SELECT_WORST, the Comparator imposes
|
||||
* the reverse index-based order: an object A is greater than an object B if
|
||||
* and only if A is less than B with the direct index-based order.
|
||||
*/
|
||||
private static class IndexOrderComparator implements Comparator<Long> {
|
||||
private final Map<Long, Integer> indexMap;
|
||||
private static final Integer FALLBACK_INDEX = Integer.MIN_VALUE;
|
||||
|
||||
public IndexOrderComparator(Map<Long, Integer> indexMap) {
|
||||
this.indexMap = indexMap;
|
||||
}
|
||||
|
||||
public int compare(Long obj1, Long obj2) {
|
||||
return compareIndices(indexMap, obj1, obj2, FALLBACK_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TextFlavorComparator extends DataFlavorComparator {
|
||||
|
||||
static final TextFlavorComparator INSTANCE = new TextFlavorComparator();
|
||||
|
||||
/**
|
||||
* Compares two {@code DataFlavor} objects. Returns a negative integer,
|
||||
* zero, or a positive integer as the first {@code DataFlavor} is worse
|
||||
* than, equal to, or better than the second.
|
||||
* <p>
|
||||
* {@code DataFlavor}s are ordered according to the rules outlined for
|
||||
* {@link DataFlavor#selectBestTextFlavor selectBestTextFlavor}.
|
||||
*
|
||||
* @param flavor1 the first {@code DataFlavor} to be compared
|
||||
* @param flavor2 the second {@code DataFlavor} to be compared
|
||||
* @return a negative integer, zero, or a positive integer as the first
|
||||
* argument is worse, equal to, or better than the second
|
||||
* @throws ClassCastException if either of the arguments is not an
|
||||
* instance of {@code DataFlavor}
|
||||
* @throws NullPointerException if either of the arguments is
|
||||
* {@code null}
|
||||
* @see DataFlavor#selectBestTextFlavor
|
||||
*/
|
||||
public int compare(DataFlavor flavor1, DataFlavor flavor2) {
|
||||
if (flavor1.isFlavorTextType()) {
|
||||
if (flavor2.isFlavorTextType()) {
|
||||
return super.compare(flavor1, flavor2);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else if (flavor2.isFlavorTextType()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A fallback implementation of {@link DesktopDatatransferService} used if
|
||||
* there is no desktop.
|
||||
*/
|
||||
private static final class DefaultDesktopDatatransferService implements DesktopDatatransferService {
|
||||
static final DesktopDatatransferService INSTANCE = getDesktopService();
|
||||
|
||||
private static DesktopDatatransferService getDesktopService() {
|
||||
ServiceLoader<DesktopDatatransferService> loader =
|
||||
ServiceLoader.load(DesktopDatatransferService.class, null);
|
||||
Iterator<DesktopDatatransferService> iterator = loader.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
return iterator.next();
|
||||
} else {
|
||||
return new DefaultDesktopDatatransferService();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* System singleton FlavorTable. Only used if there is no desktop to
|
||||
* provide an appropriate FlavorMap.
|
||||
*/
|
||||
private volatile FlavorMap flavorMap;
|
||||
|
||||
@Override
|
||||
public void invokeOnEventThread(Runnable r) {
|
||||
r.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultUnicodeEncoding() {
|
||||
return StandardCharsets.UTF_8.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlavorMap getFlavorMap(Supplier<FlavorMap> supplier) {
|
||||
FlavorMap map = flavorMap;
|
||||
if (map == null) {
|
||||
synchronized (this) {
|
||||
map = flavorMap;
|
||||
if (map == null) {
|
||||
flavorMap = map = supplier.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDesktopPresent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedHashSet<DataFlavor> getPlatformMappingsForNative(String nat) {
|
||||
return new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
|
||||
return new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTextFlavorProperties(String nat, String charset,
|
||||
String eoln, String terminators) {
|
||||
// Not needed if desktop module is absent
|
||||
}
|
||||
}
|
||||
|
||||
public static DesktopDatatransferService getDesktopService() {
|
||||
return DefaultDesktopDatatransferService.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class that provides access to {@code java.rmi.Remote} and
|
||||
* {@code java.rmi.MarshalledObject} without creating a static dependency.
|
||||
*/
|
||||
public static class RMI {
|
||||
private static final Class<?> remoteClass = getClass("java.rmi.Remote");
|
||||
private static final Class<?> marshallObjectClass = getClass("java.rmi.MarshalledObject");
|
||||
private static final Constructor<?> marshallCtor = getConstructor(marshallObjectClass, Object.class);
|
||||
private static final Method marshallGet = getMethod(marshallObjectClass, "get");
|
||||
|
||||
private static Class<?> getClass(String name) {
|
||||
try {
|
||||
return Class.forName(name, true, null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Constructor<?> getConstructor(Class<?> c, Class<?>... types) {
|
||||
try {
|
||||
return (c == null) ? null : c.getDeclaredConstructor(types);
|
||||
} catch (NoSuchMethodException x) {
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getMethod(Class<?> c, String name, Class<?>... types) {
|
||||
try {
|
||||
return (c == null) ? null : c.getMethod(name, types);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code java.rmi.Remote.class} if RMI is present; otherwise
|
||||
* {@code null}.
|
||||
*/
|
||||
static Class<?> remoteClass() {
|
||||
return remoteClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the given class is java.rmi.Remote.
|
||||
*/
|
||||
public static boolean isRemote(Class<?> c) {
|
||||
return (remoteClass != null) && remoteClass.isAssignableFrom(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new MarshalledObject containing the serialized
|
||||
* representation of the given object.
|
||||
*/
|
||||
public static Object newMarshalledObject(Object obj) throws IOException {
|
||||
try {
|
||||
return marshallCtor == null ? null : marshallCtor.newInstance(obj);
|
||||
} catch (InstantiationException | IllegalAccessException x) {
|
||||
throw new AssertionError(x);
|
||||
} catch (InvocationTargetException x) {
|
||||
Throwable cause = x.getCause();
|
||||
if (cause instanceof IOException)
|
||||
throw (IOException) cause;
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new copy of the contained marshalled object.
|
||||
*/
|
||||
public static Object getMarshalledObject(Object obj)
|
||||
throws IOException, ClassNotFoundException {
|
||||
try {
|
||||
return marshallGet == null ? null : marshallGet.invoke(obj);
|
||||
} catch (IllegalAccessException x) {
|
||||
throw new AssertionError(x);
|
||||
} catch (InvocationTargetException x) {
|
||||
Throwable cause = x.getCause();
|
||||
if (cause instanceof IOException)
|
||||
throw (IOException) cause;
|
||||
if (cause instanceof ClassNotFoundException)
|
||||
throw (ClassNotFoundException) cause;
|
||||
throw new AssertionError(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.datatransfer;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.FlavorMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Contains services which desktop provides to the datatransfer system to enrich
|
||||
* it's functionality.
|
||||
*
|
||||
* @author Petr Pchelko
|
||||
* @since 9
|
||||
*/
|
||||
public interface DesktopDatatransferService {
|
||||
|
||||
/**
|
||||
* If desktop is present - invokes a {@code Runnable} on the event dispatch
|
||||
* thread. Otherwise invokes a {@code run()} method directly.
|
||||
*
|
||||
* @param r a {@code Runnable} to invoke
|
||||
*/
|
||||
void invokeOnEventThread(Runnable r);
|
||||
|
||||
/**
|
||||
* Get a platform-dependent default unicode encoding to use in datatransfer
|
||||
* system.
|
||||
*
|
||||
* @return default unicode encoding
|
||||
*/
|
||||
String getDefaultUnicodeEncoding();
|
||||
|
||||
/**
|
||||
* Takes an appropriate {@code FlavorMap} from the desktop. If no
|
||||
* appropriate table is found - uses a provided supplier to instantiate a
|
||||
* table. If the desktop is absent - creates and returns a system singleton.
|
||||
*
|
||||
* @param supplier a constructor that should be used to create a new
|
||||
* instance of the {@code FlavorMap}
|
||||
* @return a {@code FlavorMap}
|
||||
*/
|
||||
FlavorMap getFlavorMap(Supplier<FlavorMap> supplier);
|
||||
|
||||
/**
|
||||
* Checks if desktop is present.
|
||||
*
|
||||
* @return {@code true} is the desktop is present
|
||||
*/
|
||||
boolean isDesktopPresent();
|
||||
|
||||
/**
|
||||
* Returns platform-specific mappings for the specified native format. If
|
||||
* there are no platform-specific mappings for this native, the method
|
||||
* returns an empty {@code Set}.
|
||||
*
|
||||
* @param nat a native format to return flavors for
|
||||
* @return set of platform-specific mappings for a native format
|
||||
*/
|
||||
LinkedHashSet<DataFlavor> getPlatformMappingsForNative(String nat);
|
||||
|
||||
/**
|
||||
* Returns platform-specific mappings for the specified flavor. If there are
|
||||
* no platform-specific mappings for this flavor, the method returns an
|
||||
* empty {@code Set}.
|
||||
*
|
||||
* @param df {@code DataFlavor} to return mappings for
|
||||
* @return set of platform-specific mappings for a {@code DataFlavor}
|
||||
*/
|
||||
LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df);
|
||||
|
||||
/**
|
||||
* This method is called for text flavor mappings established while parsing
|
||||
* the default flavor mappings file. It stores the "eoln" and "terminators"
|
||||
* parameters which are not officially part of the MIME type. They are MIME
|
||||
* parameters specific to the flavormap.properties file format.
|
||||
*/
|
||||
void registerTextFlavorProperties(String nat, String charset,
|
||||
String eoln, String terminators);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
#
|
||||
# This properties file is used to initialize the default
|
||||
# java.awt.datatransfer.SystemFlavorMap. It contains the X11 platform-specific,
|
||||
# default mappings between common X11 selection atoms and platform-independent
|
||||
# MIME type strings, which will be converted into
|
||||
# java.awt.datatransfer.DataFlavors.
|
||||
#
|
||||
# The standard format is:
|
||||
#
|
||||
# <native>=<MIME type>,<MIME type>, ...
|
||||
#
|
||||
# <native> should be a string identifier that the native platform will
|
||||
# recognize as a valid data format. <MIME type> should specify both a MIME
|
||||
# primary type and a MIME subtype separated by a '/'. The MIME type may include
|
||||
# parameters, where each parameter is a key/value pair separated by '=', and
|
||||
# where each parameter to the MIME type is separated by a ';'.
|
||||
#
|
||||
# Because SystemFlavorMap implements FlavorTable, developers are free to
|
||||
# duplicate DataFlavor values and set multiple values for a single native by
|
||||
# separating them with ",". If a mapping contains a duplicate key or value,
|
||||
# earlier mappings which included this key or value will be preferred.
|
||||
#
|
||||
# Mappings whose values specify DataFlavors with primary MIME types of
|
||||
# "text", and which support the charset parameter, should specify the exact
|
||||
# format in which the native platform expects the data. The "charset"
|
||||
# parameter specifies the char to byte encoding, the "eoln" parameter
|
||||
# specifies the end-of-line marker, and the "terminators" parameter specifies
|
||||
# the number of terminating NUL bytes. Note that "eoln" and "terminators"
|
||||
# are not standardized MIME type parameters. They are specific to this file
|
||||
# format ONLY. They will not appear in any of the DataFlavors returned by the
|
||||
# SystemFlavorMap at the Java level.
|
||||
#
|
||||
# If the "charset" parameter is omitted, or has zero length, the platform
|
||||
# default encoding is assumed. If the "eoln" parameter is omitted, or has
|
||||
# zero length, "\n" is assumed. If the "terminators" parameter is omitted,
|
||||
# or has a value less than zero, zero is assumed.
|
||||
#
|
||||
# Upon initialization, the data transfer subsystem will record the specified
|
||||
# details of the native text format, but the default SystemFlavorMap will
|
||||
# present a large set of synthesized DataFlavors which map, in both
|
||||
# directions, to the native. After receiving data from the application in one
|
||||
# of the synthetic DataFlavors, the data transfer subsystem will transform
|
||||
# the data stream into the format specified in this file before passing the
|
||||
# transformed stream to the native system.
|
||||
#
|
||||
# Mappings whose values specify DataFlavors with primary MIME types of
|
||||
# "text", but which do not support the charset parameter, will be treated as
|
||||
# opaque, 8-bit data. They will not undergo any transformation process, and
|
||||
# any "charset", "eoln", or "terminators" parameters specified in this file
|
||||
# will be ignored.
|
||||
#
|
||||
# See java.awt.datatransfer.DataFlavor.selectBestTextFlavor for a list of
|
||||
# text flavors which support the charset parameter.
|
||||
|
||||
UTF8_STRING=text/plain;charset=UTF-8;eoln="\n";terminators=0
|
||||
|
||||
# The COMPOUND_TEXT support for inter-client text transfer is disabled by
|
||||
# default. The reason is that many native applications prefer this format over
|
||||
# other native text formats, but are unable to decode the textual data in this
|
||||
# format properly. This results in java-to-native text transfer failures.
|
||||
# To enable the COMPOUND_TEXT support for this JRE installation uncomment
|
||||
# the line below.
|
||||
|
||||
# COMPOUND_TEXT=text/plain;charset=x-compound-text;eoln="\n";terminators=0
|
||||
|
||||
TEXT=text/plain;eoln="\n";terminators=0
|
||||
STRING=text/plain;charset=iso8859-1;eoln="\n";terminators=0
|
||||
FILE_NAME=application/x-java-file-list;class=java.util.List
|
||||
text/uri-list=application/x-java-file-list;class=java.util.List
|
||||
PNG=image/x-java-image;class=java.awt.Image
|
||||
JFIF=image/x-java-image;class=java.awt.Image
|
|
@ -0,0 +1,69 @@
|
|||
#
|
||||
# This properties file is used to initialize the default
|
||||
# java.awt.datatransfer.SystemFlavorMap. It contains the Win32 platform-
|
||||
# specific, default mappings between common Win32 Clipboard atoms and platform-
|
||||
# independent MIME type strings, which will be converted into
|
||||
# java.awt.datatransfer.DataFlavors.
|
||||
#
|
||||
# The standard format is:
|
||||
#
|
||||
# <native>=<MIME type>,<MIME type>, ...
|
||||
#
|
||||
# <native> should be a string identifier that the native platform will
|
||||
# recognize as a valid data format. <MIME type> should specify both a MIME
|
||||
# primary type and a MIME subtype separated by a '/'. The MIME type may include
|
||||
# parameters, where each parameter is a key/value pair separated by '=', and
|
||||
# where each parameter to the MIME type is separated by a ';'.
|
||||
#
|
||||
# Because SystemFlavorMap implements FlavorTable, developers are free to
|
||||
# duplicate DataFlavor values and set multiple values for a single native by
|
||||
# separating them with ",". If a mapping contains a duplicate key or value,
|
||||
# earlier mappings which included this key or value will be preferred.#
|
||||
# Mappings whose values specify DataFlavors with primary MIME types of
|
||||
# "text", and which support the charset parameter, should specify the exact
|
||||
# format in which the native platform expects the data. The "charset"
|
||||
# parameter specifies the char to byte encoding, the "eoln" parameter
|
||||
# specifies the end-of-line marker, and the "terminators" parameter specifies
|
||||
# the number of terminating NUL bytes. Note that "eoln" and "terminators"
|
||||
# are not standardized MIME type parameters. They are specific to this file
|
||||
# format ONLY. They will not appear in any of the DataFlavors returned by the
|
||||
# SystemFlavorMap at the Java level.
|
||||
#
|
||||
# If the "charset" parameter is omitted, or has zero length, the platform
|
||||
# default encoding is assumed. If the "eoln" parameter is omitted, or has
|
||||
# zero length, "\n" is assumed. If the "terminators" parameter is omitted,
|
||||
# or has a value less than zero, zero is assumed.
|
||||
#
|
||||
# Upon initialization, the data transfer subsystem will record the specified
|
||||
# details of the native text format, but the default SystemFlavorMap will
|
||||
# present a large set of synthesized DataFlavors which map, in both
|
||||
# directions, to the native. After receiving data from the application in one
|
||||
# of the synthetic DataFlavors, the data transfer subsystem will transform
|
||||
# the data stream into the format specified in this file before passing the
|
||||
# transformed stream to the native system.
|
||||
#
|
||||
# Mappings whose values specify DataFlavors with primary MIME types of
|
||||
# "text", but which do not support the charset parameter, will be treated as
|
||||
# opaque, 8-bit data. They will not undergo any transformation process, and
|
||||
# any "charset", "eoln", or "terminators" parameters specified in this file
|
||||
# will be ignored.
|
||||
#
|
||||
# See java.awt.datatransfer.DataFlavor.selectBestTextFlavor for a list of
|
||||
# text flavors which support the charset parameter.
|
||||
|
||||
UNICODE\ TEXT=text/plain;charset=utf-16le;eoln="\r\n";terminators=2
|
||||
TEXT=text/plain;eoln="\r\n";terminators=1
|
||||
HTML\ Format=text/html;charset=utf-8;eoln="\r\n";terminators=1
|
||||
Rich\ Text\ Format=text/rtf
|
||||
HDROP=application/x-java-file-list;class=java.util.List
|
||||
PNG=image/x-java-image;class=java.awt.Image
|
||||
JFIF=image/x-java-image;class=java.awt.Image
|
||||
DIB=image/x-java-image;class=java.awt.Image
|
||||
ENHMETAFILE=image/x-java-image;class=java.awt.Image
|
||||
METAFILEPICT=image/x-java-image;class=java.awt.Image
|
||||
LOCALE=application/x-java-text-encoding;class="[B"
|
||||
UniformResourceLocator=application/x-java-url;class=java.net.URL,\
|
||||
text/uri-list;eoln="\r\n";terminators=1,\
|
||||
text/plain;eoln="\r\n";terminators=1
|
||||
FileGroupDescriptorW=application/x-java-file-list;class=java.util.List
|
||||
FileGroupDescriptor=application/x-java-file-list;class=java.util.List
|
Loading…
Add table
Add a link
Reference in a new issue