remm        02/01/02 09:57:41

  Modified:    src/webdav/client/src/org/apache/webdav/lib WebdavFile.java
  Added:       src/webdav/client/src/org/apache/webdav/lib
                        WebdavException.java
               src/webdav/client/src/org/apache/webdav/ui
                        WebdavSystemView.java WebdavView.java
  Log:
  - Add WebDAV file implementation and its associated Swing view helper.
  - Code submitted by Eckard Buchner <ebuchner at web.de>
  
  Revision  Changes    Path
  1.2       +447 -252  
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavFile.java
  
  Index: WebdavFile.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavFile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebdavFile.java   2 Sep 2001 02:40:42 -0000       1.1
  +++ WebdavFile.java   2 Jan 2002 17:57:41 -0000       1.2
  @@ -1,13 +1,13 @@
   /*
  - * $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 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavFile.java,v 
1.2 2002/01/02 17:57:41 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/01/02 17:57:41 $
    *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    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
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    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 
  + *    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"
  @@ -59,267 +59,462 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   package org.apache.webdav.lib;
   
   import java.io.File;
  -import java.io.InputStream;
  +import org.apache.util.HttpURL;
  +import java.net.URL;
  +import java.net.MalformedURLException;
  +import org.apache.webdav.lib.WebdavResource;
   import java.io.IOException;
  +import org.apache.commons.httpclient.HttpException;
  +import java.util.List;
   import java.io.FilenameFilter;
  +import java.util.ArrayList;
  +import java.util.Iterator;
   import java.io.FileFilter;
  -import java.util.Vector;
  -import java.util.Hashtable;
  +import java.util.ResourceBundle;
   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.
  + * Implements a file for WebDav
    * 
  - * @author Remy Maucherat
  + * @author Eckard Buchner
    */
   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
  +  /** Directory separator */
  +  public static final char davSeparatorChar = '/';
  +  /** Directory separator */
  +  public static final String davSeparator = String.valueOf(davSeparatorChar);
  +
  +  // WebdavFile may be absolute or relative
  +  private HttpURL httpUrl = null;
  +  private String relPath = null;
  +
  +  /**
  +   * @param parent directory
  +   * @param child element in parent
  +   */
  +  public WebdavFile(WebdavFile parent, String child) throws MalformedURLException {
  +    this(
  +      parent.getAbsolutePath() + davSeparator + child,
  +      parent.getUser(),
  +      parent.getPass()
  +    );
  +  }
  +
  +  /**
  +   * @param pathname complete path to element
  +   * @param user user name
  +   * @param pass password
  +   */
  +  public WebdavFile(String pathname, String user, String pass) throws 
MalformedURLException {
  +    this(new URL(pathname), user, pass);
  +  }
  +
  +  /**
  +   * @param url file url
  +   * @param user user name
  +   * @param pass password
  +   */
  +  public WebdavFile(URL url, String user, String pass) throws MalformedURLException 
{
  +    this(new HttpURL(user, pass, url.getHost(), url.getPort(), url.getPath()));
  +  }
  +  /**
  +   * @param parent parent name
  +   * @param child name of element in parent
  +   * @param user user name
  +   * @param pass password
  +   */
  +  public WebdavFile(String parent, String child, String user, String pass) throws 
MalformedURLException {
  +    this(parent + davSeparator + child, user, pass);
  +  }
  +
  +  /**
  +   * @param httpUrl Webdav URL
  +   */
  +  public WebdavFile(HttpURL httpUrl) {
  +    super(httpUrl.getUnescapedHttpURL());
  +    this.httpUrl = httpUrl;
  +  }
  +
  +  /**
  +   * A WebdavFile with a relative file. Hence nobody keeps track
  +   * of a "working directory" the resulting object is only
  +   * a container for a String (pathname). You cannot do anything
  +   * usefull with an instance created this way
  +   */
  +  public WebdavFile(String aPath) {
  +    super(aPath);
  +    relPath = aPath;
  +  }
  +
  +  private WebdavResource createRes() {
  +    try {
  +      if(httpUrl==null)
  +        throw new WebdavException(WebdavException.RELATIVE_FILE);
  +      return new WebdavResource(httpUrl);
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    }
  +  }
  +
  +  private void closeRes(WebdavResource res) {
  +    try {
  +      if(res!=null)
  +        res.close();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    }
  +  }
  +
  +  private File [] toFileArray(List fileList) {
  +    File files [] = new File [fileList.size()];
  +    Iterator it = fileList.iterator();
  +    for(int i=0; i<files.length; i++)
  +      files[i] = (WebdavFile)it.next();
  +    return files;
  +  }
  +
  +  public String getUser() throws MalformedURLException {
  +    if(relPath!=null)
  +      return null;
  +    return httpUrl.getUserName();
  +  }
  +
  +  public String getPass() throws MalformedURLException {
  +    if(relPath!=null)
  +      return null;
  +    return httpUrl.getPassword();
  +  }
  +
  +  public String getName() {
  +    if(relPath!=null)
  +      return relPath;
  +    return httpUrl.getName();
  +  }
  +
  +  public String getParent() {
  +    if(relPath!=null)
  +      return null;
  +    String parent = httpUrl.getParent();
  +    if("/".equals(parent))
  +      return null;
  +    return parent;
  +  }
  +
  +  public File getParentFile() {
  +    String parent = getParent();
  +    if(parent==null)
  +      return null;
  +
  +    try {
  +      return new WebdavFile(getParent(), getUser(), getPass());
  +    } catch(MalformedURLException e) {
  +      throw new WebdavException(e);
  +    }
  +  }
  +
  +  public String getPath() {
  +    if(relPath!=null)
  +      return relPath;
  +    return httpUrl.getUnescapedHttpURL();
  +  }
  +
  +  public boolean isAbsolute() {
  +    return relPath==null;
  +  }
  +
  +  public String getAbsolutePath() {
  +    return getPath();
  +  }
  +
  +  public File getAbsoluteFile() {
  +    return this;
  +  }
  +
  +  public String getCanonicalPath() {
  +    return getPath();
  +  }
  +
  +  public File getCanonicalFile() {
  +    return this;
  +  }
  +
  +  public URL toURL() throws MalformedURLException {
  +    if(relPath!=null)
  +      return null;
  +    return httpUrl.toURL();
  +  }
  +
  +  public boolean canRead() {
  +    return true;
  +  }
  +
  +  public boolean canWrite() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return !res.isLocked();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean exists() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.exists();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean isDirectory() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.isCollection();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean isFile() {
  +    return !isDirectory();
  +  }
  +
  +  public boolean isHidden() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.getIsHidden();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public long lastModified() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.getGetLastModified();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public long length() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.getGetContentLength();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean createNewFile() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.putMethod("");
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean delete() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.deleteMethod();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public void deleteOnExit() {
  +    throw new WebdavException(WebdavException.NOT_IMPLEMENTED);
  +  }
  +
  +  public String[] list() {
  +    return list(null);
  +  }
  +
  +  public String[] list(FilenameFilter filter) {
  +    File [] files = listFiles(filter);
  +    String [] names = new String[files.length];
  +    for(int i=0; i<names.length; i++)
  +      names[i] = files[i].getAbsolutePath();
  +
  +    return names;
  +  }
  +
  +  public File [] listFiles() {
  +    return listFiles((FilenameFilter)null);
  +  }
  +
  +  public File [] listFiles(FilenameFilter filter) {
  +
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      WebdavResource allFiles [] = res.listWebdavResources();
  +      if(allFiles==null)
           return null;
  -    }
  -
   
  -    public File[] listFiles(FileFilter filter) {
  -        // FIXME
  +      ArrayList filtered = new ArrayList();
  +      for(int i=0; i<allFiles.length; i++) {
  +        if(filter==null || filter.accept(this, allFiles[i].getDisplayName()))
  +          filtered.add( new WebdavFile(allFiles[i].getHttpURL()) );
  +      }
  +
  +      return toFileArray(filtered);
  +
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public File [] listFiles(FileFilter filter) {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      WebdavResource allFiles [] = res.listWebdavResources();
  +      if(allFiles==null)
           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();
  -    }
  -
   
  +      ArrayList filtered = new ArrayList();
  +      for(int i=0; i<allFiles.length; i++) {
  +        WebdavFile file = new WebdavFile(allFiles[i].getHttpURL());
  +        if(filter==null || filter.accept(file))
  +          filtered.add(file);
  +      }
  +
  +      return toFileArray(filtered);
  +
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean mkdir() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.mkcolMethod();
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean mkdirs() {
  +    return mkdir();
  +  }
  +
  +  public boolean renameTo(File dest) {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      return res.moveMethod(dest.getAbsolutePath());
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  public boolean setLastModified(long time) {
  +    throw new WebdavException(WebdavException.NOT_IMPLEMENTED);
  +  }
  +
  +  public boolean setReadOnly() {
  +    WebdavResource res = null;
  +    try {
  +      res = createRes();
  +      res.setOverwrite(false);
  +      return true;
  +    } catch(Exception e) {
  +      throw new WebdavException(e);
  +    } finally {
  +      closeRes(res);
  +    }
  +  }
  +
  +  /** @todo */
  +  public static File[] listRoots() {
  +    throw new WebdavException(WebdavException.NOT_IMPLEMENTED);
  +  }
  +
  +  /** @todo */
  +  public static File createTempFile(String prefix, String suffix, File directory) {
  +    throw new WebdavException(WebdavException.NOT_IMPLEMENTED);
  +  }
  +
  +  /** @todo */
  +  public static File createTempFile(String prefix, String suffix) {
  +    return WebdavFile.createTempFile(prefix, suffix, null);
  +  }
  +
  +  public String toString() {
  +    if(relPath!=null)
  +      return relPath;
  +    return httpUrl.getUnescapedHttpURL();
  +  }
  +
  +  public int compareTo(File pathname) {
  +    if(pathname instanceof WebdavFile) {
  +      WebdavFile df = (WebdavFile)pathname;
  +      return df.getPath().compareTo(getPath());
  +    }
  +    return -1;
  +  }
  +
  +  public int compareTo(Object o) {
  +    return compareTo((File)o);
  +  }
  +
  +  public boolean equals(Object x) {
  +    if(x==null)
  +      return false;
  +
  +    if(x instanceof WebdavFile) {
  +      WebdavFile xf = (WebdavFile)x;
  +      return xf.getPath().equals(getPath());
  +    }
  +
  +    return false;
  +  }
  +
  +  public int hashCode() {
  +    return getPath().hashCode();
  +  }
   }
  -
   
  
  
  
  1.6       +18 -72    
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavException.java
  
  
  
  
  1.1                  
jakarta-slide/src/webdav/client/src/org/apache/webdav/ui/WebdavSystemView.java
  
  Index: WebdavSystemView.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/ui/WebdavSystemView.java,v
 1.1 2002/01/02 17:57:41 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2002/01/02 17:57:41 $
   *
   * ====================================================================
   *
   * 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.ui;
  
  import javax.swing.filechooser.FileSystemView;
  import java.io.File;
  import java.net.MalformedURLException;
  import java.util.List;
  import java.util.Iterator;
  import org.apache.util.HttpURL;
  import org.apache.webdav.lib.WebdavFile;
  import org.apache.webdav.lib.WebdavException;
  import javax.swing.plaf.metal.MetalFileChooserUI;
  
  /**
   * Webdav View that behaves like a javax.swing.filechoose.FileSystemView
   * 
   * @author Eckard Buchner
   */
  public class WebdavSystemView extends FileSystemView {
  
    /** Default root (Uses tomcat's http://localhost:8080/webdav) */
    public static final String DEFAULT_ROOT = "http://localhost:8080/webdav";;
    /** Default user (tomcat) */
    public static final String DEFAULT_USER = "tomcat";
    /** Default password (tomcat) */
    public static final String DEFAULT_PASS = "tomcat";
  
    /** Default Name of a new Folder */
    public static final String NEW_FOLDER_NAME = "New Folder";
  
    private WebdavFile [] roots;
  
    /**
     * Constructor (Debug only: Uses tomcat's http://localhost:8080/webdav
     */
    public WebdavSystemView() {
      this(DEFAULT_ROOT, DEFAULT_USER, DEFAULT_PASS);
    }
  
    /**
     * @param rootUrl URL of a Webdav enabled server
     * @param user null or user name
     * @param pass password
     */
    public WebdavSystemView(String rootUrl, String user, String pass) {
      try {
        roots = new WebdavFile[] {new WebdavFile(rootUrl, user, pass)};
      } catch(MalformedURLException mue) {
        throw new IllegalArgumentException(mue.toString());
      }
    }
  
    /**
     * @param rootUrls HttpURLs auf Webdav enabled servers
     */
    public WebdavSystemView(HttpURL [] rootUrls) {
      roots = new WebdavFile[rootUrls.length];
      for(int i=0; i<rootUrls.length; i++)
        roots[i] = new WebdavFile(rootUrls[i]);
    }
  
    /**
     * Default-Webdav View
     */
    public static FileSystemView getFileSystemView() {
      return new WebdavSystemView();
    }
  
    /**
     * Determines if the given file is a root partition or drive
     */
    public boolean isRoot(File f) {
      boolean isRoot = false;
      for(int i=0; i<roots.length; i++) {
        if(roots[i].equals(f))
          isRoot = true;
      }
      return isRoot;
    }
  
    /**
     * creates a new folder with a default folder name
     */
    public File createNewFolder(File containingDir) {
      try {
        WebdavFile newDir = new WebdavFile((WebdavFile)containingDir, NEW_FOLDER_NAME);
        newDir.mkdir();
        return newDir;
      } catch(MalformedURLException mue) {
        throw new IllegalArgumentException(mue.toString());
      }
    }
  
    /**
     * Returns whether a file is hidden or not.
     */
    public boolean isHiddenFile(File f) {
      return f.isHidden();
    }
  
    /**
     * Returns all root partitions on this system
     */
    public File[] getRoots() {
      return roots;
    }
  
    /**
     * By default the first root URL is the home directory
     */
    public File getHomeDirectory() {
      return roots[0];
    }
  
    /**
     * Returns a File object constructed in dir from the given filename
     */
    public File createFileObject(File dir, String filename) {
      try {
        return new WebdavFile((WebdavFile)dir, filename);
      } catch(MalformedURLException mue) {
        throw new IllegalArgumentException(mue.toString());
      }
    }
  
    /**
     * Returns a File object constructed from the given path string.
     */
    public File createFileObject(String path) {
      // remove trailing slash
      if(path.endsWith("/"))
        path = path.substring(0, path.length()-1);
  
      try {
        for(int i=0; i<roots.length; i++) {
  
          // Test full qualified path http://user:pass@host:port/root
          String fullRoot = roots[i].getAbsolutePath();
          if(path.startsWith(fullRoot))
            return new WebdavFile(path, roots[i].getUser(), roots[i].getPass());
  
          // Test "/"+root-name
          String rootName = roots[i].getName();
          if(path.startsWith("/"+rootName)) {
            // Eliminate "/"+root-name from path
            path = path.substring(rootName.length()+1);
            // Eliminate next slash (if any) to get a relative path
            if(path.startsWith("/"))
              path = path.substring(1);
            // Anything left?
            if(path.length()==0)
              return roots[i];
            // Build file from root + path
            return new WebdavFile(fullRoot, path, roots[i].getUser(), 
roots[i].getPass());
          }
        }
        // relative URL?
        return new WebdavFile(path);
  
      } catch(MalformedURLException mue) {
        throw new IllegalArgumentException(mue.toString());
      }
    }
  
    /**
     * gets the list of files
     * @todo param useFileHiding
     */
    public File[] getFiles(File dir, boolean useFileHiding) {
     return dir.listFiles();
    }
  }
  
  
  
  1.1                  
jakarta-slide/src/webdav/client/src/org/apache/webdav/ui/WebdavView.java
  
  Index: WebdavView.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/ui/WebdavView.java,v 
1.1 2002/01/02 17:57:41 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2002/01/02 17:57:41 $
   *
   * ====================================================================
   *
   * 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.ui;
  
  import java.io.File;
  import javax.swing.filechooser.FileView;
  
  /**
   * Used in JFileChooser to display Webdav elements
   * 
   * @author Eckard Buchner
   */
  public class WebdavView extends FileView {
  
    public WebdavView() {
    }
  
    public String getName(File f) {
      return f.getName();
    }
  }
  
  
  

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

Reply via email to