001 package railo.runtime.net.proxy; 002 003 import java.io.Serializable; 004 005 import railo.commons.lang.StringUtil; 006 007 public class ProxyDataImpl implements ProxyData,Serializable { 008 009 public static final ProxyData NO_PROXY = new ProxyDataImpl(); 010 011 private String server; 012 private int port=-1; 013 private String username; 014 private String password; 015 016 017 public ProxyDataImpl(String server, int port, String username, String password) { 018 if(!StringUtil.isEmpty(server,true))this.server = server; 019 if(port>0)this.port = port; 020 if(!StringUtil.isEmpty(username,true))this.username = username; 021 if(!StringUtil.isEmpty(password,true))this.password = password; 022 } 023 public ProxyDataImpl() {} 024 025 public void release() { 026 server=null; 027 port=-1; 028 username=null; 029 password=null; 030 } 031 032 /** 033 * @return the password 034 */ 035 public String getPassword() { 036 return password; 037 } 038 /** 039 * @param password the password to set 040 */ 041 public void setPassword(String password) { 042 this.password = password; 043 } 044 /** 045 * @return the port 046 */ 047 public int getPort() { 048 return port; 049 } 050 /** 051 * @param port the port to set 052 */ 053 public void setPort(int port) { 054 this.port = port; 055 } 056 /** 057 * @return the server 058 */ 059 public String getServer() { 060 return server; 061 } 062 /** 063 * @param server the server to set 064 */ 065 public void setServer(String server) { 066 this.server = server; 067 } 068 /** 069 * @return the username 070 */ 071 public String getUsername() { 072 return username; 073 } 074 /** 075 * @param username the username to set 076 */ 077 public void setUsername(String username) { 078 this.username = username; 079 } 080 081 public boolean equals(Object obj){ 082 if(obj==this) return true; 083 if(!(obj instanceof ProxyData)) return false; 084 085 ProxyData other=(ProxyData) obj; 086 087 return _eq(other.getServer(),server) && _eq(other.getUsername(),username) && _eq(other.getPassword(),password) && other.getPort()==port; 088 089 } 090 091 private boolean _eq(String left, String right) { 092 if(left==null) return right==null; 093 return left.equals(right); 094 } 095 096 public static boolean isValid(ProxyData pd){ 097 if(pd==null || pd.equals(NO_PROXY)) return false; 098 return true; 099 } 100 public static boolean hasCredentials(ProxyData data) { 101 return StringUtil.isEmpty(data.getUsername(),true); 102 } 103 public static ProxyData getInstance(String proxyserver, int proxyport, String proxyuser, String proxypassword) { 104 if(StringUtil.isEmpty(proxyserver,true)) return null; 105 return new ProxyDataImpl(proxyserver,proxyport,proxyuser,proxypassword); 106 } 107 108 public String toString(){ 109 return "server:"+server+";port:"+port+";user:"+username+";pass:"+password; 110 } 111 }