I have (attempted to) create a WebDAV service for Turbine.   I would 
appreciate comments and suggestions as I am a novice coder, so please 
don't take it to hard on me if it sucks.  You can find the three files 
at <http://www.eastnode.com>.   Hopefully the javadoc explains it a 
little... But heres what I'm doing with it (A lot more can be done, I 
think).

I get a directory listing like so:

Vector webdavfiles = WebdavService.getWebdavFiles( "/some/directory/" );
context.put("directory", webdavfiles);
data.getUser().setTemp("wfiles", webdavfiles);  // This is explained 
further on

Then in my velocity file I do something like:

#foreach ($item in $directory)
#if ($item.isDirectory())
<tr>
       <td>
  <input type=checkbox name="wfile_$item.getHashcode()"></td>
       <td><a 
href="$link.setPage("Collab,Files.vm").addPathInfo("moveto", 
$item.getFilename()).addPathInfo("currpath", 
$currpath).addPathInfo("JobId", $job.getJobId() )"><img 
src="#getContextURL('/images/folder.gif')" border="0" height="16" 
width="16"></a></td>
       <td> <a 
href="$link.setPage("Collab,Files.vm").addPathInfo("moveto", 
$item.getFilename()).addPathInfo("currpath", 
$currpath).addPathInfo("JobId", $job.getJobId() )">
         $item.getFilename()/</a> </td>
       <td">&nbsp;</td>
       <td>$item.getDisplayDate()</td>
       <td>$!item.getProperty("user")&nbsp;</td>
       <td>$!item.getProperty("descr")&nbsp;</td>
</tr>
#else
<tr>
       <td>
<input type=checkbox name="wfile_$item.getHashcode()"></td>
       <td><a 
href="$link.setScreen("Collab.RetrieveFile").addPathInfo("currpath", 
$currpath).addPathInfo("JobId", $job.getJobId() 
).addPathInfo("filename", $item.getFilename())"><img 
src="#getContextURL('/images/file.gif')" border="0" height="16" 
width="16"></a></td>
       <td><a 
href="$link.setScreen("Collab.RetrieveFile").addPathInfo("currpath", 
$currpath).addPathInfo("JobId", $job.getJobId() 
).addPathInfo("filename", $item.getFilename())">
         $item.getFilename()&nbsp;</a></td>
       <td>$item.getDisplaySize()</td>
       <td>$item.getDisplayDate()</td>
       <td>$!item.getProperty("user")&nbsp;</td>
       <td>$!item.getProperty("descr")&nbsp;</td>
</tr>
#end
#end

The checkboxes are to mark for delete and for move.  I have delete 
button and a move button with a dropdown list of folders that use these 
checkboxes.

NOTE:  The getHashcode() method is used to prevent case conflicts with 
filenames so "test" and "TEST" don't conflict when marking for a move or 
delete.

If the user executes the delete action the following code then deletes 
the files:

WebdavParameterParser wpp = (WebdavParameterParser) data.getParameters();
Vector wfiles = (Vector) data.getUser().getTemp("wfiles");
wpp.markDeleteWebdavFiles(wfiles);
WebdavService.delete(wfiles, path_of_files);

Similarly a move goes:

WebdavParameterParser wpp = (WebdavParameterParser) data.getParameters();
Vector wfiles = (Vector) data.getUser().getTemp("wfiles");
wpp.markMoveWebdavFiles(wfiles);
WebdavService.delete(wfiles, current_path, destination_path);


Also you'll notice in WebdavService there are some methods to store 
FileItems and create new directories.  This whole service is a lower 
abstraction of my collaboration mechanism that I'm working on (which is 
very app-specific, or I'd release it).

I hope you all can make sense of this and find it useful.  If it is 
worth using long-term in turbine I'll release it under the apache 
license (but I know it needs work probably :) ).

-- 
Dan Diephouse <http://www.compassarts.org/>

Reply via email to