Hi,

The resource key for a shared resource is generated by the following method which I'm not allowed to call.

        /**
         * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
         *
         * @param scope
         *            The scope of the resource
         * @param path
         *            The resource path
         * @param locale
         *            The locale
         * @param style
         *            The style (see [EMAIL PROTECTED] 
org.apache.wicket.Session})
         * @return The localized path
         */
public String resourceKey(final Class scope, final String path, final Locale locale,
                        final String style)
        {
                String alias = (String)classAliasMap.get(scope);
                if (alias == null)
                {
                        alias = scope.getName();
                }
                return alias + '/' + resourceKey(path, locale, style);
        }

I add the resource using the following method:

        /**
         * Adds a resource.
         *
         * @param name
         *            Logical name of resource
         * @param resource
         *            Resource to store
         */
        public final void add(final String name, final Resource resource)
        {
                add(Application.class, name, null, null, resource);
        }

Which decides for me that the scope is Application.class. Now all this is fine, except I don't really like the fact that I don't get the resource key and have to make a new throwaway ResourceReference to get at it.

I was wondering, could add not just return the resource key of the added resource?

Regards,
Sebastiaan


Sebastiaan van Erk wrote:
Johan Compagner wrote:
Isnt the getResourceKey() returning exactly the name? It should
because else the first call to shared resources with just the name
doesnt make much sense! Those should be the same.

Well I tried using the name first and it kept complaining that it couldn't find the resource, so I just tried this ResourceReference thing not expecting it to work but it did. I added a log line to the application.init() and it says:

mounted resource: name=cvs_nl.pdf key=org.apache.wicket.Application/cvs_nl.pdf

Thus the name and key are *not* the same, and mounting by name did not work.

Also doesnt ResourceLink uses LocalizedImageResource? That one takes
care of that. But i guess it needs a resource per locale also in the
shared resources. So that the shared resource key is there for all the
locales.

In my web page with the resource link I do the following:

fragment.add(new ResourceLink("cvEnglishLink", new ResourceReference("cvs_en.pdf")) {
    @Override
        public boolean isVisible() {
            return "en".equals(getLocale().getLanguage());
        }
    });

It's a bit of a dirty hack, but it works. As you can see, I make a ResourceLink with a ResourceReference. I don't even know *how* to make the referenced resource different for two locales. The names of the resource are just "cvs_" + language + ".pdf". I don't see that ResourceLink uses LocalizedImageResource anywhere. There is this somewhat cryptic comment though in ResourceLink:

    protected final CharSequence getURL()
    {
        if (resourceReference != null)
        {
// TODO post 1.2: should we have support for locale changes when the
            // resource reference (or resource??) is set manually..
// We should get a new resource reference for the current locale
            // then
// that points to the same resource but with another locale if it
            // exists.
            // something like
// SharedResource.getResourceReferenceForLocale(resourceReference);

            resourceReference.bind(getApplication());
return getRequestCycle().urlFor(resourceReference, resourceParameters);
        }
        return urlFor(IResourceListener.INTERFACE);
    }

It seems that I need to register a resource with the same name for different locales? But can I still mount them on different paths then? And obviously, what the comment alludes to would need to be implemented of course. :-)

So what I would want to do is mount the English resource on "/downloads/cvs_en.pdf", the Dutch resource on "/downloads/cvs_nl.pdf" and have a resource link on my page which links to the proper one depending on the locale.

Regards,
Sebastiaan



On 2/24/08, Sebastiaan van Erk <[EMAIL PROTECTED]> wrote:
Hi,

I register some DynamicWebResources in my Application's init method, as
well as mount them (in a loop, a different one for every locale):

    getSharedResources().add(name, resource);
    mountSharedResource("/downloads/" + name, new
ResourceReference(name).getSharedResourceKey());

I was wondering if there was another way to get the shared resource key
without having to construct a throwaway resource reference.

Futherhmore, in a web page I want to link to the shared resources, i.e,
I thought of using a ResourceLink. However, I was wondering how I can
make sure that the resource being linked to is the correct (localized)
resource. (They're generated PDF's, one in English, one in Dutch, and I
want the link to point to the correct one depending on the locale). My
currentsolution is just to have 2 links and override isVisible() on each
of them to check the locale, but I don't know if that's the "correct"
way to go about it.

Regards,
Sebastiaan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to