You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2012/07/07 13:06:51 UTC

git commit: NonCachingImage simplified with override #shouldAddAntiCacheParameter(), added test

Updated Branches:
  refs/heads/master 6cd29d5ee -> b834c6d35


NonCachingImage simplified with override #shouldAddAntiCacheParameter(), added test


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

Branch: refs/heads/master
Commit: b834c6d3588cc51dce20d35359235caa0e73b236
Parents: 6cd29d5
Author: svenmeier <sv...@apache.org>
Authored: Sat Jul 7 13:05:26 2012 +0200
Committer: svenmeier <sv...@apache.org>
Committed: Sat Jul 7 13:05:26 2012 +0200

----------------------------------------------------------------------
 .../wicket/markup/html/image/NonCachingImage.java  |   28 ++++-----
 .../markup/html/image/NonCachingImagePage.html     |    9 +++
 .../markup/html/image/NonCachingImagePage.java     |   49 +++++++++++++++
 .../markup/html/image/NonCachingImageTest.java     |   41 ++++++++++++
 4 files changed, 111 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/b834c6d3/wicket-core/src/main/java/org/apache/wicket/markup/html/image/NonCachingImage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/NonCachingImage.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/NonCachingImage.java
index 056a164..e29ac64 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/NonCachingImage.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/NonCachingImage.java
@@ -16,17 +16,17 @@
  */
 package org.apache.wicket.markup.html.image;
 
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.wicket.request.resource.IResource;
 import org.apache.wicket.request.resource.ResourceReference;
 
 /**
- * A subclass of {@link Image} that adds random noise to the url every request to prevent the
+ * A subclass of {@link Image} that always adds random noise to the url every request to prevent the
  * browser from caching the image.
  * 
+ * @see Image#shouldAddAntiCacheParameter()
+ * 
  * @author Igor Vaynberg (ivaynberg)
  */
 public class NonCachingImage extends Image
@@ -51,9 +51,9 @@ public class NonCachingImage extends Image
 
 	/**
 	 * Construct.
-	 *
+	 * 
 	 * @see Image#Image(String, org.apache.wicket.request.resource.IResource)
-	 *
+	 * 
 	 * @param id
 	 * @param imageResource
 	 */
@@ -65,7 +65,8 @@ public class NonCachingImage extends Image
 	/**
 	 * Construct.
 	 * 
-	 * @see Image#Image(String, org.apache.wicket.request.resource.ResourceReference, org.apache.wicket.request.mapper.parameter.PageParameters)
+	 * @see Image#Image(String, org.apache.wicket.request.resource.ResourceReference,
+	 *      org.apache.wicket.request.mapper.parameter.PageParameters)
 	 * 
 	 * @param id
 	 * @param resourceReference
@@ -117,18 +118,13 @@ public class NonCachingImage extends Image
 	}
 
 	/**
-	 * @see org.apache.wicket.markup.html.image.Image#onComponentTag(org.apache.wicket.markup.ComponentTag)
+	 * Overriden to precent caching.
+	 * 
+	 * @return always {@code true}
 	 */
 	@Override
-	protected void onComponentTag(ComponentTag tag)
+	protected boolean shouldAddAntiCacheParameter()
 	{
-		super.onComponentTag(tag);
-
-		// the parameter is already added for Ajax requests by the super call
-		if (getRequestCycle().find(AjaxRequestTarget.class) == null)
-		{
-			addAntiCacheParameter(tag);
-		}
+		return true;
 	}
-
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/b834c6d3/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.html
new file mode 100644
index 0000000..efaf89f
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.html
@@ -0,0 +1,9 @@
+<html xmlns:wicket="http://wicket.apache.org/">
+<head>
+    <title>Wicket Examples - pub</title>
+    <link rel="stylesheet" type="text/css" href="style.css"/>
+</head>
+<body>
+    <img wicket:id="image" />
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/b834c6d3/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.java
new file mode 100644
index 0000000..c88706f
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImagePage.java
@@ -0,0 +1,49 @@
+/*
+ * 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.html.image;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.PackageResourceReference;
+
+/**
+ * Demonstrates {@link NonCachingImage}.
+ * 
+ * @author svenmeier
+ */
+public final class NonCachingImagePage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 */
+	public NonCachingImage image;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param parameters
+	 *            Page parameters (ignored since this is the home page)
+	 */
+	public NonCachingImagePage(final PageParameters parameters)
+	{
+		image = new NonCachingImage("image", new PackageResourceReference(
+			NonCachingImagePage.class, "Beer.gif"));
+		image.setOutputMarkupId(true);
+		add(image);
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/b834c6d3/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImageTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImageTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImageTest.java
new file mode 100644
index 0000000..3eb2340
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/NonCachingImageTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.html.image;
+
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.util.tester.TagTester;
+
+/**
+ * Test for {@link NonCachingImage}.
+ * 
+ * @author svenmeier
+ */
+public class NonCachingImageTest extends WicketTestCase
+{
+
+	/**
+	 * {@link NonCachingImage} always adds anticache.
+	 */
+	public void test()
+	{
+		NonCachingImagePage page = tester.startPage(NonCachingImagePage.class);
+
+		TagTester tag = tester.getTagById(page.image.getMarkupId());
+
+		assertTrue(tag.getAttribute("src").contains("antiCache"));
+	}
+}
\ No newline at end of file