001/*
002 * Copyright 2002-2018 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.reactive.resource;
018
019import reactor.core.publisher.Mono;
020
021import org.springframework.core.io.Resource;
022
023/**
024 * A {@code VersionStrategy} that relies on a fixed version applied as a request
025 * path prefix, e.g. reduced SHA, version name, release date, etc.
026 *
027 * <p>This is useful for example when {@link ContentVersionStrategy} cannot be
028 * used such as when using JavaScript module loaders which are in charge of
029 * loading the JavaScript resources and need to know their relative paths.
030 *
031 * @author Rossen Stoyanchev
032 * @author Brian Clozel
033 * @since 5.0
034 * @see VersionResourceResolver
035 */
036public class FixedVersionStrategy extends AbstractPrefixVersionStrategy {
037
038        private final Mono<String> versionMono;
039
040
041        /**
042         * Create a new FixedVersionStrategy with the given version string.
043         * @param version the fixed version string to use
044         */
045        public FixedVersionStrategy(String version) {
046                super(version);
047                this.versionMono = Mono.just(version);
048        }
049
050
051        @Override
052        public Mono<String> getResourceVersion(Resource resource) {
053                return this.versionMono;
054        }
055
056}