remm        01/09/01 19:40:42

  Added:       src/webdav/client/src/org/apache/webdav/lib WebdavFile.java
  Log:
  - Add a File wrapper to WebdavResource.
  - Most of the Java 2 calls are not implemented at the moment.
  - The constructors will very likely change to match the constructors in the
    standard File class.
  
  Revision  Changes    Path
  1.1                  
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavFile.java
  
  Index: WebdavFile.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavFile.java,v 
1.1 2001/09/02 02:40:42 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2001/09/02 02:40:42 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.webdav.lib;
  
  import java.io.File;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.FilenameFilter;
  import java.io.FileFilter;
  import java.util.Vector;
  import java.util.Hashtable;
  import java.util.Enumeration;
  import java.net.URL;
  import java.net.MalformedURLException;
  
  import org.apache.commons.httpclient.HttpException;
  import org.apache.commons.httpclient.HttpStatus;
  
  /**
   * File abstraction for a Webdav resource.
   * 
   * @author Remy Maucherat
   */
  public class WebdavFile extends File {
  
  
      // ----------------------------------------------------------  Constructors
  
  
      public WebdavFile(WebdavResource resource) {
          super(resource.getHttpURL().getPath());
          this.resource = resource;
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      WebdavResource resource = null;
  
  
      // ----------------------------------------------------------- File Methods
  
  
      public String getName() {
          return resource.getHttpURL().getName();
      }
  
  
      public String getParent() {
          return resource.getHttpURL().getParent();
      }
  
  
      public File getParentFile() {
          // FIXME
          return null;
      }
  
  
      public String getPath() {
          return resource.getHttpURL().getPath();
      }
  
  
      public boolean isAbsolute() {
          return true;
      }
  
  
      public String getAbsolutePath() {
          return resource.getHttpURL().getPath();
      }
  
  
      public File getAbsoluteFile() {
          // FIXME
          return null;
      }
  
  
      public String getCanonicalPath()
          throws IOException {
          return resource.getHttpURL().getPath();
      }
  
  
      public File getCanonicalFile()
          throws IOException {
          // FIXME
          return null;
      }
  
  
      public URL toURL()
          throws MalformedURLException {
          return resource.getHttpURL().toURL();
      }
  
  
      public boolean canRead() {
          // FIXME: Also check permissions
          return resource.exists() && !resource.isCollection();
      }
  
  
      public boolean canWrite() {
          // FIXME: Also check permissions
          return resource.exists() && !resource.isCollection();
      }
  
  
      public boolean exists() {
          return resource.exists();
      }
  
  
      public boolean isDirectory() {
          return resource.isCollection();
      }
  
  
      public boolean isFile() {
          return !resource.isCollection();
      }
  
  
      public boolean isHidden() {
          return false;
      }
  
  
      public long lastModified() {
          return resource.getGetLastModified();
      }
  
  
      public long length() {
          return resource.getGetContentLength();
      }
  
  
      public boolean createNewFile()
          throws IOException {
          try {
              return resource.lockMethod();
          } catch (Exception e) {
              return false;
          }
      }
  
  
      public boolean delete() {
          try {
              return resource.deleteMethod();
          } catch (Exception e) {
              return false;
          }
      }
  
  
      public void deleteOnExit() {
          // FIXME
          // Delete when finalizing ?
      }
  
  
      public String[] list() {
          return resource.list();
      }
  
  
      public String[] list(FilenameFilter filter) {
          // FIXME
          return null;
      }
  
  
      public File[] listFiles() {
          // FIXME
          return null;
      }
  
  
      public File[] listFiles(FilenameFilter filter) {
          // FIXME
          return null;
      }
  
  
      public File[] listFiles(FileFilter filter) {
          // FIXME
          return null;
      }
  
  
      public boolean mkdir() {
          try {
              return resource.mkcolMethod();
          } catch (Exception e) {
              return false;
          }
      }
  
  
      public boolean mkdirs() {
          try {
              return resource.mkcolMethod();
          } catch (Exception e) {
              return false;
          }
      }
  
  
      public boolean renameTo(File dest) {
          try {
              return resource.moveMethod(dest.getPath());
          } catch (Exception e) {
              return false;
          }
      }
  
  
      public boolean setLastModified(long time) {
          // FIXME ?
          // I don't remember seeing the possibility of doing a touch with WebDAV
          return false;
      }
  
  
      public boolean setReadOnly() {
          return false;
      }
  
  
      public int compareTo(File pathname) {
          // FIXME
          return 1;
      }
  
  
      public int compareTo(Object o) {
          return 1;
      }
  
  
      public boolean equals(Object obj) {
          return false;
      }
  
  
      public int hashCode() {
          return getPath().hashCode();
      }
  
  
      public String toString() {
          return resource.getHttpURL().toString();
      }
  
  
  }
  
  
  
  
  

Reply via email to