You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ms...@apache.org on 2002/02/12 06:41:59 UTC

cvs commit: jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods SPPropPatchMethod.java SPPutMethod.java

msmith      02/02/11 21:41:59

  Modified:    src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir
                        SPDirectoryService.java SPFile.java
                        SPResourceNode.java SPWebFolder.java
               src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods
                        SPPropPatchMethod.java SPPutMethod.java
  Log:
  More updates (mostly for bugfixes)
  
  Revision  Changes    Path
  1.5       +6 -9      jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPDirectoryService.java
  
  Index: SPDirectoryService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPDirectoryService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SPDirectoryService.java	8 Feb 2002 04:24:05 -0000	1.4
  +++ SPDirectoryService.java	12 Feb 2002 05:41:59 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPDirectoryService.java,v 1.4 2002/02/08 04:24:05 msmith Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/08 04:24:05 $
  + * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPDirectoryService.java,v 1.5 2002/02/12 05:41:59 msmith Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/12 05:41:59 $
    *
    * ====================================================================
    *
  @@ -280,12 +280,9 @@
   	    if (parentDir.hasWriteAccess())   {
   		SPWebFile newNode = new SPWebFile(client,
   		    parentUrlPath+aFile.getName());
  -		int statusCode = newNode.putFileContent("");
  -		if ( statusCode>=200 && statusCode < 300) {
  -		    parentDir.addWebFile(newNode);
  -		    this.fileCache.put(aFile, newNode);
  -		    theNode = (SPResourceNode) newNode;
  -		}
  +	        parentDir.addWebFile(newNode);
  +		this.fileCache.put(aFile, newNode);
  +		theNode = (SPResourceNode) newNode;
   	    } else {
   		throw new HttpException("Write Access Denied in "
   		        +parentUrlPath+" ("+HttpStatus.SC_FORBIDDEN+")");
  
  
  
  1.7       +33 -8     jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPFile.java
  
  Index: SPFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPFile.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SPFile.java	11 Feb 2002 00:20:27 -0000	1.6
  +++ SPFile.java	12 Feb 2002 05:41:59 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPFile.java,v 1.6 2002/02/11 00:20:27 msmith Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/02/11 00:20:27 $
  + * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPFile.java,v 1.7 2002/02/12 05:41:59 msmith Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/02/12 05:41:59 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   
   import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.HttpStatus;
  +import org.apache.commons.httpclient.HttpClient;
   
   /**
    * Title:        SPFile.java
  @@ -141,11 +142,15 @@
        */
   
       public boolean isDirectory() {
  -	if (exists())  {
  -	    return ( getResourceNode().isWebFolder() );
  -	}
  -
  -	return false;
  +        if (_resourceNode!=null)
  +            return _resourceNode.isWebFolder();
  +        else {
  +            SPResourceNode node = directoryService.getNodeFromCache(this);
  +            if(node != null)
  +                return node.isWebFolder();
  +            else
  +                return false;
  +        }
       }
   
       public boolean isFile() {
  @@ -379,6 +384,26 @@
   
       return ( ((SPWebFile)thisNode).putFileContent(fileContent)) ;
   
  +  }
  +
  +  /* FIXME: The method below, that takes only a File object, will create the 
  +     file (doing a PUT of a zero-length object) before putting this file, if
  +     the file doesn't already exist). This is pretty silly behaviour, 
  +     so we want a more intelligent one.
  +     However, this doesn't work right - rather than track it all down for
  +     now, we just call the more inefficient one.
  +   */
  +  public int putWebFileContent(HttpClient client, File aFile) 
  +        throws Exception {
  +      /*
  +      SPResourceNode thisNode = getResourceNode();
  +
  +      if(thisNode == null)
  +          thisNode = new SPWebFile(client, getAbsolutePath());
  +      
  +      return ((SPWebFile)thisNode).putFileContent(aFile);
  +      */
  +      return putWebFileContent(aFile);      
     }
   
     public int putWebFileContent(File aFile) throws Exception  {
  
  
  
  1.5       +77 -58    jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPResourceNode.java
  
  Index: SPResourceNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPResourceNode.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SPResourceNode.java	11 Feb 2002 00:20:27 -0000	1.4
  +++ SPResourceNode.java	12 Feb 2002 05:41:59 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPResourceNode.java,v 1.4 2002/02/11 00:20:27 msmith Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/11 00:20:27 $
  + * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPResourceNode.java,v 1.5 2002/02/12 05:41:59 msmith Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/12 05:41:59 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   import java.util.Vector;
   import java.util.Hashtable;
   import java.util.Enumeration;
  +import java.util.Iterator;
   import java.io.IOException;
   
   import javax.swing.JOptionPane;
  @@ -303,99 +304,116 @@
         return getProperty(propertyName, false);
     }
   
  -  protected boolean shouldFetchProperty(String self, String possible) {
  -      if(self.equals(possible))
  -          return false;
  -      else {
  -          PropertiesCacheEntry prop = (PropertiesCacheEntry)
  -              cachedProperties.get(possible);
  +  public SPProperty getProperty(String property, boolean uncached) {
  +      PropertiesCacheEntry prop = (PropertiesCacheEntry)cachedProperties.
  +          get(property);
   
  -          if(prop != null) {
  -              if(System.currentTimeMillis() - prop.time > 1000*60*5)
  -                  return true;
  -              else
  -                  return false;
  -          }
  -          else
  -              return true;
  +      if(prop != null) {
  +          if(!uncached)
  +              return prop.prop;
  +          else if(System.currentTimeMillis() - prop.time < 1000*60*5)
  +              return prop.prop;
         }
  +
  +      Vector list = new Vector(1);
  +
  +      list.add(property);
  +      fetchProperties(list, uncached);
  +
  +      /* Now it's definately cached (either as a value, or as null indicating
  +       * that it is absent, so look it up.
  +       */
  +      prop = (PropertiesCacheEntry)cachedProperties.get(property);
  +      if(prop != null)
  +          return prop.prop;
  +      else
  +          return null;
     }
   
  +  public void fetchProperties(List properties) {
  +      fetchProperties(properties, false);
  +  }
   
  -  /* if uncached is set, this never comes out of the cache */
  -  public SPProperty getProperty(String propertyName, boolean uncached)  {
  -    PropertiesCacheEntry prop = (PropertiesCacheEntry)cachedProperties.get(
  -            propertyName);
  -
  -    if(prop != null) {
  -        if(!uncached) {
  -            return prop.prop;
  -        }
  +  public void fetchProperties(List properties, boolean uncached) {
  +      Vector propList = new Vector(properties.size());
   
  -        /* Even if an uncached property was requested, if it's less than 5
  -         * minutes old, give them a cached property.
  -         */
  -        long now = System.currentTimeMillis();
  -        if(now - prop.time < 1000*60*5) {
  -            return prop.prop;
  -        }
  +      Iterator i = properties.iterator();
   
  -    }
  +      while(i.hasNext()) {
  +          String propName = (String)i.next();
   
  -    SPPropFindMethod method = new SPPropFindMethod(getClient());
  +          PropertiesCacheEntry prop = (PropertiesCacheEntry)cachedProperties.
  +              get(propName);
   
  -    method.setPath(resourceUrlPath);
  -    method.setDepth(DepthSupport.DEPTH_0);
  +          if(prop == null || (uncached && System.currentTimeMillis() - 
  +                      prop.time > 1000*60*5)) {
  +              propList.add(propName);
  +          }
  +      }
   
  -    Vector propList = new Vector(4);
  -    propList.add(propertyName);
  -    if(shouldFetchProperty(propertyName, "current-user-privilege-set"))
  -        propList.add("current-user-privilege-set");
  -    if(shouldFetchProperty(propertyName, "lockdiscovery"))
  -        propList.add("lockdiscovery");
  +      /* We didn't need to get anything! */
  +      if(propList.size() == 0) {
  +          return;
  +      }
   
  +      /* These are very commonly requested soon after other properties - 
  +         as a simple optimisation, just request these along with others.
  +       */
  +      if(!propList.contains("current-user-privilege-set"))
  +          propList.add("current-user-privilege-set");
  +      if(!propList.contains("lockdiscovery"))
  +          propList.add("lockdiscovery");
  +
  +      SPPropFindMethod method = new SPPropFindMethod(getClient());
   
  -    try {
  +      method.setPath(resourceUrlPath);
  +      method.setDepth(DepthSupport.DEPTH_0);
  +      try {
           method.executeByName(propList.elements());
           int status = method.getStatusCode();
   
           if(status >= 200 && status < 300) {
               Enumeration props = propList.elements();
  -            SPProperty result=null;
   
               while(props.hasMoreElements()) {
                   String propName = (String)props.nextElement();
                   SPProperty spProp = (SPProperty)method.getProperty(propName);
  -                if(propName.equals(propertyName))
  -                    result = spProp;
   
                   if(spProp == null) {
                       cachedProperties.put(propName, 
                               new PropertiesCacheEntry(null));
                   }
  -
  -                System.out.println("Caching property \""+propName+"\"");
  -                cachedProperties.put(propName, 
  -                        new PropertiesCacheEntry(spProp));
  +                else {
  +                    cachedProperties.put(propName, 
  +                            new PropertiesCacheEntry(spProp));
  +                }
  +            }
  +        }
  +        else if(status == 404) {
  +            Enumeration props = propList.elements();
  +            while(props.hasMoreElements()) {
  +                String propName = (String)props.nextElement();
  +                cachedProperties.put(propName, new PropertiesCacheEntry(null));
               }
  -            return result;
           }
           else {
               showErrorMessage("Remote Failure",
  -                    "Unable to fetch property "+propertyName+" on resource "
  -                    +resourceUrlPath);
  -            return null;
  +                    "Unable to fetch properties on resource "
  +                    +resourceUrlPath+ "("+status+")");
           }
  -    } catch(Exception e) {
  -        return null;
  -    }
  +      } catch(Exception e) {
  +          e.printStackTrace();
  +      }
     }
   
  +
     public void setProperties(Enumeration properties) {
         SPPropPatchMethod method = new SPPropPatchMethod(this);
   
  +      System.err.println("Processing list of properties to set...");
         while(properties.hasMoreElements()) {
             SPProperty prop = (SPProperty)properties.nextElement();
  +          System.err.println("Adding property to set: "+prop.getLocalName()+" as value \""+encodeXML(prop.getPropertyAsString())+" with namespace="+prop.getNamespaceURI());
             method.addPropertyToSet(prop.getLocalName(), 
                     encodeXML(prop.getPropertyAsString()),
                     prop.getNamespaceURI(), prop.getNamespaceURI());
  @@ -403,6 +421,7 @@
             cachedProperties.put(prop.getName(), 
                     new PropertiesCacheEntry(prop));
         }
  +      System.err.println("Done processing list of properties to set...");
   
         try {
             method.execute();
  
  
  
  1.8       +5 -5      jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPWebFolder.java
  
  Index: SPWebFolder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPWebFolder.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SPWebFolder.java	11 Feb 2002 00:20:27 -0000	1.7
  +++ SPWebFolder.java	12 Feb 2002 05:41:59 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPWebFolder.java,v 1.7 2002/02/11 00:20:27 msmith Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/02/11 00:20:27 $
  + * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/filechooser/dir/SPWebFolder.java,v 1.8 2002/02/12 05:41:59 msmith Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/02/12 05:41:59 $
    *
    * ====================================================================
    *
  @@ -162,12 +162,12 @@
                 newChild = new SPWebFile(client, url);
             }
             newChild.addCachedProperties(propFindMethod.getResponseProperties(
  -                      url), propList);
  +                      url), (Vector)propList.clone());
             children.add(newChild);
         }
         else {
             this.addCachedProperties(propFindMethod.getResponseProperties(
  -                      url), propList);
  +                      url), (Vector)propList.clone());
         }
   
       }// while (enum...)
  
  
  
  1.3       +19 -3     jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPropPatchMethod.java
  
  Index: SPPropPatchMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPropPatchMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SPPropPatchMethod.java	17 Jul 2001 04:00:50 -0000	1.2
  +++ SPPropPatchMethod.java	12 Feb 2002 05:41:59 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPropPatchMethod.java,v 1.2 2001/07/17 04:00:50 msmith Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/07/17 04:00:50 $
  + * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPropPatchMethod.java,v 1.3 2002/02/12 05:41:59 msmith Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/12 05:41:59 $
    *
    * ====================================================================
    *
  @@ -70,11 +70,13 @@
   
   import org.apache.commons.httpclient.HttpMethod;
   import org.apache.commons.httpclient.HttpClient;
  +import org.apache.commons.httpclient.State;
   
   public class SPPropPatchMethod extends PropPatchMethod
         implements SPWebdavMethod {
   
     HttpClient client;
  +  String lockToken;
   
     public SPPropPatchMethod(HttpClient client)  {
       this.client = client;
  @@ -83,6 +85,7 @@
     public SPPropPatchMethod(SPResourceNode resource)  {
       this.client = resource.getClient();
       setPath(resource.getResourceUrlPath());
  +    lockToken = resource.getCurrentLockToken();
     }
   
     public void setClient(HttpClient client)  {
  @@ -118,6 +121,19 @@
   
     public String toString()	{
       return (new String("PropPatchMethod()"));
  +  }
  +
  +  /**
  +   * Generate additional headers needed by the request.
  +   * Overwrites this inherited function by adding If header
  +   *
  +   * @param host the host
  +   * @param state State token
  +   */
  +  public void generateHeaders(String host, State state) {
  +    super.generateHeaders(host, state);
  +    if(lockToken != null)
  +        setHeader("If", "(<" + lockToken + ">)");
     }
   
   } //End of SPPropPatchMethod class
  
  
  
  1.6       +5 -6      jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPutMethod.java
  
  Index: SPPutMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPutMethod.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SPPutMethod.java	11 Feb 2002 00:20:27 -0000	1.5
  +++ SPPutMethod.java	12 Feb 2002 05:41:59 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPutMethod.java,v 1.5 2002/02/11 00:20:27 msmith Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/02/11 00:20:27 $
  + * $Header: /home/cvs/jakarta-slide/src/contrib/webdavgui/src/java/org/apache/webdav/ui/lib/methods/SPPutMethod.java,v 1.6 2002/02/12 05:41:59 msmith Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/02/12 05:41:59 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,6 @@
         implements SPWebdavMethod {
   
     HttpClient client;
  -  private String lockToken=null;
     protected SPResourceNode resource = null;
   
     public SPPutMethod(HttpClient client)  {
  @@ -135,8 +134,8 @@
      */
     public void generateHeaders(String host, State state) {
       super.generateHeaders(host, state);
  -    if(lockToken != null)
  -        setHeader("If", "(<" + lockToken + ">)");
  +    if(resource.getCurrentLockToken() != null)
  +        setHeader("If", "(<" + resource.getCurrentLockToken() + ">) ");
       setHeader("Content-Type", "text/xml");
     }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>