欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

对于属性文件解析成I18N的缓存的方式,属性解析i18n缓存,if (log.isTr

来源: javaer 分享于  点击 43381 次 点评:44

对于属性文件解析成I18N的缓存的方式,属性解析i18n缓存,if (log.isTr


if (log.isTraceEnabled()) {        log.trace("loadLocale(" + localeKey + ")");    }    // Have we already attempted to load messages for this locale?    if (locales.get(localeKey) != null) {        return;    }    locales.put(localeKey, localeKey);    // Set up to load the property resource for this locale key, if we can    String name = config.replace('.', '/');    if (localeKey.length() > 0) {        name += "_" + localeKey;    }    name += ".properties";    InputStream is = null;    Properties props = new Properties();    // Load the specified property resource    if (log.isTraceEnabled()) {        log.trace("  Loading resource '" + name + "'");    }    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();    if (classLoader == null) {        classLoader = this.getClass().getClassLoader();    }    //sss 演示通过类加载期加载一个在classpath中的配置文件(属性文件) struts127    is = classLoader.getResourceAsStream(name);    if (is != null) {        try {            props.load(is);        } catch (IOException e) {            log.error("loadLocale()", e);        } finally {            try {                is.close();            } catch (IOException e) {                log.error("loadLocale()", e);            }        }    }    if (log.isTraceEnabled()) {        log.trace("  Loading resource completed");    }    // Copy the corresponding values into our cache    if (props.size() < 1) {        return;    }    //sss 通过遍历Propery的国际化配置文件,把配置的国际化数据从资源文件中传入到当前类的message(map)里面 struts127    synchronized (messages) {        Iterator names = props.keySet().iterator();        while (names.hasNext()) {            String key = (String) names.next();            if (log.isTraceEnabled()) {                log.trace("  Saving message key '" + messageKey(localeKey, key));            }            messages.put(messageKey(localeKey, key), props.getProperty(key));        }    }}//该片段来自于http://byrx.net
相关栏目:

用户点评