01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
20: import org.apache.commons.net.ftp.FTPClient;
21: import org.apache.commons.net.ftp.FTPClientConfig;
22: import org.apache.tools.ant.Project;
23:
24: /**
25: * The sole purpose of this class is (note that it is package-private
26: * is to serve as a separate, static compilation unit for importing
27: * FTPClientConfig, to enable users who wish to use the FTP task
28: * without using its new features to avoid the need to
29: * upgrade to jakarta-commons-net 1.4.0, where FTPClientConfig was
30: * introduced.
31: */
32: class FTPConfigurator {
33: /**
34: * configures the supplied FTPClient with the various
35: * attributes set in the supplied FTP task.
36: * @param client the FTPClient to be configured
37: * @param task the FTP task whose attributes are used to
38: * configure the client
39: * @return the client as configured.
40: */
41: static FTPClient configure(FTPClient client, FTP task) {
42: task.log("custom configuration", Project.MSG_VERBOSE);
43: FTPClientConfig config;
44: String systemTypeKey = task.getSystemTypeKey();
45: if (systemTypeKey != null && !"".equals(systemTypeKey)) {
46: config = new FTPClientConfig(systemTypeKey);
47: task.log("custom config: system key = " + systemTypeKey,
48: Project.MSG_VERBOSE);
49: } else {
50: config = new FTPClientConfig();
51: task.log("custom config: system key = default (UNIX)",
52: Project.MSG_VERBOSE);
53: }
54:
55: String defaultDateFormatConfig = task
56: .getDefaultDateFormatConfig();
57: if (defaultDateFormatConfig != null) {
58: config.setDefaultDateFormatStr(defaultDateFormatConfig);
59: task.log("custom config: default date format = "
60: + defaultDateFormatConfig, Project.MSG_VERBOSE);
61: }
62:
63: String recentDateFormatConfig = task
64: .getRecentDateFormatConfig();
65: if (recentDateFormatConfig != null) {
66: config.setRecentDateFormatStr(recentDateFormatConfig);
67: task.log("custom config: recent date format = "
68: + recentDateFormatConfig, Project.MSG_VERBOSE);
69: }
70:
71: String serverLanguageCodeConfig = task
72: .getServerLanguageCodeConfig();
73: if (serverLanguageCodeConfig != null) {
74: config.setServerLanguageCode(serverLanguageCodeConfig);
75: task.log("custom config: server language code = "
76: + serverLanguageCodeConfig, Project.MSG_VERBOSE);
77: }
78:
79: String serverTimeZoneConfig = task.getServerTimeZoneConfig();
80: if (serverTimeZoneConfig != null) {
81: config.setServerTimeZoneId(serverTimeZoneConfig);
82: task.log("custom config: server time zone ID = "
83: + serverTimeZoneConfig, Project.MSG_VERBOSE);
84: }
85:
86: String shortMonthNamesConfig = task.getShortMonthNamesConfig();
87: if (shortMonthNamesConfig != null) {
88: config.setShortMonthNames(shortMonthNamesConfig);
89: task.log("custom config: short month names = "
90: + shortMonthNamesConfig, Project.MSG_VERBOSE);
91: }
92: client.configure(config);
93: return client;
94: }
95: }
|