use of org.springframework.core.io.support.ResourcePatternResolver in project cloudbreak by hortonworks.
the class BlueprintSegmentReader method getFiles.
private List<Resource> getFiles(String configDir) throws IOException {
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
List<Resource> handleBarFiles = Arrays.stream(patternResolver.getResources("classpath:" + configDir + "/*/*.handlebars")).collect(toList());
List<Resource> jsonFiles = Arrays.stream(patternResolver.getResources("classpath:" + configDir + "/*/*.json")).collect(toList());
List<Resource> resources = new ArrayList<>();
resources.addAll(handleBarFiles);
resources.addAll(jsonFiles);
return resources;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project onebusaway-application-modules by camsys.
the class ResourceServiceImpl method getCollectionResourceAsSourceUrl.
private URL getCollectionResourceAsSourceUrl(String resourceName, LocaleProvider localeProvider) {
int index = resourceName.indexOf('=');
if (index == -1)
throw new IllegalStateException("invalid resource collection specifier: " + resourceName);
String collectionPrefix = resourceName.substring(0, index);
String collectionResourcePath = resourceName.substring(index + 1);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Map<String, String> resourceMapping = new HashMap<String, String>();
try {
org.springframework.core.io.Resource[] resources = resolver.getResources(collectionResourcePath);
for (org.springframework.core.io.Resource resource : resources) {
URL url = resource.getURL();
String name = getLocalUrlAsResourceName(url);
Resource r = getResourceForPath(name, localeProvider, url);
if (r != null) {
String path = url.getPath();
int sepIndex = path.lastIndexOf(File.separator);
if (sepIndex != -1)
path = path.substring(sepIndex + 1);
resourceMapping.put(path, r.getExternalUrl());
String alternateId = PREFIX_COLLECTION_ENTRY + collectionPrefix + ":" + path;
_resourceEntriesByResourcePath.put(alternateId, r);
}
}
File file = getOutputFile(PREFIX_COLLECTION + collectionPrefix + ".js");
PrintWriter out = new PrintWriter(file);
JSONObject obj = new JSONObject(resourceMapping);
out.println("var OBA = window.OBA || {};");
out.println("if(!OBA.Resources) { OBA.Resources = {}; }");
out.println("OBA.Resources." + collectionPrefix + " = " + obj.toString() + ";");
out.close();
return getFileAsUrl(file);
} catch (IOException ex) {
throw new IllegalStateException("error loading resources", ex);
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project jim-framework by jiangmin168168.
the class MyBatisConfig method sqlSessionFactoryBean.
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage("com.jim.dao.generated.entity");
// 分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("dialect", "postgresql");
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
// 添加插件
bean.setPlugins(new Interceptor[] { pageHelper });
// 添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
return bean.getObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project cloudbreak by hortonworks.
the class AppConfig method init.
@PostConstruct
public void init() throws IOException {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
PropertySourceLoader load = new YamlPropertySourceLoader();
for (Resource resource : patternResolver.getResources("classpath*:*-images.yml")) {
environment.getPropertySources().addLast(load.load(resource.getFilename(), resource, null));
}
for (Resource resource : loadEtcResources()) {
environment.getPropertySources().addFirst(load.load(resource.getFilename(), resource, null));
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project cloudbreak by hortonworks.
the class SaltOrchestrator method getStateConfigZip.
@Override
public byte[] getStateConfigZip() throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (ZipOutputStream zout = new ZipOutputStream(baos)) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Map<String, List<Resource>> structure = new TreeMap<>();
for (Resource resource : resolver.getResources("classpath*:salt/**")) {
String path = resource.getURL().getPath();
String dir = path.substring(path.indexOf("/salt") + "/salt".length(), path.lastIndexOf('/') + 1);
List<Resource> list = structure.get(dir);
if (list == null) {
list = new ArrayList<>();
}
structure.put(dir, list);
if (!path.endsWith("/")) {
list.add(resource);
}
}
for (Entry<String, List<Resource>> entry : structure.entrySet()) {
zout.putNextEntry(new ZipEntry(entry.getKey()));
for (Resource resource : entry.getValue()) {
LOGGER.debug("Zip salt entry: {}", resource.getFilename());
zout.putNextEntry(new ZipEntry(entry.getKey() + resource.getFilename()));
InputStream inputStream = resource.getInputStream();
byte[] bytes = IOUtils.toByteArray(inputStream);
zout.write(bytes);
zout.closeEntry();
}
}
} catch (IOException e) {
LOGGER.error("Failed to zip salt configurations", e);
throw new IOException("Failed to zip salt configurations", e);
}
return baos.toByteArray();
}
}
Aggregations