jericho     01/04/23 01:50:23

  Modified:    src/webdav/client/src/org/apache/webdav/util
                        WebdavResource.java
  Log:
  - Remove the useless UNSET flag for setting properties.
  - Move up the layout for The defaultOwner constant.
  - Add temp directory and disk usage variable and methods thingy
    for the GET method.
  - Rename the getInputStream method to getMethodData.
  - Add the getMethodDataAsString method.
  - Remove the getMethod with arguments of tempDir and filename.
    Instead of this, getMethod(java.io.File) can be used.
  
  Revision  Changes    Path
  1.46      +97 -93    
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java
  
  Index: WebdavResource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- WebdavResource.java       2001/04/22 04:53:13     1.45
  +++ WebdavResource.java       2001/04/23 08:50:20     1.46
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
 1.45 2001/04/22 04:53:13 jericho Exp $
  - * $Revision: 1.45 $
  - * $Date: 2001/04/22 04:53:13 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
 1.46 2001/04/23 08:50:20 jericho Exp $
  + * $Revision: 1.46 $
  + * $Date: 2001/04/23 08:50:20 $
    *
    * ====================================================================
    *
  @@ -231,12 +231,6 @@
   
   
       /**
  -     * No setting to find properties for this resource.
  -     */
  -    private static final int UNSET = 0;
  -    
  -
  -    /**
        * No action to find properties for this resource.
        */
       public static final int NOACTION = 1;
  @@ -267,6 +261,12 @@
   
   
       /**
  +     * Owner information for locking and unlocking.
  +     */
  +    public static final String defaultOwner = "Slide";
  +
  +
  +    /**
        * The true constant string.
        */
       public static final String TRUE = "1";
  @@ -332,6 +332,18 @@
   
   
       /**
  +     * The default temporary directory for the GET method.
  +     */
  +    private static String tempDirForGet;
  +
  +
  +    /**
  +     * The flag setter to use the disk for the GET method.
  +     */
  +    private static boolean useDiskForGet = true;
  +
  +
  +    /**
        * The flag to set the status code by propfind.
        */
       private boolean thisResource;
  @@ -374,12 +386,6 @@
   
   
       /**
  -     * Owner information for locking and unlocking.
  -     */
  -    public static final String defaultOwner = "Slide";
  -
  -
  -    /**
        * An WebDAV property, displayname.
        */
       private String displayName = "";
  @@ -685,6 +691,8 @@
        *  WebdavResource.BASIC
        *  WebdavResource.DEFAULT
        *  WebdavResource.ALL
  +     *
  +     * @param action The action type.
        */
       public static void setDefaultAction(int action) {
           defaultAction = action;
  @@ -693,6 +701,8 @@
   
       /**
        * Get the default action.
  +     *
  +     * @return The action type.
        */
       public static int getDefaultAction() {
           return defaultAction;
  @@ -706,6 +716,8 @@
        *   DepthSupport.DEPTH_0
        *   DepthSupport.DEPTH_1
        *   DepthSupport.DEPTH_INFINITY
  +     *
  +     * @param depth The depth.
        */
       public static void setDefaultDepth(int depth) {
           defaultDepth = depth;
  @@ -714,6 +726,8 @@
   
       /**
        * Get the default action.
  +     *
  +     * @return The depth.
        */
       public static int getDefaultDepth() {
           return defaultDepth;
  @@ -721,6 +735,50 @@
   
   
       /**
  +     * Get the default temporary directory for the GET method.
  +     *
  +     * @param tempDir The temporary directory.
  +     */
  +    public static void setGetTempDir(String tempDir) {
  +        tempDirForGet = tempDir;
  +    }
  +
  +
  +    /**
  +     * Get the default temporary directory for the GET method.
  +     * The default temporary directory is "temp/".
  +     *
  +     * @return The temporary directory path.
  +     *         It's set by default, if it returns null.
  +     */
  +    public static String getGetTempDir() {
  +        return tempDirForGet;
  +    }
  +
  +
  +
  +    /**
  +     * Set the use disk flag for the GET method.
  +     *
  +     * @param useDisk The use disk flag.
  +     */
  +    public static void setGetUseDisk(boolean useDisk) {
  +        useDiskForGet = useDisk;
  +    }
  +
  +
  +    /**
  +     * Get the use disk flag for the GET method.
  +     *
  +     * @return The current flag of the use disk.
  +     *         By default, it's true.
  +     */
  +    public static boolean getGetUseDisk() {
  +        return useDiskForGet;
  +    }
  +
  +
  +    /**
        * Set the HttpURL for this WebdavResource.
        *
        * @param httpURL the specified HttpURL.
  @@ -1237,12 +1295,8 @@
           throws WebdavException, IOException {
   
           switch (action) {
  -        case NOACTION:
  -            break;
           case NAME:
               setNameProperties(depth);
  -        case UNSET:
  -            // Use the basic properties for the performance by default;
           case BASIC:
               setBasicProperties(depth);
               break;
  @@ -1252,8 +1306,9 @@
           case ALL:
               setAllProp(depth);
               break;
  +        case NOACTION:
           default:
  -            throw new IllegalArgumentException("No such action type");
  +            break;
           }
       }
   
  @@ -1504,7 +1559,6 @@
                   // getcontenttype
                   String getContentType =
                       currentResource.getGetContentType();
  -                // iscollection
                   longFormat[2] = resourceTypeProperty.isCollection() ?
                       "COLLECTION" : getContentType ;
                   Date date = new Date(currentResource.getGetLastModified());
  @@ -1550,102 +1604,51 @@
   
   
       /*
  -     * Get InputStream for the GET method and set the temporary directory
  +     * Get InputStream for the GET method.
        *
  -     * @param tempDir
        * @return InputStream
        * @exception WebdavException
        * @exception IOException
        */
  -    public InputStream getInputStream(String tempDir)
  +    public InputStream getMethodData()
           throws WebdavException, IOException {
   
           WebdavClient client = getSessionInstance(httpURL);
   
           // use disk to save by default
  -        GetMethod method = new GetMethod(httpURL.getPath(), tempDir);
  +        GetMethod method = new GetMethod(httpURL.getPath());
  +        method.setUseDisk(useDiskForGet);
  +        if (tempDirForGet != null)
  +            method.setTempDir(tempDirForGet);
           client.setDebug(debug);
           method.setDebug(debug);
           client.executeMethod(method);
  -
  -        InputStream is = method.getData();
   
  -        return is;
  +        return method.getData();
       }
   
   
       /*
  -     * Execute the GET method for this WebdavResource.
  +     * Get data as a String for the GET method.
        *
  -     * @param File source file
  -     * @return true if the method is succeeded.
  -     * @exception WebdavException
  -     */
  -    public boolean getMethod(String tempFile) throws WebdavException {
  -
  -        return getMethod("temp/", tempFile);
  -    }
  -
  -
  -    /*
  -     * Execute the GET method for this WebdavResource.
  -     *
  -     * @param File source file
  -     * @param String tempDir Temporary Directory
  -     * @return true if the method is succeeded.
  +     * @return InputStream
        * @exception WebdavException
  +     * @exception IOException
        */
  -    public boolean getMethod(String tempDir, String tempFile)
  -        throws WebdavException {
  -
  -
  -        InputStream is = null;
  -        FileOutputStream fos = null;
  -        GetMethod method = null;
  -        try {
  -            WebdavClient client = getSessionInstance(httpURL);
  -
  -            // use disk to save by default
  -            String source = httpURL.getPath();
  -            method = new GetMethod(source, tempDir, tempFile);
  -            client.setDebug(debug);
  -            method.setDebug(debug);
  -            client.executeMethod(method);
  -
  -            is = method.getData();
  -
  -            String tempFileName = tempDir + tempFile;
  -            fos = new FileOutputStream(tempFileName);
  -
  -            int nb = 0;
  -            byte[] buffer = new byte[4096];
  -            while ((nb = is.read (buffer)) >= 0) {
  -                fos.write (buffer, 0, nb);
  -            }
  -
  -            fos.flush();
  -
  -        } catch(WebdavException we) {
  -            if (debug > 0)
  -                we.printStackTrace();
  -            throw new WebdavException
  -                (we.getMessage(), method.getStatusCode());
  -        } catch(Exception e) {
  -            if (debug > 0)
  -                e.printStackTrace();
  -        } finally {
  +    public String getMethodDataAsString()
  +        throws WebdavException, IOException {
   
  -            try {
  -                if (is != null) is.close();
  -                if (fos != null) fos.close();
  -            } catch(Exception ignored) {
  -            }
  -        }
  +        WebdavClient client = getSessionInstance(httpURL);
   
  -        int statusCode = method.getStatusCode();
  -        setStatusCode(statusCode);
  +        GetMethod method = new GetMethod(httpURL.getPath());
  +        method.setUseDisk(useDiskForGet);
  +        if (tempDirForGet != null)
  +            method.setTempDir(tempDirForGet);
  +        client.setDebug(debug);
  +        method.setDebug(debug);
  +        client.executeMethod(method);
   
  -        return (statusCode >= 200 && statusCode < 300) ? true : false;
  +        return method.getDataAsString();
       }
   
   
  @@ -1680,6 +1683,7 @@
   
           // use disk to save by default
           GetMethod method = new GetMethod(HttpURL.getPathQuery(path), file);
  +        method.setUseDisk(true);
           client.setDebug(debug);
           method.setDebug(debug);
           client.executeMethod(method);
  
  
  

Reply via email to