Hi Craig,
>If you add path segments ".." and "6" (or, more generally, the page
>number
you want to reference as the second segment), you should get
>where
you want to be.
The problem with this is that I want to preserve matrix parameters. Also /page/5 might not be the last path. For example, I might see this: .../page;size=10/5/descending/date
In these more complex scenarios, the simple approach of frobbing the last path segment doesn't work.
I hope you can consider my suggestion, as I truly think addOrReplaceSegment (or maybe putPathSegment) would be an incredibly valuable method. For now, I will carry on with my utility class based on regex and string replacement.
Cheers,
geoff
--
http://nextdb.net - RESTful Relational Database
http://www.nextdb.net/wiki/en/REST
--- On Thu, 2/4/10, Craig McClanahan <craigmcc_at_gmail.com> wrote:
From: Craig McClanahan <craigmcc_at_gmail.com>
Subject: Re: Re: [Jersey] can we get a UriBuilder.addOrReplaceSegment method? Tuesday, February 2, 2010 11:51 PM
To: "geoffrey hendrey" <geoff_at_nextdb.net>
Cc: users_at_jersey.dev.java.net
Date: Thursday, February 4, 2010, 7:21 PM
On Thu, Feb 4, 2010 at 6:45 PM, geoffrey hendrey <geoff_at_nextdb.net> wrote:
> Hi Craig,
>
> I don't want a new view of the same resource. For example, consider a URI
> like "/page/5". The resource for page 5 wants to be able to create links to
> /page/4 and /page/6, it is extremely useful to be able to say
> addOrReplaceSegment("/page/{page}", "6"). I can even envision a syntax like:
> addOrReplaceSegment("/page/{page}", "${page}+1") but that's above and beyond
> what I need.
>
> I hope I won't see a response saying "page numbers should be query
> parameters" since at that point the issue drifts toward the religious rather
> than the practical. There are many reasons, such as availability of matrix
> parameters to the path segments, or behaviors of web caches, that make path
> parameters preferable in some situations. I just want an easy way to take a
> resource's URI and mutate its path parameters so that I can easily create
> links to similar resource. So far, virtually everything else is a dream with
> Jersey and JSR-311, but this is one place where I think it could be
> improved.
It's too bad you don't like query parameters for this ... the
queryParam() method on UriBuilder would be just the ticket :-).
A not-recommended alternative would be to start from
UriInfo.getBaseUriBuilder() and build the whole thing up from scratch.
That would be spreading knowledge of how your uris are constructed
all over the place.
A better option might be to consider
getBaseUriBuilder().path(MyResourceClass.class) that will give you the
path matching the @Path declaration on your current resource class.
Then, you only have to add path elements for the last part.
If you really want to start from getAbsoluteUriBuilder(),assume you're
on page 5 with a path like:
...../pages/5
If you add path segments ".." and "6" (or, more generally, the page
number you want to reference as the second segment), you should get
where you want to be.
Craig
>
> Cheers,
> geoff
> --
> http://nextdb.net - RESTful Relational Database
> http://www.nextdb.net/wiki/en/REST
>