1 package com.sslexplorer.vfs.store.downloads; 2 3 import java.io.File ; 4 import java.io.FileFilter ; 5 import java.io.IOException ; 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 import java.util.List ; 9 10 import org.apache.commons.vfs.FileObject; 11 12 import com.sslexplorer.boot.ContextHolder; 13 import com.sslexplorer.core.CoreUtil; 14 import com.sslexplorer.policyframework.LaunchSession; 15 import com.sslexplorer.security.PasswordCredentials; 16 import com.sslexplorer.vfs.AbstractStore; 17 import com.sslexplorer.vfs.AbstractVFSMount; 18 import com.sslexplorer.vfs.VFSMount; 19 import com.sslexplorer.vfs.utils.URI; 20 import com.sslexplorer.vfs.utils.URI.MalformedURIException; 21 import com.sslexplorer.vfs.webdav.DAVException; 22 import com.sslexplorer.vfs.webdav.DAVStatus; 23 import com.sslexplorer.vfs.webdav.DAVUtilities; 24 25 32 public class TempStore extends AbstractStore { 33 34 37 public static final String TEMP_DOWNLOAD_MOUNT_NAME = "downloads"; 38 39 42 public TempStore() { 43 super("temp", "UTF-8"); 44 } 45 46 49 public VFSMount getMountFromString(String mountName, LaunchSession launchSession) throws DAVException { 50 try { 51 File tempDownloadDirectory = CoreUtil.getTempDownloadDirectory(getRepository().getSession()); 52 if(!mountName.equals(tempDownloadDirectory.getName())) { 53 throw new Exception ("No permission."); 54 } 55 return new DownloadsStoreMount(launchSession, tempDownloadDirectory); 56 } 57 catch(Exception e) { 58 throw new DAVException(DAVStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage()); 59 } 60 } 61 62 65 public Collection <String > getMountNames() throws Exception { 66 File tempDownloadDirectory = new File (ContextHolder.getContext().getTempDirectory(), TempStore.TEMP_DOWNLOAD_MOUNT_NAME); 67 File [] dirs = tempDownloadDirectory.listFiles(new FileFilter () { 68 public boolean accept(File pathname) { 69 return pathname.isDirectory(); 70 } 71 }); 72 List <String > l = new ArrayList <String >(); 73 if(dirs != null) { 74 for(int i = 0 ; i < dirs.length; i++) { 75 l.add(dirs[i].getName()); 76 } 77 } 78 return l; 79 } 80 81 86 public String createURIFromPath(String path) throws IllegalArgumentException { 87 throw new IllegalArgumentException (); 88 } 89 90 96 class DownloadsStoreMount extends AbstractVFSMount { 97 98 private File dir; 99 100 DownloadsStoreMount(LaunchSession launchSession, File dir) { 101 super(launchSession, TempStore.this, dir.getName(), true); 102 this.dir = dir; 103 } 104 105 108 public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException { 109 URI uri = new URI(getRootVFSURI()); 110 uri.setPath(DAVUtilities.concatenatePaths(uri.getPath(), path)); 111 FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString()); 112 return root; 113 } 114 115 118 public URI getRootVFSURI(String charset) throws MalformedURIException { 119 return new URI(dir.toURI().toString()); 120 } 121 } 122 } 123 | Popular Tags |