/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.wicket;

import java.util.Map;

import org.apache.wicket.protocol.http.RequestUtils;
import org.apache.wicket.util.string.IStringIterator;
import org.apache.wicket.util.string.StringList;
import org.apache.wicket.util.value.ValueMap;


/**
 * A typesafe abstraction and container for parameters to a requested page. Page
 * parameters in HTTP are query string values in the request URL. In other
 * protocols, the parameters to a page might come from some other source.
 * <p>
 * Pages which take a PageParameters object as an argument to their constructor
 * can be accessed directly from a URL and are known as "bookmarkable" pages
 * since the URL is stable across sessions and can be stored in a browser's
 * bookmark database.
 * 
 * @author Jonathan Locke
 */
public final class PageParameters extends ValueMap
{
	/**
	 * Null value for page parameters
	 */
	public static final PageParameters NULL = new PageParameters();

	private static final long serialVersionUID = 1L;

	/**
	 * Constructor
	 */
	public PageParameters()
	{
		super();

		setOnRequestCycle();
	}

	/**
	 * Copy constructor.
	 * 
	 * @param map
	 *            The map to copy
	 * @see ValueMap#ValueMap(java.util.Map)
	 */
	public PageParameters(final Map parameterMap)
	{
		super(parameterMap);

		setOnRequestCycle();
	}

	/**
	 * Construct.
	 * 
	 * @param keyValuePairs
	 *            List of key value pairs separated by commas. For example,
	 *            "param1=foo,param2=bar"
	 * @see ValueMap#ValueMap(String)
	 */
	public PageParameters(final String keyValuePairs)
	{
		this(keyValuePairs, ",");
	}

	/**
	 * Construct.
	 * 
	 * @param keyValuePairs
	 *            List of key value pairs separated by commas. For example,
	 *            "param1=foo,param2=bar"
	 * @param delimiter
	 *            Delimiter string used to separate key/value pairs
	 * @see ValueMap#ValueMap(String)
	 * 
	 * @deprecated Please use
	 *             {@link RequestUtils#decodeParameters(String, ValueMap)} to
	 *             decode a request URL, or
	 *             {@link ValueMap#ValueMap(String, String)} for other usecases.
	 */
	public PageParameters(final String keyValuePairs, final String delimiter)
	{
		super();

		setOnRequestCycle();

		// We can not use ValueMaps constructor as it uses
		// VariableAssignmentParser which is more suitable for markup
		// attributes, rather than URL parameters. URL param keys for
		// examples are allowed to start with a digit (e.g. 0=xxx)
		// and quotes are not "quotes".

		// Get list of strings separated by the delimiter
		final StringList pairs = StringList.tokenize(keyValuePairs, delimiter);

		// Go through each string in the list
		for (IStringIterator iterator = pairs.iterator(); iterator.hasNext();)
		{
			// Get the next key value pair
			final String pair = iterator.next();

			final int pos = pair.indexOf('=');
			if (pos == 0)
			{
				throw new IllegalArgumentException("URL parameter is missing the lvalue: " + pair);
			}
			else if (pos != -1)
			{
				final String key = pair.substring(0, pos).trim();
				final String value = pair.substring(pos + 1).trim();

				put(key, value);
			}
			else
			{
				final String key = pair.trim();
				final String value = null;

				put(key, value);
			}
		}
	}

	public Object put(Object key, Object value)
	{
		if (value instanceof String || value instanceof String[])
		{
			return super.put(key, value);
		}
		else
		{
			throw new IllegalArgumentException("You tried to add an object of type " +
					value.getClass().getName() + " to your PageParameters for key " + key +
					", but you are only allowed to use String or String[].");
		}
	}

	/**
	 * Set this on request cycle. The RequestCycle will decide whether to keep
	 * it as a reference or not.
	 * 
	 * @see RequestCycle#setPageParameters(PageParameters)
	 */
	private void setOnRequestCycle()
	{
		RequestCycle cycle = RequestCycle.get();
		if (cycle != null)
		{
			cycle.setPageParameters(this);
		}
	}
}

@@ -4109,16 +4109,201 @@
 lue)%0A%09%7B%0A
+%09%09if (!(key instanceof String))%0A%09%09%7B%0A%09%09%09throw new IllegalArgumentException(%0A%09%09%09%09%09%22PageParameter keys must be of type String, but you supplied a %22 +%0A%09%09%09%09%09%09%09key.getClass().getName());%0A%09%09%7D%0A
 %09%09if (va

Check key type, too.