View Javadoc

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  package org.apache.commons.vfs.provider.ftp;
18  
19  import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
20  import org.apache.commons.vfs.FileSystemConfigBuilder;
21  import org.apache.commons.vfs.FileSystemOptions;
22  
23  /***
24   * The config builder for various ftp configuration options
25   *
26   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
27   * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
28   */
29  public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder
30  {
31      private final static FtpFileSystemConfigBuilder builder = new FtpFileSystemConfigBuilder();
32  
33      private final static String FACTORY_KEY = FTPFileEntryParserFactory.class.getName() + ".KEY";
34      private final static String PASSIVE_MODE = FtpFileSystemConfigBuilder.class.getName() + ".PASSIVE";
35      private final static String USER_DIR_IS_ROOT = FtpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";
36      private final static String DATA_TIMEOUT = FtpFileSystemConfigBuilder.class.getName() + ".DATA_TIMEOUT";
37  
38      private final static String SERVER_LANGUAGE_CODE = FtpFileSystemConfigBuilder.class.getName() + ".SERVER_LANGUAGE_CODE";
39      private final static String DEFAULT_DATE_FORMAT = FtpFileSystemConfigBuilder.class.getName() + ".DEFAULT_DATE_FORMAT";
40      private final static String RECENT_DATE_FORMAT = FtpFileSystemConfigBuilder.class.getName() + ".RECENT_DATE_FORMAT";
41      private final static String SERVER_TIME_ZONE_ID = FtpFileSystemConfigBuilder.class.getName() + ".SERVER_TIME_ZONE_ID";
42      private final static String SHORT_MONTH_NAMES = FtpFileSystemConfigBuilder.class.getName() + ".SHORT_MONTH_NAMES";
43  
44      public static FtpFileSystemConfigBuilder getInstance()
45      {
46          return builder;
47      }
48  
49      private FtpFileSystemConfigBuilder()
50      {
51      }
52  
53      /***
54       * FTPFileEntryParserFactory which will be used for ftp-entry parsing
55       *
56       * @param opts
57       * @param factory instance of your factory
58       */
59      public void setEntryParserFactory(FileSystemOptions opts, FTPFileEntryParserFactory factory)
60      {
61          setParam(opts, FTPFileEntryParserFactory.class.getName(), factory);
62      }
63  
64      /***
65       * @param opts
66       * @see #setEntryParserFactory
67       */
68      public FTPFileEntryParserFactory getEntryParserFactory(FileSystemOptions opts)
69      {
70          return (FTPFileEntryParserFactory) getParam(opts, FTPFileEntryParserFactory.class.getName());
71      }
72  
73      /***
74       * set the FQCN of your FileEntryParser used to parse the directory listing from your server.<br />
75       * <br />
76       * <i>If you do not use the default commons-net FTPFileEntryParserFactory e.g. by using {@link #setEntryParserFactory}
77       * this is the "key" parameter passed as argument into your custom factory</i>
78       *
79       * @param opts
80       * @param key
81       */
82      public void setEntryParser(FileSystemOptions opts, String key)
83      {
84          setParam(opts, FACTORY_KEY, key);
85      }
86  
87      /***
88       * @param opts
89       * @see #setEntryParser
90       */
91      public String getEntryParser(FileSystemOptions opts)
92      {
93          return (String) getParam(opts, FACTORY_KEY);
94      }
95  
96      protected Class getConfigClass()
97      {
98          return FtpFileSystem.class;
99      }
100 
101     /***
102      * enter into passive mode
103      *
104      * @param opts
105      * @param passiveMode
106      */
107     public void setPassiveMode(FileSystemOptions opts, boolean passiveMode)
108     {
109         setParam(opts, PASSIVE_MODE, passiveMode ? Boolean.TRUE : Boolean.FALSE);
110     }
111 
112     /***
113      * @param opts
114      * @see #setPassiveMode
115      */
116     public Boolean getPassiveMode(FileSystemOptions opts)
117     {
118         return (Boolean) getParam(opts, PASSIVE_MODE);
119     }
120 
121     /***
122      * use user directory as root (do not change to fs root)
123      *
124      * @param opts
125      * @param userDirIsRoot
126      */
127     public void setUserDirIsRoot(FileSystemOptions opts, boolean userDirIsRoot)
128     {
129         setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
130     }
131 
132     /***
133      * @param opts
134      * @see #setUserDirIsRoot
135      */
136     public Boolean getUserDirIsRoot(FileSystemOptions opts)
137     {
138         return (Boolean) getParam(opts, USER_DIR_IS_ROOT);
139     }
140 
141     /***
142      * @param opts
143      * @see #setDataTimeout
144      */
145     public Integer getDataTimeout(FileSystemOptions opts)
146     {
147         return (Integer) getParam(opts, DATA_TIMEOUT);
148     }
149 
150     /***
151      * set the data timeout for the ftp client.<br />
152      * If you set the dataTimeout to <code>null</code> no dataTimeout will be set on the
153      * ftp client.
154      *
155      * @param opts
156      * @param dataTimeout
157      */
158     public void setDataTimeout(FileSystemOptions opts, Integer dataTimeout)
159     {
160         setParam(opts, DATA_TIMEOUT, dataTimeout);
161     }
162 
163     /***
164      * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
165      * for details and examples.
166      */
167     public String getServerLanguageCode(FileSystemOptions opts)
168     {
169         return (String) getParam(opts, SERVER_LANGUAGE_CODE);
170     }
171 
172     /***
173      * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
174      * for details and examples.
175      */
176     public void setServerLanguageCode(FileSystemOptions opts, String serverLanguageCode)
177     {
178         setParam(opts, SERVER_LANGUAGE_CODE, serverLanguageCode);
179     }
180 
181     /***
182      * get the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
183      * for details and examples.
184      */
185     public String getDefaultDateFormat(FileSystemOptions opts)
186     {
187         return (String) getParam(opts, DEFAULT_DATE_FORMAT);
188     }
189 
190     /***
191      * set the language code used by the server. see {@link org.apache.commons.net.ftp.FTPClientConfig}
192      * for details and examples.
193      */
194     public void setDefaultDateFormat(FileSystemOptions opts, String defaultDateFormat)
195     {
196         setParam(opts, DEFAULT_DATE_FORMAT, defaultDateFormat);
197     }
198 
199     /***
200      * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
201      */
202     public String getRecentDateFormat(FileSystemOptions opts)
203     {
204         return (String) getParam(opts, RECENT_DATE_FORMAT);
205     }
206 
207     /***
208      * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
209      */
210     public void setRecentDateFormat(FileSystemOptions opts, String recentDateFormat)
211     {
212         setParam(opts, RECENT_DATE_FORMAT, recentDateFormat);
213     }
214 
215     /***
216      * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
217      */
218     public String getServerTimeZoneId(FileSystemOptions opts)
219     {
220         return (String) getParam(opts, SERVER_TIME_ZONE_ID);
221     }
222 
223     /***
224      * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
225      */
226     public void setServerTimeZoneId(FileSystemOptions opts, String serverTimeZoneId)
227     {
228         setParam(opts, SERVER_TIME_ZONE_ID, serverTimeZoneId);
229     }
230 
231     /***
232      * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
233      */
234     public String[] getShortMonthNames(FileSystemOptions opts)
235     {
236         return (String[]) getParam(opts, SHORT_MONTH_NAMES);
237     }
238 
239     /***
240      * see {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
241      */
242     public void setShortMonthNames(FileSystemOptions opts, String[] shortMonthNames)
243     {
244     	String[] clone = null;
245     	if (shortMonthNames != null)
246     	{
247     		clone = new String[shortMonthNames.length];
248     		System.arraycopy(shortMonthNames, 0, clone, 0, shortMonthNames.length);
249     	}
250     	
251         setParam(opts, SHORT_MONTH_NAMES, clone);
252     }
253 }