1 19 20 package com.sslexplorer.vfs; 21 22 import java.io.IOException ; 23 import java.net.URI ; 24 import java.net.URISyntaxException ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 import com.sslexplorer.policyframework.LaunchSession; 33 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException; 34 import com.sslexplorer.vfs.webdav.DAVException; 35 import com.sslexplorer.vfs.webdav.DAVStatus; 36 import com.sslexplorer.vfs.webdav.DAVUtilities; 37 38 43 public abstract class AbstractStore implements VFSStore { 44 final static Log log = LogFactory.getLog(AbstractStore.class); 45 46 48 private VFSRepository repository; 49 private VFSProvider provider; 50 private String name; 51 private String charset; 52 53 54 60 public AbstractStore(String name, String charset) { 61 super(); 62 this.name = name; 63 this.charset = charset; 64 } 65 66 69 public String getMountPath(String mountName) { 70 return getName() + "/" + mountName; 71 } 72 73 76 public String getEncoding() { 77 return charset; 78 } 79 80 83 public String getName() { 84 return name; 85 } 86 87 90 public String getGuestUsername() { 91 return null; 92 } 93 94 97 public char[] getGuestPassword() { 98 return null; 99 } 100 101 104 public void init(VFSRepository repository, VFSProvider provider) { 105 this.repository = repository; 106 this.provider = provider; 107 } 108 109 112 public VFSProvider getProvider() { 113 return provider; 114 } 115 116 119 public VFSRepository getRepository() { 120 return repository; 121 } 122 123 126 public VFSResource getStoreResource() throws DAVException { 127 try { 128 return new AbstractStoreResource(getName(), repository); 129 } catch (URISyntaxException e) { 130 throw new DAVException(DAVStatus.SC_INTERNAL_SERVER_ERROR, "Failed to create store resource.", e); 131 } 132 } 133 134 class AbstractStoreResource extends AbstractVFSResource { 135 136 AbstractStoreResource(String name, VFSRepository repository) throws URISyntaxException { 137 super(new LaunchSession(getRepository().getSession()), new URI (name), true, name, repository.getRepositoryResource(), AbstractStore.this.repository); 138 } 139 140 public Iterator getChildren() throws IOException , DAVAuthenticationRequiredException { 141 List <VFSResource> l = new ArrayList <VFSResource>(); 142 try { 143 for (String mountName : getMountNames()) { 144 l.add(new MountVFSResource(mountName, this)); 145 } 146 } catch (DAVAuthenticationRequiredException dare) { 147 } catch (Exception e) { 148 log.error("Failed to get store resources.", e); 149 } 150 return l.iterator(); 151 } 152 153 } 154 155 class MountVFSResource extends AbstractVFSResource { 156 157 MountVFSResource(String mountName, VFSResource parent) throws URISyntaxException { 158 super(new LaunchSession(getRepository().getSession()), new URI (DAVUtilities.encodePath(mountName)), true, mountName, parent, AbstractStore.this.repository); 159 } 160 161 162 } 163 } | Popular Tags |