jericho     01/05/10 11:10:22

  Modified:    src/webdav/client/src/org/apache/webdav/cmd Slide.java
  Log:
  - Now, the debug level is configurable.
  
    Patch submitted by Dirk Verbeeck <dirk.verbeeck at the-ecorp.com>
  
  Revision  Changes    Path
  1.27      +57 -29    
jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java
  
  Index: Slide.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Slide.java        2001/05/08 22:12:51     1.26
  +++ Slide.java        2001/05/10 18:10:18     1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.26 
2001/05/08 22:12:51 remm Exp $
  - * $Revision: 1.26 $
  - * $Date: 2001/05/08 22:12:51 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.27 
2001/05/10 18:10:18 jericho Exp $
  + * $Revision: 1.27 $
  + * $Date: 2001/05/10 18:10:18 $
    *
    * ====================================================================
    *
  @@ -134,9 +134,9 @@
   
   
       /**
  -     * Debug mode.
  +     * The debug level.
        */
  -    private boolean debugMode = false;
  +    private int debugLevel = 0;
   
   
       /**
  @@ -180,7 +180,7 @@
                           System.out.println(version);
                           break;
                       case 'd':
  -                        slide.debugMode = true;
  +                        slide.debugLevel = Integer.MAX_VALUE;
                           break;
                       default:
                           System.exit(-1);
  @@ -197,9 +197,8 @@
                   }});
           inner.start();
       }
  +    
   
  -
  -
       /**
        * Parse the Slide client commands and execute the requests.
        */
  @@ -219,8 +218,7 @@
                   try {
                       httpURL = new HttpURL(stringUrl);
                       webdavResource = new WebdavResource(httpURL);
  -                    if (debugMode)
  -                        webdavResource.setDebug(10000);
  +                    webdavResource.setDebug(debugLevel);
                       setPath(webdavResource.getPath());
                   } catch (HttpException we) {
                       // Check authorization and try it again.
  @@ -242,8 +240,7 @@
                                   } else {
                                       webdavResource =
                                           new WebdavResource(httpURL);
  -                                    if (debugMode)
  -                                        webdavResource.setDebug(10000);
  +                                    webdavResource.setDebug(debugLevel);
                                   }
                                   setPath(webdavResource.getPath());
                               } catch (HttpException e) {
  @@ -321,8 +318,7 @@
                           httpURL = new HttpURL(inputUrl);
                           if (webdavResource == null) {
                               webdavResource = new WebdavResource(httpURL);
  -                            if (debugMode)
  -                                webdavResource.setDebug(10000);
  +                            webdavResource.setDebug(debugLevel);
                           } else {
                               webdavResource.close();
                               webdavResource.setHttpURL(inputUrl);
  @@ -356,8 +352,7 @@
                                       } else {
                                           webdavResource =
                                               new WebdavResource(httpURL);
  -                                        if (debugMode)
  -                                            webdavResource.setDebug(10000);
  +                                        webdavResource.setDebug(debugLevel);
                                       }
                                       setPath(webdavResource.getPath());
                                   } catch (HttpException e) {
  @@ -680,8 +675,7 @@
                                           webdavResource.close();
                                           webdavResource =
                                               new WebdavResource(httpURL);
  -                                        if (debugMode)
  -                                            webdavResource.setDebug(10000);
  +                                        webdavResource.setDebug(debugLevel);
                                           setPath(webdavResource.getPath());
                                       } catch (HttpException e) {
                                           System.err.println("Warning: "
  @@ -1106,10 +1100,10 @@
                   } else
                   if (todo.equalsIgnoreCase("set")) {
                       if (params.size() == 2) {
  -                        String onOrOff= (String) params.pop();
  -                        String encoding = (String) params.pop();
  -                        if (encoding.equalsIgnoreCase("urlencode")) {
  -                            if (onOrOff.equalsIgnoreCase("on")) {
  +                        String value = (String) params.pop();
  +                        String key = (String) params.pop();
  +                        if (key.equalsIgnoreCase("urlencode")) {
  +                            if (value.equalsIgnoreCase("on")) {
                                   webdavResource.setEncodeURLs(true);
                                   System.out.println
                                       ("URL encoding flag is on.");
  @@ -1118,13 +1112,41 @@
                                   System.out.println
                                       ("URL encoding flag is off.");
                               }
  +                        } else if (key.equalsIgnoreCase("debug")) {
  +                            if ((value.equalsIgnoreCase("on")) ||
  +                                (value.equalsIgnoreCase("all"))) {
  +                                debugLevel = Integer.MAX_VALUE;
  +                                webdavResource.setDebug(debugLevel);
  +                                System.out.println
  +                                    ("The debug flag is on(level=all).");
  +                            } else if (value.equalsIgnoreCase("off") ||
  +                                       (value.equalsIgnoreCase("0"))) {
  +                                webdavResource.setDebug(debugLevel = 0);
  +                                System.out.println("The debug flag is off.");
  +                            } else {
  +                                try {
  +                                    debugLevel = Integer.parseInt(value);
  +                                    webdavResource.setDebug(debugLevel);
  +                                    System.out.println
  +                                        ("The debug flag is on(level=" +
  +                                         debugLevel + ").");
  +                                } catch (NumberFormatException nfe) {
  +                                    System.err.println
  +                                        ("Invalid value, valid vlaues " +
  +                                         "are 'on', 'off', <level>");
  +                                }
  +                            }
  +                        } else {
  +                            System.err.println("Invalid option.");
                           }
  -                     }
  +                    } else {
  +                        System.err.println("Error: 'set' needs 2 parameters");
  +                    }
                   } else {
  -                    System.out.println("Invalid Command.");
  +                    System.err.println("Invalid Command.");
                   }
               } while (true);
  -
  +        
           } catch (Exception e) {
               System.err.println("Fatal Error: " + e.getMessage());
               if (command != null)
  @@ -1337,11 +1359,17 @@
               "Print value of specified property");
           System.out.println("  propput path property value   " +
               "Set property with given value");
  -        System.out.println("  set urlencode {on|off}        " +
  +        System.out.println("  set URLencode {on|off}        " +
               "Set URL encoding flag, default: on");
  -        System.out.println("Aliases: help=?, ls=dir, pwc=pwd, cc=cd, " +
  -            "copy=cp, move=mv, delete=del=rm,\n         mkcol=mkdir, " +
  -            "lls=ldir, exit=quit \n");
  +        System.out.println("  set debug {on|off|<level>}    " +
  +            "Set debug level, default: off");
  +        System.out.println
  +            ("Aliases: help=?, open=connect, ls=dir, pwc=pwd, cc=cd, " +
  +             "lls=ldir, copy=cp,\n move=mv, delete=del=rm, mkcol=mkdir, " +
  +             "propget=propfind, propput=proppatch,\n exit=quit=bye");
  +        System.out.println("Comment : Once executed, the debug mode will " +
  +                           "be active.\n\t\tBecause it's not triggered by " +
  +                           "methods yet.");
       }
   
   
  
  
  

Reply via email to