1 19 20 package com.sslexplorer.vfs; 21 22 import java.io.IOException ; 23 import java.net.URI ; 24 import java.util.Date ; 25 import java.util.Iterator ; 26 27 import org.apache.commons.vfs.FileObject; 28 29 import com.sslexplorer.policyframework.LaunchSession; 30 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException; 31 import com.sslexplorer.vfs.webdav.DAVMultiStatus; 32 import com.sslexplorer.vfs.webdav.DAVUtilities; 33 import com.sslexplorer.vfs.webdav.methods.GET; 34 35 40 public abstract class AbstractVFSResource implements VFSResource { 41 42 private boolean collection; 44 private String name; 45 private VFSResource parent; 46 private URI relativeUri; 47 private LaunchSession launchSession; 48 private VFSRepository repository; 49 50 51 61 public AbstractVFSResource(LaunchSession launchSession, URI relativeUri, boolean collection, String name, VFSResource parent, VFSRepository repository) { 62 super(); 63 this.launchSession = launchSession; 64 this.collection = collection; 65 this.name = name; 66 this.parent = parent; 67 this.relativeUri = relativeUri; 68 this.repository = repository; 69 } 70 71 74 public LaunchSession getLaunchSession() { 75 return launchSession; 76 } 77 78 81 public boolean isMount() { 82 return true; 83 } 84 85 88 public void verifyAccess() { 89 90 } 91 94 public Iterator <VFSResource> getChildren() throws IOException , DAVAuthenticationRequiredException { 95 return null; 96 } 97 98 101 public String getWebFolderPath() { 102 return parent == null ? "/fs/" : ( parent.getWebFolderPath() + relativeUri.getPath() + "/" ); 103 } 104 105 108 public FileObject getFile() throws IOException { 109 return null; 110 } 111 112 115 public int compareTo(Object object) { 116 return toString().compareTo(object.toString()); 117 } 118 119 122 public boolean isCollection() { 123 return collection; 124 } 125 126 129 public boolean isResource() { 130 return !isCollection(); 131 } 132 133 136 public VFSMount getMount() { 137 return null; 138 } 139 140 143 public String getDisplayName() { 144 String name = this.name; 145 if (isCollection()) return (name + "/"); 146 return name; 147 } 148 149 152 public String getRelativePath() { 153 return getRelativeURI().getPath(); 154 } 155 156 159 public URI getRelativeURI() { 160 return relativeUri; 161 } 162 163 166 public VFSResource getParent() { 167 try { 168 if(parent == null) { 169 String parentPath = DAVUtilities.stripLeadingSlash(DAVUtilities.getParentPath(getFullPath())); 170 if(parentPath == null || parentPath.equals("/")) { 171 return null; 172 } 173 else { 174 return repository.getResource(getLaunchSession(), parentPath, null); 175 } 176 } 177 } catch (Throwable throwable) { 178 throwable.printStackTrace(); 179 } 180 return parent; 181 } 182 183 186 public String getContentType() { 187 if (this.isNull()) return null; 188 if (this.isCollection()) return GET.COLLECTION_MIME_TYPE; 189 String mime = DAVUtilities.getMimeType(this.getDisplayName()); 190 return mime == null ? "application/octet-stream" : mime; 191 } 192 193 196 public Long getContentLength() { 197 return null; 198 } 199 200 203 public Date getLastModified() { 204 return new Date (); 205 } 206 207 210 public String getEntityTag() { 211 if (this.isNull()) return null; 212 String path = this.getRelativePath(); 213 return DAVUtilities.getETAG(path, this.getLastModified()); 214 } 215 216 219 public void delete() throws DAVMultiStatus { 220 } 221 222 225 public void copy(VFSResource dest, boolean overwrite, boolean recursive) throws DAVMultiStatus { 226 } 227 228 231 public void move(VFSResource dest, boolean overwrite) throws DAVMultiStatus { 232 } 233 234 237 public void makeCollection() { 238 } 239 240 243 public VFSInputStream getInputStream() { 244 return null; 245 } 246 247 250 public VFSOutputStream getOutputStream() { 251 return null; 252 } 253 254 257 public boolean isNull() { 258 return false; 259 } 260 261 264 public String getBasename() { 265 return name; 266 } 267 268 271 public URI getFullURI() { 272 VFSMount mount = getMount(); 273 URI uri = URI.create( mount == null ? ( "/" + getRelativeURI() ) : ( "/" + DAVUtilities.encodePath(mount.getMountString(), true) + "/" + DAVUtilities.encodePath(getRelativePath(), true) ) ); 274 return uri; 275 } 276 277 280 public String toString() { 281 return "Rel. URI = " + getRelativeURI() + ", Rel. Path = " + getRelativePath() + ", Name = " + name + " Mount = " + getMount().getMountString(); 282 } 283 284 287 public String getFullPath() { 288 VFSMount mount = getMount(); 289 return mount == null ? ( "/" + getRelativeURI() ) : ( "/" + mount.getMountString() + "/" + getRelativePath()); 290 } 291 } 292 | Popular Tags |