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 2014/02/18 10:31:07 UTC

[3/3] git commit: WICKET-5498 OutputComponentPath Html5 compliance

WICKET-5498 OutputComponentPath Html5 compliance


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

Branch: refs/heads/master
Commit: f1e84a7999da0904aa7f2ef5cdbebe4fb05eb9d8
Parents: 77cee0a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Feb 18 11:30:28 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Feb 18 11:30:28 2014 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/wicket/Component.java  | 11 ++-
 .../apache/wicket/settings/DebugSettings.java   | 38 ++++++++++
 .../wicket/settings/DebugSettingsTest.java      | 77 ++++++++++++++++++++
 .../wicket/settings/ISecuritySettingsTest.java  |  2 +-
 4 files changed, 126 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/f1e84a79/wicket-core/src/main/java/org/apache/wicket/Component.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java
index a49596e..e1b256f 100644
--- a/wicket-core/src/main/java/org/apache/wicket/Component.java
+++ b/wicket-core/src/main/java/org/apache/wicket/Component.java
@@ -3915,7 +3915,16 @@ public abstract class Component
 			tag.putInternal(MARKUP_ID_ATTR_NAME, getMarkupId());
 		}
 
-		if (getApplication().getDebugSettings().isOutputComponentPath())
+		DebugSettings debugSettings = getApplication().getDebugSettings();
+		String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
+		if (Strings.isEmpty(componentPathAttributeName) == false)
+		{
+			String path = getPageRelativePath();
+			path = path.replace("_", "__");
+			path = path.replace(':', '_');
+			tag.put(componentPathAttributeName, path);
+		}
+		else if (debugSettings.isOutputComponentPath())
 		{
 			String path = getPageRelativePath();
 			path = path.replace("_", "__");

http://git-wip-us.apache.org/repos/asf/wicket/blob/f1e84a79/wicket-core/src/main/java/org/apache/wicket/settings/DebugSettings.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/settings/DebugSettings.java b/wicket-core/src/main/java/org/apache/wicket/settings/DebugSettings.java
index 5be4213..8aa8782 100644
--- a/wicket-core/src/main/java/org/apache/wicket/settings/DebugSettings.java
+++ b/wicket-core/src/main/java/org/apache/wicket/settings/DebugSettings.java
@@ -58,6 +58,8 @@ public class DebugSettings
 
 	private boolean outputComponentPath = false;
 
+	private String componentPathAttributeName = null;
+
 	private boolean developmentUtilitiesEnabled = false;
 
 	/**
@@ -184,7 +186,9 @@ public class DebugSettings
 	 * @see #setOutputComponentPath(boolean)
 	 * @return <code>true</code> if output component path feature is enabled, <code>false</code>
 	 *         otherwise
+	 * @deprecated Use #getComponentPathAttributeName() instead
 	 */
+	@Deprecated
 	public boolean isOutputComponentPath()
 	{
 		return outputComponentPath;
@@ -196,7 +200,9 @@ public class DebugSettings
 	 *
 	 * @param outputComponentPath
 	 * @return {@code this} object for chaining
+	 * @deprecated Use #setComponentPathAttributeName() with a non-empty value
 	 */
+	@Deprecated
 	public DebugSettings setOutputComponentPath(boolean outputComponentPath)
 	{
 		this.outputComponentPath = outputComponentPath;
@@ -204,6 +210,38 @@ public class DebugSettings
 	}
 
 	/**
+	 * If the parameter value is non-empty then Wicket will use it as the name of an attribute of the
+	 * component tag to print the {@link org.apache.wicket.Component}'s path.
+	 * This can be useful for debugging and automating tests.
+	 *
+	 * For example: if {@code componentPathAttributeName} is 'data-wicket-path' then Wicket will add
+	 * an attribute to the {@link org.apache.wicket.markup.ComponentTag} for each component with name
+	 * 'data-wicket-path' and as a value the component's
+	 * {@link org.apache.wicket.Component#getPageRelativePath() page relative path}.
+	 *
+	 * @param componentPathAttributeName
+	 *          The name of the attribute for the {@link org.apache.wicket.markup.ComponentTag}.
+	 *          If {@code null} or empty then the attribute won't be rendered
+	 * @return {@code this} object for chaining
+	 */
+	public DebugSettings setComponentPathAttributeName(String componentPathAttributeName)
+	{
+		this.componentPathAttributeName = componentPathAttributeName;
+		return this;
+	}
+
+	/**
+	 * @see #setComponentPathAttributeName(String)
+	 * @return The name of the attribute for the {@link org.apache.wicket.markup.ComponentTag}.
+	 *         If {@code null} or empty then the attribute won't be rendered
+	 */
+	public String getComponentPathAttributeName()
+	{
+		return componentPathAttributeName;
+	}
+
+
+	/**
 	 * Enables all of the panels and pages, etc, from wicket-devutils package.
 	 *
 	 * @param enable

http://git-wip-us.apache.org/repos/asf/wicket/blob/f1e84a79/wicket-core/src/test/java/org/apache/wicket/settings/DebugSettingsTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/settings/DebugSettingsTest.java b/wicket-core/src/test/java/org/apache/wicket/settings/DebugSettingsTest.java
new file mode 100644
index 0000000..510c44a
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/settings/DebugSettingsTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.settings;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.MockPageWithLink;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.util.tester.TagTester;
+import org.junit.Test;
+
+/**
+ * Tests for DebugSettings
+ */
+public class DebugSettingsTest extends WicketTestCase
+{
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5498
+	 */
+	@Test
+	public void setComponentPathAttributeName()
+	{
+		String attributeName = "data-wicket-path";
+		tester.getApplication().getDebugSettings().setComponentPathAttributeName(attributeName);
+		MockPageWithLink page = new MockPageWithLink();
+		Component link = new Link(MockPageWithLink.LINK_ID)
+		{
+			@Override
+			public void onClick()
+			{
+			}
+		}.setMarkupId(MockPageWithLink.LINK_ID);
+		page.add(link);
+		tester.startPage(page);
+
+		TagTester tagTester = tester.getTagById(MockPageWithLink.LINK_ID);
+		String wicketPath = tagTester.getAttribute(attributeName);
+		assertEquals(link.getPageRelativePath(), wicketPath);
+	}
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5498
+	 */
+	@Test
+	public void setComponentPathAttributeNameDeprected()
+	{
+		tester.getApplication().getDebugSettings().setOutputComponentPath(true);
+		MockPageWithLink page = new MockPageWithLink();
+		Component link = new Link(MockPageWithLink.LINK_ID)
+		{
+			@Override
+			public void onClick()
+			{
+			}
+		}.setMarkupId(MockPageWithLink.LINK_ID);
+		page.add(link);
+		tester.startPage(page);
+
+		TagTester tagTester = tester.getTagById(MockPageWithLink.LINK_ID);
+		String wicketPath = tagTester.getAttribute("wicketpath");
+		assertEquals(link.getPageRelativePath(), wicketPath);
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f1e84a79/wicket-core/src/test/java/org/apache/wicket/settings/ISecuritySettingsTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/settings/ISecuritySettingsTest.java b/wicket-core/src/test/java/org/apache/wicket/settings/ISecuritySettingsTest.java
index 3c44692..66c733f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/settings/ISecuritySettingsTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/settings/ISecuritySettingsTest.java
@@ -28,7 +28,7 @@ import org.apache.wicket.request.flow.RedirectToUrlException;
 import org.junit.Test;
 
 /**
- * Tests for {@link ISecuritySettings}
+ * Tests for {@link SecuritySettings}
  */
 public class ISecuritySettingsTest extends WicketTestCase
 {