1 package org.apache.turbine.services.xmlrpc.util;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.util.Vector;
58
59 import java.net.URL;
60
61 import org.apache.turbine.util.Log;
62 import org.apache.turbine.services.xmlrpc.TurbineXmlRpc;
63
64 /***
65 * Test class for FileHandler.
66 *
67 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
68 * @version $Id: FileTransfer.java,v 1.1.1.1 2001/08/16 05:09:28 jvanzyl Exp $
69 */
70 public class FileTransfer
71 {
72 /***
73 * Method to allow a client to send a file to a server.
74 *
75 * @param serverURL
76 * @param sourceLocationProperty
77 * @param sourceFileName
78 * @param destinationLocationProperty
79 * @param destinationFileName
80 */
81 public static void send(String serverURL,
82 String sourceLocationProperty,
83 String sourceFileName,
84 String destinationLocationProperty,
85 String destinationFileName)
86 throws Exception
87 {
88 try
89 {
90 Vector params = new Vector();
91
92 /*
93 * fileContents
94 */
95 params.add(FileHandler.readFileContents(
96 sourceLocationProperty, sourceFileName));
97
98 /*
99 * property in TR.props which refers to the directory
100 * where the fileContents should land.
101 */
102 params.add(destinationLocationProperty);
103
104 /*
105 * name to give the file contents.
106 */
107 params.add(destinationFileName);
108
109 Boolean b = (Boolean) TurbineXmlRpc.executeRpc(
110 new URL (serverURL), "file.send", params);
111
112 }
113 catch (Exception e)
114 {
115 Log.error("Error sending file to server:", e);
116 throw new Exception(e.toString());
117 }
118 }
119
120 /***
121 * Method to allow a client to send a file to a server
122 * that requires a user name and password.
123 *
124 * @param serverURL
125 * @param username
126 * @param password
127 * @param sourceLocationProperty
128 * @param sourceFileName
129 * @param destinationLocationProperty
130 * @param destinationFileName
131 */
132 public static void send(String serverURL,
133 String username,
134 String password,
135 String sourceLocationProperty,
136 String sourceFileName,
137 String destinationLocationProperty,
138 String destinationFileName)
139 throws Exception
140 {
141 try
142 {
143 Vector params = new Vector();
144
145 /*
146 * fileContents
147 */
148 params.add(FileHandler.readFileContents(
149 sourceLocationProperty, sourceFileName));
150
151 /*
152 * property in TR.props which refers to the directory
153 * where the fileContents should land.
154 */
155 params.add(destinationLocationProperty);
156
157 /*
158 * name to give the file contents.
159 */
160 params.add(destinationFileName);
161
162 Boolean b = (Boolean) TurbineXmlRpc.executeAuthenticatedRpc(
163 new URL (serverURL),
164 username,
165 password,
166 "file.send",
167 params);
168
169 }
170 catch (Exception e)
171 {
172 Log.error("Error sending file to server:", e);
173 throw new Exception(e.toString());
174 }
175 }
176
177 /***
178 * Method to allow a client to get a file to a server.
179 *
180 * @param serverURL
181 * @param sourceLocationProperty
182 * @param sourceFileName
183 * @param destinationLocationProperty
184 * @param destinationFileName
185 */
186 public static void get(String serverURL,
187 String sourceLocationProperty,
188 String sourceFileName,
189 String destinationLocationProperty,
190 String destinationFileName)
191 throws Exception
192 {
193
194 try
195 {
196 Vector params = new Vector();
197
198 /*
199 * property in TR.props which refers to the directory
200 * where the fileContents should land.
201 */
202 params.add(sourceLocationProperty);
203
204 /*
205 * name to give the file contents.
206 */
207 params.add(sourceFileName);
208
209 String fileContents = (String) TurbineXmlRpc.executeRpc(
210 new URL (serverURL), "file.get", params);
211
212 /*
213 * Now we have the file contents, we can write
214 * them out to disk.
215 */
216 FileHandler.writeFileContents(fileContents,
217 destinationLocationProperty, destinationFileName);
218 }
219 catch (Exception e)
220 {
221 Log.error("Error getting file from server:", e);
222 throw new Exception(e.toString());
223 }
224 }
225
226 /***
227 * Method to allow a client to get a file from a server
228 * that requires a user name and password.
229 *
230 * @param serverURL
231 * @param username
232 * @param password
233 * @param sourceLocationProperty
234 * @param sourceFileName
235 * @param destinationLocationProperty
236 * @param destinationFileName
237 */
238 public static void get(String serverURL,
239 String username,
240 String password,
241 String sourceLocationProperty,
242 String sourceFileName,
243 String destinationLocationProperty,
244 String destinationFileName)
245 throws Exception
246 {
247
248 try
249 {
250 Vector params = new Vector();
251
252 /*
253 * property in TR.props which refers to the directory
254 * where the fileContents should land.
255 */
256 params.add(sourceLocationProperty);
257
258 /*
259 * name to give the file contents.
260 */
261 params.add(sourceFileName);
262
263 String fileContents = (String) TurbineXmlRpc.executeAuthenticatedRpc(
264 new URL (serverURL),
265 username,
266 password,
267 "file.get",
268 params);
269
270 /*
271 * Now we have the file contents, we can write
272 * them out to disk.
273 */
274 FileHandler.writeFileContents(fileContents,
275 destinationLocationProperty, destinationFileName);
276 }
277 catch (Exception e)
278 {
279 Log.error("Error getting file from server:", e);
280 throw new Exception(e.toString());
281 }
282 }
283
284 /***
285 * Method to allow a client to remove a file from
286 * the server
287 *
288 * @param serverURL
289 * @param sourceLocationProperty
290 * @param sourceFileName
291 */
292 public static void remove(String serverURL,
293 String sourceLocationProperty,
294 String sourceFileName)
295 throws Exception
296 {
297 try
298 {
299 Vector params = new Vector();
300
301 /*
302 * property in TR.props which refers to the directory
303 * where the fileContents should land.
304 */
305 params.add(sourceLocationProperty);
306
307 /*
308 * name to give the file contents.
309 */
310 params.add(sourceFileName);
311
312 TurbineXmlRpc.executeRpc(new URL (serverURL), "file.remove", params);
313 }
314 catch (Exception e)
315 {
316 Log.error("Error removing file from server:", e);
317 throw new Exception(e.toString());
318 }
319 }
320
321 /***
322 * Method to allow a client to remove a file from
323 * a server that requires a user name and password.
324 *
325 * @param serverURL
326 * @param username
327 * @param password
328 * @param sourceLocationProperty
329 * @param sourceFileName
330 */
331 public static void remove(String serverURL,
332 String username,
333 String password,
334 String sourceLocationProperty,
335 String sourceFileName)
336 throws Exception
337 {
338 try
339 {
340 Vector params = new Vector();
341
342 /*
343 * property in TR.props which refers to the directory
344 * where the fileContents should land.
345 */
346 params.add(sourceLocationProperty);
347
348 /*
349 * name to give the file contents.
350 */
351 params.add(sourceFileName);
352
353 TurbineXmlRpc.executeAuthenticatedRpc(new URL (serverURL),
354 username,
355 password,
356 "file.remove",
357 params);
358 }
359 catch (Exception e)
360 {
361 Log.error("Error removing file from server:", e);
362 throw new Exception(e.toString());
363 }
364 }
365 }
This page was automatically generated by Maven