Differences between revisions 1 and 2
Revision 1 as of 2006-08-09 14:58:45
Size: 1110
Comment:
Revision 2 as of 2009-09-20 22:02:47
Size: 1110
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Purpose:

Solve the problem of heavily nested paths when using MKCOL to create a directory structure with WebDAV.

i.e. store a file under /COMPANYA/2006/08/test.file requires multiple MKCOL commands as Slide needs the parent tree to exist before creating children.

Below is a java method that takes a jakarta WebdavResource and the path (such as "/COMPANYA/2006/08/") and creates the entire tree structure.

  • private static String mkallcol(WebdavResource wdr, String path) throws Exception{

    • if (path != null){
      • if (path.length() > 1){

        • path.replace('\\','/'); //Now, break up path

          java.util.StringTokenizer t = new java.util.StringTokenizer(path,"/"); String strsub = "/"; int count = t.countTokens(); //check each token EXCEPT last token, last token is filename

        while ((t.hasMoreTokens()) && (count > 1)){

        • strsub = strsub + t.nextToken() + "/";
          • wdr.mkcolMethod(wdr.getPath() + strsub);
          count--;
        • } return wdr.getPath() + strsub + t.nextToken();
        }else{
        • return "";
        }
      }else{
      • return "";
      }
    }

CreateDirectoryTreeInJava (last edited 2009-09-20 22:02:47 by localhost)