Search in sources :

Example 11 with ConfigBean

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;
}
Also used : InterConfigBean(org.eweb4j.mvc.config.bean.InterConfigBean) CheckConfigBean(org.eweb4j.config.CheckConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) InterConfigBean(org.eweb4j.mvc.config.bean.InterConfigBean) File(java.io.File) XMLReader(org.eweb4j.util.xml.XMLReader)

Example 12 with ConfigBean

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;
}
Also used : Locale(org.eweb4j.config.bean.Locale) Pattern(java.util.regex.Pattern) Prop(org.eweb4j.config.bean.Prop) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) FileNotFoundException(java.io.FileNotFoundException) ConfigBean(org.eweb4j.config.bean.ConfigBean) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) Entry(java.util.Map.Entry) BufferedInputStream(java.io.BufferedInputStream) I18N(org.eweb4j.config.bean.I18N)

Example 13 with ConfigBean

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;
        }
    }
}
Also used : Prop(org.eweb4j.config.bean.Prop) ConfigBean(org.eweb4j.config.bean.ConfigBean)

Example 14 with ConfigBean

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);
}
Also used : LogsConfigBean(org.eweb4j.config.bean.LogsConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) LogsConfigBean(org.eweb4j.config.bean.LogsConfigBean) LogConfigBean(org.eweb4j.config.bean.LogConfigBean)

Example 15 with ConfigBean

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);
    }
}
Also used : InvalidContentTypeException(org.apache.commons.fileupload.FileUploadBase.InvalidContentTypeException) ArrayList(java.util.ArrayList) UploadConfigBean(org.eweb4j.config.bean.UploadConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) InvalidContentTypeException(org.apache.commons.fileupload.FileUploadBase.InvalidContentTypeException) FileItem(org.apache.commons.fileupload.FileItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) File(java.io.File) UploadConfigBean(org.eweb4j.config.bean.UploadConfigBean)

Aggregations

ConfigBean (org.eweb4j.config.bean.ConfigBean)28 DBInfoConfigBean (org.eweb4j.orm.dao.config.bean.DBInfoConfigBean)13 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)12 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)12 File (java.io.File)10 IOCConfigBean (org.eweb4j.ioc.config.bean.IOCConfigBean)10 ActionConfigBean (org.eweb4j.mvc.config.bean.ActionConfigBean)10 InterConfigBean (org.eweb4j.mvc.config.bean.InterConfigBean)10 FieldConfigBean (org.eweb4j.mvc.config.bean.FieldConfigBean)9 ParamConfigBean (org.eweb4j.mvc.config.bean.ParamConfigBean)9 ResultConfigBean (org.eweb4j.mvc.config.bean.ResultConfigBean)9 ValidatorConfigBean (org.eweb4j.mvc.config.bean.ValidatorConfigBean)9 XMLReader (org.eweb4j.util.xml.XMLReader)6 CheckConfigBean (org.eweb4j.config.CheckConfigBean)5 Method (java.lang.reflect.Method)4 Prop (org.eweb4j.config.bean.Prop)4 ReflectUtil (org.eweb4j.util.ReflectUtil)4 IOException (java.io.IOException)3 LogsConfigBean (org.eweb4j.config.bean.LogsConfigBean)3 FileInputStream (java.io.FileInputStream)2