001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *  https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.resource;
018
019import org.springframework.core.io.Resource;
020
021/**
022 * A {@code VersionStrategy} that relies on a fixed version applied as a request
023 * path prefix, e.g. reduced SHA, version name, release date, etc.
024 *
025 * <p>This is useful for example when {@link ContentVersionStrategy} cannot be
026 * used such as when using JavaScript module loaders which are in charge of
027 * loading the JavaScript resources and need to know their relative paths.
028 *
029 * @author Brian Clozel
030 * @author Rossen Stoyanchev
031 * @since 4.1
032 * @see VersionResourceResolver
033 */
034public class FixedVersionStrategy extends AbstractVersionStrategy {
035
036        private final String version;
037
038
039        /**
040         * Create a new FixedVersionStrategy with the given version string.
041         * @param version the fixed version string to use
042         */
043        public FixedVersionStrategy(String version) {
044                super(new PrefixVersionPathStrategy(version));
045                this.version = version;
046        }
047
048
049        @Override
050        public String getResourceVersion(Resource resource) {
051                return this.version;
052        }
053
054}