You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Carlos Pita <ca...@gmail.com> on 2008/02/01 17:37:41 UTC

Mounting shared resources

Hi all,

is it possible to alias resource paths like /resources/scope/name to
simply, say, /mount_point/name?

I know there is a scope alias for shared resources, but that only
works for the scope (class) part of the path, so it can't  get shorter
that /resources/alias/path.

Then there is the mountSharedResource method, but it works on resource
by resource basis. Instead, I need to alias the path for a big number
of resources (for example, static images for my application).

Ideally,  I would like my images, following the previous example, to
be requested as:

<wicket:link><img src="img/some_image.gif"/></wicket:link>

Any chance to get this?

Thank you in advance.
Regards,
Carlos

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Mounting shared resources

Posted by Carlos Pita <ca...@gmail.com>.
Hi edvin, pictures are not my only goal, I would like to serve compressed js
and css also, and to take advantage of wicket resource caching (http header
generation). Anyway, I wrote a simple requesttargeturlcodingstrategy that
fulfills my needs. If anyone is interested, here it is:

public class SharedResourcesRequestTargetUrlCodingStrategy extends
AbstractRequestTargetUrlCodingStrategy {

    private String keyPrefix;

    public SharedResourcesRequestTargetUrlCodingStrategy(String mountPath,
Class<?> scope) {
        this(mountPath, scope, mountPath.substring(1));
    }

    public SharedResourcesRequestTargetUrlCodingStrategy(String mountPath,
Class<?> scope, String namePrefix) {
        super(mountPath);
        this.keyPrefix = scope.getCanonicalName() + "/" + namePrefix;
    }

    public IRequestTarget decode(RequestParameters requestParameters) {
        String name = requestParameters.getPath
().substring(getMountPath().length());
        requestParameters.setResourceKey(keyPrefix + name);
        return new SharedResourceRequestTarget(requestParameters);
    }

    public CharSequence encode(IRequestTarget requestTarget) {
        String key =
((ISharedResourceRequestTarget)requestTarget).getResourceKey();
        return getMountPath() + key.substring(keyPrefix.length());

    }

    public boolean matches(IRequestTarget requestTarget) {
        if (!(requestTarget instanceof ISharedResourceRequestTarget)) return
false;
        String key =
((ISharedResourceRequestTarget)requestTarget).getResourceKey();
        return key.startsWith(keyPrefix);
    }
}

Thank you
Regards
-Carlos

On Feb 1, 2008 6:31 PM, Edvin Syse <ed...@sysedata.no> wrote:

> > Then there is the mountSharedResource method, but it works on resource
> > by resource basis. Instead, I need to alias the path for a big number
> > of resources (for example, static images for my application).
> > Ideally,  I would like my images, following the previous example, to
> > be requested as:
> > <wicket:link><img src="img/some_image.gif"/></wicket:link>
>
> If your goal is just to supply static pictures and don't have
> programmatically control over them, why don't you just create an img-folder
> in
> your webroot? Then pictures will be served by your container instead of
> Wicket :)
>
> -- Edvin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Mounting shared resources

Posted by Edvin Syse <ed...@sysedata.no>.
> Then there is the mountSharedResource method, but it works on resource
> by resource basis. Instead, I need to alias the path for a big number
> of resources (for example, static images for my application).
> Ideally,  I would like my images, following the previous example, to
> be requested as:
> <wicket:link><img src="img/some_image.gif"/></wicket:link>

If your goal is just to supply static pictures and don't have programmatically control over them, why don't you just create an img-folder in 
your webroot? Then pictures will be served by your container instead of Wicket :)

-- Edvin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org