juergen     02/01/02 07:14:40

  Modified:    src/webdav/client/src/org/apache/webdav/cmd Slide.java
  Log:
  first version of the delta-v prototype (client part). Enable the new methods.
  
  Revision  Changes    Path
  1.45      +549 -4    
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.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- Slide.java        7 Nov 2001 19:32:24 -0000       1.44
  +++ Slide.java        2 Jan 2002 15:14:40 -0000       1.45
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.44 
2001/11/07 19:32:24 dirkv Exp $
  - * $Revision: 1.44 $
  - * $Date: 2001/11/07 19:32:24 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.45 
2002/01/02 15:14:40 juergen Exp $
  + * $Revision: 1.45 $
  + * $Date: 2002/01/02 15:14:40 $
    *
    * ====================================================================
    *
  @@ -68,6 +68,8 @@
   import java.io.BufferedReader;
   import java.io.InputStreamReader;
   import java.io.FileNotFoundException;
  +import java.io.FileInputStream;
  +import java.io.InputStream;
   import java.util.Date;
   import java.util.Stack;
   import java.util.Vector;
  @@ -617,6 +619,144 @@
                           System.err.println("Error: Check! " + e.getMessage());
                       }
                   } else
  +                if (todo.equalsIgnoreCase("optionsWS")) {
  +                    int count = params.size();
  +                    String param = null;
  +                    if (count > 0)
  +                        param = (String) params.pop();
  +                    try {
  +                        boolean succeeded = false;
  +                        if (param != null) {
  +                            if (!param.startsWith("/")) {
  +                                httpURL = new HttpURL(param);
  +                                Enumeration enum = null;
  +                                try {
  +                                    // OPTIONS business logic
  +                                    enum =
  +                                        webdavResource.optionsMethod(httpURL, 
webdavResource.OPTIONS_WORKSPACE);
  +                                    while (enum.hasMoreElements()) {
  +                                        System.out.println(enum.nextElement());
  +                                    }
  +                                } catch (HttpException we) {
  +                                    if (we.getStatusCode() ==
  +                                        HttpStatus.SC_UNAUTHORIZED) {
  +
  +                                        System.out.print("UserName: ");
  +                                        String userName = in.readLine();
  +                                        if (userName != null &&
  +                                            userName.length() > 0) {
  +                                            userName = userName.trim();
  +                                            System.out.print("Password: ");
  +                                            String password = in.readLine();
  +                                            if (password != null)
  +                                                password= password.trim();
  +                                            try {
  +                                                // OPTIONS business logic
  +                                                httpURL.setUserInfo(userName,
  +                                                    password);
  +                                                enum = webdavResource.
  +                                                    optionsMethod(httpURL);
  +                                                while (
  +                                                    enum.hasMoreElements()) {
  +                                                    System.out.print
  +                                                        (enum.nextElement());
  +                                                    if (enum.
  +                                                        hasMoreElements()) {
  +                                                        System.out.print
  +                                                            (", ");
  +                                                    } else {
  +                                                        System.out.println();
  +                                                    }
  +                                                }
  +                                            } catch (Exception e) {
  +                                                System.err.println("Error: "
  +                                                    + e.getMessage());
  +                                            }
  +                                        }
  +                                    } else {
  +                                        System.err.println("Error: " +
  +                                                we.getMessage());
  +                                    }
  +                                } catch (IOException e) {
  +                                    System.err.println(
  +                                        "Error: Check! " + e.getMessage());
  +                                }
  +                                httpURL = null;
  +                                continue;
  +                            }
  +                        }
  +                    } catch (Exception any) {}
  +                }else
  +                if (todo.equalsIgnoreCase("optionsVH")) {
  +                    int count = params.size();
  +                    String param = null;
  +                    if (count > 0)
  +                        param = (String) params.pop();
  +                    try {
  +                        boolean succeeded = false;
  +                        if (param != null) {
  +                            if (!param.startsWith("/")) {
  +                                httpURL = new HttpURL(param);
  +                                Enumeration enum = null;
  +                                try {
  +                                    // OPTIONS business logic
  +                                    enum =
  +                                        webdavResource.optionsMethod(httpURL, 
webdavResource.OPTIONS_VERSION_HISTORY);
  +                                    while (enum.hasMoreElements()) {
  +                                        System.out.print(enum.nextElement());
  +                                        System.out.println();
  +                                        
  +                                    }
  +                                } catch (HttpException we) {
  +                                    if (we.getStatusCode() ==
  +                                        HttpStatus.SC_UNAUTHORIZED) {
  +
  +                                        System.out.print("UserName: ");
  +                                        String userName = in.readLine();
  +                                        if (userName != null &&
  +                                            userName.length() > 0) {
  +                                            userName = userName.trim();
  +                                            System.out.print("Password: ");
  +                                            String password = in.readLine();
  +                                            if (password != null)
  +                                                password= password.trim();
  +                                            try {
  +                                                // OPTIONS business logic
  +                                                httpURL.setUserInfo(userName,
  +                                                    password);
  +                                                enum = webdavResource.
  +                                                    optionsMethod(httpURL);
  +                                                while (
  +                                                    enum.hasMoreElements()) {
  +                                                    System.out.print
  +                                                        (enum.nextElement());
  +                                                    if (enum.
  +                                                        hasMoreElements()) {
  +                                                        System.out.print
  +                                                            (", ");
  +                                                    } else {
  +                                                        System.out.println();
  +                                                    }
  +                                                }
  +                                            } catch (Exception e) {
  +                                                System.err.println("Error: "
  +                                                    + e.getMessage());
  +                                            }
  +                                        }
  +                                    } else {
  +                                        System.err.println("Error: " +
  +                                                we.getMessage());
  +                                    }
  +                                } catch (IOException e) {
  +                                    System.err.println(
  +                                        "Error: Check! " + e.getMessage());
  +                                }
  +                                httpURL = null;
  +                                continue;
  +                            }
  +                        }
  +                    } catch (Exception any) {}
  +                }else
                   // Check the status of connection
                   if (webdavResource == null) {
                       System.out.println("Not connected yet.");
  @@ -1280,6 +1420,73 @@
                           }
                       }
                   } else
  +                if (todo.equalsIgnoreCase("checkin") ||
  +                    todo.equalsIgnoreCase("commit")) {
  +                    int count = params.size();
  +                    for (int i = 0; i < count; i++) {
  +                        String path = checkUri((String) params.pop());
  +                        try {
  +                            System.out.print("Check in '" + path +
  +                                "' : ");
  +                            if (webdavResource.checkinMethod(path)) {
  +                                System.out.println("succeeded.");
  +                            } else {
  +                                System.err.println("failed.");
  +                                System.err.println(
  +                                    webdavResource.getStatusMessage());
  +                            }
  +                        } catch (HttpException we) {
  +                            System.err.println("Warning: " + we.getMessage());
  +                        } catch (IOException e) {
  +                            System.err.println("Error: Check! " +
  +                                e.getMessage());
  +                        }
  +                    }
  +                } else
  +                if (todo.equalsIgnoreCase("checkout") ) {
  +                    int count = params.size();
  +                    for (int i = 0; i < count; i++) {
  +                        String path = checkUri((String) params.pop());
  +                        try {
  +                            System.out.print("Check out'" + path +
  +                                "' : ");
  +                            if (webdavResource.checkoutMethod(path)) {
  +                                System.out.println("succeeded.");
  +                            } else {
  +                                System.err.println("failed.");
  +                                System.err.println(
  +                                    webdavResource.getStatusMessage());
  +                            }
  +                        } catch (HttpException we) {
  +                            System.err.println("Warning: " + we.getMessage());
  +                        } catch (IOException e) {
  +                            System.err.println("Error: Check! " +
  +                                e.getMessage());
  +                        }
  +                    }
  +                }else
  +                if (todo.equalsIgnoreCase("uncheckout") ) {
  +                    int count = params.size();
  +                    for (int i = 0; i < count; i++) {
  +                        String path = checkUri((String) params.pop());
  +                        try {
  +                            System.out.print("undoing Check out'" + path +
  +                                "' : ");
  +                            if (webdavResource.uncheckoutMethod(path)) {
  +                                System.out.println("succeeded.");
  +                            } else {
  +                                System.err.println("failed.");
  +                                System.err.println(
  +                                    webdavResource.getStatusMessage());
  +                            }
  +                        } catch (HttpException we) {
  +                            System.err.println("Warning: " + we.getMessage());
  +                        } catch (IOException e) {
  +                            System.err.println("Error: Check! " +
  +                                e.getMessage());
  +                        }
  +                    }
  +                }else
                   if (todo.equalsIgnoreCase("copy") ||
                       todo.equalsIgnoreCase("cp")) {
                       if (params.size() == 2) {
  @@ -1426,7 +1633,275 @@
                       } else {
                           System.err.println("Error: 'set' needs at least 2 
parameters");
                       }
  +                }
  +            // my methods
  +        
  +            else
  +                if (todo.equalsIgnoreCase("VersionControl") || 
todo.equalsIgnoreCase("vc")) {
  +                    if (params.size() == 1) {
  +                        String path = checkUri((String) params.pop());
  +                        try {
  +                            System.out.print("setting up VersionControl '" + path + 
"': ");
  +                            if (webdavResource.versionControlMethod(path)) {
  +                                System.out.println("succeeded.");
  +                            } else {
  +                                System.err.println("failed.");
  +                                System.err.println(
  +                                    webdavResource.getStatusMessage());
  +                            }
  +                        } catch (HttpException we) {
  +                            System.err.println("Warning: " + we.getMessage());
  +                        } catch (IOException e) {
  +                            System.err.println("Error: Check! " +
  +                                e.getMessage());
  +                        }
  +                    }else if (params.size() == 2) {
  +                        
  +                        String path = checkUri((String) params.pop());
  +                        String target = (String)params.pop();
  +                        try {
  +                            System.out.print("creating versioncontroled Resource '" 
+ target + "' based on '" + path + "' : ");
  +                            if (webdavResource.versionControlMethod(path, target)) {
  +                                System.out.println("succeeded.");
  +                            } else {
  +                                System.err.println("failed.");
  +                                System.err.println(
  +                                    webdavResource.getStatusMessage());
  +                            }
  +                        } catch (HttpException we) {
  +                            System.err.println("Warning: " + we.getMessage());
  +                        } catch (IOException e) {
  +                            System.err.println("Error: Check! " +
  +                                e.getMessage());
  +                        }
  +                    }
  +                    else {
  +                        System.out.println("Syntax: vc/VersionControl <path>");
  +                    }
  +                }
  +                else if (todo.equalsIgnoreCase("report")) {
  +                                        
  +                    int count = params.size();
  +                    if (count == 1){
  +                        /*Vector properties = new Vector();
  +                    for (int i = 0; i < count-1; i++) {
  +                        PropertyName property = new PropertyName("DAV:", (String) 
params.pop());
  +                        properties.addElement(property);
  +                         }*/
  +                    String path = checkUri((String) params.pop());
  +                    try {
  +                        System.out.print("Getting Version History '" +
  +                            path + "': \n");
  +                         
  +                        Enumeration propertyValues =
  +                            webdavResource.reportMethod(new HttpURL(path), 1);
  +                        if (propertyValues.hasMoreElements()){
  +                            while (propertyValues.hasMoreElements()){
  +                                System.out.println(
  +                                    propertyValues.nextElement().toString());
  +                            }
  +                        } else {
  +                            System.err.println("failed.");
  +                            System.err.println(
  +                                webdavResource.getStatusMessage());
  +                        }
  +                    } catch (HttpException we) {
  +                        System.err.println("Warning: " + we.getMessage());
  +                    } catch (IOException e) {
  +                        System.err.println("Error: Check! " +
  +                            e.getMessage());
  +                    }
  +                    } else if (count > 1){
  +                        Vector properties = new Vector();
  +                        for (int i = 0; i < count-1; i++) {
  +                            PropertyName property = new PropertyName("DAV:", 
(String) params.pop());
  +                            properties.addElement(property);
  +                         }
  +                        
  +                        String path = checkUri((String) params.pop());
  +                    try {
  +                        System.out.print("Getting version-tree Report of '" +
  +                            path + "': \n");
  +                         
  +                        Enumeration propertyValues =
  +                            webdavResource.reportMethod(new HttpURL(path), 
properties, 1);
  +                        if (propertyValues.hasMoreElements()){
  +                            while (propertyValues.hasMoreElements()){
  +                                System.out.println(
  +                                    propertyValues.nextElement().toString());
  +                            }
                   } else {
  +                            System.err.println("failed.");
  +                            System.err.println(
  +                                webdavResource.getStatusMessage());
  +                        }
  +                    } catch (HttpException we) {
  +                        System.err.println("Warning: " + we.getMessage());
  +                    } catch (IOException e) {
  +                        System.err.println("Error: Check! " +
  +                            e.getMessage());
  +                    }
  +                    }
  +                    else System.out.println("Syntax: Report <path> <properties>");
  +                
  +                }
  +            //
  +                else if (todo.equalsIgnoreCase("eReport") || 
todo.equalsIgnoreCase("eR")) {
  +                                        
  +                    int count = params.size();
  +                    if (count == 1){
  +                        
  +                        String sQuery = "<D:expand-property 
xmlns:D='DAV:'><D:property name='version-history'><D:property 
name='version-set'><D:property name='successor-set'><D:property 
name='comment'/></D:property></D:property></D:property></D:expand-property>";//(String)
 params.pop();
  +                        //String sQuery ="<D:expand-property 
xmlns:D='DAV:'><D:property name='owner'/><D:property 
name='creationdate'/></D:expand-property>";
  +                                                
  +                        String path = checkUri((String) params.pop());
  +                    try {
  +                        System.out.print("expand-property Report of '" +
  +                            path + "': \n");
  +                         
  +                        Enumeration propertyValues =
  +                            webdavResource.reportMethod(new HttpURL(path), sQuery, 
1);
  +                        if (propertyValues.hasMoreElements()){
  +                            while (propertyValues.hasMoreElements()){
  +                                
  +                                    
  +                                
  +                                
System.out.println(displayXML(propertyValues.nextElement().toString(), 0));
  +                            }
  +                        } else {
  +                            System.err.println("failed.");
  +                            System.err.println(
  +                                webdavResource.getStatusMessage());
  +                        }
  +                    } catch (HttpException we) {
  +                        System.err.println("Warning: " + we.getMessage());
  +                    } catch (IOException e) {
  +                        System.err.println("Error: Check! " +
  +                            e.getMessage());
  +                    }
  +                    }else if (count == 2){
  +                        String src = (String) params.pop();
  +                        File file = new File(dir.getCanonicalPath(), src);
  +                            if (file.exists()) {
  +                                
  +                                InputStream isQuery = new FileInputStream(file);
  +                                BufferedReader reader = new BufferedReader(new 
InputStreamReader(isQuery));
  +                                String sQuery ="";
  +                                while (reader.ready())
  +                                    sQuery += reader.readLine();
  +                                
  +                                sQuery.replace('\t',' ');
  +                                System.out.println (sQuery);
  +                                
  +                                
  +                                                
  +                        String path = checkUri((String) params.pop());
  +                    try {
  +                        System.out.print("expand-property Report of '" +
  +                            path + "': \n");
  +                         
  +                        Enumeration propertyValues =
  +                            webdavResource.reportMethod(new HttpURL(path), sQuery, 
1);
  +                        if (propertyValues.hasMoreElements()){
  +                            while (propertyValues.hasMoreElements()){
  +                                
  +                                    
  +                                
  +                                
System.out.println(displayXML(propertyValues.nextElement().toString(), 0));
  +                            }
  +                        } else {
  +                            System.err.println("failed.");
  +                            System.err.println(
  +                                webdavResource.getStatusMessage());
  +                        }
  +                    } catch (HttpException we) {
  +                        System.err.println("Warning: " + we.getMessage());
  +                    } catch (IOException e) {
  +                        System.err.println("Error: Check! " +
  +                            e.getMessage());
  +                    }
  +                            }
  +                    }
  +                    else System.out.println("Syntax: eReport path");
  +                
  +                }else if (todo.equalsIgnoreCase("lreport")|| 
todo.equalsIgnoreCase("lr")) {
  +                                        
  +                    int count = params.size();
  +                    Vector histUri = new Vector();
  +                    if (count > 1){
  +                        // getting historyUrl
  +                        String sInput;
  +                        System.out.println("HistoryUri: ");
  +                        sInput = in.readLine();
  +                        while (sInput.length() > 0){
  +                            histUri.addElement(sInput);
  +                            System.out.println("HistoryUri: ");
  +                            sInput = in.readLine();
  +                            System.out.println(sInput);
  +                        }
  +                        
  +                        
  +                    }
  +                    if (count > 1 && histUri.elements().hasMoreElements()){
  +                        Vector properties = new Vector();
  +                        for (int i = 0; i < count-1; i++) {
  +                            PropertyName property = new PropertyName("DAV:", 
(String) params.pop());
  +                            properties.addElement(property);
  +                         }
  +                        
  +                        String path = checkUri((String) params.pop());
  +                    try {
  +                        System.out.print("Getting version-tree Report of '" +
  +                            path + "': \n");
  +                         
  +                        Enumeration propertyValues =
  +                            webdavResource.reportMethod(new HttpURL(path), 
properties, histUri, 1);
  +                        if (propertyValues.hasMoreElements()){
  +                            while (propertyValues.hasMoreElements()){
  +                                System.out.println(
  +                                    propertyValues.nextElement().toString());
  +                            }
  +                } else {
  +                            System.err.println("failed.");
  +                            System.err.println(
  +                                webdavResource.getStatusMessage());
  +                        }
  +                    } catch (HttpException we) {
  +                        System.err.println("Warning: " + we.getMessage());
  +                    } catch (IOException e) {
  +                        System.err.println("Error: Check! " +
  +                            e.getMessage());
  +                    }
  +                    }
  +                    else System.out.println("Syntax: lReport <property> \n History 
URLs are needed");
  +                
  +                }else
  +                if (todo.equalsIgnoreCase("mkws")) {
  +                    int count = params.size();
  +                    for (int i = 0; i < count; i++) {
  +                        String path = checkUri((String) params.pop());
  +                        try {
  +                            System.out.print("Making '" + path +
  +                                "' workspace: ");
  +                            if (webdavResource.mkWorkspaceMethod(path)) {
  +                                System.out.println("succeeded.");
  +                            } else {
  +                                System.err.println("failed.");
  +                                System.err.println(
  +                                    webdavResource.getStatusMessage());
  +                            }
  +                        } catch (HttpException we) {
  +                            System.err.println("Warning: " + we.getMessage());
  +                        } catch (IOException e) {
  +                            System.err.println("Error: Check! " +
  +                                e.getMessage());
  +                        }
  +                    }
  +                }
  +                                                                                    
                                                                
  +            //
  +        
  +                else {
                       System.err.println("Invalid Command.");
                   }
               } while (true);
  @@ -1677,10 +2152,29 @@
           System.out.println("  grant  [<namespace>] <permission> [on <path>] to 
<principal>");
           System.out.println("  deny   [<namespace>] <permission> [on <path>] to 
<principal>");
           System.out.println("  revoke [<namespace>] <permission> [on <path>] from 
<principal>");
  +        System.out.println("  versioncontrol path           "+
  +                               "set a versionable resource under versioncontrol");
  +        System.out.println("  versioncontrol URL path       "+
  +                               "creating a versioncontrol path ...        "+
  +                               "set a versionable resource under versioncontrol");
  +        System.out.println("  checkout path                 "+
  +                               "checkout of a checkedin resource");
  +        System.out.println("  checkin path                  "+
  +                               "checkin of a checkedout resource");
  +        System.out.println("  uncheckout path               "+
  +                               "undoing changes on Resource since checkedout 
(including checkout)");
  +        System.out.println("  report path [<property>]      "+
  +                               "getting report (version-tree) for any resource");
  +        System.out.println("  eReport path                  "+
  +                               "getting report (expand-property) for any resource");
  +        System.out.println("  LReport path                  "+
  +                               "getting report (locate-by-history)");
  +        System.out.println("  mkws path ...                 " +
  +            "Make new workspace");
           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");
  +             "propget=propfind, propput=proppatch,versioncontrol=vc,\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.");
  @@ -1985,4 +2479,55 @@
                   System.out.println("   token: " + token);
           }
       }
  +    
  +    private String displayXML(String xmlString, int count){
  +        
  +        String sResult ="";
  +                
  +        if(xmlString.startsWith("</")){
  +            
  +            count --;
  +            //System.out.println("cl: " + count);
  +            for (int cc = count; cc > 0; cc--){
  +                sResult += "\t";
  +            }
  +                        
  +            try{
  +                sResult += xmlString.substring(0, xmlString.indexOf(">") + 1)+"\n";
  +                xmlString = xmlString.substring(xmlString.indexOf(">") + 1);
  +                //count --;
  +                sResult += displayXML(xmlString, count);
  +            }catch (Exception any){
  +                //sResult += "endtag" + any;
  +}
  +            
  +        }else if (xmlString.startsWith("<")){
  +            //System.out.println("op: " + count);
  +            for (int cc = count; cc > 0; cc--){
  +                sResult += "\t";
  +            }
  +            try{
  +                sResult += xmlString.substring(0, xmlString.indexOf(">") + 1)+"\n";
  +                xmlString = xmlString.substring(xmlString.indexOf(">") + 1);
  +                count ++;
  +                sResult += displayXML(xmlString, count);
  +            }catch (Exception any){
  +                //sResult += "starttag" + any;
  +            }
  +        }else {
  +            //System.out.println("em: " + count);
  +            for (int cc = count; cc > 0; cc--){
  +                sResult += "\t";
  +            }
  +            try {
  +                sResult += xmlString.substring(0, xmlString.indexOf("<"))+ "\n";
  +                xmlString = xmlString.substring(xmlString.indexOf("<"));
  +                sResult += displayXML(xmlString, count);
  +            }catch (Exception any){
  +                //sResult += any;
  +            }
  +        }
  +        return sResult;
  +    }
   }
  +
  
  
  

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

Reply via email to