You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/03/19 14:30:45 UTC

git commit: Improve the checks for existence of Application thread local. Remove some duplicated code

Updated Branches:
  refs/heads/master 7761be9b7 -> b663a176d


Improve the checks for existence of Application thread local.
Remove some duplicated code


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b663a176
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b663a176
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b663a176

Branch: refs/heads/master
Commit: b663a176d09ccd44e4482de2494c66a8eaebc2a1
Parents: 7761be9
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Mar 19 15:30:00 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Mar 19 15:30:00 2012 +0200

----------------------------------------------------------------------
 .../apache/wicket/protocol/http/RequestUtils.java  |   25 +++++---------
 1 files changed, 9 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/b663a176/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
index c7147ed..6182064 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
@@ -163,10 +163,9 @@ public final class RequestUtils
 	{
 		String charsetName = null;
 
-		Application application = Application.get();
-		if (application != null)
+		if (Application.exists())
 		{
-			charsetName = application.getRequestCycleSettings().getResponseRequestEncoding();
+			charsetName = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
 		}
 		if (Strings.isEmpty(charsetName))
 		{
@@ -182,27 +181,21 @@ public final class RequestUtils
 
 	/**
 	 * @param request
+	 *      the http servlet request to extract the charset from
 	 * @return the request's charset
 	 */
 	public static Charset getCharset(HttpServletRequest request)
 	{
-		String charsetName = null;
+		Charset charset = null;
 		if (request != null)
 		{
-			charsetName = request.getCharacterEncoding();
+			String charsetName = request.getCharacterEncoding();
+			charset = Charset.forName(charsetName);
 		}
-		if (Strings.isEmpty(charsetName))
+		if (charset == null)
 		{
-			Application application = Application.get();
-			if (application != null)
-			{
-				charsetName = application.getRequestCycleSettings().getResponseRequestEncoding();
-			}
+			charset = getDefaultCharset();
 		}
-		if (Strings.isEmpty(charsetName))
-		{
-			charsetName = "UTF-8";
-		}
-		return Charset.forName(charsetName);
+		return charset;
 	}
 }