Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8140526

cannot copy to the system clipboard using the mimetype = 'image/svg+xml'

XMLWordPrintable

    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.6.0_16"
      Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
      Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The attached java code performs the copy operation, by creating a custom data flavor using the command: DataFlavor("image/svg+xml").
      The copy operation completes successfully, but the mimetype name is mangled. Monitor the result using the Windows program Clipview.exe, from http://www.peterbuettner.de/develop/tools/clipview/index.html

      The data shows up under the name 'JAVA_DATAFLAVOR:image/svg+xml; class=java.io.InputStream' instead of the expected mimetype, which would be just 'image/svg+xml'.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the attached code and check the mimetype in the system clipboard

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      image/svg+xml
      ACTUAL -
      JAVA_DATAFLAVOR:image/svg+xml; class=java.io.InputStream

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.datatransfer.*;
      import java.awt.Toolkit;
      import java.io.ByteArrayInputStream;

      public class SVGCopy
      {
          public static void main(String[] args)
          {
      System.out.println("This is an attempt to copy to the clipboard using mimetype 'image/svg+xml'");
              Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
              SVGTransferable strSVG = new SVGTransferable("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n<svg>test</svg>");
              clip.setContents(strSVG, null);
          }
      }

      class SVGTransferable implements Transferable
      {
          private String str;
          private DataFlavor flavSVG = null;

          public SVGTransferable(String m_str)
          {
              str = m_str;
              try
              {
                   flavSVG = new DataFlavor("image/svg+xml");
                   System.out.println("created DataFlavor = " + flavSVG);
              }
              catch (Exception e)
                  {System.out.println("error creating DataFlavor : " + e);}
          }

          public DataFlavor[] getTransferDataFlavors()
          {
              return new DataFlavor[] { flavSVG };
          }

          public boolean isDataFlavorSupported(DataFlavor flavor)
          {
              return flavor.equals(flavSVG);
          }

          public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
          {
              if (flavor.equals(flavSVG))
                 return new ByteArrayInputStream(str.getBytes());
              else
                  throw new UnsupportedFlavorException(flavor);
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: