1 19 20 package com.sslexplorer.networkplaces.store.http; 21 22 import java.io.IOException ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.commons.vfs.FileObject; 27 import org.apache.commons.vfs.FileSystemException; 28 import org.apache.commons.vfs.FileSystemOptions; 29 import org.apache.commons.vfs.provider.ftp.FtpFileSystemConfigBuilder; 30 31 import com.sslexplorer.networkplaces.AbstractNetworkPlaceMount; 32 import com.sslexplorer.policyframework.LaunchSession; 33 import com.sslexplorer.security.PasswordCredentials; 34 import com.sslexplorer.vfs.VFSStore; 35 import com.sslexplorer.vfs.utils.URI; 36 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException; 37 import com.sslexplorer.vfs.webdav.DAVUtilities; 38 39 public class HTTPMount extends AbstractNetworkPlaceMount { 40 41 final static Log log = LogFactory.getLog(HTTPMount.class); 42 43 public HTTPMount(LaunchSession launchSession, VFSStore store) { 44 super(launchSession, store); 45 } 46 47 public FileSystemOptions getOptions(URI uri) { 48 FileSystemOptions options = new FileSystemOptions(); 49 return options; 50 } 51 52 public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException { 53 try { 54 URI uri = getRootVFSURI(); 55 if (credentials != null) { 56 uri.setUserinfo(DAVUtilities.encodeURIUserInfo(credentials.getUsername() + (credentials.getPassword() != null ? ":" + new String (credentials.getPassword()) : ""))); 57 } 58 uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path)); 59 FileObject fileObject = this.getStore().getRepository().getFileSystemManager().resolveFile(uri.toString(), getOptions(uri)); 60 return fileObject; 61 } catch (FileSystemException fse) { 62 if (fse.getCode().equals("vfs.provider.http/connect.error")) { 63 throw new DAVAuthenticationRequiredException(getMountString(), true); 64 } 65 throw fse; 66 } 67 } 68 } | Popular Tags |