You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Stanton <pa...@mapshed.com.au> on 2010/05/31 05:48:50 UTC
creating my own asset resolver ...
I have another server responsible for hosting images. The server's url
is a configurable item stored in memory so I need to ask the server
where to find the images.
I'd like to create an asset resolver so that I can code my pages like:
<img t:type="any" src="asset:images:myimage.gif" />
Can someone point me to the documentation regarding how to do this, or
provide an example?
Thanks, p.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: creating my own asset resolver ...
Posted by Josh Canfield <jo...@gmail.com>.
I don't think you want an asset resolver in this case because you
aren't actually serving the image from tapestry.
How about a new binding to get the right url for the file?
class CDNBindingFactory implements BindingFactory {
BindingSource _bindingSource;
public CDNBindingFactory(BindingSource bindingSource) {
_bindingSource = bindingSource;
}
public Binding newBinding(String description,
ComponentResources container,
ComponentResources component,
String expression,
Location location) {
Binding image = _bindingSource.newBinding(description,
container, component, "literal", expression, location);
return new CDNBinding(image, location); //To change body of
implemented methods use File | Settings | File Templates.
}
public class CDNBinding extends AbstractBinding {
private Binding _imageBinding;
public CDNBinding(Binding imageBinding, Location location) {
super(location);
_imageBinding = imageBinding;
}
public Object get() {
String path = _imageBinding.get().toString();
if (path.charAt(0) == '/') {
path = path.substring(1);
}
// Use your server path here
return "http://www.google.com/" + path;
}
}
}
Add it to your AppModule
public static void contributeBindingSource(
MappedConfiguration<String, BindingFactory> configuration,
BindingSource bindingSource
) {
configuration.add("cdn", new CDNBindingFactory(bindingSource));
}
Then use it like this:
<img src="${cdn:intl/en_ALL/images/srpr/logo1w.png}" alt="Homepage Logo"/>
or
<img src="${cdn:prop:homepageLogo}" alt="Homepage Logo"/>
Josh
On Sun, May 30, 2010 at 8:48 PM, Paul Stanton <pa...@mapshed.com.au> wrote:
> I have another server responsible for hosting images. The server's url is a
> configurable item stored in memory so I need to ask the server where to find
> the images.
>
> I'd like to create an asset resolver so that I can code my pages like:
> <img t:type="any" src="asset:images:myimage.gif" />
>
> Can someone point me to the documentation regarding how to do this, or
> provide an example?
>
> Thanks, p.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org