Search in sources :

Example 61 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project mybatis.flying by limeng32.

the class SqlSessionFactoryConfig method createSqlSessionFactoryBean.

@Bean(name = "sqlSessionFactory")
@Primary
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    /**
     * 设置datasource
     */
    sqlSessionFactoryBean.setDataSource(dataSource1);
    VFS.addImplClass(SpringBootVFS.class);
    /**
     * 设置mybatis configuration 扫描路径
     */
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("Configuration.xml"));
    /**
     * 设置typeAlias 包扫描路径
     */
    sqlSessionFactoryBean.setTypeAliasesPackage("indi.mybatis.flying");
    /**
     * 添加mapper 扫描路径
     */
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] ra1 = resolver.getResources("classpath*:indi/mybatis/flying/mapper*/*.xml");
    // 扫描映射文件
    sqlSessionFactoryBean.setMapperLocations(ra1);
    return sqlSessionFactoryBean;
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ClassPathResource(org.springframework.core.io.ClassPathResource) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 62 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project hale by halestudio.

the class AbstractCellExplanation method findLocales.

/**
 * Determine the locales a resource is available for.
 *
 * @param clazz the clazz the resource resides next to
 * @param baseName the base name of the resource
 * @param suffix the suffix of the resource file, e.g.
 *            <code>properties</code>
 * @param defaultLocale the default locale to be assumed for an unqualified
 *            resource
 * @return the set of locales the resource is available for
 * @throws IOException if an error occurs trying to determine the resource
 *             files
 */
public static Set<Locale> findLocales(final Class<?> clazz, final String baseName, final String suffix, Locale defaultLocale) throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(clazz.getClassLoader());
    String pkg = clazz.getPackage().getName().replaceAll("\\.", "/");
    String pattern = pkg + "/" + baseName + "*." + suffix;
    return Arrays.stream(resolver.getResources(pattern)).map(resource -> {
        String fileName = resource.getFilename();
        if (fileName != null && fileName.startsWith(baseName)) {
            fileName = fileName.substring(baseName.length());
            if (fileName.endsWith("." + suffix)) {
                if (fileName.length() == suffix.length() + 1) {
                    // default locale file
                    return defaultLocale;
                } else {
                    String localeIdent = fileName.substring(0, fileName.length() - suffix.length() - 1);
                    String language = "";
                    String country = "";
                    String variant = "";
                    String[] parts = localeIdent.split("_");
                    int index = 0;
                    if (parts.length > index && parts[index].isEmpty()) {
                        index++;
                    }
                    if (parts.length > index) {
                        language = parts[index++];
                    }
                    if (parts.length > index) {
                        country = parts[index++];
                    }
                    if (parts.length > index) {
                        variant = parts[index++];
                    }
                    return new Locale(language, country, variant);
                }
            } else {
                log.error("Invalid resource encountered");
                return null;
            }
        } else {
            log.error("Invalid resource encountered");
            return null;
        }
    }).filter(locale -> locale != null).collect(Collectors.toSet());
}
Also used : Locale(java.util.Locale) Arrays(java.util.Arrays) Cell(eu.esdihumboldt.hale.common.align.model.Cell) CellExplanation(eu.esdihumboldt.hale.common.align.model.CellExplanation) ALogger(de.fhg.igd.slf4jplus.ALogger) Set(java.util.Set) IOException(java.io.IOException) ALoggerFactory(de.fhg.igd.slf4jplus.ALoggerFactory) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) Entity(eu.esdihumboldt.hale.common.align.model.Entity) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Collectors(java.util.stream.Collectors) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) List(java.util.List) ResourceBundle(java.util.ResourceBundle) Locale(java.util.Locale) Map(java.util.Map) Entry(java.util.Map.Entry) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Nullable(javax.annotation.Nullable) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) Joiner(com.google.common.base.Joiner) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 63 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class PropsFilePropertiesSource method doReadConfig.

/**
 * This overridden method reads the jawr.properties from
 * Jar!META-INF/jawr.properties.
 */
@Override
protected Properties doReadConfig() {
    if (log.isDebugEnabled()) {
        log.debug("PropsFilePropertiesSource::doReadConfig");
    }
    Properties properties;
    /**
     * Call super class doReadConfig If there is default configLocation
     * location specified in Servlet Init Params
     */
    if (defaultConfigLocation != null) {
        properties = super.doReadConfig();
    } else {
        properties = new Properties();
    }
    try {
        PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
        Resource[] resources = resolver.getResources("classpath*:META-INF/jawr.properties");
        if (resources != null) {
            for (Resource resource : resources) {
                if (log.isDebugEnabled()) {
                    log.debug("Properties Resource Location: " + resource.getURL());
                }
                if (resource != null && resource.getInputStream() != null) {
                    // here
                    properties.load(resource.getInputStream());
                }
            }
        } else {
            throw new RuntimeException(JAWR_PROPS_NOT_FOUND);
        }
    } catch (IOException e) {
        throw new RuntimeException(JAWR_PROPS_NOT_FOUND);
    }
    if (properties.size() == 0) {
        throw new RuntimeException(NO_JAWR_PROPS);
    }
    // JAFFA-531
    List<String> appendedProps = properties.keySet().stream().map(Object::toString).filter(s -> s.endsWith("+")).collect(Collectors.toList());
    for (String key : appendedProps) {
        String originalKey = key.substring(0, key.length() - 1);
        if (!properties.containsKey(originalKey)) {
            log.error(String.format(BASE_KEY_DNE, originalKey));
        } else {
            String valueToAppend = getPropertyObjectString(properties.get(key));
            StringBuilder originalValue = new StringBuilder(getPropertyObjectString(properties.get(originalKey)));
            if (originalValue.length() > 0 && valueToAppend.length() > 0) {
                originalValue.append(", ");
            }
            properties.setProperty(originalKey, originalValue.append(valueToAppend).toString());
            if (log.isDebugEnabled()) {
                log.debug("Appending " + valueToAppend + " to jawr property " + originalKey);
            }
            properties.remove(key);
        }
    }
    return properties;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Logger(org.apache.log4j.Logger) List(java.util.List) Properties(java.util.Properties) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Resource(org.springframework.core.io.Resource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver)

Example 64 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class DwrServlet method init.

@Override
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
    super.init(servletConfig);
    if (log.isDebugEnabled()) {
        log.debug("initializing DwrServlet Extension");
    }
    try {
        Enumeration en = servletConfig.getInitParameterNames();
        boolean skipDefaultConfig = false;
        while (en.hasMoreElements()) {
            String paramName = (String) en.nextElement();
            String paramValue = servletConfig.getInitParameter(paramName);
            // meta-config
            if (paramName.startsWith("meta-config") && paramValue != null && !"".equals(paramValue.trim())) {
                PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
                resources = resolver.getResources(paramValue);
            }
            // skipDefaultConfig
            if (paramName.startsWith("skipDefaultConfig") && paramValue != null && !"".equals(paramValue.trim())) {
                skipDefaultConfig = Boolean.parseBoolean(paramValue);
            }
        }
        /*
			 * Nothing will get loaded into dwr container, since no resources
			 * found in classpath and default config got skipped.
			 */
        if ((resources == null || resources.length == 0) && skipDefaultConfig) {
            throw new IOException(Messages.getString("DwrXmlConfigurator.MissingConfigFile", new String[] { "jar!META-INF/dwr.xml" }));
        }
        /*
			 * When there is no resources found under meta-inf and the
			 * skipDefaultConfig set to false then the validation handled for
			 * default config and the default config will get load into
			 * container by super class.
			 */
        if (resources == null && !skipDefaultConfig) {
            return;
        }
        org.jaffa.dwr.util.ContainerUtil.configureFromResource(getContainer(), servletConfig, resources);
        ContainerUtil.publishContainer(getContainer(), servletConfig);
    } catch (IOException | ParserConfigurationException | SAXException e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) Enumeration(java.util.Enumeration) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver) SAXException(org.xml.sax.SAXException)

Example 65 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class ActionServlet method initModuleConfig.

protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
    }
    // to support default behaviour.
    if (!"classpath*:/META-INF/struts-config.xml".equals(paths)) {
        return super.initModuleConfig(prefix, paths);
    }
    ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
    ModuleConfig config = factoryObject.createModuleConfig(prefix);
    Digester digester = initConfigDigester();
    PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
    try {
        Resource[] resources = resolver.getResources(paths);
        if (resources != null && resources.length > 0) {
            for (Resource resource : resources) {
                digester.push(config);
                if (resource == null) {
                    continue;
                }
                parseModuleConfigFile(digester, resource);
            }
        } else {
            String msg = internal.getMessage("configMissing", paths);
            log.error(msg);
            throw new UnavailableException(msg);
        }
        getServletContext().setAttribute("org.apache.struts.action.MODULE" + config.getPrefix(), config);
        FormBeanConfig[] fbs = config.findFormBeanConfigs();
        for (int i = 0; i < fbs.length; i++) {
            if (fbs[i].getDynamic()) {
                fbs[i].getDynaActionFormClass();
            }
        }
    } catch (IOException ie) {
        throw new ServletException(ie);
    }
    return config;
}
Also used : ModuleConfigFactory(org.apache.struts.config.ModuleConfigFactory) Resource(org.springframework.core.io.Resource) UnavailableException(javax.servlet.UnavailableException) ModuleConfig(org.apache.struts.config.ModuleConfig) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) FormBeanConfig(org.apache.struts.config.FormBeanConfig) Digester(org.apache.commons.digester.Digester) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)135 Resource (org.springframework.core.io.Resource)86 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)53 IOException (java.io.IOException)37 Bean (org.springframework.context.annotation.Bean)30 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)29 ArrayList (java.util.ArrayList)16 Properties (java.util.Properties)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 File (java.io.File)13 InputStream (java.io.InputStream)12 Test (org.junit.jupiter.api.Test)12 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PageHelper (com.github.pagehelper.PageHelper)10 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)10 Primary (org.springframework.context.annotation.Primary)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)7 URL (java.net.URL)6