001 package railo.commons.io.res.type.ftp; 002 003 import railo.commons.lang.StringUtil; 004 005 public final class FTPConnectionData { 006 007 public String username=""; 008 public String password=""; 009 public String host="localhost"; 010 public int port=0; 011 012 private String proxyserver; 013 private int proxyport; 014 private String proxyuser; 015 private String proxypassword; 016 017 018 public String load(String path) { 019 username=""; 020 password=""; 021 host=null; 022 port=21; 023 // TODO impl proxy 024 025 int atIndex=path.indexOf('@'); 026 int slashIndex=path.indexOf('/'); 027 if(slashIndex==-1){ 028 slashIndex=path.length(); 029 path+="/"; 030 } 031 int index; 032 033 // username/password 034 if(atIndex!=-1) { 035 index=path.indexOf(':'); 036 if(index!=-1 && index<atIndex) { 037 username=path.substring(0,index); 038 password=path.substring(index+1,atIndex); 039 } 040 else username=path.substring(0,atIndex); 041 } 042 // host port 043 if(slashIndex>atIndex+1) { 044 index=path.indexOf(':',atIndex+1); 045 if(index!=-1 && index>atIndex && index<slashIndex) { 046 host=path.substring(atIndex+1,index); 047 port=Integer.parseInt(path.substring(index+1,slashIndex)); 048 } 049 else host=path.substring(atIndex+1,slashIndex); 050 } 051 //if(slashIndex==-1)return "/"; 052 return path.substring(slashIndex); 053 } 054 055 056 057 /** 058 * @see java.lang.Object#toString() 059 */ 060 public String toString() { 061 return "username:"+username+";password:"+password+";hostname:"+host+";port:"+port; 062 } 063 064 065 066 public String key() { 067 if(StringUtil.isEmpty(username)) 068 return host+_port(); 069 return username+":"+password+"@"+host+_port(); 070 } 071 072 073 074 private String _port() { 075 if(port>0) return ":"+port; 076 return ""; 077 } 078 079 080 081 public boolean hasProxyData() { 082 return getProxyserver()!=null; 083 } 084 085 086 087 /** 088 * @return the proxypassword 089 */ 090 public String getProxypassword() { 091 return proxypassword; 092 } 093 094 095 096 /** 097 * @return the proxyport 098 */ 099 public int getProxyport() { 100 return proxyport; 101 } 102 103 104 105 /** 106 * @return the proxyserver 107 */ 108 public String getProxyserver() { 109 return proxyserver; 110 } 111 112 113 114 /** 115 * @return the proxyuser 116 */ 117 public String getProxyuser() { 118 return proxyuser; 119 } 120 /** 121 * 122 * @see java.lang.Object#equals(java.lang.Object) 123 */ 124 public boolean equals(Object obj) { 125 if(this==obj)return true; 126 if(!(obj instanceof FTPConnectionData)) return false; 127 return key().equals(((FTPConnectionData)obj).key()); 128 } 129 }