KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > WebOptions


1 /*
2  * CVSGrab
3  * Author: Ludovic Claude (ludovicc@users.sourceforge.net)
4  * Distributable under BSD license.
5  */

6 package net.sourceforge.cvsgrab;
7
8 import java.util.Properties JavaDoc;
9
10 /**
11  * Options for the web repository
12  *
13  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
14  * @version $Revision: 1.4 $ $Date: 2005/06/25 19:51:33 $
15  * @created on 9 mars 2004
16  */

17 public class WebOptions {
18
19     private HttpProxy _httpProxy;
20     private WebAuthentification _webAuthentification;
21     private String JavaDoc _rootUrl;
22     private String JavaDoc _packagePath;
23     private String JavaDoc _projectRoot;
24     private String JavaDoc _versionTag;
25     private String JavaDoc _queryParams;
26     private String JavaDoc _webInterfaceId;
27
28     /**
29      * Setup the the http proxy and the web authentification settings.
30      */

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 JavaDoc 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 JavaDoc 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     /**
99      * @return Returns the rootUrl.
100      */

101     public String JavaDoc getRootUrl() {
102         return _rootUrl;
103     }
104
105     /**
106      * Sets the url for the root of the CVS repository accessible via ViewCVS
107      * @param rootUrl The rootUrl to set.
108      */

109     public void setRootUrl(String JavaDoc rootUrl) {
110         if (rootUrl != null) {
111             _rootUrl = WebBrowser.forceFinalSlash(rootUrl);
112         }
113     }
114
115     /**
116      * @return Returns the packagePath.
117      */

118     public String JavaDoc getPackagePath() {
119         return _packagePath;
120     }
121
122     /**
123      * Sets the path of the package/module to update from CVS
124      * @param packagePath The packagePath to set.
125      */

126     public void setPackagePath(String JavaDoc packagePath) {
127         if (packagePath != null) {
128             _packagePath = WebBrowser.forceFinalSlash(packagePath);
129         }
130     }
131
132     /**
133      * @return The project root, used by CVS with multiple repositories
134      */

135     public String JavaDoc getProjectRoot() {
136         return _projectRoot;
137     }
138
139     public void setProjectRoot(String JavaDoc projectRoot) {
140         if (projectRoot != null) {
141             _projectRoot = projectRoot;
142         }
143     }
144
145     /**
146      * @return Returns the versionTag.
147      */

148     public String JavaDoc getVersionTag() {
149         return _versionTag;
150     }
151
152     /**
153      * Sets the name of the tagged version of the files to retrieve, or null
154      * @param versionTag The versionTag to set.
155      */

156     public void setVersionTag(String JavaDoc versionTag) {
157         if (versionTag != null) {
158             _versionTag = versionTag;
159         }
160     }
161
162     /**
163      * @return Returns the queryParams.
164      */

165     public String JavaDoc getQueryParams() {
166         return _queryParams;
167     }
168
169     /**
170      * @param queryParams The queryParams to set.
171      */

172     public void setQueryParams(String JavaDoc queryParams) {
173         if (queryParams != null) {
174             _queryParams = queryParams;
175         }
176     }
177
178     /**
179      * Gets the webInterfaceId.
180      * @return the webInterfaceId.
181      */

182     public String JavaDoc getWebInterfaceId() {
183         return _webInterfaceId;
184     }
185
186     /**
187      * Sets the webInterfaceId.
188      * @param webInterfaceId The webInterfaceId to set.
189      */

190     public void setWebInterfaceId(String JavaDoc webInterfaceId) {
191         if (webInterfaceId != null) {
192             _webInterfaceId = webInterfaceId;
193         }
194     }
195
196     /**
197      * Gets the httpProxy.
198      * @return the httpProxy.
199      */

200     public HttpProxy getHttpProxy() {
201         return _httpProxy;
202     }
203
204     /**
205      * Sets the httpProxy.
206      * @param httpProxy The httpProxy to set.
207      */

208     public void setHttpProxy(HttpProxy httpProxy) {
209         this._httpProxy = httpProxy;
210     }
211
212     /**
213      * Gets the webAuthentification.
214      * @return the webAuthentification.
215      */

216     public WebAuthentification getWebAuthentification() {
217         return _webAuthentification;
218     }
219
220     /**
221      * Sets the webAuthentification.
222      * @param webAuthentification The webAuthentification to set.
223      */

224     public void setWebAuthentification(WebAuthentification webAuthentification) {
225         this._webAuthentification = webAuthentification;
226     }
227
228     /**
229      * Clears the location parameters
230      */

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     /**
241      * Nested element for configuring the proxy for http connections
242      *
243      * @author lclaude
244      * @created May 14, 2002
245      */

246     public class HttpProxy {
247         private String JavaDoc _host = null;
248         private int _port = 0;
249         private String JavaDoc _ntDomain = null;
250         private String JavaDoc _username = null;
251         private String JavaDoc _password = null;
252
253         /**
254          * Setup the proxy
255          */

256         public void setup() {
257             if (_host != null && _port == 0) {
258                 throw new IllegalArgumentException JavaDoc("port argument is not specified in the proxy");
259             }
260             WebBrowser.getInstance().useProxy(_host, _port, _ntDomain, _username, _password);
261         }
262
263         /**
264          * @param properties
265          */

266         public void writeProperties(Properties JavaDoc 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         /**
285          * @param properties
286          */

287         public void readProperties(Properties JavaDoc properties) {
288             setHost(properties.getProperty(CVSGrab.PROXY_HOST_OPTION));
289             try {
290                 setPort(Integer.parseInt(properties.getProperty(CVSGrab.PROXY_PORT_OPTION)));
291             } catch (NumberFormatException JavaDoc 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         /**
301          * Gets the host.
302          * @return the host.
303          */

304         public String JavaDoc getHost() {
305             return _host;
306         }
307
308         /**
309          * Gets the ntDomain.
310          * @return the ntDomain.
311          */

312         public String JavaDoc getNtdomain() {
313             return _ntDomain;
314         }
315
316         /**
317          * Gets the password.
318          * @return the password.
319          */

320         public String JavaDoc getPassword() {
321             return _password;
322         }
323
324         /**
325          * Gets the port.
326          * @return the port.
327          */

328         public int getPort() {
329             return _port;
330         }
331
332         /**
333          * Gets the user.
334          * @return the user.
335          */

336         public String JavaDoc getUsername() {
337             return _username;
338         }
339
340         /**
341          * Sets the host
342          *
343          * @param value The new host value
344          */

345         public void setHost(String JavaDoc value) {
346             _host = value;
347         }
348
349         /**
350          * Sets the port
351          *
352          * @param value The new port value
353          */

354         public void setPort(int value) {
355             _port = value;
356         }
357
358         /**
359          * Sets the nt domain
360          *
361          * @param ntDomain The new net domain
362          */

363         public void setNtdomain(String JavaDoc ntDomain) {
364             this._ntDomain = ntDomain;
365         }
366
367         /**
368          * Sets the username
369          *
370          * @param value The new username value
371          */

372         public void setUsername(String JavaDoc value) {
373             _username = value;
374         }
375
376         /**
377          * Sets the password
378          *
379          * @param value The new password value
380          */

381         public void setPassword(String JavaDoc value) {
382             _password = value;
383         }
384
385     }
386
387     /**
388      * Nested element for configuring the web server authentification
389      *
390      * @author lclaude
391      * @created May 14, 2002
392      */

393     public class WebAuthentification {
394         private String JavaDoc _user = null;
395         private String JavaDoc _password = null;
396
397         /**
398          * Setup the web authentification
399          *
400          * @throws BuildException Description of the Exception
401          */

402         public void setup() {
403             WebBrowser.getInstance().useWebAuthentification(_user, _password);
404         }
405
406         /**
407          * @param properties
408          */

409         public void writeProperties(Properties JavaDoc 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         /**
419          * @param properties
420          */

421         public void readProperties(Properties JavaDoc properties) {
422             setUsername(properties.getProperty(CVSGrab.WEB_USER_OPTION));
423             setPassword(properties.getProperty(CVSGrab.WEB_PASSWORD_OPTION));
424         }
425
426         /**
427          * Gets the password.
428          * @return the password.
429          */

430         public String JavaDoc getPassword() {
431             return _password;
432         }
433
434         /**
435          * Gets the user.
436          * @return the user.
437          */

438         public String JavaDoc getUsername() {
439             return _user;
440         }
441
442         /**
443          * Sets the username
444          *
445          * @param value The new username value
446          */

447         public void setUsername(String JavaDoc value) {
448             _user = value;
449         }
450
451         /**
452          * Sets the password
453          *
454          * @param value The new password value
455          */

456         public void setPassword(String JavaDoc value) {
457             _password = value;
458         }
459
460     }
461
462 }
463
Popular Tags