0,0 → 1,91 |
/** |
* Extends and based on Apache Struts source code. |
* |
* Copyleft Anatoli Klassen (anatoli@aksoft.net) |
*/ |
package ak.strutsx.taglib; |
|
import java.util.Locale; |
|
import javax.servlet.jsp.JspException; |
import javax.servlet.jsp.tagext.TagSupport; |
|
import org.apache.struts.Globals; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.util.ResponseUtils; |
|
public class MessageTag |
extends org.apache.struts.taglib.bean.MessageTag |
{ |
protected String valuesName = null; |
|
public String getValuesName() |
{ |
return this.valuesName; |
} |
|
public void setValuesName(String valuesName) |
{ |
this.valuesName = valuesName; |
} |
|
protected String valuesProperty = null; |
|
public String getValuesProperty() |
{ |
return this.valuesProperty; |
} |
|
public void setValuesProperty(String valuesProperty) |
{ |
this.valuesProperty = valuesProperty; |
} |
|
public int doStartTag() |
throws JspException |
{ |
String key = this.key; |
if(key == null) { |
Object value = RequestUtils.lookup(pageContext, name, property, scope); |
if(value != null && !(value instanceof String)) { |
JspException e = new JspException(messages.getMessage("message.property", key)); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
key = (String)value; |
} |
|
Object[] values = null; |
if(valuesName != null || valuesProperty != null) { |
Object valuesObj = RequestUtils.lookup(pageContext, |
(valuesName == null) ? name : valuesName, valuesProperty, scope); |
if(valuesObj != null && !(valuesObj instanceof Object[])) { |
JspException e = new JspException("Properties are not an array"); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
values = (Object[])valuesObj; |
} |
|
String message = RequestUtils.message(pageContext, this.bundle, |
this.localeKey, key, values); |
|
if(message == null) { |
JspException e = new JspException |
(messages.getMessage("message.message", "\"" + key + "\"")); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
|
ResponseUtils.write(pageContext, message); |
return SKIP_BODY; |
} |
|
public void release() |
{ |
super.release(); |
valuesName = null; |
valuesProperty = null; |
} |
} |