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 2011/07/03 13:56:54 UTC

svn commit: r1142419 - /wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/info/ComponentInfo.java

Author: mgrigorov
Date: Sun Jul  3 11:56:53 2011
New Revision: 1142419

URL: http://svn.apache.org/viewvc?rev=1142419&view=rev
Log:
WICKET-3862 ComponentInfo: simplified -, : encoding procedure


Modified:
    wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/info/ComponentInfo.java

Modified: wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/info/ComponentInfo.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/info/ComponentInfo.java?rev=1142419&r1=1142418&r2=1142419&view=diff
==============================================================================
--- wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/info/ComponentInfo.java (original)
+++ wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/info/ComponentInfo.java Sun Jul  3 11:56:53 2011
@@ -32,20 +32,38 @@ import org.apache.wicket.util.string.Str
 public class ComponentInfo
 {
 	private static final char BEHAVIOR_INDEX_SEPARATOR = '.';
-	private static final String SEPARATOR = "-";
-	private static final String COMPONENT_SEPARATOR = ":";
-
-	private static final String TMP_PLACEHOLDER = "[[[[[[[WICKET[[TMP]]DASH]]" + Math.random() +
-		"]]]]";
+	private static final char SEPARATOR = '-';
+	private static final char COMPONENT_SEPARATOR = ':';
 
+	/**
+	 * Replaces ':' with '-', and '-' with '--'.
+	 * 
+	 * @param path
+	 *            the path to the component in its page
+	 * @return the encoded path
+	 */
 	private static String encodeComponentPath(CharSequence path)
 	{
 		if (path != null)
 		{
-			path = Strings.replaceAll(path, SEPARATOR, TMP_PLACEHOLDER);
-			path = Strings.replaceAll(path, COMPONENT_SEPARATOR, SEPARATOR);
-			path = Strings.replaceAll(path, TMP_PLACEHOLDER, SEPARATOR + SEPARATOR);
-			return path.toString();
+			StringBuilder result = new StringBuilder();
+			int length = path.length();
+			for (int i = 0; i < length; i++)
+			{
+				char c = path.charAt(i);
+				switch (c)
+				{
+					case COMPONENT_SEPARATOR :
+						result.append(SEPARATOR);
+						break;
+					case SEPARATOR :
+						result.append(SEPARATOR).append(SEPARATOR);
+						break;
+					default :
+						result.append(c);
+				}
+			}
+			return result.toString();
 		}
 		else
 		{
@@ -53,14 +71,40 @@ public class ComponentInfo
 		}
 	}
 
+	/**
+	 * Replaces '--' with '-' and '-' with ':'
+	 * 
+	 * @param path
+	 *            the encoded path of the component in its page
+	 * @return the (non-encoded) path of the component in its page
+	 */
 	private static String decodeComponentPath(CharSequence path)
 	{
 		if (path != null)
 		{
-			path = Strings.replaceAll(path, SEPARATOR + SEPARATOR, TMP_PLACEHOLDER).toString();
-			path = Strings.replaceAll(path, SEPARATOR, COMPONENT_SEPARATOR);
-			path = Strings.replaceAll(path, TMP_PLACEHOLDER, SEPARATOR).toString();
-			return path.toString();
+			StringBuilder result = new StringBuilder();
+			int length = path.length();
+			for (int i = 0; i < length; i++)
+			{
+				char c = path.charAt(i);
+				switch (c)
+				{
+					case SEPARATOR :
+						if ((i < length - 1) && (path.charAt(i + 1) == SEPARATOR))
+						{
+							i++;
+							result.append(SEPARATOR);
+						}
+						else
+						{
+							result.append(COMPONENT_SEPARATOR);
+						}
+						break;
+					default :
+						result.append(c);
+				}
+			}
+			return result.toString();
 		}
 		else
 		{