commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/webdav WebdavFileObject.java
Date Wed, 26 May 2004 08:24:51 GMT
imario      2004/05/26 01:24:51

  Modified:    vfs/src/java/org/apache/commons/vfs/provider/webdav
                        WebdavFileObject.java
  Log:
  report isWriteable,isReadable depending on the possible webdav-options (GET/POST)
  
  Revision  Changes    Path
  1.17      +93 -4     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
  
  Index: WebdavFileObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- WebdavFileObject.java	23 May 2004 18:34:33 -0000	1.16
  +++ WebdavFileObject.java	26 May 2004 08:24:51 -0000	1.17
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2003,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -39,6 +39,8 @@
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Map;
  +import java.util.Set;
  +import java.util.TreeSet;
   
   /**
    * A WebDAV file.
  @@ -53,6 +55,7 @@
       private final WebDavFileSystem fileSystem;
       private WebdavResource resource;
       private boolean redirectionResolved = false;
  +    private Set allowedMethods = null;
       // private HttpURL url;
   
       public WebdavFileObject(final GenericFileName name,
  @@ -77,6 +80,10 @@
       {
           if (resource != null)
           {
  +            // clear cached data
  +            redirectionResolved = false;
  +            allowedMethods = null;
  +
               resource.close();
               resource = null;
           }
  @@ -109,6 +116,8 @@
               {
                   if (status == 401 || status == 403)
                   {
  +                    setAllowedMethods(null);
  +
                       // System.err.println("process on " + System.identityHashCode(this));
                       // permission denied on this object, but we might get some informations
from the parent
                       processParentDavResource();
  @@ -125,6 +134,7 @@
               redirectionResolved = true;
               resource.getHttpURL().setPath(optionsMethod.getPath());
   
  +            setAllowedMethods(optionsMethod.getAllowedMethods());
               boolean exists = false;
               for (Enumeration enum = optionsMethod.getAllowedMethods(); enum.hasMoreElements();)
               {
  @@ -162,6 +172,31 @@
           }
       }
   
  +    private void setAllowedMethods(Enumeration allowedMethods)
  +    {
  +        this.allowedMethods = new TreeSet();
  +
  +        if (allowedMethods == null)
  +        {
  +            return;
  +        }
  +
  +        while (allowedMethods.hasMoreElements())
  +        {
  +            this.allowedMethods.add(allowedMethods.nextElement());
  +        }
  +    }
  +
  +    private boolean hasAllowedMethods(String method) throws IOException
  +    {
  +        if (allowedMethods == null)
  +        {
  +            getAllowedMethods();
  +        }
  +
  +        return allowedMethods.contains(method);
  +    }
  +
       private void resolveRedirection() throws IOException, FileSystemException
       {
           if (redirectionResolved)
  @@ -174,6 +209,7 @@
           final int status = fileSystem.getClient().executeMethod(optionsMethod);
           if (status >= 200 && status <= 299)
           {
  +            setAllowedMethods(optionsMethod.getAllowedMethods());
               resource.getHttpURL().setPath(optionsMethod.getPath());
               redirectionResolved = true;
           }
  @@ -338,6 +374,8 @@
        */
       protected FileObject[] doListChildrenResolved() throws Exception
       {
  +        doAttach();
  +
           WebdavResource[] children = new org.apache.webdav.lib.WebdavResource[0];
           try
           {
  @@ -387,6 +425,9 @@
           {
               throw new FileSystemException("vfs.provider.webdav/create-collection.error",
resource.getStatusMessage());
           }
  +
  +        // reread allowed methods
  +        allowedMethods = null;
       }
   
       /**
  @@ -399,6 +440,9 @@
           {
               throw new FileSystemException("vfs.provider.webdav/delete-file.error", resource.getStatusMessage());
           }
  +
  +        // reread allowed methods
  +        allowedMethods = null;
       }
   
       /**
  @@ -406,11 +450,19 @@
        */
       protected void doRename(FileObject newfile) throws Exception
       {
  +        // final GenericFileName name = (GenericFileName) newfile.getName();
  +        // HttpURL url = new HttpURL(name.getUserName(), name.getPassword(), name.getHostName(),
name.getPort(), newfile.getName().getPath());
  +        // String uri = url.getURI();
  +        // System.err.println(resource.getHttpURL().getPath());
  +
           final boolean ok = resource.moveMethod(newfile.getName().getPath());
           if (!ok)
           {
               throw new FileSystemException("vfs.provider.webdav/rename-file.error", resource.getStatusMessage());
           }
  +
  +        // reread allowed methods
  +        allowedMethods = null;
       }
   
       /**
  @@ -464,6 +516,9 @@
               {
                   throw new FileSystemException("vfs.provider.webdav/write-file.error", resource.getStatusMessage());
               }
  +
  +            // reread allowed methods
  +            allowedMethods = null;
           }
       }
   
  @@ -495,5 +550,39 @@
           }
   
           return attributes;
  +    }
  +
  +    protected boolean doIsReadable() throws Exception
  +    {
  +        return hasAllowedMethods("GET");
  +    }
  +
  +    protected boolean doIsWriteable() throws Exception
  +    {
  +        return hasAllowedMethods("POST");
  +    }
  +
  +    private void getAllowedMethods() throws IOException
  +    {
  +        if (allowedMethods != null)
  +        {
  +            return;
  +        }
  +
  +        final OptionsMethod optionsMethod = new OptionsMethod(getName().getPath());
  +        optionsMethod.setFollowRedirects(true);
  +        final int status = fileSystem.getClient().executeMethod(optionsMethod);
  +        if (status < 200 || status > 299)
  +        {
  +            if (status == 401 || status == 403)
  +            {
  +                setAllowedMethods(null);
  +                return;
  +            }
  +        }
  +
  +        setAllowedMethods(optionsMethod.getAllowedMethods());
  +
  +        return;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message