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:41:37 UTC

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

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/986e990d
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/986e990d
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/986e990d

Branch: refs/heads/wicket-1.5.x
Commit: 986e990d4ac09d8795d5adc640e5753bfe19c62f
Parents: d806060
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:31:08 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/986e990d/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 3991287..e63162b 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
@@ -162,10 +162,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))
 		{
@@ -181,27 +180,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;
 	}
 }