Coverage report

  %line %branch
org.apache.turbine.services.xmlrpc.util.FileTransfer
0% 
0% 

 1  
 package org.apache.turbine.services.xmlrpc.util;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 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;
 20  
 import java.util.Vector;
 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 264148 2005-08-29 14:21:04Z henning $
 35  
  */
 36  0
 public class FileTransfer
 37  
 {
 38  
     /** Logging */
 39  0
     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 serverURL,
 51  
                             String sourceLocationProperty,
 52  
                             String sourceFileName,
 53  
                             String destinationLocationProperty,
 54  
                             String destinationFileName)
 55  
             throws TurbineException
 56  
     {
 57  
         try
 58  
         {
 59  0
             Vector params = new Vector();
 60  
 
 61  
             /*
 62  
              * fileContents
 63  
              */
 64  0
             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  0
             params.add(destinationLocationProperty);
 72  
 
 73  
             /*
 74  
              * name to give the file contents.
 75  
              */
 76  0
             params.add(destinationFileName);
 77  
 
 78  0
             Boolean b = (Boolean) TurbineXmlRpc.executeRpc(
 79  
                     new URL(serverURL), "file.send", params);
 80  
 
 81  
         }
 82  0
         catch (Exception e)
 83  
         {
 84  0
             log.error("Error sending file to server:", e);
 85  0
             throw new TurbineException(e);
 86  0
         }
 87  0
     }
 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 serverURL,
 103  
                             String username,
 104  
                             String password,
 105  
                             String sourceLocationProperty,
 106  
                             String sourceFileName,
 107  
                             String destinationLocationProperty,
 108  
                             String destinationFileName)
 109  
             throws TurbineException
 110  
     {
 111  
         try
 112  
         {
 113  0
             Vector params = new Vector();
 114  
 
 115  
             /*
 116  
              * fileContents
 117  
              */
 118  0
             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  0
             params.add(destinationLocationProperty);
 126  
 
 127  
             /*
 128  
              * name to give the file contents.
 129  
              */
 130  0
             params.add(destinationFileName);
 131  
 
 132  0
             Boolean b = (Boolean) TurbineXmlRpc.executeAuthenticatedRpc(
 133  
                     new URL(serverURL),
 134  
                     username,
 135  
                     password,
 136  
                     "file.send",
 137  
                     params);
 138  
 
 139  
         }
 140  0
         catch (Exception e)
 141  
         {
 142  0
             log.error("Error sending file to server:", e);
 143  0
             throw new TurbineException(e);
 144  0
         }
 145  0
     }
 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 serverURL,
 158  
                            String sourceLocationProperty,
 159  
                            String sourceFileName,
 160  
                            String destinationLocationProperty,
 161  
                            String destinationFileName)
 162  
             throws TurbineException
 163  
     {
 164  
 
 165  
         try
 166  
         {
 167  0
             Vector params = new Vector();
 168  
 
 169  
             /*
 170  
              * property in TR.props which refers to the directory
 171  
              * where the fileContents should land.
 172  
              */
 173  0
             params.add(sourceLocationProperty);
 174  
 
 175  
             /*
 176  
              * name to give the file contents.
 177  
              */
 178  0
             params.add(sourceFileName);
 179  
 
 180  0
             String fileContents = (String) TurbineXmlRpc.executeRpc(
 181  
                     new URL(serverURL), "file.get", params);
 182  
 
 183  
             /*
 184  
              * Now we have the file contents, we can write
 185  
              * them out to disk.
 186  
              */
 187  0
             FileHandler.writeFileContents(fileContents,
 188  
                     destinationLocationProperty, destinationFileName);
 189  
         }
 190  0
         catch (Exception e)
 191  
         {
 192  0
             log.error("Error getting file from server:", e);
 193  0
             throw new TurbineException(e);
 194  0
         }
 195  0
     }
 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 serverURL,
 210  
                            String username,
 211  
                            String password,
 212  
                            String sourceLocationProperty,
 213  
                            String sourceFileName,
 214  
                            String destinationLocationProperty,
 215  
                            String destinationFileName)
 216  
             throws TurbineException
 217  
     {
 218  
 
 219  
         try
 220  
         {
 221  0
             Vector params = new Vector();
 222  
 
 223  
             /*
 224  
              * property in TR.props which refers to the directory
 225  
              * where the fileContents should land.
 226  
              */
 227  0
             params.add(sourceLocationProperty);
 228  
 
 229  
             /*
 230  
              * name to give the file contents.
 231  
              */
 232  0
             params.add(sourceFileName);
 233  
 
 234  0
             String fileContents = (String) TurbineXmlRpc.executeAuthenticatedRpc(
 235  
                     new URL(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  0
             FileHandler.writeFileContents(fileContents,
 246  
                     destinationLocationProperty, destinationFileName);
 247  
         }
 248  0
         catch (Exception e)
 249  
         {
 250  0
             log.error("Error getting file from server:", e);
 251  0
             throw new TurbineException(e);
 252  0
         }
 253  0
     }
 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 serverURL,
 264  
                               String sourceLocationProperty,
 265  
                               String sourceFileName)
 266  
             throws TurbineException
 267  
     {
 268  
         try
 269  
         {
 270  0
             Vector params = new Vector();
 271  
 
 272  
             /*
 273  
              * property in TR.props which refers to the directory
 274  
              * where the fileContents should land.
 275  
              */
 276  0
             params.add(sourceLocationProperty);
 277  
 
 278  
             /*
 279  
              * name to give the file contents.
 280  
              */
 281  0
             params.add(sourceFileName);
 282  
 
 283  0
             TurbineXmlRpc.executeRpc(new URL(serverURL), "file.remove", params);
 284  
         }
 285  0
         catch (Exception e)
 286  
         {
 287  0
             log.error("Error removing file from server:", e);
 288  0
             throw new TurbineException(e);
 289  0
         }
 290  0
     }
 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 serverURL,
 303  
                               String username,
 304  
                               String password,
 305  
                               String sourceLocationProperty,
 306  
                               String sourceFileName)
 307  
             throws TurbineException
 308  
     {
 309  
         try
 310  
         {
 311  0
             Vector params = new Vector();
 312  
 
 313  
             /*
 314  
              * property in TR.props which refers to the directory
 315  
              * where the fileContents should land.
 316  
              */
 317  0
             params.add(sourceLocationProperty);
 318  
 
 319  
             /*
 320  
              * name to give the file contents.
 321  
              */
 322  0
             params.add(sourceFileName);
 323  
 
 324  0
             TurbineXmlRpc.executeAuthenticatedRpc(new URL(serverURL),
 325  
                     username,
 326  
                     password,
 327  
                     "file.remove",
 328  
                     params);
 329  
         }
 330  0
         catch (Exception e)
 331  
         {
 332  0
             log.error("Error removing file from server:", e);
 333  0
             throw new TurbineException(e);
 334  0
         }
 335  0
     }
 336  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.