config包之MessageResourcesConfig浅析

org.apache.struts.config.MessageResourcesConfig浅析

在struts-config.xml配置文件中每个<message-resources>都对应着一个org.apache.struts.config.MessageResourcesConfig对象
<message-resources>元素用来配置Resource Bundle,Resource Bundle用于存放本地化消息文本。

<message-resources>元素中的className是指定和<message-resources>元素对应的配置类。默认值为org.apache.struts.config.MessageResourcesConfig。
<message-resources>元素中的factory指定消息资源的工厂类。默认为org.apache.struts.util.PropertyMessageResourcesFactory类。它在org.apache.struts.config.MessageResourcesConfig中对应的属性为String factory。
<message-resources>元素中的key是指定ResouBundle存放在ServletConrce text对象中时采用的属性key。默认值为由Globals.MESSAGES_KEY定义的字符串常量。只允许有一个Resource Bundle采用默认的属性key。它在org.apache.struts.config.MessageResourcesConfig中对应的属性为String key。
<message-resources>元素中的null是指定MessageResources类如何处理未知的消息key。如果此项为true,将返回空字符串。如果此项为false,将返回类似"???global.label.missing???"的字符串。该属性为可选项,默认值为true。它在org.apache.struts.config.MessageResourcesConfig中对应的属性为boolean nullValue
<message-resources>元素中的parameter是指定Resource Bundle的消息资源文件名。例如:如果此项设为"packq.pack2.ApplicationResources",那么对应的实际资源文件存放路径为:WEB-INF/class/pack1/pack2/ApplicationResources.properties。它在org.apache.struts.config.MessageResourcesConfig中对应的属性为String parameter。

以上属性在org.apache.struts.config.MessageResourcesConfig中都有对应的get和set方法,与普通的JAVABEAN差不多。

类中方法解析
public class MessageResourcesConfig implements Serializable {

    protected boolean configured = false;

    protected String factory =
        "org.apache.struts.util.PropertyMessageResourcesFactory";

    public String getFactory() {
        return (this.factory);
    }

    public void setFactory(String factory) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.factory = factory;
    }

    protected String key = Globals.MESSAGES_KEY;

    public String getKey() {
        return (this.key);
    }

    public void setKey(String key) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.key = key;
    }

    protected boolean nullValue = true;

    public boolean getNull() {
        return (this.nullValue);
    }

    public void setNull(boolean nullValue) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.nullValue = nullValue;
    }

    protected String parameter = null;

    public String getParameter() {
        return (this.parameter);
    }

    public void setParameter(String parameter) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.parameter = parameter;
    }

    public void freeze() {

        configured = true;

    }

    public String toString() {

        StringBuffer sb = new StringBuffer("MessageResourcesConfig[");
        sb.append("factory=");
        sb.append(this.factory);
        sb.append(",null=");
        sb.append(this.nullValue);
        sb.append(",parameter=");
        sb.append(this.parameter);
        sb.append("]");
        return (sb.toString());

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值