001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.vfs.provider.ftp;
018:
019: import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
020: import org.apache.commons.vfs.FileSystemConfigBuilder;
021: import org.apache.commons.vfs.FileSystemOptions;
022:
023: /**
024: * The config builder for various ftp configuration options
025: *
026: * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
027: * @version $Revision: 480428 $ $Date: 2006-11-28 22:15:24 -0800 (Tue, 28 Nov 2006) $
028: */
029: public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder {
030: private final static FtpFileSystemConfigBuilder builder = new FtpFileSystemConfigBuilder();
031:
032: private final static String FACTORY_KEY = FTPFileEntryParserFactory.class
033: .getName()
034: + ".KEY";
035: private final static String PASSIVE_MODE = FtpFileSystemConfigBuilder.class
036: .getName()
037: + ".PASSIVE";
038: private final static String USER_DIR_IS_ROOT = FtpFileSystemConfigBuilder.class
039: .getName()
040: + ".USER_DIR_IS_ROOT";
041: private final static String DATA_TIMEOUT = FtpFileSystemConfigBuilder.class
042: .getName()
043: + ".DATA_TIMEOUT";
044:
045: private final static String SERVER_LANGUAGE_CODE = FtpFileSystemConfigBuilder.class
046: .getName()
047: + ".SERVER_LANGUAGE_CODE";
048: private final static String DEFAULT_DATE_FORMAT = FtpFileSystemConfigBuilder.class
049: .getName()
050: + ".DEFAULT_DATE_FORMAT";
051: private final static String RECENT_DATE_FORMAT = FtpFileSystemConfigBuilder.class
052: .getName()
053: + ".RECENT_DATE_FORMAT";
054: private final static String SERVER_TIME_ZONE_ID = FtpFileSystemConfigBuilder.class
055: .getName()
056: + ".SERVER_TIME_ZONE_ID";
057: private final static String SHORT_MONTH_NAMES = FtpFileSystemConfigBuilder.class
058: .getName()
059: + ".SHORT_MONTH_NAMES";
060:
061: public static FtpFileSystemConfigBuilder getInstance() {
062: return builder;
063: }
064:
065: private FtpFileSystemConfigBuilder() {
066: }
067:
068: /**
069: * FTPFileEntryParserFactory which will be used for ftp-entry parsing
070: *
071: * @param opts
072: * @param factory instance of your factory
073: */
074: public void setEntryParserFactory(FileSystemOptions opts,
075: FTPFileEntryParserFactory factory) {
076: setParam(opts, FTPFileEntryParserFactory.class.getName(),
077: factory);
078: }
079:
080: /**
081: * @param opts
082: * @see #setEntryParserFactory
083: */
084: public FTPFileEntryParserFactory getEntryParserFactory(
085: FileSystemOptions opts) {
086: return (FTPFileEntryParserFactory) getParam(opts,
087: FTPFileEntryParserFactory.class.getName());
088: }
089:
090: /**
091: * set the FQCN of your FileEntryParser used to parse the directory listing from your server.<br />
092: * <br />
093: * <i>If you do not use the default commons-net FTPFileEntryParserFactory e.g. by using {@link #setEntryParserFactory}
094: * this is the "key" parameter passed as argument into your custom factory</i>
095: *
096: * @param opts
097: * @param key
098: */
099: public void setEntryParser(FileSystemOptions opts, String key) {
100: setParam(opts, FACTORY_KEY, key);
101: }
102:
103: /**
104: * @param opts
105: * @see #setEntryParser
106: */
107: public String getEntryParser(FileSystemOptions opts) {
108: return (String) getParam(opts, FACTORY_KEY);
109: }
110:
111: protected Class getConfigClass() {
112: return FtpFileSystem.class;
113: }
114:
115: /**
116: * enter into passive mode
117: *
118: * @param opts
119: * @param passiveMode
120: */
121: public void setPassiveMode(FileSystemOptions opts,
122: boolean passiveMode) {
123: setParam(opts, PASSIVE_MODE, passiveMode ? Boolean.TRUE
124: : Boolean.FALSE);
125: }
126:
127: /**
128: * @param opts
129: * @see #setPassiveMode
130: */
131: public Boolean getPassiveMode(FileSystemOptions opts) {
132: return (Boolean) getParam(opts, PASSIVE_MODE);
133: }
134:
135: /**
136: * use user directory as root (do not change to fs root)
137: *
138: * @param opts
139: * @param userDirIsRoot
140: */
141: public void setUserDirIsRoot(FileSystemOptions opts,
142: boolean userDirIsRoot) {
143: setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE
144: : Boolean.FALSE);
145: }
146:
147: /**
148: * @param opts
149: * @see #setUserDirIsRoot
150: */
151: public Boolean getUserDirIsRoot(FileSystemOptions opts) {
152: return (Boolean) getParam(opts, USER_DIR_IS_ROOT);
153: }
154:
155: /**
156: * @param opts
157: * @see #setDataTimeout
158: */
159: public Integer getDataTimeout(FileSystemOptions opts) {
160: return (Integer) getParam(opts, DATA_TIMEOUT);
161: }
162:
163: /**
164: * set the data timeout for the ftp client.<br />
165: * If you set the dataTimeout to <code>null</code> no dataTimeout will be set on the
166: * ftp client.
167: *
168: * @param opts
169: * @param dataTimeout
170: */
171: public void setDataTimeout(FileSystemOptions opts,
172: Integer dataTimeout) {
173: setParam(opts, DATA_TIMEOUT, dataTimeout);
174: }
175:
176: /**
177: * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
178: * for details and examples.
179: */
180: public String getServerLanguageCode(FileSystemOptions opts) {
181: return (String) getParam(opts, SERVER_LANGUAGE_CODE);
182: }
183:
184: /**
185: * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
186: * for details and examples.
187: */
188: public void setServerLanguageCode(FileSystemOptions opts,
189: String serverLanguageCode) {
190: setParam(opts, SERVER_LANGUAGE_CODE, serverLanguageCode);
191: }
192:
193: /**
194: * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
195: * for details and examples.
196: */
197: public String getDefaultDateFormat(FileSystemOptions opts) {
198: return (String) getParam(opts, DEFAULT_DATE_FORMAT);
199: }
200:
201: /**
202: * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
203: * for details and examples.
204: */
205: public void setDefaultDateFormat(FileSystemOptions opts,
206: String defaultDateFormat) {
207: setParam(opts, DEFAULT_DATE_FORMAT, defaultDateFormat);
208: }
209:
210: /**
211: * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
212: */
213: public String getRecentDateFormat(FileSystemOptions opts) {
214: return (String) getParam(opts, RECENT_DATE_FORMAT);
215: }
216:
217: /**
218: * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
219: */
220: public void setRecentDateFormat(FileSystemOptions opts,
221: String recentDateFormat) {
222: setParam(opts, RECENT_DATE_FORMAT, recentDateFormat);
223: }
224:
225: /**
226: * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
227: */
228: public String getServerTimeZoneId(FileSystemOptions opts) {
229: return (String) getParam(opts, SERVER_TIME_ZONE_ID);
230: }
231:
232: /**
233: * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
234: */
235: public void setServerTimeZoneId(FileSystemOptions opts,
236: String serverTimeZoneId) {
237: setParam(opts, SERVER_TIME_ZONE_ID, serverTimeZoneId);
238: }
239:
240: /**
241: * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
242: */
243: public String[] getShortMonthNames(FileSystemOptions opts) {
244: return (String[]) getParam(opts, SHORT_MONTH_NAMES);
245: }
246:
247: /**
248: * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
249: */
250: public void setShortMonthNames(FileSystemOptions opts,
251: String[] shortMonthNames) {
252: String[] clone = null;
253: if (shortMonthNames != null) {
254: clone = new String[shortMonthNames.length];
255: System.arraycopy(shortMonthNames, 0, clone, 0,
256: shortMonthNames.length);
257: }
258:
259: setParam(opts, SHORT_MONTH_NAMES, clone);
260: }
261: }
|