beetl属性文件支持自动发现,以beetl-前缀即可。

This commit is contained in:
thinkgem
2018-01-07 22:28:02 +08:00
parent a59c978603
commit c629a2005a
4 changed files with 257 additions and 242 deletions

View File

@@ -1,74 +1,89 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package com.jeesite.common.io;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import com.jeesite.common.lang.ExceptionUtils;
/**
* 资源供给类
* @author ThinkGem
* @version 2016-9-16
*/
public class ResourceUtils extends org.springframework.util.ResourceUtils {
private static ResourceLoader resourceLoader = new DefaultResourceLoader();
/**
* 获取ClassLoader
*/
public static ClassLoader getClassLoader() {
return resourceLoader.getClassLoader();
}
/**
* 获取资源加载器可读取jar内的文件
*/
public static Resource getResource(String location) {
return resourceLoader.getResource(location);
}
/**
* 获取资源文件流(用后记得关闭)
* @param location
* @author ThinkGem
* @throws IOException
*/
public static InputStream getResourceFileStream(String location) throws IOException{
Resource resource = resourceLoader.getResource(location);
return resource.getInputStream();
}
/**
* 获取资源文件内容
* @param location
* @author ThinkGem
*/
public static String getResourceFileContent(String location){
InputStream is = null;
try{
is = ResourceUtils.getResourceFileStream(location);
return IOUtils.toString(is, "UTF-8");
}catch (IOException e) {
throw ExceptionUtils.unchecked(e);
}finally{
IOUtils.closeQuietly(is);
}
}
/**
* 获取资源加载器可读取jar内的文件
* @author ThinkGem
*/
public static ResourceLoader getResourceLoader() {
return resourceLoader;
}
}
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package com.jeesite.common.io;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import com.jeesite.common.lang.ExceptionUtils;
/**
* 资源供给类
* @author ThinkGem
* @version 2016-9-16
*/
public class ResourceUtils extends org.springframework.util.ResourceUtils {
private static ResourceLoader resourceLoader = new DefaultResourceLoader();
/**
* 获取资源加载器可读取jar内的文件
* @author ThinkGem
*/
public static ResourceLoader getResourceLoader() {
return resourceLoader;
}
/**
* 获取ClassLoader
*/
public static ClassLoader getClassLoader() {
return resourceLoader.getClassLoader();
}
/**
* 获取资源加载器可读取jar内的文件
*/
public static Resource getResource(String location) {
return resourceLoader.getResource(location);
}
/**
* 获取资源文件流(用后记得关闭)
* @param location
* @author ThinkGem
* @throws IOException
*/
public static InputStream getResourceFileStream(String location) throws IOException{
Resource resource = resourceLoader.getResource(location);
return resource.getInputStream();
}
/**
* 获取资源文件内容
* @param location
* @author ThinkGem
*/
public static String getResourceFileContent(String location){
InputStream is = null;
try{
is = ResourceUtils.getResourceFileStream(location);
return IOUtils.toString(is, "UTF-8");
}catch (IOException e) {
throw ExceptionUtils.unchecked(e);
}finally{
IOUtils.closeQuietly(is);
}
}
/**
* Spring 搜索资源文件
* @param locationPattern
* @author ThinkGem
*/
public static Resource[] getResources(String locationPattern){
try {
return new PathMatchingResourcePatternResolver()
.getResources(locationPattern);
} catch (IOException e) {
throw ExceptionUtils.unchecked(e);
}
}
}