--- MessageArgumentTag.java.orig 2004-10-04 10:19:11.995213714 -0700 +++ MessageArgumentTag.java 2004-10-04 10:41:08.033316344 -0700 @@ -16,23 +16,25 @@ package org.apache.taglibs.i18n; -import java.text.MessageFormat; - import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspTagException; -import javax.servlet.jsp.tagext.Tag; +import javax.servlet.jsp.tagext.BodyContent; +import javax.servlet.jsp.tagext.BodyTag; import javax.servlet.jsp.tagext.TagSupport; /** * This class implements is used inside a MessageTag to create an ordered - * list of arguments to use with java.text.MessageFormat. + * list of arguments to use with java.text.MessageFormat. It must contain + * either a 'value' attribute or a non-empty body. *
*
- * <i18n:getMessage key="test"/> - * <i18n:msgArg value="<%= test %>"/> - * <i18n:msgArg value="<%= test %>"/> - * </i18n:getMessage> + * <i18n:message key="test"> + * <i18n:messagegArg value="<%= test %>"/> + * <i18n:messagegArg> + * <my:someTag/> + * </i18n:messagegArg> + * </i18n:message> * etc... **
@@ -42,13 +44,34 @@
* @author Tim Dawson
*
*/
-public class MessageArgumentTag extends TagSupport
+public class MessageArgumentTag extends TagSupport implements BodyTag
{
-
+ private Object attr;
+ private BodyContent cont;
+
+ public void setValue(Object argumentValue)
+ {
+ attr = argumentValue;
+ }
+
+ public int doStartTag()
+ {
+ return EVAL_BODY_BUFFERED;
+ }
+
+ public void setBodyContent(BodyContent b)
+ {
+ cont = b;
+ }
+
+ public void doInitBody()
+ {
+ }
+
/**
* locate the parent tag and add the argument to the Message's arg list
*/
- public void setValue(Object argumentValue) throws JspException
+ public int doEndTag() throws JspException
{
// Get the parent MessageTag
MessageTag messageTag = null;
@@ -63,8 +86,21 @@
"i18n:msgArg tag must be nested inside a message tag.");
}
+ // Check the value attribute and body
+ if (attr == null && cont == null)
+ throw new JspTagException(
+ "i18n:msgArg tag must have either a 'value' attribute or a body.");
+ if (attr != null && cont != null)
+ throw new JspTagException(
+ "i18n:msgArg tag may not have both a 'value' attribute and a body.");
+
// now we know we're safe to add the argument
- messageTag.addArg(argumentValue);
+ messageTag.addArg((attr != null) ? attr : cont.getString());
+
+ attr = null;
+ cont = null;
+
+ return EVAL_PAGE;
}
}
--- taglibs-i18n.tld.orig 2004-10-04 10:18:10.977434463 -0700
+++ taglibs-i18n.tld 2004-10-04 10:18:38.868419367 -0700
@@ -106,10 +106,10 @@