users@jersey.java.net

Re: Closest sample for File/Folder browsing

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 05 Dec 2007 15:39:26 +0100

Hi Farrukh,

Could you provide some example URI or URI templates? as that would help
me understand better ways to model things.

Below is a general approach to browsing directories or files:

For example:

   public class FileBrowser {
     private String path;

     public FileBrowser(String path) { this.path = path }

     @GET public File getFile() {
       String absolutePath = getAbsolutePath(path);
       return new File(absolutePath);
     }
   }


   @Path("/")
   public class MyResource() {
     @Path(value="browse/{path}", limited=false)
     public FileBrowser fileBrowser(@UriParam("path") String path) {
       return new FileBrowser(path);
     }
   }

So GET request to /browse/a/b/c/d will create a FileBrowser to serve
state for "a/b/c/d". The limited=false means that all the URI path is
consumed, if you set it to true then only a path segment is consumed.

Based on the path you can return different objects with different
behaviors e.g. you could return a DirBrowser or FileBrowser based on if
the path points to a file or directory. In general it allows for very
dynamic behavior based on the URI path hierarchy.

Hope this helps,
Paul.

Farrukh Najmi wrote:
>
> Dear colleagues,
>
> I am new to Jersey and like what I see very much and plan to use it in
> my project's (ebXML RegRep 4.0 implementation) REST interface.
>
> My first REST interface needs to allow browsing of the content in the
> ebXML RegRep using a familiar file/folder hierarchy where the URL path
> encodes the composition hierarchy structure of the objects in the registry.
>
> I see in archives a long thread about resources and sub-resources:
>
> <https://jersey.dev.java.net/servlets/BrowseList?list=users&by=thread&from=976123>
>
>
> Being new to Jersey I do not grok it all yet. However, I have found the
> Bookmarks example and looking at it
> for inspiration. Are there any closer examples than the Bookmarks one
> for my use case? Thanks for sharing any samples
> pointers or advice.
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109