Shooting from the hip here, but...
One way of going about this would be to contribute a RequestFilter,
rather than a Dispatcher.
RequestFilters get to pass on whatever request they want.
So you could wrap the request with a customized request that modifies
the result of getPath() based on which host is being run.
Something like:
public class DynamicAssetRequestFilter implements RequestFilter {
private final SymbolSource _source;
public DynamicAssetRequestFilter(final SymbolSource source) {
_source=source;
}
public boolean service(Request request, Response response,
RequestHandler handler) {
if
(request.getPath().startsWith(TapestryConstants.ASSET_PATH_PREFIX)) {
return handler.service(new
DynamicAssetRequest(request),response);
}
return handler.service(request,response);
}
class DynamicAssetRequest implements Request {
private final Request _request;
private final String _path;
DynamicAssetRequest(final Request request) {
_request = request;
String path = getPath();
String host = source.valueForSymbol("host");
_path = //process the path as appropriate to put host in
where you need it
}
//implement the Request interface by calling through to the
wrapped request
...
//override getPath.
public String getPath() {
return _path;
}
}
}
On Mar 28, 2008, at 3/289:52 AM , Andreas Pardeike wrote:
Yes, I think that would work. Only problem there is that I still
want to have all benefits of caching that the build-in services
deliver. And I can't see how to just *modify* the asset path
inside the dispatcher and pass it on to Tapestry...
/Andreas
On 28 mar 2008, at 15.36, Cordenier Christophe wrote:
And what about a custom AssetDispatcher ?
-----Message d'origine-----
De : Andreas Pardeike [mailto:[EMAIL PROTECTED]
Envoyé : vendredi 28 mars 2008 15:22
À : Tapestry users
Objet : Re: T5: Custom asset locator?
Thanks Christope, but it's not quite what I want. To illustrate
my problem, take a look at the request headers I want to process:
GET /assets/i/test.gif HTTP/1.1
Host: www.SITE_A.com
and
GET /assets/i/test.gif HTTP/1.1
Host: www.SITE_B.com
If I just create my own binding, the request urls would still contain
the real folder inside /assets and my requests would look like
GET /assets/SITE_A/i/test.gif HTTP/1.1
GET /assets/SITE_B/i/test.gif HTTP/1.1
which I rather not want.
/Andreas
On 28 mar 2008, at 15.10, Cordenier Christophe wrote:
Hello
I'm not sure this can help, this is just an idea,
but maybe it would be easier to create a new type of binding Factory
upon the AssetBinding factory to add dynamic datas.
Best regards,
Christophe.
-----Message d'origine-----
De : Andreas Pardeike [mailto:[EMAIL PROTECTED]
Envoyé : vendredi 28 mars 2008 14:58
À : Tapestry users
Objet : T5: Custom asset locator?
Hi everyone,
First: many many thanks to the list for all the valuable info I
get from it (either as passive reading or answers to my questions!)
My problem: I want to expand the virtual /assets mapping because
in the app I am writing, I use the current host name to run
different
sites/layouts.
So I want to implement that
Host: www.SITE_A.com
<img src="${asset:classpath:/i/test.gif}" />
points to SITE_A/i/test.gif
and
Host: www.SITE_B.com
<img src="${asset:classpath:/i/test.gif}" />
points to SITE_B/i/test.gif
instead of the default way to do it by using
<img src="${asset:classpath:/CURRENTSITE/i/test.gif}" />
or @Path("classpath:${host}/i/test.gif")
and have it dynamically expand to the same paths. The motivation
behind
this is that
a) users at SITE_A could replace the url with 'SITE_B' and peek at
other
resources
b) the url's get very long and for some reason I don't want to go
into
here, I need to match the URLs style with some dynamic paths that
fetch resources from a db - there, I automatically take care of the
host name.
I couldn't find a example on how to expand/overwrite asset lookup
(in
the same way I expanded template lookup). All I want is to add a
subfolder on the fly to the asset path and still use the same build
in asset service.
/Andreas Pardeike
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]