You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by kn...@apache.org on 2008/09/15 00:00:27 UTC

svn commit: r695298 - in /wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket: IPage.java PageParameters.java RequestCycle.java request/PageParameters.java

Author: knopp
Date: Sun Sep 14 15:00:27 2008
New Revision: 695298

URL: http://svn.apache.org/viewvc?rev=695298&view=rev
Log: (empty)

Added:
    wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/PageParameters.java   (contents, props changed)
      - copied, changed from r695070, wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/PageParameters.java
Removed:
    wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/PageParameters.java
Modified:
    wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/IPage.java
    wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/RequestCycle.java

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/IPage.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/IPage.java?rev=695298&r1=695297&r2=695298&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/IPage.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/IPage.java Sun Sep 14 15:00:27 2008
@@ -46,4 +46,30 @@
 	 * Renders the page 
 	 */
 	public void renderPage();
+	
+	/**
+	 * Bookmarkable page can be instantiated using a bookmarkable URL.
+	 * 
+	 * @return Returns true if the page is bookmarkable.
+	 */
+	public boolean isBookmarkable();
+
+	/**
+	 * Gets whether the page is stateless. Components on stateless page must not render any
+	 * statefull urls, and components on statefull page must not render any stateless urls.
+	 * Statefull urls are urls, which refer to a certain (current) page instance.
+	 * 
+	 * @return Whether this page is stateless
+	 */
+	public boolean isPageStateless();
+
+	/**
+	 * Returns the {@link PageParameters} for the page. Each bookmarkable page instance
+	 * should have {@link PageParameters} associated with it. The page parameters are
+	 * initialized from URL when page is created and are updated on every page render
+	 * request.
+	 * 
+	 * @return page parameters or <code>null</code>
+	 */
+	public PageParameters getPageParameters();
 }

Copied: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/PageParameters.java (from r695070, wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/PageParameters.java)
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/PageParameters.java?p2=wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/PageParameters.java&p1=wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/PageParameters.java&r1=695070&r2=695298&rev=695298&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/request/PageParameters.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/PageParameters.java Sun Sep 14 15:00:27 2008
@@ -1,4 +1,4 @@
-package org.apache._wicket.request;
+package org.apache._wicket;
 
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -8,290 +8,394 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache._wicket.request.RequestHandlerEncoder;
 import org.apache.wicket.util.lang.Objects;
 import org.apache.wicket.util.string.StringValue;
 
+/**
+ * Mutable class that holds parameters of a Page. Page parameters consist of indexed parameters and
+ * named parameters. Indexed parameters are URL segments before the query string. Named parameters
+ * are usually represented as query string params (i.e. ?arg1=var1&amp;arg2=val)
+ * <p>
+ * How those parameters are populated depends on the {@link RequestHandlerEncoder}s
+ * 
+ * @author Matej Knopp
+ */
 public class PageParameters implements Serializable
 {
 
 	private static final long serialVersionUID = 1L;
 
+	/**
+	 * Construct.
+	 */
 	public PageParameters()
-    {
+	{
 
-    }
+	}
 
-    public PageParameters(PageParameters copy)
-    {
-        if (copy == null)
-        {
-            throw new IllegalArgumentException("Copy argument may not be null.");
-        }
-        if (copy.indexedParameters != null)
-            this.indexedParameters = new ArrayList<String>(copy.indexedParameters);
-
-        if (copy.queryStringParameters != null)
-            this.queryStringParameters = new ArrayList<Entry>(copy.queryStringParameters);
-    }
+	/**
+	 * Copy constructor.
+	 * 
+	 * @param copy
+	 */
+	public PageParameters(PageParameters copy)
+	{
+		if (copy == null)
+		{
+			throw new IllegalArgumentException("Copy argument may not be null.");
+		}
+		if (copy.indexedParameters != null)
+			this.indexedParameters = new ArrayList<String>(copy.indexedParameters);
+
+		if (copy.namedParameters != null)
+			this.namedParameters = new ArrayList<Entry>(copy.namedParameters);
+	}
 
-    private List<String> indexedParameters = null;
+	private List<String> indexedParameters = null;
 
-    private static class Entry implements Serializable
-    {
+	private static class Entry implements Serializable
+	{
 		private static final long serialVersionUID = 1L;
-		
+
 		private String key;
-        private String value;
-    };
+		private String value;
+	};
 
-    private List<Entry> queryStringParameters = null;
+	private List<Entry> namedParameters = null;
 
-    public int getIndexedParamsCount()
-    {
-        return indexedParameters != null ? indexedParameters.size() : 0;
-    }
-
-    public void setIndexedParam(int index, Object object)
-    {
-        if (indexedParameters == null)
-            indexedParameters = new ArrayList<String>(index);
-
-        for (int i = indexedParameters.size(); i <= index; ++i)
-        {
-            indexedParameters.add(null);
-        }
-
-        indexedParameters.set(index, object != null ? object.toString() : null);
-    }
-
-    public StringValue getIndexedParam(int index)
-    {
-        if (indexedParameters != null)
-        {
-            if (index >= 0 && index < indexedParameters.size())
-            {
-                return StringValue.valueOf(indexedParameters.get(index));
-            }
-        }
-        return StringValue.valueOf((String)null);
-    };
-
-    public void removeIndexedParam(int index)
-    {
-        if (indexedParameters != null)
-        {
-            if (index >= 0 && index < indexedParameters.size())
-            {
-                indexedParameters.remove(index);
-            }
-        }
-    }
-
-    public Set<String> getQueryParamKeys()
-    {
-        if (queryStringParameters == null || queryStringParameters.isEmpty())
-        {
-            return Collections.emptySet();
-        }
-        Set<String> set = new TreeSet<String>();
-        for (Entry entry : queryStringParameters)
-        {
-            set.add(entry.key);
-        }
-        return Collections.unmodifiableSet(set);
-    }
-
-    public StringValue getQueryParam(String name)
-    {
-        if (name == null)
-        {
-            throw new IllegalArgumentException("Parameter name may not be null.");
-        }
-        if (queryStringParameters != null)
-        {
-            for (Entry entry : queryStringParameters)
-            {
-                if (entry.key.equals(name))
-                {
-                    return StringValue.valueOf(entry.value);
-                }
-            }
-        }
-        return StringValue.valueOf((String)null);
-    }
-
-    public List<StringValue> getQueryParams(String name)
-    {
-        if (name == null)
-        {
-            throw new IllegalArgumentException("Parameter name may not be null.");
-        }
-        if (queryStringParameters != null)
-        {
-            List<StringValue> result = new ArrayList<StringValue>();
-            for (Entry entry : queryStringParameters)
-            {
-                if (entry.key.equals(name))
-                {
-                    result.add(StringValue.valueOf(entry.value));
-                }
-            }
-            return Collections.unmodifiableList(result);
-        }
-        else
-        {
-            return Collections.emptyList();
-        }
-    }
-
-    public void removeQueryParam(String name)
-    {
-        if (name == null)
-        {
-            throw new IllegalArgumentException("Parameter name may not be null.");
-        }
-        if (queryStringParameters != null)
-        {
-            for (Iterator<Entry> i = queryStringParameters.iterator(); i.hasNext();)
-            {
-                Entry e = i.next();
-                if (e.key.equals(name))
-                {
-                    i.remove();
-                }
-            }
-        }
-    }
-
-    public void addQueryParam(String name, Object value)
-    {
-        addQueryParam(name, value, -1);
-    }
-
-    public void addQueryParam(String name, Object value, int index)
-    {
-
-        if (name == null)
-        {
-            throw new IllegalArgumentException("Parameter name may not be null.");
-        }
-
-        if (value == null)
-        {
-            throw new IllegalArgumentException("Parameter value may not be null.");
-        }
-
-        if (queryStringParameters == null)
-            queryStringParameters = new ArrayList<Entry>(1);
-        Entry entry = new Entry();
-        entry.key = name;
-        entry.value = value.toString();
-
-        if (index == -1)
-            queryStringParameters.add(entry);
-        else
-            queryStringParameters.add(index, entry);
-    }
-
-    public void setQueryParam(String name, Object value, int index)
-    {
-        removeQueryParam(name);
-
-        if (value != null)
-        {
-            addQueryParam(name, value);
-        }
-    }
-
-    public void setQueryParam(String name, Object value)
-    {
-        setQueryParam(name, value, -1);
-    }
-
-    public void clearIndexedParams()
-    {
-        this.indexedParameters = null;
-    }
-
-    public void clearQueryParams()
-    {
-        this.queryStringParameters = null;
-    }
-
-    void assign(PageParameters other)
-    {
-        if (this != other)
-        {
-            this.indexedParameters = other.indexedParameters;
-            this.queryStringParameters = other.queryStringParameters;
-        }
-    }
-
-    @Override
-    public boolean equals(Object obj)
-    {
-        if (this == obj)
-        {
-            return true;
-        }
-
-        if (obj instanceof PageParameters == false)
-        {
-            return false;
-        }
-
-        PageParameters rhs = (PageParameters)obj;
-        if (!Objects.equal(indexedParameters, rhs.indexedParameters))
-        {
-            return false;
-        }
-
-        if (queryStringParameters == null || rhs.queryStringParameters == null)
-        {
-            return rhs.queryStringParameters == queryStringParameters;
-        }
-
-        if (queryStringParameters.size() != rhs.queryStringParameters.size())
-        {
-            return false;
-        }
-
-        for (String key : getQueryParamKeys())
-        {
-            List<StringValue> values1 = getQueryParams(key);
-            Set<String> v1 = new TreeSet<String>();
-            List<StringValue> values2 = rhs.getQueryParams(key);
-            Set<String> v2 = new TreeSet<String>();
-            for (StringValue sv : values1)
-            {
-                v1.add(sv.toString());
-            }
-            for (StringValue sv : values2)
-            {
-                v2.add(sv.toString());
-            }
-            if (v1.equals(v2) == false)
-            {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    public static boolean equals(PageParameters p1, PageParameters p2)
-    {
-    	if (Objects.equal(p1, p2))
-    	{
-    		return true;
-    	}
-    	if (p1 == null && p2.getIndexedParamsCount() == 0 && p2.getQueryParamKeys().isEmpty())
-    	{
-    		return true;
-    	}
-    	if (p2 == null && p1.getIndexedParamsCount() == 0 && p1.getQueryParamKeys().isEmpty())
-    	{
-    		return true;
-    	}
-    	return false;
-    }
+	/**
+	 * @return count of indexed parameters
+	 */
+	public int getIndexedParamsCount()
+	{
+		return indexedParameters != null ? indexedParameters.size() : 0;
+	}
+
+	/**
+	 * Sets the indexed parameter on given index
+	 * 
+	 * @param index
+	 * @param object
+	 */
+	public void setIndexedParameter(int index, Object object)
+	{
+		if (indexedParameters == null)
+			indexedParameters = new ArrayList<String>(index);
+
+		for (int i = indexedParameters.size(); i <= index; ++i)
+		{
+			indexedParameters.add(null);
+		}
+
+		indexedParameters.set(index, object != null ? object.toString() : null);
+	}
+
+	/**
+	 * @param index
+	 * @return indexed parameter on given index
+	 */
+	public StringValue getIndexedParameter(int index)
+	{
+		if (indexedParameters != null)
+		{
+			if (index >= 0 && index < indexedParameters.size())
+			{
+				return StringValue.valueOf(indexedParameters.get(index));
+			}
+		}
+		return StringValue.valueOf((String)null);
+	};
+
+	/**
+	 * Removes indexed parameter on given index
+	 * 
+	 * @param index
+	 */
+	public void removeIndexedParameter(int index)
+	{
+		if (indexedParameters != null)
+		{
+			if (index >= 0 && index < indexedParameters.size())
+			{
+				indexedParameters.remove(index);
+			}
+		}
+	}
+
+	/**
+	 * Return set of all named parameter names.
+	 * 
+	 * @return named parameter names
+	 */
+	public Set<String> getNamedParameterKeys()
+	{
+		if (namedParameters == null || namedParameters.isEmpty())
+		{
+			return Collections.emptySet();
+		}
+		Set<String> set = new TreeSet<String>();
+		for (Entry entry : namedParameters)
+		{
+			set.add(entry.key);
+		}
+		return Collections.unmodifiableSet(set);
+	}
+
+	/**
+	 * Returns parameter value of named parameter with given name
+	 * 
+	 * @param name
+	 * @return parameter value
+	 */
+	public StringValue getNamedParameter(String name)
+	{
+		if (name == null)
+		{
+			throw new IllegalArgumentException("Parameter name may not be null.");
+		}
+		if (namedParameters != null)
+		{
+			for (Entry entry : namedParameters)
+			{
+				if (entry.key.equals(name))
+				{
+					return StringValue.valueOf(entry.value);
+				}
+			}
+		}
+		return StringValue.valueOf((String)null);
+	}
+
+	/**
+	 * Return list of all values for named parameter with given name
+	 * 
+	 * @param name
+	 * @return list of parameter values
+	 */
+	public List<StringValue> getNamedParameters(String name)
+	{
+		if (name == null)
+		{
+			throw new IllegalArgumentException("Parameter name may not be null.");
+		}
+		if (namedParameters != null)
+		{
+			List<StringValue> result = new ArrayList<StringValue>();
+			for (Entry entry : namedParameters)
+			{
+				if (entry.key.equals(name))
+				{
+					result.add(StringValue.valueOf(entry.value));
+				}
+			}
+			return Collections.unmodifiableList(result);
+		}
+		else
+		{
+			return Collections.emptyList();
+		}
+	}
+
+	/**
+	 * Removes named parameter with given name.
+	 * 
+	 * @param name
+	 */
+	public void removeNamedParameter(String name)
+	{
+		if (name == null)
+		{
+			throw new IllegalArgumentException("Parameter name may not be null.");
+		}
+		if (namedParameters != null)
+		{
+			for (Iterator<Entry> i = namedParameters.iterator(); i.hasNext();)
+			{
+				Entry e = i.next();
+				if (e.key.equals(name))
+				{
+					i.remove();
+				}
+			}
+		}
+	}
+
+	/**
+	 * Adds value to named parameter with given name.
+	 * 
+	 * @param name
+	 * @param value
+	 */
+	public void addNamedParameter(String name, Object value)
+	{
+		addNamedParameter(name, value, -1);
+	}
+
+	/**
+	 * Adds named parameter to a specified position. The {@link RequestHandlerEncoder}s may or may
+	 * not take the order into account.
+	 * 
+	 * @param name
+	 * @param value
+	 * @param index
+	 */
+	public void addNamedParameter(String name, Object value, int index)
+	{
+
+		if (name == null)
+		{
+			throw new IllegalArgumentException("Parameter name may not be null.");
+		}
+
+		if (value == null)
+		{
+			throw new IllegalArgumentException("Parameter value may not be null.");
+		}
+
+		if (namedParameters == null)
+			namedParameters = new ArrayList<Entry>(1);
+		Entry entry = new Entry();
+		entry.key = name;
+		entry.value = value.toString();
+
+		if (index == -1)
+			namedParameters.add(entry);
+		else
+			namedParameters.add(index, entry);
+	}
+
+	/**
+	 * Sets the named parameter on specified position. The {@link RequestHandlerEncoder}s may or
+	 * may not take the order into account.
+	 * 
+	 * @param name
+	 * @param value
+	 * @param index
+	 */
+	public void setNamedParameter(String name, Object value, int index)
+	{
+		removeNamedParameter(name);
+
+		if (value != null)
+		{
+			addNamedParameter(name, value);
+		}
+	}
+
+	/**
+	 * Sets the value for named parameter with given name.
+	 * 
+	 * @param name
+	 * @param value
+	 */
+	public void setNamedParameter(String name, Object value)
+	{
+		setNamedParameter(name, value, -1);
+	}
+
+	/**
+	 * Removes all indexed parameters.
+	 */
+	public void clearIndexedParameters()
+	{
+		this.indexedParameters = null;
+	}
+
+	/**
+	 * Removes all named parameters.
+	 */
+	public void clearNamedParameters()
+	{
+		this.namedParameters = null;
+	}
+
+	/**
+	 * Copy the paga parameters
+	 * 
+	 * @param other
+	 */
+	public void assign(PageParameters other)
+	{
+		if (this != other)
+		{
+			this.indexedParameters = other.indexedParameters;
+			this.namedParameters = other.namedParameters;
+		}
+	}
+
+	@Override
+	public boolean equals(Object obj)
+	{
+		if (this == obj)
+		{
+			return true;
+		}
+
+		if (obj instanceof PageParameters == false)
+		{
+			return false;
+		}
+
+		PageParameters rhs = (PageParameters)obj;
+		if (!Objects.equal(indexedParameters, rhs.indexedParameters))
+		{
+			return false;
+		}
+
+		if (namedParameters == null || rhs.namedParameters == null)
+		{
+			return rhs.namedParameters == namedParameters;
+		}
+
+		if (namedParameters.size() != rhs.namedParameters.size())
+		{
+			return false;
+		}
+
+		for (String key : getNamedParameterKeys())
+		{
+			List<StringValue> values1 = getNamedParameters(key);
+			Set<String> v1 = new TreeSet<String>();
+			List<StringValue> values2 = rhs.getNamedParameters(key);
+			Set<String> v2 = new TreeSet<String>();
+			for (StringValue sv : values1)
+			{
+				v1.add(sv.toString());
+			}
+			for (StringValue sv : values2)
+			{
+				v2.add(sv.toString());
+			}
+			if (v1.equals(v2) == false)
+			{
+				return false;
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * Compares two {@link PageParameters} objects.
+	 * 
+	 * @param p1
+	 * @param p2
+	 * @return <code>true</code> if the objects are equal, <code>false</code> otherwise.
+	 */
+	public static boolean equals(PageParameters p1, PageParameters p2)
+	{
+		if (Objects.equal(p1, p2))
+		{
+			return true;
+		}
+		if (p1 == null && p2.getIndexedParamsCount() == 0 && p2.getNamedParameterKeys().isEmpty())
+		{
+			return true;
+		}
+		if (p2 == null && p1.getIndexedParamsCount() == 0 && p1.getNamedParameterKeys().isEmpty())
+		{
+			return true;
+		}
+		return false;
+	}
 }

Propchange: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/PageParameters.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/RequestCycle.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/RequestCycle.java?rev=695298&r1=695297&r2=695298&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/RequestCycle.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/_wicket/RequestCycle.java Sun Sep 14 15:00:27 2008
@@ -83,6 +83,7 @@
 
 	protected UrlRenderer newUrlRenderer()
 	{
+		// All URLs will be rendered relative to current request (can be overriden afterwards)
 		return new UrlRenderer(getRequest().getUrl());
 	}