use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.
the class InterceptorConfig method check.
public static synchronized String check() {
String error = null;
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
if (cb != null) {
for (String filePath : cb.getMvc().getInterXmlFiles().getPath()) {
if (filePath != null && filePath.length() > 0) {
File configFile = new File(ConfigConstant.CONFIG_BASE_PATH + filePath);
try {
XMLReader reader = BeanXMLUtil.getBeanXMLReader(configFile);
reader.setBeanName("interceptor");
reader.setClass("interceptor", InterConfigBean.class);
List<InterConfigBean> interList = reader.read();
if (interList == null || interList.isEmpty()) {
error = rebuildXmlFile(configFile, ConfigErrCons.CANNOT_READ_CONFIG_INFO);
} else {
for (Iterator<InterConfigBean> it = interList.iterator(); it.hasNext(); ) {
InterConfigBean inter = it.next();
String error1 = CheckConfigBean.checkMVCInterceptor(inter, filePath);
if (error1 != null) {
if (error != null) {
error += error1;
} else {
error = error1;
}
}
}
if (error == null) {
for (Iterator<InterConfigBean> it = interList.iterator(); it.hasNext(); ) {
InterConfigBean inter = it.next();
if (!"".equals(inter.getClazz())) {
InterConfigBeanCache.add(inter);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
error = rebuildXmlFile(configFile, CommonUtil.getExceptionString(e));
}
}
}
if (error != null) {
InterConfigBeanCache.clear();
}
}
return error;
}
use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.
the class Props method readProperties.
// 读取properties的全部信息
public static synchronized String readProperties(Prop f, boolean isCreate) throws IOException {
if (f == null || f.getPath().length() == 0)
return null;
String id = f.getId();
String path = f.getPath();
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
I18N i18n = cb.getLocales();
final String sufPro = ".properties";
if (i18n != null) {
for (Locale l : i18n.getLocale()) {
String suffix1 = "_" + l.getLanguage() + "_" + l.getCountry();
String tmpPath1 = path.replace(sufPro, suffix1 + sufPro);
i18nIds.add(id);
if (FileUtil.exists(ConfigConstant.CONFIG_BASE_PATH + tmpPath1)) {
Prop p = new Prop();
p.setGlobal("false");
p.setId(id + suffix1);
p.setPath(tmpPath1);
// 递归,把国际化文件内容加载仅缓存
readProperties(p, false);
// 如果存在国际化文件,那么默认的文件允许不存在
isCreate = false;
continue;
}
String suffix2 = "_" + l.getLanguage();
String tmpPath2 = path.replace(sufPro, suffix2 + sufPro);
if (FileUtil.exists(ConfigConstant.CONFIG_BASE_PATH + tmpPath2)) {
Prop p = new Prop();
p.setGlobal("false");
p.setId(id + suffix2);
p.setPath(tmpPath2);
// 递归,把国际化文件内容加载仅缓存
readProperties(p, false);
// 如果存在国际化文件,那么默认的文件允许不存在
isCreate = false;
continue;
}
}
}
String error = null;
String filePath = ConfigConstant.CONFIG_BASE_PATH + path;
String global = f.getGlobal();
Properties properties = new Properties();
InputStream in = null;
Hashtable<String, String> tmpHt = new Hashtable<String, String>();
try {
in = new BufferedInputStream(new FileInputStream(filePath));
properties.load(in);
//第一遍全部加进来
Props.loadProperty(properties, tmpHt);
//渲染 ${} 引用值
Pattern pattern = Pattern.compile(RegexList.property_single_regexp);
for (Iterator<Entry<String, String>> it = tmpHt.entrySet().iterator(); it.hasNext(); ) {
Entry<String, String> e = it.next();
String key = e.getKey();
String property = e.getValue();
Props.renderVarable(pattern, key, property, tmpHt);
}
if ("true".equalsIgnoreCase(global) || "1".equalsIgnoreCase(global)) {
globalMap.putAll(tmpHt);
log.debug("global | map -> " + tmpHt.toString());
} else if (id != null && id.length() > 0) {
props.put(id, tmpHt);
log.debug("id -> " + id + " | map -> " + tmpHt.toString());
}
} catch (FileNotFoundException e) {
log.warn(filePath + ", file not found!", e);
if (isCreate) {
boolean flag = FileUtil.createFile(filePath);
if (flag) {
error = filePath + " create success";
Props.writeProperties(filePath, "framework", "eweb4j");
log.warn(error);
} else {
log.warn(filePath + " create fail");
}
}
} finally {
if (in != null)
in.close();
}
return error;
}
use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.
the class Props method removeProp.
public static synchronized void removeProp(String propId, String key) throws IOException {
if (propId == null)
return;
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
List<Prop> files = cb.getProperties().getFile();
for (Prop f : files) {
if (propId.equals(f.getId())) {
Map<String, String> map = props.get(propId);
if (map == null)
break;
String filePath = ConfigConstant.CONFIG_BASE_PATH + f.getPath();
removeProperties(filePath, key);
break;
}
}
}
use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.
the class LogFactory method getORMLogger.
public static Log getORMLogger(Class<?> clazz) {
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
LogsConfigBean logs = cb == null ? new LogsConfigBean() : cb.getOrm().getLogs();
return new LogImpl(logs, "ORM", clazz);
}
use of org.eweb4j.config.bean.ConfigBean in project eweb4j-framework by laiweiwei.
the class UploadUtil method handleUpload.
public static void handleUpload(Context context) throws Exception {
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
UploadConfigBean ucb = cb.getMvc().getUpload();
String tmpDir = ucb.getTmp();
int memoryMax = CommonUtil.strToInt(CommonUtil.parseFileSize(ucb.getMaxMemorySize()) + "");
long sizeMax = CommonUtil.parseFileSize(ucb.getMaxRequestSize());
if (tmpDir.trim().length() == 0)
tmpDir = "${RootPath}" + File.separator + "WEB-INF" + File.separator + "tmp";
tmpDir = tmpDir.replace("${RootPath}", ConfigConstant.ROOT_PATH);
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(memoryMax);
factory.setRepository(new File(tmpDir));
ServletFileUpload _upload = new ServletFileUpload(factory);
if (!_upload.isMultipartContent(context.getRequest()))
return;
_upload.setSizeMax(sizeMax);
try {
List<FileItem> items = _upload.parseRequest(context.getRequest());
Iterator<FileItem> it = items.iterator();
while (it.hasNext()) {
FileItem item = it.next();
String fieldName = item.getFieldName();
if (item.isFormField()) {
String value = item.getString();
context.getQueryParamMap().put(fieldName, new String[] { value });
} else {
String fileName = item.getName();
if (fileName == null || fileName.trim().length() == 0)
continue;
String stamp = CommonUtil.getNowTime("yyyyMMddHHmmss");
File tmpFile = new File(tmpDir + File.separator + stamp + "_" + fileName);
item.write(tmpFile);
UploadFile uploadFile = new UploadFile(tmpFile, fileName, fieldName, item.getSize(), item.getContentType());
if (context.getUploadMap().containsKey(fieldName)) {
context.getUploadMap().get(fieldName).add(uploadFile);
} else {
List<UploadFile> uploads = new ArrayList<UploadFile>();
uploads.add(uploadFile);
context.getUploadMap().put(fieldName, uploads);
}
}
}
} catch (InvalidContentTypeException e) {
throw new Exception("upload file error", e);
}
}
Aggregations