All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ayongw.thymeleaf.dynamicurl.bootconf.DynamicResourceLocationDialectAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.github.ayongw.thymeleaf.dynamicurl.bootconf;

import com.github.ayongw.thymeleaf.dynamicurl.dialect.DynamicProcessConf;
import com.github.ayongw.thymeleaf.dynamicurl.dialect.DynamicResourceLocationDialect;
import com.github.ayongw.thymeleaf.dynamicurl.service.DynamicResourceLocationService;
import com.github.ayongw.thymeleaf.dynamicurl.service.PropertyDynamicResourceLocationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring5.SpringTemplateEngine;

import java.util.Map;

/**
 * 本地静态资源动态替换工具服务
 *
 * @author jiangguangtao 2018/4/30
 */
@Configuration
@ConditionalOnClass(SpringTemplateEngine.class)
@EnableConfigurationProperties({LocalResourceMappingConfigProps.class})
public class DynamicResourceLocationDialectAutoConfiguration {

    private LocalResourceMappingConfigProps localResourceMapping;

    public DynamicResourceLocationDialectAutoConfiguration(LocalResourceMappingConfigProps localResourceMapping) {
        this.localResourceMapping = localResourceMapping;
    }

    @Bean
    @ConditionalOnMissingBean
    public DynamicResourceLocationService dynamicResourceLocationService() {
        Map remoteUrlMap = localResourceMapping.getRemoteUrlMap();

        return new PropertyDynamicResourceLocationService(remoteUrlMap);
    }


    @Bean
    public DynamicResourceLocationDialect dynamicResourceLocationDialect() {
        DynamicProcessConf conf = new DynamicProcessConf();
        conf.setEnableProcess(localResourceMapping.isEnable());
        conf.setEnableLocalReplace(localResourceMapping.isEnableLocal());
        conf.setEnableRemoteReplace(localResourceMapping.isEnableRemote());
        conf.setLocalReplaceSuffix(localResourceMapping.getLocalSuffix());

        if (StringUtils.isNotBlank(localResourceMapping.getRemotePrefix())) {
            conf.setRemoteReplacePrefixes(StringUtils.split(localResourceMapping.getRemotePrefix()));
        }
        return new DynamicResourceLocationDialect(conf);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy