title: Create svg DataFlavor in java with dataflavor image/svg+xml
body: <p>So I want to create a <strong>DataFlavor</strong> that contains a string and has the mimetype image/svg+xml using java. I am not quite sure I get how the DataFlavor and mimetype are connected. I did not quite understand the Java tutorials <a href="http://www-inf.int-evry.fr/COURS/java/javatutorial/uiswing/dnd/dataflavor.html" rel="nofollow" title="DataFlavor">1</a>.</p>
  
  <p>What I want is to be able to move my string that I generated as an svg object to other programs using the system clipboard.</p>
  
  <p>The code i am using now is:</p>
  
  <pre><code>import java.awt.Toolkit;
  import java.awt.datatransfer.ClipboardOwner;
  import java.awt.datatransfer.DataFlavor;
  import java.awt.datatransfer.Transferable;
  import java.awt.datatransfer.UnsupportedFlavorException;
  
  
  
  public class SvgClip implements Transferable, ClipboardOwner
  {
  
      private String string;
  
      public SvgClip(String str)
  
      {
          string = str;
      }
  
      public DataFlavor[] getTransferDataFlavors()
  
      {    
          DataFlavor flavor = new DataFlavor();
          try{
              //flavor = new DataFlavor("image/svg+xml");S
              flavor = new DataFlavor("image/svg+xml;class=java.lang.String");
          }catch (Exception ex) {
              ex.printStackTrace();
          }
          return new DataFlavor[]{flavor};    
      }
  
      public boolean isDataFlavorSupported(DataFlavor flavor)        
      {    
          return DataFlavor.imageFlavor.equals(flavor);    
      }
  
      public Object getTransferData(DataFlavor flavor) throws        
              UnsupportedFlavorException        
      {    
          if (!isDataFlavorSupported(flavor))        
              throw new UnsupportedFlavorException(flavor);    
          return string;    
      }
  
      public void lostOwnership(java.awt.datatransfer.Clipboard clip,        
              java.awt.datatransfer.Transferable tr)        
      {    
          return;    
      }
  }
  </code></pre>
  
  <p>however, this is not working , i get <code>java.io.IOException: image/svg+xml</code>
  when trying to create it with:</p>
  
  <pre><code>SvgClip strSel = new SvgClip(newfileString);
  clipboard.setContents(strSel, null);
  </code></pre>
  
  <p>Anyone have any idea?</p>