org.apache.taglibs.i18n
Class MessageTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.apache.taglibs.i18n.MessageTag
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.Tag

public class MessageTag
extends javax.servlet.jsp.tagext.BodyTagSupport

This class implements a body tag that allows you to use a resource bundle to internationalize content in a web page. The "key" attribute is required, and is used to look up content in the resource bundle. The "args" attribute is optional, and if present, provides items to pass to a MessageFormat. The BundleTag must first be used in order to ensure that the proper bundle is loaded.

Examples

  <i18n:bundle baseName="test"/>
  <i18n:getMessage key="test"/>
  <i18n:getMessage key="test" args="1,2,3"/>
  etc...
  

Author:
Tim Dawson
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
MessageTag()
           
 
Method Summary
protected  void addArg(java.lang.Object arg)
          adds to the list of arguments used when formatting the message
 int doAfterBody()
          If key is not found, use the body content as a default value.
 int doEndTag()
          Performs the proper runtime substitution.
 int doStartTag()
          locates the bundle and gets the value
 void release()
          clears the argument list so that sub tags can call addArgument clears out any previous key and value in case key is not provided, or the value is null
 void setArgs(java.lang.Object[] args)
          allows setting all the arguments at once
 void setBundle(java.util.ResourceBundle aBundle)
          sets the bundle to an actual ResourceBundle object
if neither bundle or bundleRef are specified, uses the bundle most recently defined on the page by the i18n:bundle tag
 void setBundleRef(java.lang.String varName)
          sets the bundle based on a variable defined in the page
if neither bundle or bundleRef are specified, uses the first bundle defined on the page by the i18n:bundle tag
 void setDebug(boolean value)
          Turn debugging log messages on or off
 void setKey(java.lang.String key)
          sets the key to use when looking up the value in the bundle
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doInitBody, getBodyContent, getPreviousOut, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Constructor Detail

MessageTag

public MessageTag()
Method Detail

setKey

public final void setKey(java.lang.String key)
sets the key to use when looking up the value in the bundle


setBundleRef

public final void setBundleRef(java.lang.String varName)
sets the bundle based on a variable defined in the page
if neither bundle or bundleRef are specified, uses the first bundle defined on the page by the i18n:bundle tag


setBundle

public final void setBundle(java.util.ResourceBundle aBundle)
sets the bundle to an actual ResourceBundle object
if neither bundle or bundleRef are specified, uses the bundle most recently defined on the page by the i18n:bundle tag


setDebug

public final void setDebug(boolean value)
Turn debugging log messages on or off


addArg

protected final void addArg(java.lang.Object arg)
adds to the list of arguments used when formatting the message


setArgs

public final void setArgs(java.lang.Object[] args)
allows setting all the arguments at once


release

public final void release()
clears the argument list so that sub tags can call addArgument clears out any previous key and value in case key is not provided, or the value is null

Specified by:
release in interface javax.servlet.jsp.tagext.Tag
Overrides:
release in class javax.servlet.jsp.tagext.BodyTagSupport

doStartTag

public final int doStartTag()
                     throws javax.servlet.jsp.JspException
locates the bundle and gets the value

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

doAfterBody

public int doAfterBody()
                throws javax.servlet.jsp.JspException
If key is not found, use the body content as a default value.

Specified by:
doAfterBody in interface javax.servlet.jsp.tagext.IterationTag
Overrides:
doAfterBody in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

doEndTag

public final int doEndTag()
                   throws javax.servlet.jsp.JspException
Performs the proper runtime substitution. If an id attribute was specified, then it is assumed that this tag is merely defining a string variable; otherwise output is provided.

Specified by:
doEndTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException


Copyright ? 2000-2004 The Apache Software Foundation. All Rights Reserved.