yangys
2024-03-31 53c8d3e3bd3596132b362f20e52aef380d493a84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.qianwen.core.i18n.source;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 
/* loaded from: blade-starter-i18n-9.3.0.0-SNAPSHOT.jar:org/springblade/core/i18n/source/WildcardReloadableResourceBundleMessageSource.class */
public class WildcardReloadableResourceBundleMessageSource extends ReloadableResourceBundleMessageSource {
    private static final Logger log = LoggerFactory.getLogger(WildcardReloadableResourceBundleMessageSource.class);
    private static final String PROPERTIES_SUFFIX = ".properties";
    private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
 
    protected List<String> calculateAllFilenames(String basename, Locale locale) {
        List<String> filenames = super.calculateAllFilenames(basename, locale);
        if (basename.contains("*")) {
            filenames.remove(basename);
        }
        return filenames;
    }
 
    protected List<String> calculateFilenamesForLocale(String basename, Locale locale) {
        String basename2 = basename.replace(".", "/");
        List<String> fileNames = new ArrayList<>();
        List<String> matchFilenames = super.calculateFilenamesForLocale(basename2, locale);
        for (String matchFilename : matchFilenames) {
            try {
                Resource[] resources = this.resolver.getResources("classpath*:" + matchFilename + PROPERTIES_SUFFIX);
                for (Resource resource : resources) {
                    String sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, "");
                    fileNames.add(sourcePath);
                }
            } catch (IOException ex) {
                log.error("读取国际化信息文件异常", ex);
            }
        }
        return fileNames;
    }
}