Author: knopp
Date: Sat Sep 6 11:02:04 2008
New Revision: 692698
URL: http://svn.apache.org/viewvc?rev=692698&view=rev
Log:
Next generation url handling. Maybe.
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandler.java
(with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandlerEncoder.java
(with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestParameters.java
(with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/Url.java
(with props)
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/UrlRequestParameters.java
(with props)
wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/
wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/UrlTest.java
(with props)
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandler.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandler.java?rev=692698&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandler.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandler.java
Sat Sep 6 11:02:04 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.requestng;
+
+import org.apache.wicket.RequestCycle;
+
+/**
+ * A request target is the base entity that is the subject of a request.
Different types of request
+ * have different request targets. For instance a request for a bookmarkable
page differs from a
+ * request for a link on a previously rendered page, which in turn differs
from a request for a
+ * shared resource.
+ *
+ * @author Eelco Hillenius
+ * @author Matej Knopp
+ */
+public interface RequestHandler
+{
+ /**
+ * Generates a response.
+ *
+ * @param requestCycle
+ * the current request cycle
+ */
+ void respond(RequestCycle requestCycle);
+
+ /**
+ * This method is called at the end of a request cycle to indicate that
processing is done and
+ * that cleaning up of the subject(s) of this target may be done.
+ *
+ * @param requestCycle
+ * the current request cycle
+ */
+ void detach(RequestCycle requestCycle);
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandlerEncoder.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandlerEncoder.java?rev=692698&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandlerEncoder.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandlerEncoder.java
Sat Sep 6 11:02:04 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.requestng;
+
+/**
+ * Encodes [EMAIL PROTECTED] RequestHandler}(s) into [EMAIL PROTECTED] Url}(s)
and decodes [EMAIL PROTECTED] Url}(s) to
+ * [EMAIL PROTECTED] RequestHandler}(s). For [EMAIL PROTECTED]
RequestHandler}s and [EMAIL PROTECTED] Url}s the implementation
+ * doesn't know the [EMAIL PROTECTED] #encode(RequestHandler)} and [EMAIL
PROTECTED] #decode(Url, RequestParameters)}
+ * methods must return <code>null</code>.
+ *
+ * @author Matej Knopp
+ */
+public interface RequestHandlerEncoder
+{
+ /**
+ * Returns [EMAIL PROTECTED] RequestHandler} for the request or
<code>null</code> if the encoder does not
+ * recognize the URL.
+ *
+ * @param url
+ * @param requestParameters
+ * provides access to all GET and POST request parameters
+ * @return RequestHandler instance or <code>null</code>
+ */
+ RequestHandler decode(Url url, RequestParameters requestParameters);
+
+ /**
+ * Returns the [EMAIL PROTECTED] Url} for given [EMAIL PROTECTED]
RequestHandler} or <code>null</code> if the
+ * encoder does not recognize the request handler.
+ *
+ * @param requestHandler
+ * @return Url instance or <code>null</code>.
+ */
+ Url encode(RequestHandler requestHandler);
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestHandlerEncoder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestParameters.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestParameters.java?rev=692698&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestParameters.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestParameters.java
Sat Sep 6 11:02:04 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.requestng;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.wicket.util.string.StringValue;
+
+/**
+ * Represents request parameters.
+ *
+ * @author Matej Knopp
+ */
+public interface RequestParameters
+{
+ /**
+ * Returns immutable set of all available parameter names.
+ *
+ * @return list of parameter names
+ */
+ public Set<String> getParameterNames();
+
+ /**
+ * Returns single value for parameter with specified name. This method
always returns non-null
+ * result even if the parameter does not exist.
+ *
+ * @see StringValue#isNull()
+ *
+ * @param name
+ * parameter name
+ * @return [EMAIL PROTECTED] StringValue} wrapping the actual value
+ */
+ public StringValue getParameterValue(String name);
+
+ /**
+ * Returns list of values for parameter with specified name. If the
parameter does not exist
+ * this method returns <code>null</code>
+ *
+ * @param name
+ * parameter name
+ * @return list of all values for given parameter or <code>null</code>
if parameter does not
+ * exist
+ */
+ public List<StringValue> getParameterValues(String name);
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/RequestParameters.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/Url.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/Url.java?rev=692698&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/Url.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/Url.java
Sat Sep 6 11:02:04 2008
@@ -0,0 +1,435 @@
+/*
+ * 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.requestng;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.util.lang.Objects;
+import org.apache.wicket.util.string.StringValue;
+import org.apache.wicket.util.string.Strings;
+
+ /**
+ * Represents the URL part after Wicket Filter.
+ * <p>
+ * URL consists of segments and query parameters.
+ * <p>
+ * Example URLs:
+ *
+ * <pre>
+ * foo/bar/baz?a=1&b=5 - segments:
["foo","bar,"baz], query parameters:
["a"="1", "b"="5"]
+ * foo/bar//baz?=4&6 - segments: ["foo", "bar",
"", "baz"], query parameters: [""="4",
"6"=""]
+ * /foo/bar/ - segments: ["", "foo",
"bar", ""]
+ * foo/bar// - segments: ["foo", "bar",
"", ""]
+ * ?a=b - segments: [ ], query parameters: ["a"="b"]
+ * / - segments: ["", ""]
+ * </pre>
+ *
+ * The Url class takes care of encoding and decoding of the segments and
parameters.
+ *
+ * @author Matej Knopp
+ */
+public final class Url implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private final List<String> segments = new ArrayList<String>();
+
+ private List<QueryParameter> parameters = new
ArrayList<QueryParameter>();
+
+ /**
+ * Construct.
+ */
+ public Url()
+ {
+ }
+
+ /**
+ * Construct.
+ *
+ * @param url
+ * url being copied
+ */
+ public Url(Url url)
+ {
+ segments.addAll(url.getSegments());
+ parameters.addAll(url.getQueryParameters());
+ }
+
+ /**
+ * Returns segments of the URL. Segments form the part before query
string.
+ *
+ * @return mutable list of segments
+ */
+ public List<String> getSegments()
+ {
+ return segments;
+ }
+
+ /**
+ * Returns query parameters of the URL.
+ *
+ * @return mutable list of query parameters
+ */
+ public List<QueryParameter> getQueryParameters()
+ {
+ return parameters;
+ }
+
+ /**
+ * Convenience method that removes all query parameters with given name.
+ *
+ * @param name
+ * query parameter name
+ */
+ public void removeQueryParameters(String name)
+ {
+ for (Iterator<QueryParameter> i =
getQueryParameters().iterator(); i.hasNext();)
+ {
+ QueryParameter param = i.next();
+ if (Objects.equal(name, param.getName()))
+ {
+ i.remove();
+ }
+ }
+ }
+
+ /**
+ * Convenience method that removes all query parameters with given name
and adds new query
+ * parameter with specified name and value
+ *
+ * @param name
+ * @param value
+ */
+ public void setQueryParameter(String name, Object value)
+ {
+ removeQueryParameters(name);
+ if (value != null)
+ {
+ QueryParameter parameter = new QueryParameter(name,
value.toString());
+ getQueryParameters().add(parameter);
+ }
+ }
+
+ /**
+ * Returns first query parameter with specified name or null if such
query parameter doesn't
+ * exist.
+ *
+ * @param name
+ * @return query parameter or <code>null</code>
+ */
+ public QueryParameter getQueryParameter(String name)
+ {
+ for (QueryParameter parameter : parameters)
+ {
+ if (Objects.equal(name, parameter.getName()))
+ {
+ return parameter;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the value of first query parameter with specified name. Note
that this method never
+ * returns <code>null</code>. Not even if the parameter does not exist.
+ *
+ * @see StringValue#isNull()
+ *
+ * @param name
+ * @return [EMAIL PROTECTED] StringValue} instance wrapping the
parameter value
+ */
+ public StringValue getQueryParameterValue(String name)
+ {
+ QueryParameter parameter = getQueryParameter(name);
+ if (parameter == null)
+ {
+ return StringValue.valueOf((String)null);
+ }
+ else
+ {
+ return StringValue.valueOf(parameter.getValue());
+ }
+ }
+
+ /**
+ * Represents a single query parameter
+ *
+ * @author Matej Knopp
+ */
+ public final static class QueryParameter
+ {
+ private final String name;
+ private final String value;
+
+ /**
+ * Creates new [EMAIL PROTECTED] QueryParameter} instance. The
<code>name</code> and
+ * <code>value</code> parameters must not be <code>null</code>,
though they can be
+ * empty strings.
+ *
+ * @param name
+ * parameter name
+ * @param value
+ * parameter value
+ */
+ public QueryParameter(String name, String value)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("Argument
'name' can not be null.");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("Argument
'value' can not be null.");
+ }
+ this.name = name;
+ this.value = value;
+ }
+
+ /**
+ * Returns query parameter name.
+ *
+ * @return query parameter name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Returns query parameter value.
+ *
+ * @return query parameter value
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj instanceof QueryParameter == false)
+ {
+ return false;
+ }
+ QueryParameter rhs = (QueryParameter)obj;
+ return Objects.equal(this.getName(), rhs.getName()) &&
+ Objects.equal(this.getValue(), rhs.getValue());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hashCode(getName(), getValue());
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder result = new StringBuilder();
+ result.append(encode(getName()));
+ if (!Strings.isEmpty(getValue()))
+ {
+ result.append('=');
+ result.append(encode(getValue()));
+ }
+ return result.toString();
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj instanceof Url == false)
+ {
+ return false;
+ }
+ Url rhs = (Url)obj;
+
+ return getSegments().equals(rhs.getSegments()) &&
+ getQueryParameters().equals(rhs.getQueryParameters());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hashCode(getSegments(), getQueryParameters());
+ }
+
+ private static String encode(String string)
+ {
+ try
+ {
+ return URLEncoder.encode(string, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new WicketRuntimeException(e);
+ }
+ }
+
+ private static String decode(String string)
+ {
+ try
+ {
+ return URLDecoder.decode(string, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new WicketRuntimeException(e);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder result = new StringBuilder();
+ for (String s : getSegments())
+ {
+ if (result.length() > 0)
+ {
+ result.append('/');
+ }
+ result.append(encode(s));
+ }
+
+ boolean first = true;
+
+ for (QueryParameter p : getQueryParameters())
+ {
+ if (first)
+ {
+ result.append("?");
+ first = false;
+ }
+ else
+ {
+ result.append("&");
+ }
+ result.append(p.toString());
+ }
+
+ return result.toString();
+ }
+
+ private static QueryParameter parseQueryParameter(String qp)
+ {
+ if (qp.indexOf('=') == -1)
+ {
+ return new QueryParameter(decode(qp), "");
+ }
+ String parts[] = qp.split("=");
+ if (parts.length == 0)
+ {
+ return new QueryParameter("", "");
+ }
+ else if (parts.length == 1)
+ {
+ return new QueryParameter("", decode(parts[0]));
+ }
+ else
+ {
+ return new QueryParameter(decode(parts[0]),
decode(parts[1]));
+ }
+ }
+
+ /**
+ * Parses the given URL string.
+ *
+ * @param url
+ * @return Url object
+ */
+ public static Url parse(String url)
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("Argument 'url' may
not be null.");
+ }
+
+ Url result = new Url();
+
+ String segments;
+ String query;
+
+ int qIndex = url.indexOf('?');
+
+ if (qIndex == -1)
+ {
+ segments = url;
+ query = "";
+ }
+ else
+ {
+ segments = url.substring(0, qIndex);
+ query = url.substring(qIndex + 1);
+ }
+
+ if (segments.length() > 0)
+ {
+
+ boolean removeLast = false;
+ if (segments.endsWith("/"))
+ {
+ // we need to append something and remove it
after splitting because otherwise the
+ // trailing slashes will be lost
+ segments += "/x";
+ removeLast = true;
+ }
+
+ String segmentArray[] = segments.split("/");
+
+ if (removeLast)
+ {
+ segmentArray[segmentArray.length - 1] = null;
+ }
+
+ for (String s : segmentArray)
+ {
+ if (s != null)
+ {
+ result.segments.add(decode(s));
+ }
+ }
+ }
+
+ if (query.length() > 0)
+ {
+ String queryArray[] = query.split("&");
+ for (String s : queryArray)
+ {
+ result.parameters.add(parseQueryParameter(s));
+ }
+ }
+
+ return result;
+ };
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/Url.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/UrlRequestParameters.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/UrlRequestParameters.java?rev=692698&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/UrlRequestParameters.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/UrlRequestParameters.java
Sat Sep 6 11:02:04 2008
@@ -0,0 +1,82 @@
+/*
+ * 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.requestng;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.wicket.requestng.Url.QueryParameter;
+import org.apache.wicket.util.lang.Objects;
+import org.apache.wicket.util.string.StringValue;
+
+/**
+ * Utility class that expresses query parameters from [EMAIL PROTECTED] Url}
as [EMAIL PROTECTED] RequestParameters}.
+ *
+ * @author Matej Knopp
+ */
+public class UrlRequestParameters implements RequestParameters
+{
+ private final Url url;
+
+ /**
+ * Construct.
+ * @param url
+ */
+ public UrlRequestParameters(Url url)
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("Argument 'url' may
not be null.");
+ }
+ this.url = url;
+ }
+
+ public Set<String> getParameterNames()
+ {
+ Set<String> result = new HashSet<String>();
+ for (QueryParameter parameter : url.getQueryParameters())
+ {
+ result.add(parameter.getName());
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ public StringValue getParameterValue(String name)
+ {
+ return url.getQueryParameterValue(name);
+ }
+
+ public List<StringValue> getParameterValues(String name)
+ {
+ List<StringValue> values = null;
+ for (QueryParameter parameter : url.getQueryParameters())
+ {
+ if (Objects.equal(name, parameter.getName()))
+ {
+ if (values == null)
+ {
+ values = new ArrayList<StringValue>();
+ }
+
values.add(StringValue.valueOf(parameter.getValue()));
+ }
+ }
+ return values != null ? Collections.unmodifiableList(values) :
null;
+ }
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/requestng/UrlRequestParameters.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/UrlTest.java
URL:
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/UrlTest.java?rev=692698&view=auto
==============================================================================
---
wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/UrlTest.java
(added)
+++
wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/UrlTest.java
Sat Sep 6 11:02:04 2008
@@ -0,0 +1,164 @@
+/*
+ * 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.requestng;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.requestng.Url.QueryParameter;
+
+/**
+ * @author Matej Knopp
+ */
+public class UrlTest extends TestCase
+{
+ private void checkSegments(Url url, String... segments)
+ {
+ assertEquals(Arrays.asList(segments), url.getSegments());
+ }
+
+ private void checkQueryParams(Url url, String... params)
+ {
+ List<QueryParameter> list = new ArrayList<QueryParameter>();
+ for (int i = 0; i < params.length; i += 2)
+ {
+ QueryParameter p = new QueryParameter(params[i],
params[i + 1]);
+ list.add(p);
+ }
+
+ assertEquals(list, url.getQueryParameters());
+ }
+
+ /**
+ *
+ */
+ public void testParse1()
+ {
+ String s = "foo/bar/baz?a=4&b=5";
+ Url url = Url.parse(s);
+ checkSegments(url, "foo", "bar", "baz");
+ checkQueryParams(url, "a", "4", "b", "5");
+ }
+
+ /**
+ *
+ */
+ public void testParse2()
+ {
+ String s = "foo/bar//baz?=4&6";
+ Url url = Url.parse(s);
+ checkSegments(url, "foo", "bar", "", "baz");
+ checkQueryParams(url, "", "4", "6", "");
+ }
+
+ /**
+ *
+ */
+ public void testParse3()
+ {
+ String s = "//foo/bar/";
+ Url url = Url.parse(s);
+ checkSegments(url, "", "", "foo", "bar", "");
+ checkQueryParams(url);
+ }
+
+ /**
+ *
+ */
+ public void testParse4()
+ {
+ String s = "/foo/bar//";
+ Url url = Url.parse(s);
+ checkSegments(url, "", "foo", "bar", "", "");
+ checkQueryParams(url);
+ }
+
+ /**
+ *
+ */
+ public void testParse5()
+ {
+ String s = "foo/b%3Dr/b%26z/x%3F?a=b&x%3F%264=y%3Dz";
+ Url url = Url.parse(s);
+ checkSegments(url, "foo", "b=r", "b&z", "x?");
+ checkQueryParams(url, "a", "b", "x?&4", "y=z");
+ }
+
+ /**
+ *
+ */
+ public void testParse6()
+ {
+ String s = "";
+ Url url = Url.parse(s);
+ checkSegments(url);
+ checkQueryParams(url);
+ }
+
+ /**
+ *
+ */
+ public void testParse7()
+ {
+ String s = "?a=b";
+ Url url = Url.parse(s);
+ checkSegments(url);
+ checkQueryParams(url, "a", "b");
+ }
+
+ /**
+ *
+ */
+ public void testParse8()
+ {
+ String s = "/";
+ Url url = Url.parse(s);
+ checkSegments(url, "", "");
+ checkQueryParams(url);
+ }
+
+ /**
+ *
+ */
+ public void testParse9()
+ {
+ String s = "/?a=b";
+ Url url = Url.parse(s);
+ checkSegments(url, "", "");
+ checkQueryParams(url, "a", "b");
+ }
+
+ /**
+ *
+ */
+ public void testRender1()
+ {
+ Url url = new Url();
+ url.getSegments().add("foo");
+ url.getSegments().add("b=r");
+ url.getSegments().add("b&z");
+ url.getSegments().add("x?");
+ url.setQueryParameter("a", "b");
+ url.setQueryParameter("x?&4", "y=z");
+
+ assertEquals("foo/b%3Dr/b%26z/x%3F?a=b&x%3F%264=y%3Dz",
url.toString());
+ }
+
+}
Propchange:
wicket/sandbox/knopp/experimental/wicket/src/test/java/org/apache/wicket/requestng/UrlTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain