001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.html.image;
018
019import org.apache.wicket.model.IModel;
020import org.apache.wicket.request.mapper.parameter.PageParameters;
021import org.apache.wicket.request.resource.IResource;
022import org.apache.wicket.request.resource.ResourceReference;
023
024/**
025 * A subclass of {@link Image} that always adds random noise to the url every request to prevent the
026 * browser from caching the image.
027 * 
028 * @see Image#shouldAddAntiCacheParameter()
029 * 
030 * @author Igor Vaynberg (ivaynberg)
031 */
032public class NonCachingImage extends Image
033{
034        private static final long serialVersionUID = 1L;
035
036        /**
037         * Construct.
038         * 
039         * @see Image#Image(String, IModel)
040         * 
041         * @param id
042         * @param model
043         */
044        public NonCachingImage(String id, IModel<?> model)
045        {
046                super(id, model);
047        }
048
049        /**
050         * Construct.
051         * 
052         * @see Image#Image(String, IResource, IResource...)
053         * 
054         * @param id
055         * @param imageResource
056         */
057        public NonCachingImage(String id, IResource imageResource)
058        {
059                super(id, imageResource);
060        }
061
062        /**
063         * Construct.
064         * 
065         * @see Image#Image(String, ResourceReference, PageParameters, ResourceReference...)
066         * 
067         * @param id
068         * @param resourceReference
069         * @param resourceParameters
070         */
071        public NonCachingImage(String id, ResourceReference resourceReference,
072                PageParameters resourceParameters)
073        {
074                super(id, resourceReference, resourceParameters);
075        }
076
077        /**
078         * Construct.
079         * 
080         * @see Image#Image(String, ResourceReference, ResourceReference...)
081         * 
082         * @param id
083         * @param resourceReference
084         */
085        public NonCachingImage(String id, ResourceReference resourceReference)
086        {
087                super(id, resourceReference);
088        }
089
090        /**
091         * Construct.
092         * 
093         * @see Image#Image(String, String)
094         * 
095         * 
096         * @param id
097         * @param string
098         */
099        public NonCachingImage(String id, String string)
100        {
101                super(id, string);
102        }
103
104        /**
105         * Construct.
106         * 
107         * @see Image#Image(String)
108         * 
109         * @param id
110         */
111        public NonCachingImage(String id)
112        {
113                super(id);
114        }
115
116        /**
117         * Overridden to prevent caching.
118         * 
119         * @return always {@code true}
120         */
121        @Override
122        protected boolean shouldAddAntiCacheParameter()
123        {
124                return true;
125        }
126}