1 /* 2 * $HeadURL: $ 3 * $Date: $ 4 * $Revision: $ 5 * $Author: $ 6 * 7 * Copyright (c) 2005 MindTree Consulting Ltd. 8 * 9 * This file is part of Insight. 10 * 11 * Insight is free software: you can redistribute it and/or modify it under the 12 * terms of the GNU General Public License as published by the Free Software 13 * Foundation, either version 3 of the License, or (at your option) any later 14 * version. 15 * 16 * Insight is distributed in the hope that it will be useful, but 17 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 19 * Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License along with 22 * Insight. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 package com.mindtree.techworks.insight.download; 26 27 import java.net.PasswordAuthentication; 28 29 /** 30 * <code>ProxyInfo</code> is a data object that holds information about proxy 31 * related parameters. 32 * 33 * @author: balajiseshadri 34 * @version: 35 */ 36 public class ProxyInfo { 37 38 // 39 // Instance variables 40 // 41 42 /** 43 * Contains information about the HTTP Proxy 44 */ 45 private ProtocolProxyInfo httpProxyInfo; 46 47 /** 48 * Contains information about the FTP Proxy 49 */ 50 private ProtocolProxyInfo ftpProxyInfo; 51 52 /** 53 * Contains information about the SOCKS Proxy 54 */ 55 private ProtocolProxyInfo socksProxyInfo; 56 57 /** 58 * Identifies if authentication is required 59 */ 60 private boolean isAuthenticationRequired; 61 62 /** 63 * Password information for proxy 64 */ 65 private PasswordAuthentication passwordInformation; 66 67 68 // 69 // Accessors 70 // 71 72 /** 73 * Sets the HTTP Proxy information. 74 * 75 * @param host HTTP Proxy host 76 * @param port HTTP Proxy port 77 */ 78 public void setHttpProxyInfo (String host, int port) { 79 80 this.httpProxyInfo = new ProtocolProxyInfo(host, port); 81 } 82 83 /** 84 * Gets the HTTP Proxy information 85 * 86 * @return ProtocolProxyInfo object containing the HTTP Proxy information. 87 */ 88 public ProtocolProxyInfo getHttpProxyInfo () { 89 90 return this.httpProxyInfo; 91 } 92 93 /** 94 * Sets the FTP Proxy information. 95 * 96 * @param host FTP Proxy host 97 * @param port FTP Proxy port 98 */ 99 public void setFtpProxyInfo (String host, int port) { 100 101 this.ftpProxyInfo = new ProtocolProxyInfo(host, port); 102 } 103 104 /** 105 * Gets the FTP Proxy information 106 * 107 * @return ProtocolProxyInfo object containing the FTP Proxy information. 108 */ 109 public ProtocolProxyInfo getFtpProxyInfo () { 110 111 return this.ftpProxyInfo; 112 } 113 114 /** 115 * Sets the SOCKS Proxy information. 116 * 117 * @param host SOCKS Proxy host 118 * @param port SOCKS Proxy port 119 */ 120 public void setSocksProxyInfo (String host, int port) { 121 122 this.socksProxyInfo = new ProtocolProxyInfo(host, port); 123 } 124 125 /** 126 * Gets the SOCKS Proxy information 127 * 128 * @return ProtocolProxyInfo object containing the SOCKS Proxy information. 129 */ 130 public ProtocolProxyInfo getSocksProxyInfo () { 131 132 return this.socksProxyInfo; 133 } 134 135 136 /** 137 * @return Returns the isAuthenticationRequired. 138 */ 139 public boolean isAuthenticationRequired () { 140 141 return isAuthenticationRequired; 142 } 143 144 /** 145 * @param isAuthenticationRequired The isAuthenticationRequired to set. 146 */ 147 public void setAuthenticationRequired (boolean isAuthenticationRequired) { 148 149 this.isAuthenticationRequired = isAuthenticationRequired; 150 } 151 152 /** 153 * @return Returns the passwordInformation. 154 */ 155 public PasswordAuthentication getPasswordInformation () { 156 157 return passwordInformation; 158 } 159 160 /** 161 * @param userName The username to set. 162 * @param password The password to set. 163 */ 164 public void setPasswordInformation (String userName, String password) { 165 166 this.passwordInformation = new PasswordAuthentication(userName, 167 password.toCharArray()); 168 } 169 170 // 171 // Bean to contain proxy information 172 // 173 174 /** 175 * Contains information about a particular proxy host for a protocol. 176 * 177 * @author Bindul Bhowmik 178 * @version $Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $ 179 */ 180 public class ProtocolProxyInfo { 181 182 /** 183 * The hostname of the proxy 184 */ 185 private String host; 186 187 /** 188 * The port to connect to 189 */ 190 private int port; 191 192 /** 193 * Creates a ProtocolProxyInfo class 194 * 195 * @param host The host to set 196 * @param port The port to set 197 */ 198 public ProtocolProxyInfo (String host, int port) { 199 200 this.host = host; 201 this.port = port; 202 } 203 204 205 /** 206 * @return Returns the host. 207 */ 208 public String getHost () { 209 210 return host; 211 } 212 213 /** 214 * @return Returns the port. 215 */ 216 public int getPort () { 217 218 return port; 219 } 220 221 /** 222 * Checks if the proxy information is set. 223 * @return If the proxy host is set. 224 */ 225 public boolean isSet() { 226 return !(null == host || host.length() == 0); 227 } 228 } 229 }