jvanzyl     01/06/25 22:37:10

  Modified:    src/java/org/apache/turbine/services/xmlrpc/util
                        FileHandler.java
  Log:
  - more decoupling
  - get properties from parent service not from turbine
  
  Revision  Changes    Path
  1.7       +29 -24    
jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/util/FileHandler.java
  
  Index: FileHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/xmlrpc/util/FileHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FileHandler.java  2001/06/14 14:17:53     1.6
  +++ FileHandler.java  2001/06/26 05:37:09     1.7
  @@ -63,12 +63,9 @@
   import java.io.StringWriter;
   
   import javax.mail.internet.MimeUtility;
  +import org.apache.turbine.services.TurbineServices;
  +import org.apache.turbine.services.xmlrpc.XmlRpcService;
   
  -import org.apache.turbine.util.Log;
  -
  -import org.apache.turbine.services.resources.TurbineResources;
  -import org.apache.turbine.services.servlet.TurbineServlet;
  -
   /**
    * A Handler for use with the XML-RPC service that will deal
    * with clients sending file to the server (Turbine application)
  @@ -92,15 +89,19 @@
    * The client must then decode the file contents and write the
    * decoded file contents to disk.
    *
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
    */
   public class FileHandler
   {
  +    protected XmlRpcService service;
  +
       /**
        * Default Constructor
        */
       public FileHandler()
       {
  +        service =  (XmlRpcService)TurbineServices.getInstance()
  +            .getService(XmlRpcService.SERVICE_NAME);
       }
   
       /**
  @@ -185,11 +186,11 @@
        * @param file: path to file to encode.
        * @return String encoded contents of the requested file.
        */
  -    public static String readFileContents(String targetLocationProperty,
  -                                          String fileName)
  +    public String readFileContents(String targetLocationProperty,
  +                                   String fileName)
       {
  -        String file = TurbineServlet.getRealPath(
  -            TurbineResources.getString(targetLocationProperty) +
  +        String file = service.getRealPath(
  +            service.getConfiguration().getString(targetLocationProperty) +
                   "/" + fileName);
   
           try
  @@ -217,16 +218,17 @@
           }
           catch (IOException ioe)
           {
  -            Log.error("[FileHandler] Unable to encode the contents " +
  +            service.getCategory().error(
  +                "[FileHandler] Unable to encode the contents " +
                   "of the request file.", ioe);
   
               return null;
           }
       }
   
  -    public static boolean writeFileContents(String fileContents,
  -                                            String targetLocationProperty,
  -                                            String fileName)
  +    public boolean writeFileContents(String fileContents,
  +                                     String targetLocationProperty,
  +                                     String fileName)
       {
           /*
            * The target location is always within the webapp to
  @@ -235,8 +237,8 @@
            */
   
           File targetLocation = new File(
  -            TurbineServlet.getRealPath(
  -                TurbineResources.getString(
  +            service.getRealPath(
  +                service.getConfiguration().getString(
                       targetLocationProperty)));
   
           if (targetLocation.exists() == false)
  @@ -249,15 +251,17 @@
   
               if (targetLocation.mkdirs() == false)
               {
  -                Log.error("[FileHandler] Could not create target location: " +
  +                service.getCategory().error(
  +                    "[FileHandler] Could not create target location: " +
                       targetLocation + ". Cannot transfer file from client.");
   
                   return false;
               }
               else
               {
  -                Log.info("[FileHandler] Creating target location:" + targetLocation 
+
  -                 " in order to complete file transfer from client.");
  +                service.getCategory().info(
  +                    "[FileHandler] Creating target location:" + targetLocation +
  +                    " in order to complete file transfer from client.");
               }
           }
   
  @@ -284,7 +288,8 @@
           }
           catch (IOException ioe)
           {
  -            Log.error("[FileHandler] Could not write the decoded file " +
  +            service.getCategory().error(
  +                "[FileHandler] Could not write the decoded file " +
                   "contents to disk for the following reason.", ioe);
   
               return false;
  @@ -299,8 +304,8 @@
        * @param sourceLocationProperty
        * @param sourceFileName
        */
  -    public static void remove(String sourceLocationProperty,
  -                              String sourceFileName)
  +    public void remove(String sourceLocationProperty,
  +                       String sourceFileName)
       {
           /*
            * The target location is always within the webapp to
  @@ -309,8 +314,8 @@
            */
   
           File sourceFile = new File(
  -            TurbineServlet.getRealPath(
  -                TurbineResources.getString(sourceLocationProperty) +
  +            service.getRealPath(
  +                service.getConfiguration().getString(sourceLocationProperty) +
                       "/" + sourceFileName));
   
           if (sourceFile.exists())
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to