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 je...@apache.org on 2001/04/11 18:03:57 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/util WebdavSession.java WebdavResource.java

jericho     01/04/11 09:03:57

  Modified:    src/webdav/client/src/org/apache/webdav/util
                        WebdavSession.java WebdavResource.java
  Log:
  - Subclassing for events processing.
  - Changed to the not static methods.
  
  Revision  Changes    Path
  1.2       +85 -32    jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavSession.java
  
  Index: WebdavSession.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavSession.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebdavSession.java	2001/03/08 08:19:04	1.1
  +++ WebdavSession.java	2001/04/11 16:03:55	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavSession.java,v 1.1 2001/03/08 08:19:04 jericho Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/03/08 08:19:04 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavSession.java,v 1.2 2001/04/11 16:03:55 jericho Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/04/11 16:03:55 $
    *
    * ====================================================================
    *
  @@ -70,6 +70,9 @@
   import java.net.MalformedURLException;
   import org.apache.webdav.lib.WebdavClient;
   import org.apache.webdav.lib.Credentials;
  +import org.apache.webdav.lib.ProgressUtil;
  +import org.apache.webdav.lib.ProgressEvent;
  +import org.apache.webdav.lib.ProgressListener;
   
   /**
    *
  @@ -78,15 +81,29 @@
    *
    * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
    */
  -public class WebdavSession {
  +public class WebdavSession implements ProgressListener {
   
  +    // ---------------------------------------------------- Instance Variables
   
  +
       /**
  -     * Infomation hashtable for WebDAV clients for HTTP/1.1 communication.
  +     * Infomation hashtable for WebDAV clients  HTTP/1.1 communication.
        */
       private static Hashtable clientInfo = new Hashtable();
   
   
  +    /**
  +     * The session progress.
  +     */
  +    private ProgressUtil sessionProgress = new ProgressUtil();
  +
  +
  +    /**
  +     * To debug.
  +     */
  +    private int debug = 0;
  +
  +
       // ------------------------------------------------------  Public methods
   
   
  @@ -95,25 +112,27 @@
        * If the same authority is requested, the method returns the same client.
        * Otherwise, the method returns a new client instance.
        *
  -     * @param httpUrl The HTTP URL to connect.  only used the authority part.
  +     * @param httpURL The http URL to connect.  only used the authority part.
        * @return An instance of <code>WebdavClient</code>.
        * @exception IOException
        */
  -    public static WebdavClient getSessionInstance(HttpURL httpUrl)
  +    public WebdavClient getSessionInstance(HttpURL httpURL)
           throws IOException {
   
  -        String authority = httpUrl.getAuthority();
  +        String authority = httpURL.getAuthority();
           WebdavClient client = (WebdavClient) clientInfo.get(authority);
           // setting for the first time.
           if (client == null) {
  -            client = new WebdavClient(httpUrl.toURL());
  +            client = new WebdavClient(httpURL.toURL());
   
  -            String userName = httpUrl.getUserName();
  +            String userName = httpURL.getUserName();
               if (userName != null && userName.length() > 0) {
  -                String password = httpUrl.getPassword();
  +                String password = httpURL.getPassword();
                   client.setCredentials(new Credentials(userName, password));
               }
           }
  +        client.getProgressUtil().addProgressListener(this);
  +        setSession(httpURL, client);
   
           return client;
       }
  @@ -128,12 +147,12 @@
        * @return An instance of <code>WebdavClient</code>.
        * @exception IOException
        */
  -    public static WebdavClient getSessionInstance(String authority)
  +    public WebdavClient getSessionInstance(String authority)
           throws IOException {
   
  -        HttpURL httpUrl = new HttpURL(authority);
  +        HttpURL httpURL = new HttpURL(authority);
   
  -        return getSessionInstance(httpUrl);
  +        return getSessionInstance(httpURL);
       }
   
   
  @@ -141,14 +160,14 @@
        * Seek a <code>WebdavClient</code> instance.
        * If the return value is null, there is no instance.
        *
  -     * @param httpUrl The http URL to connect. only used the authority part.
  +     * @param httpURL The http URL to connect. only used the authority part.
        * @return An instance of <code>WebdavClient</code>.
        * @exception MalformedURLException
        */
  -    public static WebdavClient seekSession(HttpURL httpUrl)
  +    public WebdavClient seekSession(HttpURL httpURL)
           throws MalformedURLException {
   
  -        String authority = httpUrl.getAuthority();
  +        String authority = httpURL.getAuthority();
           WebdavClient client = (WebdavClient) clientInfo.get(authority);
   
           return client;
  @@ -162,7 +181,7 @@
        * @param authority The authority string.
        * @return An instance of <code>WebdavClient</code>.
        */
  -    public static WebdavClient seekSession(String authority) {
  +    public WebdavClient seekSession(String authority) {
   
           WebdavClient client = (WebdavClient) clientInfo.get(authority);
   
  @@ -177,7 +196,7 @@
        * @param partOfAuthority The part of the authority string.
        * @return Authorities to have the given string.
        */
  -    public static Enumeration seekSessionKeys(String partOfAuthority) {
  +    public Enumeration seekSessionKeys(String partOfAuthority) {
   
           Vector keys = new Vector();
   
  @@ -198,7 +217,7 @@
        *
        * @return Authorities of all session.
        */
  -    public static Enumeration seekSessionKeys() {
  +    public Enumeration seekSessionKeys() {
   
           return clientInfo.keys();
       }
  @@ -211,20 +230,20 @@
        * It is used the authority part of http URL that is useful to save
        * each connection having the user, host and port information.
        *
  -     * @param httpUrl The http URL to save information of the WebDAV client.
  +     * @param httpURL The http URL to save information of the WebDAV client.
        * @param client The <code>WebdavClient</code> instance to save.
        * @exception MalformedURLException Required the given arguments matched.
        */
  -    public static void setSession(HttpURL httpUrl, WebdavClient client)
  +    public void setSession(HttpURL httpURL, WebdavClient client)
           throws MalformedURLException {
   
           // Check that the given http URL is going alright.
  -        if (!httpUrl.getHost().equalsIgnoreCase(client.getHost()) ||
  -            httpUrl.getPort() != client.getPort())
  +        if (!httpURL.getHost().equalsIgnoreCase(client.getHost()) ||
  +            httpURL.getPort() != client.getPort())
               throw new MalformedURLException
                   ("Not matched between the given URL and client");
   
  -        clientInfo.put(httpUrl.getAuthority(), client);
  +        clientInfo.put(httpURL.getAuthority(), client);
       }
   
   
  @@ -239,25 +258,25 @@
        * @param client The <code>WebdavClient</code> instance to save.
        * @exception MalformedURLException Required the given arguments matched.
        */
  -    public static void setSession(String authority, WebdavClient client)
  +    public void setSession(String authority, WebdavClient client)
           throws MalformedURLException {
   
  -        HttpURL httpUrl = new HttpURL(authority);
  +        HttpURL httpURL = new HttpURL(authority);
   
  -        setSession(httpUrl, client);
  +        setSession(httpURL, client);
       }
   
   
       /**
        * Close connection and unset the <code>WebdavClient</code> instance.
        *
  -     * @param httpUrl The http URL to remove a WebDAV client.
  +     * @param httpURL The http URL to remove a WebDAV client.
        * @exception IOException Error in closing socket.
        */
  -    public static void unsetSession(HttpURL httpUrl)
  +    public void unsetSession(HttpURL httpURL)
           throws IOException {
   
  -        String authority = httpUrl.getAuthority();
  +        String authority = httpURL.getAuthority();
   
           unsetSession(authority);
       }
  @@ -269,12 +288,15 @@
        * @param authority The authority string.
        * @exception IOException Error in closing socket.
        */
  -    public static void unsetSession(String authority)
  +    public void unsetSession(String authority)
           throws IOException {
   
           WebdavClient webdavClient = seekSession(authority);
           // in case of aleady not unset.
           if (webdavClient != null) {
  +            // Remove the progress listener.
  +            webdavClient.getProgressUtil().removeProgressListener(this);
  +
               webdavClient.endSession();
               clientInfo.remove(authority);
           }
  @@ -286,16 +308,47 @@
        *
        * @exception IOException Error in closing socket.
        */
  -    public static void unsetSessionAll() throws IOException {
  +    public void unsetSessionAll() throws IOException {
   
           Enumeration authorities = clientInfo.keys();
           while (authorities.hasMoreElements()) {
               String authority = (String) authorities.nextElement();
               WebdavClient webdavClient = seekSession(authority);
               if (webdavClient != null) {
  +                // Remove the progress listener.
  +                webdavClient.getProgressUtil().removeProgressListener(this);
  +
                   webdavClient.endSession();
                   clientInfo.remove(authority);
               }
           }
  +    }
  +
  +
  +    /**
  +     * Progressing by the progress event.
  +     *
  +     * @param pe The progress event.
  +     */
  +    public void progressing(ProgressEvent pe) {
  +        if (debug > 3)
  +            System.err.println("[EVENT/WebdavSession] " +
  +                               "action:" + pe.getAction() +
  +                               ((pe.getResourceName() == null) ? "" :
  +                               ", resource:" + pe.getResourceName()) +
  +                               ", soMany:" + pe.getSoMany() +
  +                               ", remained:" + pe.getRemainedSize() +
  +                               ", total:" + pe.getTotalSize());
  +        getProgressUtil().fireProgress(pe);
  +    }
  +
  +
  +    /**
  +     * Get the utility of this progress event and listener.
  +     *
  +     * @return ProgressUtil
  +     */
  +    public ProgressUtil getProgressUtil() {
  +        return sessionProgress;
       }
   }
  
  
  
  1.35      +30 -28    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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- WebdavResource.java	2001/04/10 11:24:22	1.34
  +++ WebdavResource.java	2001/04/11 16:03:56	1.35
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v 1.34 2001/04/10 11:24:22 jericho Exp $
  - * $Revision: 1.34 $
  - * $Date: 2001/04/10 11:24:22 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v 1.35 2001/04/11 16:03:56 jericho Exp $
  + * $Revision: 1.35 $
  + * $Date: 2001/04/11 16:03:56 $
    *
    * ====================================================================
    *
  @@ -92,7 +92,7 @@
    *
    * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
    */
  -public class WebdavResource {
  +public class WebdavResource extends WebdavSession {
   
   
       // -------------------------------------------------------  Constructors
  @@ -1052,7 +1052,7 @@
        * Close the session of this client
        */
       public void close() throws IOException {
  -        WebdavSession.unsetSession(httpURL);
  +        unsetSession(httpURL);
       }
   
   
  @@ -1245,13 +1245,13 @@
       public void setEncodeURLs(boolean encodeURLs)
           throws MalformedURLException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           State state = client.getState();
           if (state != null) {
               state.setEncodeURLs(encodeURLs);
               client.setState(state);
  -            WebdavSession.setSession(httpURL, client);
  +            setSession(httpURL, client);
           }
       }
   
  @@ -1270,7 +1270,7 @@
       public InputStream getInputStream(String tempDir)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           // use disk to save by default
           GetMethod method = new GetMethod(httpURL.getPath(), tempDir);
  @@ -1311,7 +1311,7 @@
           FileOutputStream fos = null;
           GetMethod method = null;
           try {
  -            WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +            WebdavClient client = getSessionInstance(httpURL);
   
               // use disk to save by default
               String source = httpURL.getPath();
  @@ -1380,7 +1380,7 @@
       public boolean getMethod(String path, File file)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           // use disk to save by default
           GetMethod method = new GetMethod(HttpURL.getAbsPathQuery(path), file);
  @@ -1423,7 +1423,7 @@
       public boolean putMethod(String path, String data)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           PutMethod method = new PutMethod(HttpURL.getPath(path));
           method.sendData(data);
  @@ -1466,7 +1466,7 @@
       public boolean putMethod(String path, File file)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           PutMethod method = new PutMethod(HttpURL.getPath(path));
           method.sendData(file);
  @@ -1505,7 +1505,7 @@
       public boolean optionsMethod(String path)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           OptionsMethod method;
           if (path.trim().equals("*"))
  @@ -1564,7 +1564,8 @@
       public static Enumeration optionsMethod(HttpURL httpURL)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavSession session = new WebdavSession();
  +        WebdavClient client = session.getSessionInstance(httpURL);
   
           OptionsMethod method = new OptionsMethod(httpURL.getPath());
           client.executeMethod(method);
  @@ -1583,7 +1584,7 @@
                   options.addElement(davCapabilities.nextElement());
               }
           }
  -        WebdavSession.unsetSession(httpURL);
  +        session.unsetSession(httpURL);
   
           return options.elements();
       }
  @@ -1630,7 +1631,7 @@
       public Enumeration propfindMethod(String path, int depth)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           // Check the path alright.
           path = HttpURL.getPath(path);
  @@ -1715,7 +1716,7 @@
       public Enumeration propfindMethod(String path, Vector properties)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(this.httpURL);
  +        WebdavClient client = getSessionInstance(this.httpURL);
   
           // Check the path alright.
           path = HttpURL.getPath(path);
  @@ -1841,7 +1842,7 @@
       public boolean proppatchMethod(String path, Hashtable property)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           PropPatchMethod method = new PropPatchMethod(HttpURL.getPath(path));
           Enumeration names = property.keys();
  @@ -1896,7 +1897,7 @@
       public boolean headMethod(String path)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           HeadMethod method = new HeadMethod(HttpURL.getPath(path));
           client.executeMethod(method);
  @@ -1936,7 +1937,7 @@
       public boolean deleteMethod(String path)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           DeleteMethod method = new DeleteMethod(HttpURL.getPath(path));
           client.executeMethod(method);
  @@ -1979,7 +1980,7 @@
       public boolean moveMethod(String source, String destination)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           MoveMethod method = new MoveMethod(source, destination);
           client.executeMethod(method);
  @@ -2005,7 +2006,8 @@
       public boolean copyMethod(String destination)
           throws WebdavException, IOException {
   
  -        boolean result = copyMethod(HttpURL.getPath(destination));
  +        boolean result = copyMethod(httpURL.getPath(),
  +                                    HttpURL.getPath(destination));
           if (result)
               setAllProp(httpURL, DepthSupport.DEPTH_0);
           return result;
  @@ -2024,7 +2026,7 @@
       public boolean copyMethod(String source, String destination)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           CopyMethod method = new CopyMethod(source, destination);
           client.executeMethod(method);
  @@ -2067,7 +2069,7 @@
       public boolean mkcolMethod(String path)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           MkcolMethod method = new MkcolMethod(HttpURL.getPath(path));
           client.executeMethod(method);
  @@ -2162,7 +2164,7 @@
       public boolean lockMethod(String path, String owner, short timeout)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           // default lock type setting
           short lockType = LockMethod.SCOPE_EXCLUSIVE;
  @@ -2182,7 +2184,7 @@
           setStatusCode(statusCode, lock);
           if (statusCode >= 200 && statusCode < 300) {
               client.setState(state);
  -            WebdavSession.setSession(httpURL, client);
  +            setSession(httpURL, client);
               return true;
           }
   
  @@ -2218,7 +2220,7 @@
       public boolean unlockMethod(String path)
           throws WebdavException, IOException {
   
  -        WebdavClient client = WebdavSession.getSessionInstance(httpURL);
  +        WebdavClient client = getSessionInstance(httpURL);
   
           // Get the lock for the given path.
           State state = client.getState();
  @@ -2243,7 +2245,7 @@
           if (statusCode >= 200 && statusCode < 300) {
               state.removeLocks(path);
               client.setState(state);
  -            WebdavSession.setSession(httpURL, client);
  +            setSession(httpURL, client);
               return true;
           }