This wasn't it. I found out that IndexedParamUrlCodingStrategy did the same 
thing so I changed to that one and still get the error.. sigh...

-- Edvin

Edvin Syse skrev:
Here goes the other one I think there might be a problem with, since it deals with PageMaps etc, and I'm not all that familiar with them. I didn't write much of this code, just changed what I needed to get it to work the way I wanted:

/**
 * Url coding strategy for pages that encode number based
 * parameters without having the numbers in the url.
 *
* The parameters are given on the form /param0-value/param1-value/ etc. and the
 * paramnames are "0", "1" etc.
 *
 *
 */
public class NumberedRequestTargetUrlCodingStrategy extends AbstractRequestTargetUrlCodingStrategy {
    /** bookmarkable page class. */
    protected final WeakReference/* <Class> */bookmarkablePageClassRef;

    /** page map name. */
    private final String pageMapName;

    public NumberedRequestTargetUrlCodingStrategy(final String mountPath,
            final Class bookmarkablePageClass, String pageMapName) {
        super(mountPath);

        if (bookmarkablePageClass == null) {
            throw new IllegalArgumentException(
                    "Argument bookmarkablePageClass must be not null");
        }

this.bookmarkablePageClassRef = new WeakReference(bookmarkablePageClass);
        this.pageMapName = pageMapName;
    }

    /**
* @see org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy#decode(org.apache.wicket.request.RequestParameters)
     */
    public IRequestTarget decode(RequestParameters requestParameters) {
        final String parametersFragment = requestParameters.getPath()
                .substring(getMountPath().length());
final PageParameters parameters = new PageParameters(decodeParameters(
                parametersFragment, requestParameters.getParameters()));
        String pageMapName = (String) parameters
                .remove(WebRequestCodingStrategy.PAGEMAP);
        if (requestParameters.getPageMapName() == null) {
            requestParameters.setPageMapName(pageMapName);
        } else {
            pageMapName = requestParameters.getPageMapName();
        }

// do some extra work for checking whether this is a normal request to a // bookmarkable page, or a request to a stateless page (in which case a
        // wicket:interface parameter should be available
        final String interfaceParameter = (String) parameters
                .remove(WebRequestCodingStrategy.INTERFACE_PARAMETER_NAME);

        if (interfaceParameter != null) {
WebRequestCodingStrategy.addInterfaceParameters(interfaceParameter,
                    requestParameters);
return new BookmarkableListenerInterfaceRequestTarget(pageMapName,
                    (Class) bookmarkablePageClassRef.get(),
                    parameters,
                    requestParameters.getComponentPath(),
                    requestParameters.getInterfaceName(),
                    1);
        } else {
            return new BookmarkablePageRequestTarget(pageMapName,
                    (Class) bookmarkablePageClassRef.get(), parameters);
        }
    }

    /**
* @see org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy#encode(org.apache.wicket.IRequestTarget)
     */
    public final CharSequence encode(final IRequestTarget requestTarget) {
        if (!(requestTarget instanceof IBookmarkablePageRequestTarget)) {
            throw new IllegalArgumentException(
                    "This encoder can only be used with " + "instances of "
+ IBookmarkablePageRequestTarget.class.getName());
        }

        final AppendingStringBuffer url = new AppendingStringBuffer(40);
        url.append(getMountPath());
final IBookmarkablePageRequestTarget target = (IBookmarkablePageRequestTarget) requestTarget;

        PageParameters pageParameters = target.getPageParameters();
        String pagemap = pageMapName != null ? pageMapName : target
                .getPageMapName();
        if (pagemap != null) {
            if (pageParameters == null) {
                pageParameters = new PageParameters();
            }
            pageParameters.put(WebRequestCodingStrategy.PAGEMAP, pagemap);
        }
        appendParameters(url, pageParameters);
        return url;
    }

    /**
* @see org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy#matches(org.apache.wicket.IRequestTarget)
     */
    public boolean matches(IRequestTarget requestTarget) {
        if (requestTarget instanceof IBookmarkablePageRequestTarget) {
IBookmarkablePageRequestTarget target = (IBookmarkablePageRequestTarget) requestTarget;
            if (((Class) bookmarkablePageClassRef.get()).equals(target
                    .getPageClass())) {
                if (this.pageMapName == null) {
                    return true;
                } else {
return this.pageMapName.equals(target.getPageMapName());
                }
            }
        }
        return false;
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
return "NumberedBookmarkablePageEncoder[page=" + (Class) bookmarkablePageClassRef.get() + "]";
    }

protected void appendParameters(AppendingStringBuffer url, Map parameters) {
        if (parameters != null && parameters.size() > 0) {
            final Iterator entries;
            if (UnitTestSettings.getSortUrlParameters()) {
                entries = new TreeMap(parameters).entrySet().iterator();
            } else {
                entries = parameters.entrySet().iterator();
            }
            while (entries.hasNext()) {
                Map.Entry entry = (Entry) entries.next();
                Object value = entry.getValue();
                if (value != null) {
                    if (value instanceof String[]) {
                        String[] values = (String[]) value;
                        for (int i = 0; i < values.length; i++) {
                            appendValue(url, values[i]);
                        }
                    } else {
                        appendValue(url, value.toString());
                    }
                }
            }
        }
    }

    private void appendValue(AppendingStringBuffer url, String value) {
        String escapedValue = urlEncode(value);
        if (!Strings.isEmpty(escapedValue)) {
            url.append("/").append(escapedValue);
        }
    }

    @Override
protected ValueMap decodeParameters(String urlFragment, Map urlParameters) {
        // Hack off any leading slash
        if (urlFragment.startsWith("/")) {
            urlFragment = urlFragment.substring(1);
        }

        if (urlFragment.length() == 0) {
            return new ValueMap();
        }

        // Split into pairs
        final String[] args = urlFragment.split("/");

        // Loop through args
        ValueMap parameters = new ValueMap();
        for (int i = 0; i < args.length; i++) {
            String value = urlDecode(args[i]);
            parameters.add(String.valueOf(i), value);
        }

        if (urlParameters != null) {
            parameters.putAll(urlParameters);
        }

        return parameters;
    }

}

Can any of this be dangerous?

-- Edvin

---------------------------------------------------------------------
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]

Reply via email to