KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > net > FTPConfigurator


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional.net;
19 import org.apache.commons.net.ftp.FTPClient;
20 import org.apache.commons.net.ftp.FTPClientConfig;
21 import org.apache.tools.ant.Project;
22
23 /**
24  * The sole purpose of this class is (note that it is package-private
25  * is to serve as a separate, static compilation unit for importing
26  * FTPClientConfig, to enable users who wish to use the FTP task
27  * without using its new features to avoid the need to
28  * upgrade to jakarta-commons-net 1.4.0, where FTPClientConfig was
29  * introduced.
30   */

31 class FTPConfigurator {
32     /**
33      * configures the supplied FTPClient with the various
34      * attributes set in the supplied FTP task.
35      * @param client the FTPClient to be configured
36      * @param task the FTP task whose attributes are used to
37      * configure the client
38      * @return the client as configured.
39      */

40     static FTPClient configure(FTPClient client, FTP task) {
41         task.log("custom configuration", Project.MSG_VERBOSE);
42         FTPClientConfig config;
43         String JavaDoc systemTypeKey = task.getSystemTypeKey();
44         if (systemTypeKey != null && !"".equals(systemTypeKey)) {
45             config = new FTPClientConfig(systemTypeKey);
46             task.log("custom config: system key = "
47                     + systemTypeKey, Project.MSG_VERBOSE);
48         } else {
49             config = new FTPClientConfig();
50             task.log("custom config: system key = default (UNIX)",
51                     Project.MSG_VERBOSE);
52         }
53
54         String JavaDoc defaultDateFormatConfig = task.getDefaultDateFormatConfig();
55         if (defaultDateFormatConfig != null) {
56             config.setDefaultDateFormatStr(defaultDateFormatConfig);
57             task.log("custom config: default date format = "
58                     + defaultDateFormatConfig, Project.MSG_VERBOSE);
59         }
60
61         String JavaDoc recentDateFormatConfig = task.getRecentDateFormatConfig();
62         if (recentDateFormatConfig != null) {
63             config.setRecentDateFormatStr(recentDateFormatConfig);
64             task.log("custom config: recent date format = "
65                     + recentDateFormatConfig, Project.MSG_VERBOSE);
66         }
67
68         String JavaDoc serverLanguageCodeConfig = task.getServerLanguageCodeConfig();
69         if (serverLanguageCodeConfig != null) {
70             config.setServerLanguageCode(serverLanguageCodeConfig);
71             task.log("custom config: server language code = "
72                     + serverLanguageCodeConfig, Project.MSG_VERBOSE);
73         }
74
75         String JavaDoc serverTimeZoneConfig = task.getServerTimeZoneConfig();
76         if (serverTimeZoneConfig != null) {
77             config.setServerTimeZoneId(serverTimeZoneConfig);
78             task.log("custom config: server time zone ID = "
79                     + serverTimeZoneConfig, Project.MSG_VERBOSE);
80         }
81
82         String JavaDoc shortMonthNamesConfig = task.getShortMonthNamesConfig();
83         if (shortMonthNamesConfig != null) {
84             config.setShortMonthNames(shortMonthNamesConfig);
85             task.log("custom config: short month names = "
86                     + shortMonthNamesConfig, Project.MSG_VERBOSE);
87         }
88         client.configure(config);
89         return client;
90     }
91 }
92
Popular Tags