1 package com.sslexplorer.vfs.store.site; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.Arrays ; 6 import java.util.Collection ; 7 8 import org.apache.commons.vfs.FileObject; 9 10 import com.sslexplorer.boot.ContextHolder; 11 import com.sslexplorer.extensions.ExtensionBundle; 12 import com.sslexplorer.policyframework.LaunchSession; 13 import com.sslexplorer.security.PasswordCredentials; 14 import com.sslexplorer.vfs.AbstractStore; 15 import com.sslexplorer.vfs.AbstractVFSMount; 16 import com.sslexplorer.vfs.FileObjectVFSResource; 17 import com.sslexplorer.vfs.VFSMount; 18 import com.sslexplorer.vfs.VFSResource; 19 import com.sslexplorer.vfs.utils.URI; 20 import com.sslexplorer.vfs.utils.URI.MalformedURIException; 21 import com.sslexplorer.vfs.webdav.DAVUtilities; 22 23 28 public class SiteStore extends AbstractStore { 29 30 private File siteDir; 31 32 35 public SiteStore() { 36 super("site", "UTF-8"); 37 siteDir = new File (ContextHolder.getContext().getConfDirectory(), "site"); 38 if(!siteDir.exists()) { 39 siteDir.mkdirs(); 40 } 41 } 42 43 49 public VFSMount getMountFromString(String mountName, LaunchSession launchSession) { 50 if(mountName.equals("icons")) { 51 return new SiteIconsMount(); 52 } 53 return null; 54 } 55 56 59 public Collection <String > getMountNames() throws Exception { 60 return Arrays.asList(new String [] { "icons" }); 61 } 62 63 68 public String createURIFromPath(String path) throws IllegalArgumentException { 69 throw new IllegalArgumentException (); 70 } 71 72 class SiteIconsMount extends AbstractVFSMount { 73 74 private ExtensionBundle bundle; 75 76 SiteIconsMount() { 77 super(null, SiteStore.this, "icons", false); 78 } 79 80 public VFSResource getResource(String path, PasswordCredentials requestCredentials) 81 throws IOException { 82 VFSResource parent = null; 83 if (path.equals("")) { 84 parent = getStore().getStoreResource(); 85 } 86 return new FileObjectVFSResource(getLaunchSession(), this, 87 parent, 88 path, 89 getStore().getRepository(), 90 requestCredentials); 91 } 92 93 98 public URI getRootVFSURI(String charset) throws MalformedURIException { 99 File baseDir = new File (siteDir, "icons"); 100 if(!baseDir.exists()) { 101 baseDir.mkdirs(); 102 } 103 return new URI(baseDir.toURI().toString()); 104 } 105 106 protected FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException { 107 URI uri = getRootVFSURI(); 108 uri.setPath(DAVUtilities.concatenatePaths(uri.getPath(), path)); 109 FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString()); 110 return root; 111 } 112 } 113 } 114 | Popular Tags |