Search in sources :

Example 1 with Locale

use of org.eweb4j.config.bean.Locale in project eweb4j-framework by laiweiwei.

the class CheckConfigBean method checkEWeb4JConfigBean.

public static String checkEWeb4JConfigBean(ConfigBean cb) {
    String error = null;
    StringBuilder sb = new StringBuilder();
    if (!"true".equalsIgnoreCase(cb.getReload()) && !"false".equalsIgnoreCase(cb.getReload()) && !"1".equals(cb.getReload()) && !"0".equals(cb.getReload())) {
        sb.append("当前您填写的:( reload=").append(cb.getReload()).append(" )是错误的!它只能填写为:true|false|1|0 中的一种 ;").append("\n");
    }
    if (!"true".equalsIgnoreCase(cb.getDebug()) && !"false".equalsIgnoreCase(cb.getDebug()) && !"1".equals(cb.getDebug()) && !"0".equals(cb.getDebug())) {
        sb.append("当前您填写的:( debug=").append(cb.getDebug()).append(" )是错误的!它只能填写为:true|false|1|0 中的一种 ;").append("\n");
    }
    I18N i18n = cb.getLocales();
    StringBuilder locSB = new StringBuilder();
    for (java.util.Locale jl : java.util.Locale.getAvailableLocales()) {
        if (locSB.length() > 0) {
            locSB.append(", ");
        }
        locSB.append(jl.getLanguage());
        locSB.append("_").append(jl.getCountry());
    }
    if (i18n != null) {
        for (Locale l : i18n.getLocale()) {
            boolean flag = false;
            for (java.util.Locale jl : java.util.Locale.getAvailableLocales()) {
                if (jl.getLanguage().equals(l.getLanguage()) || jl.getCountry().equals(l.getCountry())) {
                    flag = true;
                }
            }
            if (!flag) {
                sb.append("当前您填写的:( language=").append(l.getLanguage()).append(", country=").append(l.getCountry()).append("  即:").append(l.getLanguage()).append("_").append(l.getCountry()).append(" )是错误的!它只能填写为:").append(locSB.toString());
                break;
            }
        }
    }
    Properties props = cb.getProperties();
    if (props != null) {
        for (Prop file : props.getFile()) {
            String path = file.getPath();
            if (path != null && path.length() == 0)
                continue;
            if (!path.endsWith(".properties"))
                sb.append("当前您填写的:( propPath=").append(path).append(" )是错误的!它必须以 .properties 后缀;").append("\n");
            String global = file.getGlobal();
            if (!"true".equalsIgnoreCase(global) && !"false".equalsIgnoreCase(global) && !"1".equals(global) && !"0".equals(global)) {
                sb.append("当前您填写的:( global=").append(global).append(" )是错误的!它只能填写为:true|false|1|0 中的一种 ;").append("\n");
            }
        }
    }
    if (!"".equals(sb.toString())) {
        error = "\n<br /><b>" + ConfigConstant.START_FILE_PATH() + ":</b>\n" + sb.toString();
    }
    return error;
}
Also used : Locale(org.eweb4j.config.bean.Locale) Prop(org.eweb4j.config.bean.Prop) Properties(org.eweb4j.config.bean.Properties) I18N(org.eweb4j.config.bean.I18N)

Example 2 with Locale

use of org.eweb4j.config.bean.Locale 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 3 with Locale

use of org.eweb4j.config.bean.Locale in project eweb4j-framework by laiweiwei.

the class ConfigBeanCreator method create.

public static ConfigBean create() {
    ConfigBean cb = new ConfigBean();
    I18N i18n = new I18N();
    Locale locale = new Locale();
    locale.setLanguage(java.util.Locale.CHINA.getLanguage());
    locale.setCountry(java.util.Locale.CHINA.getCountry());
    i18n.getLocale().add(locale);
    cb.setLocales(i18n);
    Properties props = new Properties();
    Prop file = new Prop();
    props.getFile().add(file);
    cb.setProperties(props);
    LogsConfigBean lcb = new LogsConfigBean();
    ConfigIOC ioc = new ConfigIOC();
    IOCXmlFiles iocXmlFiles = new IOCXmlFiles();
    iocXmlFiles.setPath(new ArrayList<String>());
    ioc.setIocXmlFiles(iocXmlFiles);
    ioc.setLogs(lcb);
    cb.setIoc(ioc);
    ConfigORM orm = new ConfigORM();
    orm.setLogs(lcb);
    Ddl ddl = new Ddl();
    orm.setDdl(ddl);
    ORMXmlFiles ormXmlFiles = new ORMXmlFiles();
    orm.setOrmXmlFiles(ormXmlFiles);
    ScanPojoPackage spp = new ScanPojoPackage();
    orm.setScanPojoPackage(spp);
    DBInfoXmlFiles dbInfoXmlFiles = new DBInfoXmlFiles();
    dbInfoXmlFiles.setPath(new ArrayList<String>());
    orm.setDbInfoXmlFiles(dbInfoXmlFiles);
    cb.setOrm(orm);
    ConfigMVC mvc = new ConfigMVC();
    mvc.setLogs(lcb);
    UploadConfigBean upload = new UploadConfigBean();
    mvc.setUpload(upload);
    ActionXmlFile actionFiles = new ActionXmlFile();
    actionFiles.setPath(new ArrayList<String>());
    mvc.setActionXmlFiles(actionFiles);
    InterXmlFile intFiles = new InterXmlFile();
    intFiles.setPath(new ArrayList<String>());
    mvc.setInterXmlFiles(intFiles);
    ScanActionPackage sap = new ScanActionPackage();
    mvc.setScanActionPackage(sap);
    ScanInterceptorPackage sip = new ScanInterceptorPackage();
    mvc.setScanInterceptorPackage(sip);
    cb.setMvc(mvc);
    return cb;
}
Also used : Locale(org.eweb4j.config.bean.Locale) ActionXmlFile(org.eweb4j.config.bean.ActionXmlFile) Prop(org.eweb4j.config.bean.Prop) ConfigIOC(org.eweb4j.config.bean.ConfigIOC) ConfigMVC(org.eweb4j.config.bean.ConfigMVC) InterXmlFile(org.eweb4j.config.bean.InterXmlFile) UploadConfigBean(org.eweb4j.config.bean.UploadConfigBean) ConfigBean(org.eweb4j.config.bean.ConfigBean) LogsConfigBean(org.eweb4j.config.bean.LogsConfigBean) ScanInterceptorPackage(org.eweb4j.config.bean.ScanInterceptorPackage) Properties(org.eweb4j.config.bean.Properties) ScanPojoPackage(org.eweb4j.config.bean.ScanPojoPackage) Ddl(org.eweb4j.config.bean.Ddl) IOCXmlFiles(org.eweb4j.config.bean.IOCXmlFiles) ConfigORM(org.eweb4j.config.bean.ConfigORM) LogsConfigBean(org.eweb4j.config.bean.LogsConfigBean) ScanActionPackage(org.eweb4j.config.bean.ScanActionPackage) ORMXmlFiles(org.eweb4j.config.bean.ORMXmlFiles) I18N(org.eweb4j.config.bean.I18N) DBInfoXmlFiles(org.eweb4j.config.bean.DBInfoXmlFiles) UploadConfigBean(org.eweb4j.config.bean.UploadConfigBean)

Aggregations

I18N (org.eweb4j.config.bean.I18N)3 Locale (org.eweb4j.config.bean.Locale)3 Prop (org.eweb4j.config.bean.Prop)3 ConfigBean (org.eweb4j.config.bean.ConfigBean)2 Properties (org.eweb4j.config.bean.Properties)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Hashtable (java.util.Hashtable)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 Pattern (java.util.regex.Pattern)1 ActionXmlFile (org.eweb4j.config.bean.ActionXmlFile)1 ConfigIOC (org.eweb4j.config.bean.ConfigIOC)1 ConfigMVC (org.eweb4j.config.bean.ConfigMVC)1 ConfigORM (org.eweb4j.config.bean.ConfigORM)1 DBInfoXmlFiles (org.eweb4j.config.bean.DBInfoXmlFiles)1 Ddl (org.eweb4j.config.bean.Ddl)1 IOCXmlFiles (org.eweb4j.config.bean.IOCXmlFiles)1