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;
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations