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/04/02 14:19:15 UTC

[2/2] git commit: WICKET-4485 TagUtils uses wrong separator in its #copyAttributes()

WICKET-4485 TagUtils uses wrong separator in its #copyAttributes()

Add a map with some default entries for the most used attributes. The map is public so that user applications can add more entries if needed. If there is no entry then the fallback is "; ".


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

Branch: refs/heads/master
Commit: ca5d7b224ce6106531b87294209c03128cbf4241
Parents: 1a6fc63
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Apr 2 14:16:32 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Apr 2 14:16:32 2012 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/markup/TagUtils.java    |   31 +++++++++++---
 1 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/ca5d7b22/wicket-core/src/main/java/org/apache/wicket/markup/TagUtils.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/TagUtils.java b/wicket-core/src/main/java/org/apache/wicket/markup/TagUtils.java
index d2091fb..7fd4e4d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/TagUtils.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/TagUtils.java
@@ -16,17 +16,31 @@
  */
 package org.apache.wicket.markup;
 
-import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.util.value.IValueMap;
+import org.apache.wicket.util.value.ValueMap;
 
 
 /**
- * Some utils to handle tags which otherwise would bloat the Tag AP.
+ * Some utils to handle tags which otherwise would bloat the Tag API.
  * 
  * @author Juergen Donnerstag
  */
 public class TagUtils
 {
+	private static final String DEFAULT_ATTRIBUTE_SEPARATOR = "; ";
+	/**
+	 * A map that keeps the separators which should be used for the different HTML
+	 * element attributes.
+	 */
+	// 'public' so that user applications can add/modify the entries, if needed
+	public static final IValueMap ATTRIBUTES_SEPARATORS = new ValueMap();
+	static {
+		ATTRIBUTES_SEPARATORS.put("class", " ");
+		ATTRIBUTES_SEPARATORS.put("style", DEFAULT_ATTRIBUTE_SEPARATOR);
+		ATTRIBUTES_SEPARATORS.put("onclick", DEFAULT_ATTRIBUTE_SEPARATOR);
+	}
+
 	/**
 	 * Constructor
 	 */
@@ -147,16 +161,18 @@ public class TagUtils
 
 	/**
 	 * Copy attributes from e.g. &lt;wicket:panel&gt; (or border) to the "calling" tag.
-	 * 
+	 *
 	 * @see <a href="http://issues.apache.org/jira/browse/WICKET-2874">WICKET-2874</a>
 	 * @see <a href="https://issues.apache.org/jira/browse/WICKET-3812">WICKET-3812</a>
-	 * 
+	 *
 	 * @param component
+	 *      the markup container which attributes will be copied
 	 * @param tag
+	 *      the component tag where the attributes will be applied
 	 */
-	public static void copyAttributes(final Component component, final ComponentTag tag)
+	public static void copyAttributes(final MarkupContainer component, final ComponentTag tag)
 	{
-		IMarkupFragment markup = ((MarkupContainer)component).getMarkup(null);
+		IMarkupFragment markup = component.getMarkup(null);
 		String namespace = markup.getMarkupResourceStream().getWicketNamespace() + ":";
 
 		MarkupElement elem = markup.get(0);
@@ -168,7 +184,8 @@ public class TagUtils
 				// exclude "wicket:XX" attributes
 				if (key.startsWith(namespace) == false)
 				{
-					tag.append(key, panelTag.getAttribute(key), ", ");
+					String separator = ATTRIBUTES_SEPARATORS.getString(key, DEFAULT_ATTRIBUTE_SEPARATOR);
+					tag.append(key, panelTag.getAttribute(key), separator);
 				}
 			}
 		}