1 package com.sslexplorer.vfs.store.apps; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.ArrayList ; 6 import java.util.Collection ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.apache.commons.vfs.FileObject; 13 14 import com.sslexplorer.extensions.ExtensionBundle; 15 import com.sslexplorer.extensions.store.ExtensionStore; 16 import com.sslexplorer.policyframework.LaunchSession; 17 import com.sslexplorer.security.PasswordCredentials; 18 import com.sslexplorer.vfs.AbstractStore; 19 import com.sslexplorer.vfs.AbstractVFSMount; 20 import com.sslexplorer.vfs.FileObjectVFSResource; 21 import com.sslexplorer.vfs.VFSMount; 22 import com.sslexplorer.vfs.VFSResource; 23 import com.sslexplorer.vfs.utils.URI; 24 import com.sslexplorer.vfs.utils.URI.MalformedURIException; 25 import com.sslexplorer.vfs.webdav.DAVUtilities; 26 27 38 public class ApplicationStore extends AbstractStore { 39 40 final static Log log = LogFactory.getLog(ApplicationStore.class); 41 42 45 public ApplicationStore() { 46 super("apps", "UTF-8"); 47 } 48 49 55 public VFSMount getMountFromString(String mountName, LaunchSession launchSession) { 56 try { 57 if (ExtensionStore.getInstance().getExtensionBundle(mountName) != null) { 58 return new ApplicationStoreMount(launchSession, ExtensionStore.getInstance().getExtensionBundle(mountName)); 59 } else 60 return null; 61 } catch (Exception e) { 62 log.error("Failed to create application store mount.", e); 63 return null; 64 } 65 66 } 67 68 public Collection <String > getMountNames() throws Exception { 69 Iterator itr = ExtensionStore.getInstance().getExtensionBundles().iterator(); 70 List <String > l = new ArrayList <String >(); 71 while (itr.hasNext()) { 72 ExtensionBundle b = (ExtensionBundle) itr.next(); 73 l.add(b.getId()); 74 } 75 return l; 76 } 77 78 83 public String createURIFromPath(String path) throws IllegalArgumentException { 84 throw new IllegalArgumentException (); 85 } 86 87 class ApplicationStoreMount extends AbstractVFSMount { 88 89 private ExtensionBundle bundle; 90 91 ApplicationStoreMount(LaunchSession launchSession, ExtensionBundle bundle) throws MalformedURIException { 92 super(launchSession, ApplicationStore.this, bundle.getId(), true); 93 this.bundle = bundle; 94 } 95 96 public VFSResource getResource(String path, PasswordCredentials requestCredentials) 97 throws IOException { 98 if (path.equalsIgnoreCase("private") || path.equalsIgnoreCase("upgrade")) { 99 throw new IOException ("Permission denied."); 100 } 101 VFSResource parent = null; 102 if (path.equals("")) { 103 parent = getStore().getStoreResource(); 104 } 105 return new FileObjectVFSResource(getLaunchSession(), this, 106 parent, 107 path, 108 getStore().getRepository(), 109 requestCredentials); 110 } 111 112 117 public URI getRootVFSURI(String charset) throws MalformedURIException { 118 File baseDir = bundle.getBaseDir(); 119 if("true".equals(System.getProperty("sslexplorer.useDevConfig"))) { 120 String basedir = ".." + File.separator + bundle.getId() + File.separator + "build" + File.separator + "extension"; 121 File f = new File (basedir); 122 if(f.exists()) { 123 baseDir = f; 124 } 125 } 126 return new URI(baseDir.toURI().toString()); 127 } 128 129 protected FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException { 130 URI uri = getRootVFSURI(); 131 uri.setPath(DAVUtilities.concatenatePaths(uri.getPath(), path)); 132 FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString()); 133 return root; 134 } 135 } 136 } 137 | Popular Tags |