1 6 package net.sourceforge.cvsgrab; 7 8 import java.util.Properties ; 9 10 17 public class WebOptions { 18 19 private HttpProxy _httpProxy; 20 private WebAuthentification _webAuthentification; 21 private String _rootUrl; 22 private String _packagePath; 23 private String _projectRoot; 24 private String _versionTag; 25 private String _queryParams; 26 private String _webInterfaceId; 27 28 31 public void setupConnectionSettings() { 32 if (_httpProxy != null) { 33 _httpProxy.setup(); 34 } 35 if (_webAuthentification != null) { 36 _webAuthentification.setup(); 37 } 38 } 39 40 public void readProperties(Properties properties) { 41 setRootUrl(properties.getProperty(CVSGrab.ROOT_URL_OPTION)); 42 setPackagePath(properties.getProperty(CVSGrab.PACKAGE_PATH_OPTION)); 43 setProjectRoot(properties.getProperty(CVSGrab.PROJECT_ROOT_OPTION)); 44 setVersionTag(properties.getProperty(CVSGrab.TAG_OPTION)); 45 setQueryParams(properties.getProperty(CVSGrab.QUERY_PARAMS_OPTION)); 46 setWebInterfaceId(properties.getProperty(CVSGrab.WEB_INTERFACE_OPTION)); 47 48 if (CVSGrab.getLog().isDebugEnabled()) { 49 CVSGrab.getLog().debug("Web option/root url = " + getRootUrl()); 50 CVSGrab.getLog().debug("Web option/package path = " + getPackagePath()); 51 CVSGrab.getLog().debug("Web option/project root = " + getProjectRoot()); 52 CVSGrab.getLog().debug("Web option/version tag = " + getVersionTag()); 53 CVSGrab.getLog().debug("Web option/query params = " + getQueryParams()); 54 CVSGrab.getLog().debug("Web option/web interface = " + getWebInterfaceId()); 55 } 56 57 if (properties.containsKey(CVSGrab.PROXY_HOST_OPTION)) { 58 if (_httpProxy == null) { 59 _httpProxy = new HttpProxy(); 60 } 61 _httpProxy.readProperties(properties); 62 } 63 if (properties.containsKey(CVSGrab.WEB_USER_OPTION)) { 64 if (_webAuthentification == null) { 65 _webAuthentification = new WebAuthentification(); 66 } 67 _webAuthentification.readProperties(properties); 68 } 69 } 70 71 public void writeProperties(Properties properties) { 72 if (getRootUrl() != null) { 73 properties.setProperty(CVSGrab.ROOT_URL_OPTION, getRootUrl()); 74 } 75 if (getPackagePath() != null) { 76 properties.setProperty(CVSGrab.PACKAGE_PATH_OPTION, getPackagePath()); 77 } 78 if (getProjectRoot() != null) { 79 properties.setProperty(CVSGrab.PROJECT_ROOT_OPTION, getProjectRoot()); 80 } 81 if (getVersionTag() != null) { 82 properties.setProperty(CVSGrab.TAG_OPTION, getVersionTag()); 83 } 84 if (getQueryParams() != null) { 85 properties.setProperty(CVSGrab.QUERY_PARAMS_OPTION, getQueryParams()); 86 } 87 if (getWebInterfaceId() != null) { 88 properties.setProperty(CVSGrab.WEB_INTERFACE_OPTION, getWebInterfaceId()); 89 } 90 if (_httpProxy != null) { 91 _httpProxy.writeProperties(properties); 92 } 93 if (_webAuthentification != null) { 94 _webAuthentification.writeProperties(properties); 95 } 96 } 97 98 101 public String getRootUrl() { 102 return _rootUrl; 103 } 104 105 109 public void setRootUrl(String rootUrl) { 110 if (rootUrl != null) { 111 _rootUrl = WebBrowser.forceFinalSlash(rootUrl); 112 } 113 } 114 115 118 public String getPackagePath() { 119 return _packagePath; 120 } 121 122 126 public void setPackagePath(String packagePath) { 127 if (packagePath != null) { 128 _packagePath = WebBrowser.forceFinalSlash(packagePath); 129 } 130 } 131 132 135 public String getProjectRoot() { 136 return _projectRoot; 137 } 138 139 public void setProjectRoot(String projectRoot) { 140 if (projectRoot != null) { 141 _projectRoot = projectRoot; 142 } 143 } 144 145 148 public String getVersionTag() { 149 return _versionTag; 150 } 151 152 156 public void setVersionTag(String versionTag) { 157 if (versionTag != null) { 158 _versionTag = versionTag; 159 } 160 } 161 162 165 public String getQueryParams() { 166 return _queryParams; 167 } 168 169 172 public void setQueryParams(String queryParams) { 173 if (queryParams != null) { 174 _queryParams = queryParams; 175 } 176 } 177 178 182 public String getWebInterfaceId() { 183 return _webInterfaceId; 184 } 185 186 190 public void setWebInterfaceId(String webInterfaceId) { 191 if (webInterfaceId != null) { 192 _webInterfaceId = webInterfaceId; 193 } 194 } 195 196 200 public HttpProxy getHttpProxy() { 201 return _httpProxy; 202 } 203 204 208 public void setHttpProxy(HttpProxy httpProxy) { 209 this._httpProxy = httpProxy; 210 } 211 212 216 public WebAuthentification getWebAuthentification() { 217 return _webAuthentification; 218 } 219 220 224 public void setWebAuthentification(WebAuthentification webAuthentification) { 225 this._webAuthentification = webAuthentification; 226 } 227 228 231 public void clearLocation() { 232 _rootUrl = null; 233 _packagePath = null; 234 _projectRoot = null; 235 _versionTag = null; 236 _queryParams = null; 237 _webInterfaceId = null; 238 } 239 240 246 public class HttpProxy { 247 private String _host = null; 248 private int _port = 0; 249 private String _ntDomain = null; 250 private String _username = null; 251 private String _password = null; 252 253 256 public void setup() { 257 if (_host != null && _port == 0) { 258 throw new IllegalArgumentException ("port argument is not specified in the proxy"); 259 } 260 WebBrowser.getInstance().useProxy(_host, _port, _ntDomain, _username, _password); 261 } 262 263 266 public void writeProperties(Properties properties) { 267 if (getHost() != null) { 268 properties.setProperty(CVSGrab.PROXY_HOST_OPTION, getHost()); 269 } 270 if (getPort() != 0) { 271 properties.setProperty(CVSGrab.PROXY_PORT_OPTION, String.valueOf(getPort())); 272 } 273 if (getNtdomain() != null) { 274 properties.setProperty(CVSGrab.PROXY_NTDOMAIN_OPTION, getNtdomain()); 275 } 276 if (getUsername() != null) { 277 properties.setProperty(CVSGrab.PROXY_USER_OPTION, getUsername()); 278 } 279 if (getPassword() != null) { 280 properties.setProperty(CVSGrab.PROXY_PASSWORD_OPTION, getPassword()); 281 } 282 } 283 284 287 public void readProperties(Properties properties) { 288 setHost(properties.getProperty(CVSGrab.PROXY_HOST_OPTION)); 289 try { 290 setPort(Integer.parseInt(properties.getProperty(CVSGrab.PROXY_PORT_OPTION))); 291 } catch (NumberFormatException ex) { 292 CVSGrab.getLog().error("Parameter " + CVSGrab.PROXY_PORT_OPTION + " must be a number"); 293 throw ex; 294 } 295 setNtdomain(properties.getProperty(CVSGrab.PROXY_NTDOMAIN_OPTION)); 296 setUsername(properties.getProperty(CVSGrab.PROXY_USER_OPTION)); 297 setPassword(properties.getProperty(CVSGrab.PROXY_PASSWORD_OPTION)); 298 } 299 300 304 public String getHost() { 305 return _host; 306 } 307 308 312 public String getNtdomain() { 313 return _ntDomain; 314 } 315 316 320 public String getPassword() { 321 return _password; 322 } 323 324 328 public int getPort() { 329 return _port; 330 } 331 332 336 public String getUsername() { 337 return _username; 338 } 339 340 345 public void setHost(String value) { 346 _host = value; 347 } 348 349 354 public void setPort(int value) { 355 _port = value; 356 } 357 358 363 public void setNtdomain(String ntDomain) { 364 this._ntDomain = ntDomain; 365 } 366 367 372 public void setUsername(String value) { 373 _username = value; 374 } 375 376 381 public void setPassword(String value) { 382 _password = value; 383 } 384 385 } 386 387 393 public class WebAuthentification { 394 private String _user = null; 395 private String _password = null; 396 397 402 public void setup() { 403 WebBrowser.getInstance().useWebAuthentification(_user, _password); 404 } 405 406 409 public void writeProperties(Properties properties) { 410 if (getUsername() != null) { 411 properties.setProperty(CVSGrab.WEB_USER_OPTION, getUsername()); 412 } 413 if (getPassword() != null) { 414 properties.setProperty(CVSGrab.WEB_PASSWORD_OPTION, getPassword()); 415 } 416 } 417 418 421 public void readProperties(Properties properties) { 422 setUsername(properties.getProperty(CVSGrab.WEB_USER_OPTION)); 423 setPassword(properties.getProperty(CVSGrab.WEB_PASSWORD_OPTION)); 424 } 425 426 430 public String getPassword() { 431 return _password; 432 } 433 434 438 public String getUsername() { 439 return _user; 440 } 441 442 447 public void setUsername(String value) { 448 _user = value; 449 } 450 451 456 public void setPassword(String value) { 457 _password = value; 458 } 459 460 } 461 462 } 463 | Popular Tags |