Java Code Examples for java.awt.datatransfer.DataFlavor#isMimeTypeEqual()

The following examples show how to use java.awt.datatransfer.DataFlavor#isMimeTypeEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DnDUtils.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String extractDropLink(@Nonnull final DropTargetDropEvent dtde) throws Exception {
  String foundHtmlLink = null;
  String foundMozLink = null;
  for (final DataFlavor df : dtde.getCurrentDataFlavors()) {
    if (df.getRepresentationClass() == String.class) {
      if (foundHtmlLink == null && df.isMimeTypeEqual(MIME_TEXT_HTML)) {
        final String link = extractHtmlLink(true, (String) dtde.getTransferable().getTransferData(df));
        if (link != null) {
          foundHtmlLink = link;
        }
      }
    } else if (df.getRepresentationClass() == InputStream.class && df.isMimeTypeEqual(MIME_MOZ_URL)) {
      if (foundMozLink == null) {
        final InputStream in = ((InputStream) dtde.getTransferable().getTransferData(df));
        final StringWriter string = new StringWriter();
        IOUtils.copy(in, string, Charset.defaultCharset());
        IOUtils.closeQuietly(in);
        foundMozLink = removeZeroChars(string.toString().split("\\n")[0]).trim();
      }
    }
  }
  return foundMozLink == null ? foundHtmlLink : foundMozLink;
}
 
Example 2
Source File: WClipboard.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
        getFormatsForTransferable(contents, getDefaultFlavorTable());

    openClipboard(this);

    try {
        for (Long format : formatMap.keySet()) {
            DataFlavor flavor = formatMap.get(format);

            try {
                byte[] bytes = WDataTransferer.getInstance().
                    translateTransferable(contents, flavor, format);
                publishClipboardData(format, bytes);
            } catch (IOException e) {
                // Fix 4696186: don't print exception if data with
                // javaJVMLocalObjectMimeType failed to serialize.
                // May remove this if-check when 5078787 is fixed.
                if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                      e instanceof java.io.NotSerializableException)) {
                    e.printStackTrace();
                }
            }
        }
    } finally {
        closeClipboard();
    }
}
 
Example 3
Source File: WClipboard.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void setContentsNative(Transferable contents) {

        // Don't use delayed Clipboard rendering for the Transferable's data.
        // If we did that, we would call Transferable.getTransferData on
        // the Toolkit thread, which is a security hole.
        //
        // Get all of the target formats into which the Transferable can be
        // translated. Then, for each format, translate the data and post
        // it to the Clipboard.
        Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
            getFormatsForTransferable(contents, flavorMap);

        openClipboard(this);

        try {
            for (Long format : formatMap.keySet()) {
                DataFlavor flavor = formatMap.get(format);

                try {
                    byte[] bytes = WDataTransferer.getInstance().
                        translateTransferable(contents, flavor, format);
                    publishClipboardData(format, bytes);
                } catch (IOException e) {
                    // Fix 4696186: don't print exception if data with
                    // javaJVMLocalObjectMimeType failed to serialize.
                    // May remove this if-check when 5078787 is fixed.
                    if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                          e instanceof java.io.NotSerializableException)) {
                        e.printStackTrace();
                    }
                }
            }
        } finally {
            closeClipboard();
        }
    }
 
Example 4
Source File: TableTransferHandler.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canImport(TransferSupport support) {
    boolean supportedFlavor = false;

    for (DataFlavor flavor : support.getDataFlavors()) {
        if (flavor.isMimeTypeEqual(DataTransferable.FLAVORS[0])) {
            supportedFlavor = true;
            break;
        }
    }

    return supportedFlavor;
}
 
Example 5
Source File: DnDUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public static boolean isFileOrLinkOrText(@Nonnull final DropTargetDragEvent dtde) {
  boolean result = false;
  for (final DataFlavor flavor : dtde.getCurrentDataFlavors()) {
    if (flavor.isFlavorJavaFileListType() || flavor.isFlavorTextType() || flavor.isMimeTypeEqual(MIME_MOZ_URL) || flavor.isMimeTypeEqual(MIME_TEXT_PLAIN) || flavor.isMimeTypeEqual(MIME_TEXT_HTML)) {
      result = true;
      break;
    }
  }
  return result;
}
 
Example 6
Source File: WClipboard.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
        getFormatsForTransferable(contents, getDefaultFlavorTable());

    openClipboard(this);

    try {
        for (Long format : formatMap.keySet()) {
            DataFlavor flavor = formatMap.get(format);

            try {
                byte[] bytes = WDataTransferer.getInstance().
                    translateTransferable(contents, flavor, format);
                publishClipboardData(format, bytes);
            } catch (IOException e) {
                // Fix 4696186: don't print exception if data with
                // javaJVMLocalObjectMimeType failed to serialize.
                // May remove this if-check when 5078787 is fixed.
                if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                      e instanceof java.io.NotSerializableException)) {
                    e.printStackTrace();
                }
            }
        }
    } finally {
        closeClipboard();
    }
}
 
Example 7
Source File: WClipboard.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
        getFormatsForTransferable(contents, getDefaultFlavorTable());

    openClipboard(this);

    try {
        for (Long format : formatMap.keySet()) {
            DataFlavor flavor = formatMap.get(format);

            try {
                byte[] bytes = WDataTransferer.getInstance().
                    translateTransferable(contents, flavor, format);
                publishClipboardData(format, bytes);
            } catch (IOException e) {
                // Fix 4696186: don't print exception if data with
                // javaJVMLocalObjectMimeType failed to serialize.
                // May remove this if-check when 5078787 is fixed.
                if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                      e instanceof java.io.NotSerializableException)) {
                    e.printStackTrace();
                }
            }
        }
    } finally {
        closeClipboard();
    }
}
 
Example 8
Source File: DataTransferer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }

    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        return AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {

            StringBuilder allowedFiles = new StringBuilder(str.length());
            String [] uriArray = str.split("(\\s)+");

            for (String fileName : uriArray)
            {
                File file = new File(fileName);
                if (file.exists() &&
                    !(isFileInWebstartedCache(file) ||
                    isForbiddenToRead(file, userProtectionDomain)))
                {
                    if (0 != allowedFiles.length())
                    {
                        allowedFiles.append("\\r\\n");
                    }

                    allowedFiles.append(fileName);
                }
            }

            return allowedFiles.toString();
        });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }
}
 
Example 9
Source File: DataTransferer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }

    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        return AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {

            StringBuilder allowedFiles = new StringBuilder(str.length());
            String [] uriArray = str.split("(\\s)+");

            for (String fileName : uriArray)
            {
                File file = new File(fileName);
                if (file.exists() &&
                    !(isFileInWebstartedCache(file) ||
                    isForbiddenToRead(file, userProtectionDomain)))
                {
                    if (0 != allowedFiles.length())
                    {
                        allowedFiles.append("\\r\\n");
                    }

                    allowedFiles.append(fileName);
                }
            }

            return allowedFiles.toString();
        });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }
}
 
Example 10
Source File: WClipboard.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
        getFormatsForTransferable(contents, getDefaultFlavorTable());

    openClipboard(this);

    try {
        for (Long format : formatMap.keySet()) {
            DataFlavor flavor = formatMap.get(format);

            try {
                byte[] bytes = WDataTransferer.getInstance().
                    translateTransferable(contents, flavor, format);
                publishClipboardData(format, bytes);
            } catch (IOException e) {
                // Fix 4696186: don't print exception if data with
                // javaJVMLocalObjectMimeType failed to serialize.
                // May remove this if-check when 5078787 is fixed.
                if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                      e instanceof java.io.NotSerializableException)) {
                    e.printStackTrace();
                }
            }
        }
    } finally {
        closeClipboard();
    }
}
 
Example 11
Source File: WClipboard.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
        getFormatsForTransferable(contents, getDefaultFlavorTable());

    openClipboard(this);

    try {
        for (Long format : formatMap.keySet()) {
            DataFlavor flavor = formatMap.get(format);

            try {
                byte[] bytes = WDataTransferer.getInstance().
                    translateTransferable(contents, flavor, format);
                publishClipboardData(format, bytes);
            } catch (IOException e) {
                // Fix 4696186: don't print exception if data with
                // javaJVMLocalObjectMimeType failed to serialize.
                // May remove this if-check when 5078787 is fixed.
                if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                      e instanceof java.io.NotSerializableException)) {
                    e.printStackTrace();
                }
            }
        }
    } finally {
        closeClipboard();
    }
}
 
Example 12
Source File: DataTransferer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 13
Source File: DataTransferable.java    From nmonvisualizer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
    return flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType);
}
 
Example 14
Source File: DataTransferer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 15
Source File: DataTransferer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 16
Source File: DataTransferer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 17
Source File: DataTransferer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 18
Source File: DataTransferer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 19
Source File: DataTransferer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}
 
Example 20
Source File: DataTransferer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
        throws IOException
{
    if (null == System.getSecurityManager()
        || !flavor.isMimeTypeEqual("text/uri-list"))
    {
        return str;
    }


    String ret_val = "";
    final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);

    try {
        ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                public Object run() {

                    StringBuffer allowedFiles = new StringBuffer(str.length());
                    String [] uriArray = str.split("(\\s)+");

                    for (String fileName : uriArray)
                    {
                        File file = new File(fileName);
                        if (file.exists() &&
                            !(isFileInWebstartedCache(file) ||
                            isForbiddenToRead(file, userProtectionDomain)))
                        {

                            if (0 != allowedFiles.length())
                            {
                                allowedFiles.append("\\r\\n");
                            }

                            allowedFiles.append(fileName);
                        }
                    }

                    return allowedFiles.toString();
                }
            });
    } catch (PrivilegedActionException pae) {
        throw new IOException(pae.getMessage(), pae);
    }

    return ret_val;
}