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/05/08 15:56:51 UTC

git commit: WICKET-4541 Warn if wicket:container has an attribute

Updated Branches:
  refs/heads/master 21d5ac58f -> 6de4d3b40


WICKET-4541 Warn if wicket:container has an attribute


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

Branch: refs/heads/master
Commit: 6de4d3b4067087e1e2b12ae1277d8b52071e5374
Parents: 21d5ac5
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue May 8 16:56:03 2012 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue May 8 16:56:03 2012 +0300

----------------------------------------------------------------------
 .../org/apache/wicket/markup/MarkupParser.java     |    3 +
 .../parser/filter/WicketContainerTagHandler.java   |   93 +++++++++++++++
 .../html/repeater/data/table/NoRecordsToolbar.html |    2 +-
 3 files changed, 97 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/6de4d3b4/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java b/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java
index 4720314..f7872a5 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/MarkupParser.java
@@ -18,6 +18,7 @@ package org.apache.wicket.markup;
 
 import java.util.ArrayList;
 
+import org.apache.wicket.Application;
 import org.apache.wicket.Page;
 import org.apache.wicket.markup.html.form.AutoLabelTagHandler;
 import org.apache.wicket.markup.parser.IMarkupFilter;
@@ -31,6 +32,7 @@ import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
 import org.apache.wicket.markup.parser.filter.OpenCloseTagExpander;
 import org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler;
 import org.apache.wicket.markup.parser.filter.StyleAndScriptIdentifier;
+import org.apache.wicket.markup.parser.filter.WicketContainerTagHandler;
 import org.apache.wicket.markup.parser.filter.WicketLinkTagHandler;
 import org.apache.wicket.markup.parser.filter.WicketMessageTagHandler;
 import org.apache.wicket.markup.parser.filter.WicketNamespaceHandler;
@@ -176,6 +178,7 @@ public class MarkupParser extends AbstractMarkupParser
 		// Append it. See WICKET-4390
 		filters.add(new StyleAndScriptIdentifier(), StyleAndScriptIdentifier.class);
 		filters.add(new ConditionalCommentFilter());
+		filters.add(new WicketContainerTagHandler(Application.get().usesDevelopmentConfig()));
 
 		return filters;
 	}

http://git-wip-us.apache.org/repos/asf/wicket/blob/6de4d3b4/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketContainerTagHandler.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketContainerTagHandler.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketContainerTagHandler.java
new file mode 100755
index 0000000..af22ece
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketContainerTagHandler.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.parser.filter;
+
+import java.text.ParseException;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.WicketTag;
+import org.apache.wicket.markup.parser.AbstractMarkupFilter;
+import org.apache.wicket.util.value.IValueMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This markup filter warns if a wicket:container tag has an attribute besides wicket:id. This is
+ * most likely a programmer mistake because the wicket:container tag won't be available in
+ * deployment mode.
+ *
+ * The filter is only active in development mode and does nothing in deployment mode.
+ *
+ * @since 6.0
+ */
+public class WicketContainerTagHandler extends AbstractMarkupFilter
+{
+	private static final Logger log = LoggerFactory.getLogger(WicketContainerTagHandler.class);
+
+	private final boolean usesDevelopmentConfig;
+
+	public WicketContainerTagHandler(boolean usesDevelopmentConfig)
+	{
+		this.usesDevelopmentConfig = usesDevelopmentConfig;
+	}
+
+	@Override
+	protected final MarkupElement onComponentTag(ComponentTag tag) throws ParseException
+	{
+		if (usesDevelopmentConfig)
+		{
+			if (tag instanceof WicketTag)
+			{
+				WicketTag wtag = (WicketTag)tag;
+				if (tag.isOpen() && wtag.isContainerTag())
+				{
+					handleContainerTag(wtag);
+				}
+			}
+		}
+
+		return tag;
+	}
+
+	private void handleContainerTag(WicketTag containerTag)
+	{
+		IValueMap attributes = containerTag.getAttributes();
+		for (String attribute : attributes.keySet())
+		{
+			if (ignoreAttribute(attribute))
+			{
+				continue;
+			}
+
+			reportAttribute(containerTag, attribute);
+		}
+	}
+
+	private void reportAttribute(WicketTag containerTag, String attribute)
+	{
+		log.warn(
+			"wicket:container with id '{}' has attribute '{}' in markup, which will be ignored in deployment mode",
+			containerTag.getId(), attribute);
+	}
+
+	private boolean ignoreAttribute(String attribute)
+	{
+		return attribute.equalsIgnoreCase(getWicketNamespace() + ":id");
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/6de4d3b4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/NoRecordsToolbar.html
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/NoRecordsToolbar.html b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/NoRecordsToolbar.html
index 1f3ca4d..1018dd8 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/NoRecordsToolbar.html
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/NoRecordsToolbar.html
@@ -18,7 +18,7 @@
 <wicket:panel xmlns:wicket="http://wicket.apache.org">
 	<tr class="norecords-tr">
 		<td wicket:id="td" class="norecords-td">
-			<wicket:container wicket:id="msg" class="norecords">[no records found message]</wicket:container>
+			<wicket:container wicket:id="msg">[no records found message]</wicket:container>
 		</td>
 	</tr>
 </wicket:panel>
\ No newline at end of file