KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > xmlrpc > util > FileTransfer


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

18
19 import java.net.URL JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.turbine.services.xmlrpc.TurbineXmlRpc;
25 import org.apache.turbine.util.TurbineException;
26
27 /**
28  * Test class for FileHandler.
29  *
30  * @deprecated This is not scope of the Service itself but of an
31  * application which uses the service. This class shouldn't
32  * be part of Turbine but of an addon application.
33  * @author <a HREF="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
34  * @version $Id: FileTransfer.java,v 1.7.2.2 2004/05/20 03:06:49 seade Exp $
35  */

36 public class FileTransfer
37 {
38     /** Logging */
39     private static Log log = LogFactory.getLog(FileTransfer.class);
40
41     /**
42      * Method to allow a client to send a file to a server.
43      *
44      * @param serverURL
45      * @param sourceLocationProperty
46      * @param sourceFileName
47      * @param destinationLocationProperty
48      * @param destinationFileName
49      */

50     public static void send(String JavaDoc serverURL,
51                             String JavaDoc sourceLocationProperty,
52                             String JavaDoc sourceFileName,
53                             String JavaDoc destinationLocationProperty,
54                             String JavaDoc destinationFileName)
55             throws TurbineException
56     {
57         try
58         {
59             Vector JavaDoc params = new Vector JavaDoc();
60
61             /*
62              * fileContents
63              */

64             params.add(FileHandler.readFileContents(
65                     sourceLocationProperty, sourceFileName));
66
67             /*
68              * property in TR.props which refers to the directory
69              * where the fileContents should land.
70              */

71             params.add(destinationLocationProperty);
72
73             /*
74              * name to give the file contents.
75              */

76             params.add(destinationFileName);
77
78             Boolean JavaDoc b = (Boolean JavaDoc) TurbineXmlRpc.executeRpc(
79                     new URL JavaDoc(serverURL), "file.send", params);
80
81         }
82         catch (Exception JavaDoc e)
83         {
84             log.error("Error sending file to server:", e);
85             throw new TurbineException(e);
86         }
87     }
88
89     /**
90      * Method to allow a client to send a file to a server
91      * that requires a user name and password.
92      *
93      * @param serverURL
94      * @param username
95      * @param password
96      * @param sourceLocationProperty
97      * @param sourceFileName
98      * @param destinationLocationProperty
99      * @param destinationFileName
100      * @throws TurbineException
101      */

102     public static void send(String JavaDoc serverURL,
103                             String JavaDoc username,
104                             String JavaDoc password,
105                             String JavaDoc sourceLocationProperty,
106                             String JavaDoc sourceFileName,
107                             String JavaDoc destinationLocationProperty,
108                             String JavaDoc destinationFileName)
109             throws TurbineException
110     {
111         try
112         {
113             Vector JavaDoc params = new Vector JavaDoc();
114
115             /*
116              * fileContents
117              */

118             params.add(FileHandler.readFileContents(
119                     sourceLocationProperty, sourceFileName));
120
121             /*
122              * property in TR.props which refers to the directory
123              * where the fileContents should land.
124              */

125             params.add(destinationLocationProperty);
126
127             /*
128              * name to give the file contents.
129              */

130             params.add(destinationFileName);
131
132             Boolean JavaDoc b = (Boolean JavaDoc) TurbineXmlRpc.executeAuthenticatedRpc(
133                     new URL JavaDoc(serverURL),
134                     username,
135                     password,
136                     "file.send",
137                     params);
138
139         }
140         catch (Exception JavaDoc e)
141         {
142             log.error("Error sending file to server:", e);
143             throw new TurbineException(e);
144         }
145     }
146
147     /**
148      * Method to allow a client to get a file to a server.
149      *
150      * @param serverURL
151      * @param sourceLocationProperty
152      * @param sourceFileName
153      * @param destinationLocationProperty
154      * @param destinationFileName
155      * @throws TurbineException
156      */

157     public static void get(String JavaDoc serverURL,
158                            String JavaDoc sourceLocationProperty,
159                            String JavaDoc sourceFileName,
160                            String JavaDoc destinationLocationProperty,
161                            String JavaDoc destinationFileName)
162             throws TurbineException
163     {
164
165         try
166         {
167             Vector JavaDoc params = new Vector JavaDoc();
168
169             /*
170              * property in TR.props which refers to the directory
171              * where the fileContents should land.
172              */

173             params.add(sourceLocationProperty);
174
175             /*
176              * name to give the file contents.
177              */

178             params.add(sourceFileName);
179
180             String JavaDoc fileContents = (String JavaDoc) TurbineXmlRpc.executeRpc(
181                     new URL JavaDoc(serverURL), "file.get", params);
182
183             /*
184              * Now we have the file contents, we can write
185              * them out to disk.
186              */

187             FileHandler.writeFileContents(fileContents,
188                     destinationLocationProperty, destinationFileName);
189         }
190         catch (Exception JavaDoc e)
191         {
192             log.error("Error getting file from server:", e);
193             throw new TurbineException(e);
194         }
195     }
196
197     /**
198      * Method to allow a client to get a file from a server
199      * that requires a user name and password.
200      *
201      * @param serverURL
202      * @param username
203      * @param password
204      * @param sourceLocationProperty
205      * @param sourceFileName
206      * @param destinationLocationProperty
207      * @param destinationFileName
208      */

209     public static void get(String JavaDoc serverURL,
210                            String JavaDoc username,
211                            String JavaDoc password,
212                            String JavaDoc sourceLocationProperty,
213                            String JavaDoc sourceFileName,
214                            String JavaDoc destinationLocationProperty,
215                            String JavaDoc destinationFileName)
216             throws TurbineException
217     {
218
219         try
220         {
221             Vector JavaDoc params = new Vector JavaDoc();
222
223             /*
224              * property in TR.props which refers to the directory
225              * where the fileContents should land.
226              */

227             params.add(sourceLocationProperty);
228
229             /*
230              * name to give the file contents.
231              */

232             params.add(sourceFileName);
233
234             String JavaDoc fileContents = (String JavaDoc) TurbineXmlRpc.executeAuthenticatedRpc(
235                     new URL JavaDoc(serverURL),
236                     username,
237                     password,
238                     "file.get",
239                     params);
240
241             /*
242              * Now we have the file contents, we can write
243              * them out to disk.
244              */

245             FileHandler.writeFileContents(fileContents,
246                     destinationLocationProperty, destinationFileName);
247         }
248         catch (Exception JavaDoc e)
249         {
250             log.error("Error getting file from server:", e);
251             throw new TurbineException(e);
252         }
253     }
254
255     /**
256      * Method to allow a client to remove a file from
257      * the server
258      *
259      * @param serverURL
260      * @param sourceLocationProperty
261      * @param sourceFileName
262      */

263     public static void remove(String JavaDoc serverURL,
264                               String JavaDoc sourceLocationProperty,
265                               String JavaDoc sourceFileName)
266             throws TurbineException
267     {
268         try
269         {
270             Vector JavaDoc params = new Vector JavaDoc();
271
272             /*
273              * property in TR.props which refers to the directory
274              * where the fileContents should land.
275              */

276             params.add(sourceLocationProperty);
277
278             /*
279              * name to give the file contents.
280              */

281             params.add(sourceFileName);
282
283             TurbineXmlRpc.executeRpc(new URL JavaDoc(serverURL), "file.remove", params);
284         }
285         catch (Exception JavaDoc e)
286         {
287             log.error("Error removing file from server:", e);
288             throw new TurbineException(e);
289         }
290     }
291
292     /**
293      * Method to allow a client to remove a file from
294      * a server that requires a user name and password.
295      *
296      * @param serverURL
297      * @param username
298      * @param password
299      * @param sourceLocationProperty
300      * @param sourceFileName
301      */

302     public static void remove(String JavaDoc serverURL,
303                               String JavaDoc username,
304                               String JavaDoc password,
305                               String JavaDoc sourceLocationProperty,
306                               String JavaDoc sourceFileName)
307             throws TurbineException
308     {
309         try
310         {
311             Vector JavaDoc params = new Vector JavaDoc();
312
313             /*
314              * property in TR.props which refers to the directory
315              * where the fileContents should land.
316              */

317             params.add(sourceLocationProperty);
318
319             /*
320              * name to give the file contents.
321              */

322             params.add(sourceFileName);
323
324             TurbineXmlRpc.executeAuthenticatedRpc(new URL JavaDoc(serverURL),
325                     username,
326                     password,
327                     "file.remove",
328                     params);
329         }
330         catch (Exception JavaDoc e)
331         {
332             log.error("Error removing file from server:", e);
333             throw new TurbineException(e);
334         }
335     }
336 }
337
Popular Tags