You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by td...@apache.org on 2001/06/13 05:24:44 UTC

cvs commit: jakarta-taglibs/i18n/src/org/apache/taglibs/i18n BundleTEI.java ConditionalTagSupport.java BundleTag.java IfdefTag.java IfndefTag.java MessageTag.java

tdawson     01/06/12 20:24:44

  Modified:    i18n/conf i18n.tld
               i18n/examples/web index.jsp
               i18n/src/org/apache/taglibs/i18n BundleTag.java
                        IfdefTag.java IfndefTag.java MessageTag.java
  Added:       i18n/examples/src/org/apache/taglibs/i18n
                        i18n-test2.properties i18n-test2_en.properties
                        i18n-test2_fr.properties i18n-test2_ja.properties
               i18n/examples/web bundle_contents.jsp bundle_multiple.jsp
                        ifdef.jsf ifndef.jsf locale_attribute.jsp
                        locale_browser.jsp locale_object.jsp message.jsf
               i18n/src/org/apache/taglibs/i18n BundleTEI.java
                        ConditionalTagSupport.java
  Removed:     i18n/examples/web index2.jsp index3.jsp
  Log:
  updated BundleTag to allow multiple uses per page, as long
  as the bundle's locale's language matches (to avoid charset
  issues)
  
  also updated the examples to reflect these changes. documentation
  has not been updated yet.
  
  Revision  Changes    Path
  1.2       +37 -1     jakarta-taglibs/i18n/conf/i18n.tld
  
  Index: i18n.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/i18n/conf/i18n.tld,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- i18n.tld	2001/05/05 17:15:16	1.1
  +++ i18n.tld	2001/06/13 03:24:35	1.2
  @@ -6,18 +6,24 @@
     <jspversion>1.1</jspversion>
     <shortname>i18n</shortname>
     <info>
  -    These are WAM!NET internationalization tags.
  +    These are the Apache Jakarta internationalization tags.
     </info>
   
     <tag>
       <name>bundle</name>
       <tagclass>org.apache.taglibs.i18n.BundleTag</tagclass>
  +    <teiclass>org.apache.taglibs.i18n.BundleTEI</teiclass>
       <info>Must be placed in a JSP before any other i18n tags.</info>
       <attribute>
         <name>baseName</name>
         <required>true</required>
       </attribute>
       <attribute>
  +      <name>id</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
         <name>locale</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
  @@ -35,6 +41,16 @@
       <bodycontent>JSP</bodycontent>
       <info>Must occur after a localize tag.</info>
       <attribute>
  +      <name>bundle</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>bundleRef</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
         <name>key</name>
         <required>true</required>
         <rtexprvalue>true</rtexprvalue>
  @@ -63,6 +79,16 @@
       <bodycontent>JSP</bodycontent>
       <info>Must occur after a localize tag.</info>
       <attribute>
  +      <name>bundle</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>bundleRef</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
         <name>key</name>
         <required>true</required>
         <rtexprvalue>true</rtexprvalue>
  @@ -74,6 +100,16 @@
       <tagclass>org.apache.taglibs.i18n.IfndefTag</tagclass>
       <bodycontent>JSP</bodycontent>
       <info>Must occur after a localize tag.</info>
  +    <attribute>
  +      <name>bundle</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +      <name>bundleRef</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +    </attribute>
       <attribute>
         <name>key</name>
         <required>true</required>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/src/org/apache/taglibs/i18n/i18n-test2.properties
  
  Index: i18n-test2.properties
  ===================================================================
  # this is an alternate test base file
  #
  # it is merely here to show how to use multiple bundles
  # with the i18n tag tag library
  #
  # to keep the test simple, the base file just contains
  # a single key with an english value. all other locales
  # have no values in them (again, keeping things simple)
  #
  #  having matching locales for all bundles is important
  # to avoid exceptions at runtime due to mismatching locales
  
  test1=this is a test of the second base properties file
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/src/org/apache/taglibs/i18n/i18n-test2_en.properties
  
  Index: i18n-test2_en.properties
  ===================================================================
  # this is an alternate test file for english
  #
  # it is merely here to show how to use multiple bundles
  # with the i18n tag tag library
  #
  # to keep the test simple, the base file just contains
  # a single key with an english value. all other locales
  # have no values in them (again, keeping things simple)
  #
  #  having matching locales for all bundles is important
  # to avoid exceptions at runtime due to mismatching locales
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/src/org/apache/taglibs/i18n/i18n-test2_fr.properties
  
  Index: i18n-test2_fr.properties
  ===================================================================
  # this is an alternate test file for french
  #
  # it is merely here to show how to use multiple bundles
  # with the i18n tag tag library
  #
  # to keep the test simple, the base file just contains
  # a single key with an english value. all other locales
  # have no values in them (again, keeping things simple)
  #
  #  having matching locales for all bundles is important
  # to avoid exceptions at runtime due to mismatching locales
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/src/org/apache/taglibs/i18n/i18n-test2_ja.properties
  
  Index: i18n-test2_ja.properties
  ===================================================================
  # this is an alternate test file for japanese
  #
  # it is merely here to show how to use multiple bundles
  # with the i18n tag tag library
  #
  # to keep the test simple, the base file just contains
  # a single key with an english value. all other locales
  # have no values in them (again, keeping things simple)
  #
  #  having matching locales for all bundles is important
  # to avoid exceptions at runtime due to mismatching locales
  
  
  
  1.2       +11 -6     jakarta-taglibs/i18n/examples/web/index.jsp
  
  Index: index.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/i18n/examples/web/index.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- index.jsp	2001/03/31 16:08:48	1.1
  +++ index.jsp	2001/06/13 03:24:38	1.2
  @@ -5,31 +5,31 @@
     if ( "en".equals(lang) )
       {
       session.setAttribute("userLocale",Locale.ENGLISH);
  -    response.sendRedirect("index2.jsp");
  +    response.sendRedirect("locale_attribute.jsp");
       return;
       }
     else if ( "en-US".equals(lang) )
       {
       session.setAttribute("userLocale",Locale.US);
  -    response.sendRedirect("index2.jsp");
  +    response.sendRedirect("locale_attribute.jsp");
       return;
       }
     else if ( "fr".equals(lang) )
       {
       session.setAttribute("userLocale",Locale.FRENCH);
  -    response.sendRedirect("index2.jsp");
  +    response.sendRedirect("locale_attribute.jsp");
       return;
       }
     else if ( "ja".equals(lang) )
       {
       session.setAttribute("userLocale",Locale.JAPANESE);
  -    response.sendRedirect("index2.jsp");
  +    response.sendRedirect("locale_attribute.jsp");
       return;
       }
     else if ( "".equals(lang) )
       {
  -    session.removeAttribute("userLocale");
  -    response.sendRedirect("index2.jsp");
  +    session.invalidate();
  +    response.sendRedirect("locale_browser.jsp");
       return;
       }
   %>
  @@ -50,5 +50,10 @@
   <br><a href="index.jsp?language=fr">French</a>
   <br><a href="index.jsp?language=ja">Japanese</a>
   <br><a href="index.jsp?language=">Use Browser Settings</a>
  +<p>
  +<br><a href="bundle_multiple.jsp">View Multiple Bundles in Action</a>
  +<a href="bundle_multiple.txt">(source)</a>
  +<br><a href="bundle_contents.jsp">Show Bundle Contents</a>
  +<a href="bundle_contents.txt">(source)</a>
   </BODY>
   </HTML>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/bundle_contents.jsp
  
  Index: bundle_contents.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %>
  
  <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"
               id="bundle"/>
  
  <%
  java.util.TreeSet set = new java.util.TreeSet();
  for ( java.util.Enumeration enum = bundle.getKeys(); enum.hasMoreElements(); )
    {
    set.add(enum.nextElement());
    }
  %>
  
  <HTML>
  <HEAD>
    <TITLE>Examples of I18N Custom Tag Library Tag Usage</TITLE>
  </HEAD>
  <BODY>
  
  This page displays all key/value pairs in the bundle.
  
  locale = <b><%= pageContext.getResponse().getLocale() %></b><br>
  charset = <b><%= pageContext.getResponse().getCharacterEncoding() %></b><br>
  
  <H2>WebApp translations</H2>
  <TABLE>
  <%
  int index = 0;
  for ( java.util.Iterator iter = set.iterator(); iter.hasNext(); )
    {
    String key = (String)iter.next();
    if ( index++ % 2 == 0 )
      {
      %>
      <TR BGCOLOR="#e0e0e0">
      <%
      }
    else
      {
      %>
      <TR>
      <%
      }
      %>
    <TD><%= key %></TD><TD><%= bundle.getString(key) %></TD>
    </TR>
    <%
    }
  %>
  </TABLE>
  
  </BODY>
  </HTML>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/bundle_multiple.jsp
  
  Index: bundle_multiple.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %>
  
  <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"
               id="bundle1"/>
  
  <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test2"
               id="bundle2"/>
  
  <HTML>
  <HEAD>
    <TITLE>Examples of I18N Custom Tag Library Tag Usage</TITLE>
  </HEAD>
  <BODY>
  
  <i18n:message bundleRef="bundle1" key="test1"/><P/>
  <i18n:message bundleRef="bundle2" key="test1"/><P/>
  
  </BODY>
  </HTML>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/ifdef.jsf
  
  Index: ifdef.jsf
  ===================================================================
  The <i>ifdef</i> tag allows for optional processing to occur if a tag is defined. If the tag is undefined, the body of the tag is not processed.<br>
  
    <pre>
    &lt;i18n:ifdef key="USONLY"&gt;
       Only users specifying en-US as their locale will see this!
    &lt;/i18n:ifdef&gt;
    </pre>
    <i>
    <i18n:ifdef key="USONLY">
       Only users specifying en-US as their locale will see this!
    </i18n:ifdef>
    </i>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/ifndef.jsf
  
  Index: ifndef.jsf
  ===================================================================
  The <i>ifndef</i> tag allows for optional processing to occur if a tag is NOT defined. If the tag is defined, the body of the tag is not processed.<br>
  
  
    <pre>
    &lt;i18n:ifndef key="USONLY"&gt;
       Only users specifying something OTHER than en-US\
       as their locale will see this!
    &lt;/i18n:ifndef&gt;
    </pre>
    <i>
    <i18n:ifndef key="USONLY">
       Only users specifying something OTHER than en-US\
       as their locale will see this!
    </i18n:ifndef>
    </i>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/locale_attribute.jsp
  
  Index: locale_attribute.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %>
  
  <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"
               localeAttribute="userLocale"/>
  
  <HTML>
  <HEAD>
    <TITLE>Examples of I18N Custom Tag Library Tag Usage</TITLE>
  </HEAD>
  <BODY>
  
  The <b>i18n</b> tag library contains tags to support internationalization and
  localization.<p>
  
  The <i>bundle</i> tag provides no HTML output; it simply sets the bundle used
  by the rest of the i18n tags on the page.  A baseName must be provided, and a
  locale is optional.<p>
  
  For this page, the locale has been provided as a runtime expression value that
  happens to be hardcoded to Locale.US. Any object could have been provided,
  for example, a database lookup could have been used.<p>
  
  <hr>
  <%@ include file="message.jsf" %>
  <hr>
  <%@ include file="ifdef.jsf" %>
  <hr>
  <%@ include file="ifndef.jsf" %>
  <hr>
  
  </BODY>
  </HTML>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/locale_browser.jsp
  
  Index: locale_browser.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %>
  
  <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"/>
  
  <HTML>
  <HEAD>
    <TITLE>Examples of I18N Custom Tag Library Tag Usage</TITLE>
  </HEAD>
  <BODY>
  
  The <b>i18n</b> tag library contains tags to support internationalization and
  localization.<p>
  
  The <i>bundle</i> tag provides no HTML output; it simply sets the bundle used
  by the rest of the i18n tags on the page.  A baseName must be provided, and a
  locale is optional.<p>
  
  For this page, the locale has not been specified. The <b>Accept-Language</b>
  heading sent by the user's browser is used to determine which locale to use.<p>
  
  <hr>
  <%@ include file="message.jsf" %>
  <hr>
  <%@ include file="ifdef.jsf" %>
  <hr>
  <%@ include file="ifndef.jsf" %>
  <hr>
  
  </BODY>
  </HTML>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/locale_object.jsp
  
  Index: locale_object.jsp
  ===================================================================
  <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %>
  
  <i18n:bundle baseName="org.apache.taglibs.i18n.i18n-test"
               locale="<%= java.util.Locale.US %>"/>
  
  <HTML>
  <HEAD>
    <TITLE>Examples of I18N Custom Tag Library Tag Usage</TITLE>
  </HEAD>
  <BODY>
  
  The <b>i18n</b> tag library contains tags to support internationalization and
  localization.<p>
  
  The <i>bundle</i> tag provides no HTML output; it simply sets the bundle used
  by the rest of the i18n tags on the page.  A baseName must be provided, and a
  locale is optional.<p>
  
  For this page, the locale has been provided as a runtime expression value that
  happens to be hardcoded to Locale.US. Any object could have been provided,
  for example, a database lookup could have been used.<p>
  
  <hr>
  <%@ include file="message.jsf" %>
  <hr>
  <%@ include file="ifdef.jsf" %>
  <hr>
  <%@ include file="ifndef.jsf" %>
  <hr>
  
  </BODY>
  </HTML>
  
  
  
  1.1                  jakarta-taglibs/i18n/examples/web/message.jsf
  
  Index: message.jsf
  ===================================================================
  <%
    // these will be used in formatting the message for test2
    java.util.Date  dateArg   = new java.util.Date();
    java.lang.Float numberArg = new java.lang.Float("123.45");
  %>
  
  
  The current locale is <%= pageContext.getResponse().getLocale() %>.
  Items show in <i>italics</i> are localized.
  
  <hr>
  
  The <i>message</i> tag with no body displays the value provided for the provided key in the bundle named by the localize tag.<br>
  
    <pre>&lt;i18n:message key="test1"/&gt;</pre>
    <i><i18n:message key="test1"/></i>
  
  <hr>
  
  The <i>message</i> tag with nested <i>messageArg</i> tags make use of the <code>java.text.MessageFormat</code> class.<br>
  
    <pre>
    &lt;i18n:message key="test2"&gt;
      &lt;i18n:messageArg value="&lt;%= dateArg %&gt;"/&gt;
      &lt;i18n:messageArg value="&lt;%= numberArg %&gt;"/&gt;
    &lt;/i18n:message&gt;
    </pre>
    <i>
    <i18n:message key="test2">
      <i18n:messageArg value="<%= dateArg %>"/>
      <i18n:messageArg value="<%= numberArg %>"/>
    </i18n:message>
    </i>
  <hr>
  
  The <i>message</i> tag with a defined body provides a default in case a particular locale doesn't have the key defined. This is also useful to <ul><li>provide some text during development</li><li>allow the JSP's to be laid out using standard html editing tools</li><li>provide "if not" JSP processing</li></ul><br>
  
    <pre>
    &lt;i18n:message key="test3"&gt;
       This text would be displayed if a language neglected to
       define a value for test3.
    &lt;/i18n:message&gt;
    </pre>
    <i>
    <i18n:message key="test3">
       This text would be displayed if a language neglected to
       define a value for test3.
    </i18n:message>
    </i>
  
  
  
  1.2       +30 -6     jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java
  
  Index: BundleTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BundleTag.java	2001/03/31 16:08:48	1.1
  +++ BundleTag.java	2001/06/13 03:24:41	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java,v 1.1 2001/03/31 16:08:48 glenn Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/03/31 16:08:48 $
  + * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTag.java,v 1.2 2001/06/13 03:24:41 tdawson Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/06/13 03:24:41 $
    *
    * ====================================================================
    * 
  @@ -241,13 +241,37 @@
           // cache the locale for later use within this user's session
           BundleTag.setLocale(pageContext,this.baseName,bundle.getLocale());
           }
  -    
  -    // cache the bundle for use by message tags within this request
  -    ResourceHelper.setBundle(pageContext,bundle);
  +
  +    // different handling is necessary if multiple bundle tags are in use
  +    ResourceBundle firstBundle = ResourceHelper.getBundle(pageContext);
  +    if ( firstBundle != null )
  +        {
  +        // throw an exception if the locale.country doesn't match
  +        String got = firstBundle.getLocale().getLanguage();
  +        String exp = bundle.getLocale().getLanguage();
  +        if ( !got.equals(exp) )
  +            {
  +            throw new JspException("Locale language mismatch: '" + this.baseName + "'" +
  +                                   " got: '" + got + "'" +
  +                                   " expected: '" + exp + "'");
  +            }
  +        }
  +    else
  +        {
  +        // cache the bundle for use by message tags within this request
  +        ResourceHelper.setBundle(pageContext,bundle);
  +        }
   
       // set the locale for the response
       pageContext.getResponse().setLocale(bundle.getLocale());
   
  +    // set the bundle as a variable in the page
  +    String id = this.getId();
  +    if ( id != null )
  +        {
  +        pageContext.setAttribute(id,bundle,PageContext.PAGE_SCOPE);
  +        }
  +    
       // ignore the body of this tag
       return Tag.SKIP_BODY;
       }
  
  
  
  1.2       +13 -98    jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfdefTag.java
  
  Index: IfdefTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfdefTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IfdefTag.java	2001/03/31 16:08:48	1.1
  +++ IfdefTag.java	2001/06/13 03:24:42	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfdefTag.java,v 1.1 2001/03/31 16:08:48 glenn Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/03/31 16:08:48 $
  + * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfdefTag.java,v 1.2 2001/06/13 03:24:42 tdawson Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/06/13 03:24:42 $
    *
    * ====================================================================
    * 
  @@ -77,15 +77,16 @@
    *  resource bundle for the required "key" attribute, then the enclosed JSP
    *  is evaluated, otherwise, it is skipped.
    *  <P>
  - *  This allows the JSP author to cleanly skip entire sections of functionality
  - *  when they have not been implemented for a particular language.
  + *  The ifdef and ifndef tags allow the JSP author to conditionally evaluate
  + *  sections of a JSP based on whether or not a value is provided for the
  + *  given key.
    *  <P>
    *  <H2>Examples</H2>
    *  <PRE>
    *  &lt;i18n:localize bundle="test"/&gt;
  - *  &lt;i18n:require key="test"&gt;
  + *  &lt;i18n:ifdef key="test"&gt;
    *  misc html and jsp
  - *  &lt;/i18n:require&gt;
  + *  &lt;/i18n:ifdef&gt;
    *  etc...
    *  </PRE>
    *  <P>
  @@ -93,109 +94,23 @@
    *  @author <a href="mailto:tdawson@wamnet.com">Tim Dawson</a>
    *
    */
  -public class IfdefTag extends BodyTagSupport
  +public class IfdefTag extends ConditionalTagSupport
     {
  -
  -  // the key used to look up the value 
  -  private String key = null;
  -
     /**
  -   *  sets the key to use when looking up the value in the bundle
  -   */
  -  public void setKey(String key)
  -    {
  -    this.key = key;
  -    }
  -
  -  /**
  -   *  @return the key to use
  -   */
  -  public String getKey()
  -    {
  -    return this.key;
  -    }
  -
  -  /**
  -   *  clears out any previous key in case it's provided by an instance
  -   *  (in which case it would use the previous key if we didn't do something)
  -   */
  -  public void setPageContext(PageContext pc)
  -    {
  -    super.setPageContext(pc);
  -    this.key = null;
  -    }
  -
  -  /**
      *  locates the bundle and tests whether the key has a value
      */
  -  public int doStartTag()
  +  public boolean shouldEvaluate()
             throws JspException
       {
  -    // assume the key has a value, return something else if otherwise
  -    int returnValue;
  -
  -    // ensure we have a key
  -    if ( key == null )
  -        {
  -        throw new JspException("IfdefTag requires a key.");
  -        }
  -
  -    // ensure a bundle was defined
  -    ResourceBundle bundle = ResourceHelper.getBundle(pageContext);
  -    if ( bundle == null )
  -        {
  -        throw new JspException("A bundle must be defined by the BundleTag prior to using a IfdefTag.");
  -        }
  -
  -    // see if the bundle has a value, watching out for the exception
  -    String value = null;
  -    try
  -        {
  -        value = bundle.getString(key);
  -        }
  -    catch (java.util.MissingResourceException e)
  -        {
  -        value = null;
  -        }
  -
  -    // evaluate the body if a value was found, otherwise skip it
  +    String value = this.getValue();
       if ( value == null || value.length() == 0 )
           {
  -        returnValue = BodyTag.SKIP_BODY;
  +        return false;
           }
       else
  -        {
  -        returnValue = BodyTag.EVAL_BODY_TAG;
  -        }
  -
  -    return returnValue;
  -    }
  -
  -  /**
  -   * Prints the body of the tag.
  -   * <P>
  -   * Always return the flag for processing the rest of the JSP page.
  -   *
  -   * @return the flag for processing the rest of the JSP page.
  -   * @exception JspException if the writing out of the body fails.
  -   */
  -  public int doEndTag() throws JspException
  -    {
  -    try
  -        {
  -        if (bodyContent != null)
  -            {
  -            bodyContent.writeOut(bodyContent.getEnclosingWriter());
  -            }
  -        }
  -    catch (java.io.IOException ioe)
           {
  -        throw new JspException("IO Error: " + ioe.getMessage());
  +        return true;
           }
  -
  -    // This is not a loop, so always prccess the rest of the JSP page
  -    return BodyTag.EVAL_PAGE;
       }
  -
   
     } // IfdefTag
  
  
  
  1.2       +13 -98    jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfndefTag.java
  
  Index: IfndefTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfndefTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IfndefTag.java	2001/03/31 16:08:48	1.1
  +++ IfndefTag.java	2001/06/13 03:24:42	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfndefTag.java,v 1.1 2001/03/31 16:08:48 glenn Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/03/31 16:08:48 $
  + * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/IfndefTag.java,v 1.2 2001/06/13 03:24:42 tdawson Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/06/13 03:24:42 $
    *
    * ====================================================================
    * 
  @@ -77,15 +77,16 @@
    *  resource bundle for the required "key" attribute, then the enclosed JSP
    *  is evaluated, otherwise, it is skipped.
    *  <P>
  - *  This allows the JSP author to cleanly skip entire sections of functionality
  - *  when they have not been implemented for a particular language.
  + *  The ifdef and ifndef tags allow the JSP author to conditionally evaluate
  + *  sections of a JSP based on whether or not a value is provided for the
  + *  given key.
    *  <P>
    *  <H2>Examples</H2>
    *  <PRE>
    *  &lt;i18n:localize bundle="test"/&gt;
  - *  &lt;i18n:require key="test"&gt;
  + *  &lt;i18n:ifndef key="test"&gt;
    *  misc html and jsp
  - *  &lt;/i18n:require&gt;
  + *  &lt;/i18n:ifndef&gt;
    *  etc...
    *  </PRE>
    *  <P>
  @@ -93,109 +94,23 @@
    *  @author <a href="mailto:tdawson@wamnet.com">Tim Dawson</a>
    *
    */
  -public class IfndefTag extends BodyTagSupport
  +public class IfndefTag extends ConditionalTagSupport
     {
  -
  -  // the key used to look up the value 
  -  private String key = null;
  -
     /**
  -   *  sets the key to use when looking up the value in the bundle
  -   */
  -  public void setKey(String key)
  -    {
  -    this.key = key;
  -    }
  -
  -  /**
  -   *  @return the key to use
  -   */
  -  public String getKey()
  -    {
  -    return this.key;
  -    }
  -
  -  /**
  -   *  clears out any previous key in case it's provided by an instance
  -   *  (in which case it would use the previous key if we didn't do something)
  -   */
  -  public void setPageContext(PageContext pc)
  -    {
  -    super.setPageContext(pc);
  -    this.key = null;
  -    }
  -
  -  /**
      *  locates the bundle and tests whether the key has a value
      */
  -  public int doStartTag()
  +  public boolean shouldEvaluate()
             throws JspException
       {
  -    // assume the key has a value, return something else if otherwise
  -    int returnValue;
  -
  -    // ensure we have a key
  -    if ( key == null )
  -        {
  -        throw new JspException("IfndefTag requires a key.");
  -        }
  -
  -    // ensure a bundle was defined
  -    ResourceBundle bundle = ResourceHelper.getBundle(pageContext);
  -    if ( bundle == null )
  -        {
  -        throw new JspException("A bundle must be defined by the BundleTag prior to using a IfndefTag.");
  -        }
  -
  -    // see if the bundle has a value, watching out for the exception
  -    String value = null;
  -    try
  -        {
  -        value = bundle.getString(key);
  -        }
  -    catch (java.util.MissingResourceException e)
  -        {
  -        value = null;
  -        }
  -
  -    // evaluate the body if a value was found, otherwise skip it
  +    String value = this.getValue();
       if ( value == null || value.length() == 0 )
           {
  -        returnValue = BodyTag.EVAL_BODY_TAG;
  +        return true;
           }
       else
  -        {
  -        returnValue = BodyTag.SKIP_BODY;
  -        }
  -
  -    return returnValue;
  -    }
  -
  -  /**
  -   * Prints the body of the tag.
  -   * <P>
  -   * Always return the flag for processing the rest of the JSP page.
  -   *
  -   * @return the flag for processing the rest of the JSP page.
  -   * @exception JspException if the writing out of the body fails.
  -   */
  -  public int doEndTag() throws JspException
  -    {
  -    try
  -        {
  -        if (bodyContent != null)
  -            {
  -            bodyContent.writeOut(bodyContent.getEnclosingWriter());
  -            }
  -        }
  -    catch (java.io.IOException ioe)
           {
  -        throw new JspException("IO Error: " + ioe.getMessage());
  +        return false;
           }
  -
  -    // This is not a loop, so always prccess the rest of the JSP page
  -    return BodyTag.EVAL_PAGE;
       }
  -
   
     } // IfndefTag
  
  
  
  1.2       +60 -26    jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/MessageTag.java
  
  Index: MessageTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/MessageTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MessageTag.java	2001/03/31 16:08:48	1.1
  +++ MessageTag.java	2001/06/13 03:24:42	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/MessageTag.java,v 1.1 2001/03/31 16:08:48 glenn Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/03/31 16:08:48 $
  + * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/MessageTag.java,v 1.2 2001/06/13 03:24:42 tdawson Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/06/13 03:24:42 $
    *
    * ====================================================================
    * 
  @@ -103,20 +103,20 @@
   public class MessageTag extends BodyTagSupport
     {
     // instance variables used during processing
  -  private String key = null;
  -  private String value = null;
  -  private ResourceBundle bundle = null;
  +  private String               _key = null;
  +  private String               _value = null;
  +  private ResourceBundle       _bundle = null;
   
     // these are reused for each message tag; luckily tags are thread-safe
  -  private final MessageFormat messageFormat = new MessageFormat("");
  -  private final List arguments = new ArrayList();
  +  private final MessageFormat  _messageFormat = new MessageFormat("");
  +  private final List           _arguments = new ArrayList();
   
     /**
      *  sets the key to use when looking up the value in the bundle
      */
     public void setKey(String key)
       {
  -    this.key = key;
  +    _key = key;
       }
   
     /**
  @@ -124,15 +124,47 @@
      */
     public String getKey()
       {
  -    return this.key;
  +    return _key;
       }
   
     /**
  +   *  sets the bundle based on a variable defined in the page<br>
  +   *  if neither bundle or bundleRef are specified, uses the first bundle
  +   *  defined on the page by the i18n:bundle tag
  +   */
  +  public void setBundleRef(String varName)
  +    {
  +    _bundle = (ResourceBundle)pageContext.getAttribute(varName);
  +    }
  +
  +  /**
  +   *  sets the bundle to an actual ResourceBundle object<br>
  +   *  if neither bundle or bundleRef are specified, uses the bundle most recently
  +   *  defined on the page by the i18n:bundle tag
  +   */
  +  public void setBundle(ResourceBundle aBundle)
  +    {
  +    _bundle = aBundle;
  +    }
  +
  +  /**
  +   *  @return the bundle to use
  +   */
  +  public ResourceBundle getBundle()
  +    {
  +    if ( _bundle == null )
  +        {
  +        _bundle = ResourceHelper.getBundle(pageContext);
  +        }
  +    return _bundle;
  +    }
  +
  +  /**
      *  adds to the list of arguments used when formatting the message
      */
     public void addArg(Object arg)
       {
  -    this.arguments.add(arg);
  +    _arguments.add(arg);
       }
   
     /**
  @@ -140,7 +172,7 @@
      */
     public void setArgs(Object[] args)
       {
  -    this.arguments.addAll(Arrays.asList(args));
  +    _arguments.addAll(Arrays.asList(args));
       }
   
     /**
  @@ -148,13 +180,13 @@
      *  clears out any previous key and value in case key is not provided,
      *  or the value is null
      */
  -  public void setPageContext(PageContext pc)
  +  public void release()
       {
  -    super.setPageContext(pc);
  -    this.arguments.clear();
  -    this.key = null;
  -    this.value = null;
  -    this.bundle = null;
  +    super.release();
  +    _arguments.clear();
  +    _key = null;
  +    _value = null;
  +    _bundle = null;
       }
   
     /**
  @@ -163,6 +195,9 @@
     public int doStartTag()
             throws JspException
       {
  +    String key = this.getKey();
  +    ResourceBundle bundle = this.getBundle();
  +    
       // ensure we have a key
       if ( key == null )
           {
  @@ -170,7 +205,6 @@
           }
   
       // ensure a bundle was defined
  -    bundle = ResourceHelper.getBundle(pageContext);
       if ( bundle == null )
           {
           throw new JspException("A bundle must be defined by the BundleTag prior to using a MessageTag.");
  @@ -179,7 +213,7 @@
       // see if the bundle has a value, if not, we default to the tag contents
       try
           {
  -        this.value = bundle.getString(key);
  +        _value = bundle.getString(key);
           }
       catch (java.util.MissingResourceException e)
           {
  @@ -199,16 +233,16 @@
       try
           {
           // If there is a body content to print out, do so
  -        if ( this.value != null )
  +        if ( _value != null )
               {
  -            if ( arguments != null )
  +            if ( _arguments != null )
                   {
                   // reformat the value as specified
  -                messageFormat.setLocale(bundle.getLocale());
  -                messageFormat.applyPattern(value);
  -                value = messageFormat.format(arguments.toArray());
  +                _messageFormat.setLocale(_bundle.getLocale());
  +                _messageFormat.applyPattern(_value);
  +                _value = _messageFormat.format(_arguments.toArray());
                   }
  -            this.pageContext.getOut().print(value);
  +            this.pageContext.getOut().print(_value);
               }
           else if (bodyContent != null)
               {
  
  
  
  1.1                  jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/BundleTEI.java
  
  Index: BundleTEI.java
  ===================================================================
  /*
   *
   * Copyright (c) 1999,2000,2001 WAM!NET Professional Services, LLC
   * All Rights Reserved.
   *
   *
   */
  
  package org.apache.taglibs.i18n;
  
  import javax.servlet.jsp.tagext.TagData;
  import javax.servlet.jsp.tagext.TagExtraInfo;
  import javax.servlet.jsp.tagext.VariableInfo;
  
  
  /**
   * Defines the possible JSP beans available within the the body
   * of the iterator tag.
   */
  public class BundleTEI extends TagExtraInfo
    {
  
    /**
     * Standard no-arg constructor. No actions performed.
     */
    public BundleTEI()
      {
      super();
      }
  
    /**
     * Returns two VariableInfo objects that define the following
     * body objects
     * <UL>
     * <LI>A variable that represents the current value of the iterator.
     * The name to reference this object is defined in the iterator tag
     * with the value "varName". The type of this object is defined by
     * the "varType" value passed in the iterator tag.
     * </UL>
     *
     * @param data a value of type 'TagData'
     * @return a value of type 'VariableInfo[]'
     */
    public VariableInfo[] getVariableInfo( TagData data )
      {
      String varName = data.getAttributeString("id");
      if ( varName == null )
          {
          return new VariableInfo[]
                      {
                      };
          }
      else
          {
          return new VariableInfo[]
                      {
                      new VariableInfo( varName,
                                        "java.util.ResourceBundle",
                                        true,
                                        VariableInfo.AT_BEGIN ),
                      };
          }
      }
  
    } // BundleTEI
  
  
  
  1.1                  jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/ConditionalTagSupport.java
  
  Index: ConditionalTagSupport.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-taglibs/i18n/src/org/apache/taglibs/i18n/ConditionalTagSupport.java,v 1.1 2001/06/13 03:24:41 tdawson Exp $
   * $Revision: 1.1 $
   * $Date: 2001/06/13 03:24:41 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.taglibs.i18n;
  
  import java.io.IOException;
  
  import java.util.ResourceBundle;
  
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.PageContext;
  import javax.servlet.jsp.tagext.BodyTag;
  import javax.servlet.jsp.tagext.BodyTagSupport;
  
  
  /**
   *  This class provides the base implementation for the ifdef and ifndef tags.
   *  Subclasses must provide an implementation of the shouldEvaluate() method.
   *
   *  @author <a href="mailto:tdawson@wamnet.com">Tim Dawson</a>
   *
   */
  public abstract class ConditionalTagSupport extends BodyTagSupport
    {
    // instance variables used during processing
    private String               _key = null;
    private ResourceBundle       _bundle = null;
  
    /**
     *  sets the key to use when looking up the value in the bundle
     */
    public void setKey(String key)
      {
      _key = key;
      }
  
    /**
     *  @return the key to use
     */
    public String getKey()
      {
      return _key;
      }
  
    /**
     *  sets the bundle based on a variable defined in the page<br>
     *  if neither bundle or bundleRef are specified, uses the first bundle
     *  defined on the page by the i18n:bundle tag
     */
    public void setBundleRef(String varName)
      {
      _bundle = (ResourceBundle)pageContext.getAttribute(varName);
      }
  
    /**
     *  sets the bundle to an actual ResourceBundle object<br>
     *  if neither bundle or bundleRef are specified, uses the bundle most recently
     *  defined on the page by the i18n:bundle tag
     */
    public void setBundle(ResourceBundle aBundle)
      {
      _bundle = aBundle;
      }
  
    /**
     *  @return the bundle to use
     */
    public ResourceBundle getBundle()
      {
      if ( _bundle == null )
          {
          _bundle = ResourceHelper.getBundle(pageContext);
          }
      return _bundle;
      }
  
    /**
     *  clears out the key for the next usage
     */
    public void release()
      {
      super.release();
      _key = null;
      _bundle = null;
      }
  
    /**
     *  must be overridden by a subclass to return a boolean value
     */
    public abstract boolean shouldEvaluate()
            throws JspException;
  
    /**
     *  returns (if any) the value specified for the key in the bundle. if no
     *  value is specified, traps the MissingResourceException and returns null
     */
    protected String getValue()
            throws JspException
      {
      String name = this.getClass().getName();
      
      // ensure we have a key
      String key = this.getKey();
      if ( this.getKey() == null)
          {
          throw new JspException(name + " requires a key.");
          }
  
      // ensure a bundle was defined
      ResourceBundle bundle = this.getBundle();
      if ( this.getBundle() == null)
          {
          throw new JspException("A bundle must be provided as an attribute or defined by the i18n:bundle tag prior to using a " + name + ".");
          }
  
      String value = null;
      try
          {
          value = bundle.getString(key);
          }
      catch (java.util.MissingResourceException e)
          {
          value = null;
          }
      return value;
      }
  
    /**
     *  locates the bundle and tests whether the key has a value
     */
    public int doStartTag()
            throws JspException
      {
      int returnValue;
  
      // evaluate the body if a value was found, otherwise skip it
      if ( this.shouldEvaluate() )
          {
          returnValue = BodyTag.EVAL_BODY_TAG;
          }
      else
          {
          returnValue = BodyTag.SKIP_BODY;
          }
  
      return returnValue;
      }
  
    /**
     * Prints the body of the tag.
     * <P>
     * Always return the flag for processing the rest of the JSP page.
     *
     * @return the flag for processing the rest of the JSP page.
     * @exception JspException if the writing out of the body fails.
     */
    public int doEndTag() throws JspException
      {
      try
          {
          if (bodyContent != null)
              {
              bodyContent.writeOut(bodyContent.getEnclosingWriter());
              }
          }
      catch (java.io.IOException ioe)
          {
          throw new JspException("IO Error: " + ioe.getMessage());
          }
  
      // This is not a loop, so always process the rest of the JSP page
      return BodyTag.EVAL_PAGE;
      }
  
  
    } // IfdefTag