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.request.resource.caching.version;
018
019import java.util.regex.Pattern;
020
021import org.apache.wicket.request.resource.caching.IStaticCacheableResource;
022import org.apache.wicket.util.lang.Args;
023
024/**
025 * provides a static version string for all package resources 
026 *
027 * @author Peter Ertl
028 *
029 * @since 1.5
030 */
031public class StaticResourceVersion implements IResourceVersion
032{
033        private final String version;
034        private final Pattern pattern;
035
036        /**
037         * create static version provider
038         *
039         * @param version
040         *             static version string to deliver for all queries resources
041         */
042        public StaticResourceVersion(String version)
043        {
044                this.version = Args.notNull(version, "version");
045                this.pattern = Pattern.compile(Pattern.quote(version));
046        }
047
048        @Override
049        public String getVersion(IStaticCacheableResource resource)
050        {
051                return version;
052        }
053
054        @Override
055        public Pattern getVersionPattern()
056        {
057                return pattern;
058        }
059}