1 package fr.jayasoft.ivy.repository.vfs; 2 3 import fr.jayasoft.ivy.Ivy; 4 5 public class VfsURI { 6 private String host; 7 private String passwd; 8 private String path; 9 private String scheme; 10 private String user; 11 12 static final public String SCHEME_CIFS = "smb"; 14 static final public String SCHEME_FILE = "file"; 15 static final public String SCHEME_FTP = "ftp"; 16 static final public String SCHEME_HTTP = "http"; 17 static final public String SCHEME_HTTPS = "https"; 18 static final public String SCHEME_SFTP = "sftp"; 19 static final public String SCHEME_WEBDAV = "webdav"; 20 static final public String [] SUPPORTED_SCHEMES = new String [] { 21 SCHEME_FILE, 23 }; 24 25 31 static public VfsURI vfsURIFactory(String scheme, String resource, Ivy ivy) { 32 VfsURI vfsURI = null; 33 if (scheme.equals(SCHEME_CIFS)) { 34 vfsURI = new VfsURI(SCHEME_CIFS, 35 ivy.getVariable(VfsTestHelper.PROP_VFS_USER_ID), 36 ivy.getVariable(VfsTestHelper.PROP_VFS_USER_PASSWD), 37 ivy.getVariable(VfsTestHelper.PROP_VFS_HOST), 38 ivy.getVariable(VfsTestHelper.PROP_VFS_SAMBA_REPO) + "/" + resource); 39 } else if (scheme.equals(SCHEME_FILE)) { 40 vfsURI = new VfsURI(SCHEME_FILE, 41 null, 42 null, 43 null, 44 VfsTestHelper.CWD + "/" + VfsTestHelper.TEST_REPO_DIR + "/" + resource); 45 } else if (scheme.equals(SCHEME_FTP)) { 46 vfsURI = new VfsURI(SCHEME_FTP, 47 ivy.getVariable(VfsTestHelper.PROP_VFS_USER_ID), 48 ivy.getVariable(VfsTestHelper.PROP_VFS_USER_PASSWD), 49 ivy.getVariable(VfsTestHelper.PROP_VFS_HOST), 50 VfsTestHelper.CWD + "/" + VfsTestHelper.TEST_REPO_DIR + "/" + resource); 51 } else if (scheme.equals(SCHEME_SFTP)) { 52 vfsURI = new VfsURI(SCHEME_SFTP, 53 ivy.getVariable(VfsTestHelper.PROP_VFS_USER_ID), 54 ivy.getVariable(VfsTestHelper.PROP_VFS_USER_PASSWD), 55 ivy.getVariable(VfsTestHelper.PROP_VFS_HOST), 56 VfsTestHelper.CWD + "/" + VfsTestHelper.TEST_REPO_DIR + "/" + resource) ; 57 } 58 return vfsURI; 59 } 60 61 70 public VfsURI(String scheme, String user, String passwd, String host, String path) { 71 this.scheme = scheme.trim(); 72 73 if (user != null) { 74 this.user = user.trim(); 75 } else { 76 this.user = null; 77 } 78 79 if (passwd != null) { 80 this.passwd = passwd.trim(); 81 } else { 82 this.passwd = null; 83 } 84 85 if (host != null) { 86 this.host = host.trim(); 87 } else { 88 this.host = null; 89 } 90 91 this.path = normalizePath(path); 92 } 93 94 99 public String getVfsURI() { 100 StringBuffer uri = new StringBuffer (); 101 uri.append(this.scheme + "://"); 102 103 if (user != null && user.trim().length() > 0) { 105 uri.append(this.user + ":"); 106 107 if (passwd != null && passwd.trim().length() > 0) { 108 this.passwd = passwd.trim(); 109 } else { 110 this.passwd = ""; 111 } 112 uri.append(this.passwd + "@"); 113 } 114 115 if (host != null && host.trim().length() > 0) { 117 this.host = host.trim(); 118 uri.append(this.host); 119 } 120 121 uri.append(this.path); 122 return uri.toString(); 123 } 124 125 131 private String normalizePath(String path) { 132 String normalizedPath = path.replaceAll("\\\\", "/"); 134 135 normalizedPath = normalizedPath.replaceAll("//+", "/"); 137 138 if(! normalizedPath.startsWith("/")) { 140 normalizedPath = "/" + normalizedPath; 141 } 142 143 return normalizedPath.trim(); 144 } 145 146 public String toString() { 147 return getVfsURI(); 148 } 149 150 public String getScheme() { 151 return scheme; 152 } 153 } 154 | Popular Tags |