Drag and Drop with spaces under Unix

Upload core product.
Post Reply
cactuscomputing
Posts: 10
Joined: Wed Feb 11, 2009 6:59 pm

Drag and Drop with spaces under Unix

Post by cactuscomputing »

Hi,

JFileUpload when running under Unix (Linux Fedora) does not seem to like file names with spaces in them when dropped on to the applet. Note the same file works fine when running under windows. I fixed this problem by modifying the processDrop method so that URLDecoder is used (I've added a bunch more logging as well):

Code: Select all

if (path.length()>0){                        
   File f = new File(path);
   if (!f.exists()) {
        try {// on unix files with spaces fail, unless this called
            path = URLDecoder.decode(path, "UTF-8");
            f = new File(path);
        } catch (Exception ex){
           log.info(ex.getMessage());
           return;
        }                           
   }
   if ( f.exists()){
        if ( f.length() > 0){
               if ( f.canRead()){
                     filenames.add(f.getAbsolutePath());
               }else{
                     log.info("File with no read access <" + path +">");
               }
        }else{
              log.info("Zero length file <" + path +">");
        }
   } else{
         log.info("File does not exist <" + path +">");
   }
}
Note since we're only going to support D&D I've not investigated the inclusion of these files via other routes.

Note also as a suggestion, you could create a drop support class that does actual work of processing a drop, and then classes that require it can simply call its methods, consider:

Code: Select all

public class ProgressPanelWithDrop extends ProgressPanel implements DropTargetListener{
    
    private DropSupport drop;
    
    public ProgressPanelWithDrop(Conf cnf){
        super(cnf);
        drop = new DropSupport();
        // drop onto entire progress panel
        new DropTarget(this, DnDConstants.ACTION_COPY, this, true);
    }
    
    @Override
    public void setController(final TransferController controller){
        super.setController(controller);
        drop.setController(controller);
    } 

    public void dragEnter(DropTargetDragEvent dtde) {
       drop.dragEnter(dtde);        
    }

    public void dragExit(DropTargetEvent dte) {
        drop.dragExit(dte);       
    }

    public void dragOver(DropTargetDragEvent dtde) {
        drop.dragOver(dtde);     
    }

    public void drop(DropTargetDropEvent dtde) {
        drop.drop(dtde);          
    }

    public void dropActionChanged(DropTargetDragEvent dtde) {
        drop.dropActionChanged(dtde);      
    }

}
This avoids duplicating code.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: Drag and Drop with spaces under Unix

Post by support »

Thanks for the report.
We have a similar problem with some Ubuntu/Linux (not with space but with non-ASCII char). However, the behavior depends on Ubuntu version (no problem under Ubuntu 8.04, and problem under 7.0 and 8.10). I'm going to check your solutions and see if it could fix such issues.

Post Reply