hmm i guess it would be easier if we just made this method protected i
think:

AbstractRequestTargetUrlCodingStrategy
private void appendValue(AppendingStringBuffer url, String key, String
value)

and this one is already protected:
protected ValueMap decodeParameters(String urlFragment, Map urlParameters)

so then you can generate your own param string by extending
SharedResourceRequestTargetUrlCodingStrategy
and override those 2 methods.

johan


On 7/2/07, Karl M. Davis <[EMAIL PROTECTED]> wrote:

 Igor,

I actually did figure out a way to get this working without having to do
any (major) hacking.  Pretty simple, too, once I figured it out.  I just
created a new IndexedParamResourceUrlCodingStrategy class (included below)
and mounted that.  For anyone else looking to do this, here is the relevant
code:

// Register the resource with the web application
app.getSharedResources().add("resourceName", customResource);

// Mount the resource
ResourceReference ref = new ResourceReference("resourceName");
app.mount(new IndexedParamResourceUrlCodingStrategy("mountUrl", 
ref.getSharedResourceKey()));


That takes care of just about everything.  However, right about that
point, you'll likely run into the following bug:
https://issues.apache.org/jira/browse/WICKET-631.  I did have to hack
around that a bit, unfortunately.  In my DynamicWebResource class, I added a
"cachedParams" ThreadLocal and cache the parameter ValueMap during
setHeaders(WebResponse) in it, because the parameters get wiped out before
getResourceState() is called.  Here's the code for that in case anyone needs
it:

public class SomeResource extends DynamicWebResource
{
        private static ThreadLocal<ValueMap> cachedParams;

        ...

        /**
         * @see 
org.apache.wicket.markup.html.DynamicWebResource#setHeaders(org.apache.wicket.protocol.http.WebResponse)
         */
        @Override
        protected void setHeaders(WebResponse response)
        {
                super.setHeaders(response);
                cachedParams.set(getParameters());
        }

        ...
        
        /**
         * @see 
org.apache.wicket.markup.html.DynamicWebResource#getResourceState()
         */
        @Override
        protected ResourceState getResourceState()
        {
                ValueMap params = cachedParams.get();
                ...
        }
}


And voila!  I now have mounted resources with pretty indexed parameters
like the following:

.../myresource/folderparam/folderparam/fileparam


I'm not sure how to go about submitting patches, but the following class
would probably help others looking to do the same out.  I stole most of the
code for it wholesale from IndexedParamUrlCodingStrategy, anyways.

/**
 * This class is similar to [EMAIL PROTECTED] IndexedParamUrlCodingStrategy}, 
but for
 * [EMAIL PROTECTED] Resource}s, not bookmarkable pages.
 *
 * NOTE: The code for [EMAIL PROTECTED] 
#appendParameters(AppendingStringBuffer, Map)} and
 * [EMAIL PROTECTED] #decodeParameters(String, Map)} was copied verbatim from
 * [EMAIL PROTECTED] IndexedParamUrlCodingStrategy}.
 *
 * @author Karl M. Davis
 */
public class IndexedParamResourceUrlCodingStrategy extends
                SharedResourceRequestTargetUrlCodingStrategy
{
        /**
         * Constructor.
         *
         * @param mountPath
         *            the path to mount the [EMAIL PROTECTED] Resource} at
         * @param resourceKey
         *            the key of the [EMAIL PROTECTED] Resource} (see
         *            [EMAIL PROTECTED] 
ResourceReference#getSharedResourceKey()})
         */
        public IndexedParamResourceUrlCodingStrategy(String mountPath,
                        String resourceKey)
        {
                super(mountPath, resourceKey);
        }

        /**
         * @see 
org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#appendParameters(org.apache.wicket.util.string.AppendingStringBuffer,
         *      java.util.Map)
         */
        protected void appendParameters(AppendingStringBuffer url, Map 
parameters)
        {
                int i = 0;
                while (parameters.containsKey(String.valueOf(i)))
                {
                        String value = (String) 
parameters.get(String.valueOf(i));
                        url.append("/").append(urlEncode(value));
                        i++;
                }

                String pageMap = (String) parameters
                                .get(WebRequestCodingStrategy.PAGEMAP);
                if (pageMap != null)
                {
                        i++;
                        url.append("/").append(WebRequestCodingStrategy.PAGEMAP)
                                        .append("/").append(urlEncode(pageMap));
                }

                if (i != parameters.size())
                {
                        throw new WicketRuntimeException(
                                        "Not all parameters were encoded. Make sure 
all parameter names are integers in consecutive order starting with zero. Current 
parameter names are: "
                                                        + 
parameters.keySet().toString());
                }
        }

        /**
         * @see 
org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#decodeParameters(java.lang.String,
         *      java.util.Map)
         */
        protected ValueMap decodeParameters(String urlFragment, Map 
urlParameters)
        {
                PageParameters params = new PageParameters();
                if (urlFragment == null)
                {
                        return params;
                }
                if (urlFragment.startsWith("/"))
                {
                        urlFragment = urlFragment.substring(1);
                }

                String[] parts = urlFragment.split("/");
                for (int i = 0; i < parts.length; i++)
                {
                        if (WebRequestCodingStrategy.PAGEMAP.equals(parts[i]))
                        {
                                i++;
                                params.put(WebRequestCodingStrategy.PAGEMAP,
                                                urlDecode(parts[i]));
                        }
                        else
                        {
                                params.put(String.valueOf(i), 
urlDecode(parts[i]));
                        }
                }
                return params;
        }
}


Enjoy!
Karl M. Davis


Igor Vaynberg wrote:

On 6/30/07, Karl M. Davis <[EMAIL PROTECTED]> wrote:
>
> Hey there all,
>
> I've got a DynamicWebResource that I'm mounting via
> mountSharedResource(...) and creating a ResourceLink to.  That Resource
> requires parameters and I'd love for it to operate similar to how
> IndexedParamUrlCodingStrategy works, where my parameters are numbered
> and look like just an extension of the URL.
>
> For example:
> .../myresource/folderparam/folderparam/fileparam
>
> Any way to do that?  I've been poking around in WebRequestCodingStrategy
>
> and it looks like I could override some of the stuff there to get
> started, but that looks hackish and rather complicated.  I think that'd
> only get me halfway; that would allow me to encode the URLs but I'm
> unsure of where I'd need to decode them when the link is clicked on.
>
> I'd appreciate any pointers on this one.


right now we do not support different coding strategies for resorce
mounts, although probably we could pretty easily. please add an rfe to jira.


-igor







Thanks much in advance,
> Karl
>
> -------------------------------------------------------------------------
>
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>

------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

------------------------------

_______________________________________________
Wicket-user mailing list
[EMAIL PROTECTED]://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to