You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2011/09/16 06:50:16 UTC

svn commit: r1171386 - /wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java

Author: ivaynberg
Date: Fri Sep 16 04:50:16 2011
New Revision: 1171386

URL: http://svn.apache.org/viewvc?rev=1171386&view=rev
Log:
WICKET-4055

Modified:
    wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java

Modified: wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java?rev=1171386&r1=1171385&r2=1171386&view=diff
==============================================================================
--- wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java (original)
+++ wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java Fri Sep 16 04:50:16 2011
@@ -51,16 +51,25 @@ public class LocaleFirstMapper extends A
 	/**
 	 * @see org.apache.wicket.request.IRequestMapper#getCompatibilityScore(org.apache.wicket.request.Request)
 	 */
-	public int getCompatibilityScore(final Request request)
+	public int getCompatibilityScore(Request request)
 	{
+		if (getLocaleFromUrl(request) != null)
+		{
+			request = stripLocaleSegment(request);
+		}
+
 		// since we match all urls the score is simply delegated to the chain
 		return chain.getCompatibilityScore(request);
 	}
 
-	/**
-	 * @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
-	 */
-	public IRequestHandler mapRequest(Request request)
+	private Request stripLocaleSegment(Request request)
+	{
+		Url url = request.getUrl();
+		url.getSegments().remove(0);
+		return request.cloneWithUrl(url);
+	}
+
+	private Locale getLocaleFromUrl(Request request)
 	{
 		// locale is the first segment in the url
 		List<String> segments = request.getUrl().getSegments();
@@ -69,20 +78,25 @@ public class LocaleFirstMapper extends A
 			String localeAsString = segments.get(0);
 			if (!Strings.isEmpty(localeAsString))
 			{
-				Locale locale = LocaleHelper.parseLocale(localeAsString);
-				if (locale != null)
-				{
-					Session.get().setLocale(locale);
-
-					// now that we have proccessed the first segment we need to strip from the url
-					Url url = request.getUrl();
-					url.getSegments().remove(0);
-
-					// create a request based on the new url
-					request = request.cloneWithUrl(url);
-				}
+				return LocaleHelper.parseLocale(localeAsString);
 			}
 		}
+		return null;
+	}
+
+	/**
+	 * @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
+	 */
+	public IRequestHandler mapRequest(Request request)
+	{
+		Locale locale = getLocaleFromUrl(request);
+		if (locale != null)
+		{
+			Session.get().setLocale(locale);
+
+			// now that we have proccessed the first segment we need to strip from the url
+			request = stripLocaleSegment(request);
+		}
 
 		// chain url processing
 		return chain.mapRequest(request);