1   /*
2    * $Id: FileView.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.ftp.server;
12  
13  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.apache.ftpserver.ftplet.FileObject;
17  import org.apache.ftpserver.ftplet.FileSystemView;
18  import org.apache.ftpserver.ftplet.FtpException;
19  
20  public class FileView implements FileSystemView
21  {
22  
23      protected final Log logger = LogFactory.getLog(getClass());
24      private CountDownLatch started = new CountDownLatch(1);
25      private ServerState state;
26  
27      public FileView(ServerState state)
28      {
29          this.state = state;
30      }
31  
32      public void flagStarted(int count)
33      {
34          started.countDown();
35      }
36  
37      public FileObject getHomeDirectory() throws FtpException
38      {
39          return new Directory("/", state);
40      }
41  
42      public FileObject getCurrentDirectory() throws FtpException
43      {
44          return new Directory("/", state);
45      }
46  
47      public boolean changeDirectory(String dir) throws FtpException
48      {
49          return true;
50      }
51  
52      public FileObject getFileObject(String name) throws FtpException
53      {
54          logger.debug("request for: " + name);
55          if (state.getDownloadNames().contains(name))
56          {
57              return new DownloadFile(name, state);
58          }
59          // TODO - is this standard FTP convention?
60          else if (null != name && name.endsWith("/"))
61          {
62              return new Directory(name, state);
63          }
64          else
65          {
66              return new UploadFile(name, state);
67          }
68      }
69  
70      public boolean isRandomAccessible() throws FtpException
71      {
72          return true;
73      }
74  
75      public void dispose()
76      {
77          // no-op
78      }
79  
80  }