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());
}
}