KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > ftp > FtpFileSystemConfigBuilder


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

16 package org.apache.commons.vfs.provider.ftp;
17
18 import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
19 import org.apache.commons.vfs.FileSystemConfigBuilder;
20 import org.apache.commons.vfs.FileSystemOptions;
21
22 /**
23  * The config builder for various ftp configuration options
24  *
25  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
26  */

27 public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder
28 {
29     private final static FtpFileSystemConfigBuilder builder = new FtpFileSystemConfigBuilder();
30
31     private final static String JavaDoc FACTORY_KEY = FTPFileEntryParserFactory.class.getName() + ".KEY";
32     private final static String JavaDoc PASSIVE_MODE = FtpFileSystemConfigBuilder.class.getName() + ".PASSIVE";
33     private final static String JavaDoc USER_DIR_IS_ROOT = FtpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";
34     private final static String JavaDoc DATA_TIMEOUT = FtpFileSystemConfigBuilder.class.getName() + ".DATA_TIMEOUT";
35
36     public static FtpFileSystemConfigBuilder getInstance()
37     {
38         return builder;
39     }
40
41     private FtpFileSystemConfigBuilder()
42     {
43     }
44
45     /**
46      * FTPFileEntryParserFactory which will be used for ftp-entry parsing
47      *
48      * @param opts
49      * @param factory instance of your factory
50      */

51     public void setEntryParserFactory(FileSystemOptions opts, FTPFileEntryParserFactory factory)
52     {
53         setParam(opts, FTPFileEntryParserFactory.class.getName(), factory);
54     }
55
56     /**
57      * @param opts
58      * @return
59      * @see #setEntryParserFactory
60      */

61     public FTPFileEntryParserFactory getEntryParserFactory(FileSystemOptions opts)
62     {
63         return (FTPFileEntryParserFactory) getParam(opts, FTPFileEntryParserFactory.class.getName());
64     }
65
66     /**
67      * set the FQCN of your FileEntryParser used to parse the directory listing from your server.<br />
68      * <br />
69      * <i>If you do not use the default commons-net FTPFileEntryParserFactory e.g. by using {@link #setEntryParserFactory}
70      * this is the "key" parameter passed as argument into your custom factory</i>
71      *
72      * @param opts
73      * @param key
74      */

75     public void setEntryParser(FileSystemOptions opts, String JavaDoc key)
76     {
77         setParam(opts, FACTORY_KEY, key);
78     }
79
80     /**
81      * @param opts
82      * @return
83      * @see #setEntryParser
84      */

85     public String JavaDoc getEntryParser(FileSystemOptions opts)
86     {
87         return (String JavaDoc) getParam(opts, FACTORY_KEY);
88     }
89
90     protected Class JavaDoc getConfigClass()
91     {
92         return FtpFileSystem.class;
93     }
94
95     /**
96      * enter into passive mode
97      *
98      * @param opts
99      * @param passiveMode
100      */

101     public void setPassiveMode(FileSystemOptions opts, boolean passiveMode)
102     {
103         setParam(opts, PASSIVE_MODE, passiveMode ? Boolean.TRUE : Boolean.FALSE);
104     }
105
106     /**
107      * @param opts
108      * @return
109      * @see #setPassiveMode
110      */

111     public Boolean JavaDoc getPassiveMode(FileSystemOptions opts)
112     {
113         return (Boolean JavaDoc) getParam(opts, PASSIVE_MODE);
114     }
115
116     /**
117      * use user directory as root (do not change to fs root)
118      *
119      * @param opts
120      * @param userDirIsRoot
121      */

122     public void setUserDirIsRoot(FileSystemOptions opts, boolean userDirIsRoot)
123     {
124         setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
125     }
126
127     /**
128      * @param opts
129      * @return
130      * @see #setUserDirIsRoot
131      */

132     public Boolean JavaDoc getUserDirIsRoot(FileSystemOptions opts)
133     {
134         return (Boolean JavaDoc) getParam(opts, USER_DIR_IS_ROOT);
135     }
136
137     /**
138      * @param opts
139      * @return
140      * @see #setDataTimeout
141      */

142     public Integer JavaDoc getDataTimeout(FileSystemOptions opts)
143     {
144         return (Integer JavaDoc) getParam(opts, DATA_TIMEOUT);
145     }
146
147     /**
148      * set the data timeout for the ftp client.<br />
149      * If you set the dataTimeout to <code>null</code> no dataTimeout will be set on the
150      * ftp client.
151      *
152      * @param opts
153      * @param dataTimeout
154      */

155     public void setDataTimeout(FileSystemOptions opts, Integer JavaDoc dataTimeout)
156     {
157         setParam(opts, DATA_TIMEOUT, dataTimeout);
158     }
159 }
160
Popular Tags