Ok, the URL thing looks like it might have been a red herring. It seems to only allow you to place a shortcut/link/alias to that URL.
Instead I went down the platform specific route. With the help of Appl technote TN1085 (Using the Drag Manager to Interact With and Manipulate File System Entities):
http://developer.apple.com/technotes/tn/tn1085.html
With that and that fact the java<->native code interaction on the mac is dead easy (no C glue code is needed) I was eventually able to figure out how to the get directory that a drop occurs in, therefore allowing me to copy the dragged files to the correct location. I had to use a couple of un-documented apple classes tho. Mainly to allow me to turn an FSSpec to a java.io.File.
This code is for MacOS classic, but it may be possible to convert it to MacOS X easily - I can’t say for definate as I don’t have MacOS X yet.
import com.apple.mrj.datatransfer.*;
import com.apple.mrj.dnd.*;
import com.apple.mrj.*;
import com.apple.mrj.jdirect.*;
import com.apple.mrj.macos.toolbox.AEDesc;
import com.apple.mrj.macos.toolbox.FSSpec;
import com.apple.mrj.macos.libraries.*;
import java.awt.*;
import java.net.*;
import java.io.*;
public class DragTest extends Frame implements DragLib, InterfaceLib {
private final OSTypeFlavor kDragPromisedFlavor = new OSTypeFlavor( new MRJOSType( "fssP" ) );
private final OSTypeFlavor flavorTypePromisedHFS = new OSTypeFlavor( new MRJOSType( "phfs" ) );
private final MRJOSType typeAlias = new MRJOSType( "alis" );
private final MRJOSType typeFSS = new MRJOSType( "fss " );
public DragTest() {
addMouseListener( new DragInit() );
}
public native static short GetDropLocation( int theDrag, byte[] dropLocation );
public native static short AECoerceDesc( byte[] theAEDesc, int toType, byte[] result );
class PromiseHFSFlavor extends ByteArrayStruct {
public PromiseHFSFlavor() {
// 4+4+2+4
super( 14 );
}
public void setFileType( MRJOSType type ) {
setIntAt( 0, type.toInt() );
}
public void setFileCreator( MRJOSType type ) {
setIntAt( 4, type.toInt() );
}
public void setFlags( int flags ) {
setShortAt( 8, (short)flags );
}
public void setPromisedFlavor( OSTypeFlavor flavor ) {
setIntAt( 0, flavor.getOSType().toInt() );
}
}
class FSSpecHandle extends HandleStruct {
public FSSpecHandle( int handle ) {
super( handle );
}
public short getVolumeRef() {
return getShortAt( 0 );
}
public int getParentID() {
return getIntAt( 2 );
}
public String getName() {
byte[] bytes = getBytesAt( 6, 64 );
int len = 0xFF & bytes[ 0 ];
if ( len >= 64 )
throw new RuntimeException( "error in FSSpec name length" );
return new String( bytes, 1, len );
}
public int getSize() {
return 70;
}
}
class DragInit extends DragInitiatorAdapter {
public void dragGesture( DragInitiatorEvent e ) {
System.out.println( e );
OutgoingDrag drag = e.getDrag();
try {
/*URL url = new URL( "http://10.0.0.6/manual/index.html" );
String urld = url.toString() + "\nNew Features in Version 2.0";
Transfer trans = new Transfer();
OSTypeFlavor flav = new OSTypeFlavor( new MRJOSType( "DNLD" ) );
trans.addFlavor( flav, new ByteArrayInputStream( urld.getBytes() ) );
drag.addItem( trans );*/
Transfer trans = new Transfer();
PromiseHFSFlavor phfs = new PromiseHFSFlavor();
// doesn't seem to matter what filetype/creator we
// specify
//phfs.setFileType( new MRJOSType( "TEXT" ) );
//phfs.setFileCreator( new MRJOSType( "JPL " ) );
phfs.setFlags( 0 );
phfs.setPromisedFlavor( kDragPromisedFlavor );
trans.addFlavor( flavorTypePromisedHFS, phfs.getBytes() );
trans.addFlavor( kDragPromisedFlavor, new byte[ 0 ] );
drag.addItem( trans );
}
catch( Exception ex ) {
ex.printStackTrace();
}
}
public void dragCompleted( DragInitiatorEvent e ) {
OutgoingDrag drag = e.getDrag();
if ( !drag.isDropAccepted() )
return;
int dragRef = drag.getRef();
//System.out.println( "dragRef=" + dragRef );
//System.out.println( e );
AEDesc dropLocAlias = new AEDesc();
if ( GetDropLocation( dragRef, dropLocAlias.getByteArray() ) != 0 ) {
//System.err.println( "error getting drop location" );
return; // an error occurred
}
//System.out.println( "got drop location" );
if ( dropLocAlias.getDescriptorType() != typeAlias.toInt() ) {
System.err.println( "error descriptor not alis: " + new MRJOSType( dropLocAlias.getDescriptorType() ) );
return; // an error occurred
}
//System.out.println( dropLocAlias.getDescriptorType() );
AEDesc dropLocFSS = new AEDesc();
if ( AECoerceDesc( dropLocAlias.getByteArray(), typeFSS.toInt(), dropLocFSS.getByteArray() ) != 0 ) {
System.err.println( "error coercing to typeFSS" );
return; // an error occurred
}
//System.out.println( dropLocFSS.getDescriptorType() );
//AEDisposeDesc( dropLocAlias );
int dataHandle = dropLocFSS.getDataHandle();
FSSpecHandle fss = new FSSpecHandle( dataHandle );
//String name = fss.getName();
//System.out.println( name );
//int parentID = fss.getParentID();
//System.out.println( parentID );
FSSpec fsspec = new FSSpec( fss );
File file = fsspec.toFile();
System.out.println( file );
dropLocAlias.dispose();
dropLocFSS.dispose();
if ( file.isDirectory() ) {
File index = new File( file, "index.html" );
if ( !index.exists() ) {
try {
Writer writer = new OutputStreamWriter( new BufferedOutputStream( new FileOutputStream( index ) ) );
writer.write( "<html>\n<head><title>Test Drag</title></head>\n<body>Testing MRJ drag</body>\n</html>" );
writer.flush();
writer.close();
}
catch( Exception ex ) {
ex.printStackTrace();
}
}
}
}
public void dragFailed( DragInitiatorEvent e ) {
System.out.println( e );
}
}
public Dimension getPreferredSize() {
return new Dimension( 320, 240 );
}
public static void main( String[] args ) {
DragTest dt = new DragTest();
dt.pack();
dt.show();
}
}