Revision: 1254
          http://stripes.svn.sourceforge.net/stripes/?rev=1254&view=rev
Author:   fdaoud
Date:     2010-06-08 20:35:12 +0000 (Tue, 08 Jun 2010)

Log Message:
-----------
Fix for STS-683

Modified Paths:
--------------
    trunk/stripes/resources/stripes.tld
    trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
    
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
    trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsMapTag.java

Modified: trunk/stripes/resources/stripes.tld
===================================================================
--- trunk/stripes/resources/stripes.tld 2010-06-08 20:03:28 UTC (rev 1253)
+++ trunk/stripes/resources/stripes.tld 2010-06-08 20:35:12 UTC (rev 1254)
@@ -819,9 +819,9 @@
         </attribute>
         <attribute>
             <description>
-               The (optional) anchor that is appended at the end of the 
generated URL.
-               If the URL specified by the value attribute already contains 
the anchor then
-               the anchor specified by this attribute takes precedence.
+              The (optional) anchor that is appended at the end of the 
generated URL.
+              If the URL specified by the value attribute already contains the 
anchor then
+              the anchor specified by this attribute takes precedence.
             </description>
             
<name>anchor</name><required>false</required><rtexprvalue>true</rtexprvalue>
         </attribute>
@@ -1055,8 +1055,11 @@
             through that collection calling getCatId() and getName() on each 
cat to produce
             HTML option tags.</p>
 
-            <p>The tag will attempt to localize the labels attributes of the 
option tags that are
-            generated. To do this it will look up labels in the field resource 
bundle using:</p>
+            <p>By default, the tag will attempt to localize the labels 
attributes of the option tags that are
+            generated. To override this default and turn off this behavior, 
thus saving unnecessary resource
+            bundle lookups, set the localizeLabels attribute to false.</p>
+         
+            <p>To do label localization, the tag will look up labels in the 
field resource bundle using:</p>
 
             <ul>
               <li>{className}.{labelPropertyValue}</li>
@@ -1076,7 +1079,8 @@
               <li>com.myco.Gender.M</li>
             </ul>
 
-            <p>If no localized label can be found then the value of the label 
property will be used.</p>
+            <p>If no localized label can be found, or if the localizeLabels 
attribute is set to false,
+            then the value of the label property will be used.</p>
 
             <p>Optionally, the group attribute may be used to generate 
&lt;optgroup&gt; tags. The value of
             this attribute is used to retrieve the corresponding property on 
each object of the collection.
@@ -1107,7 +1111,8 @@
                 The name of the property (of the beans in the collection) that 
should be used to
                 generate the value of each option (i.e. the value that is sent 
to the server).
             </description>
-            
<name>value</name><required>false</required><rtexprvalue>true</rtexprvalue></attribute>
+            
<name>value</name><required>false</required><rtexprvalue>true</rtexprvalue>
+        </attribute>
         <attribute>
             <description>
                 The name of the property (of the beans in the collection) that 
should be used to
@@ -1143,6 +1148,17 @@
             ]]></description>
             
<name>group</name><required>false</required><rtexprvalue>true</rtexprvalue>
         </attribute>
+        <attribute>
+            <description>
+                Determines whether attempts to localize labels will occur. If 
set to true (the default), labels will be
+                localized as described above. If set to false, no resource 
bundle lookups will be made, which can
+                improve performance.
+            </description>
+            <name>localizeLabels</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <type>java.lang.Boolean</type>
+        </attribute>
 
         <!-- Start: Standard HTML attributes -->
         
<attribute><description>@accesskey@</description><name>accesskey</name><required>false</required><rtexprvalue>true</rtexprvalue></attribute>
@@ -1187,8 +1203,11 @@
             the various JSP scopes and set it on the tag.  The tag would then 
proceed to iterate
             through that Map calling getKey() and getValue() on each cat to 
produce HTML option tags.</p>
 
-            <p>The tag will attempt to localize the labels attributes of the 
option tags that are
-            generated. To do this it will look up labels in the field resource 
bundle. If no
+            <p>By default, the tag will attempt to localize the labels 
attributes of the option tags that are
+            generated. To override this default and turn off this behavior, 
thus saving unnecessary resource
+            bundle lookups, set the localizeLabels attribute to false.</p>
+         
+            <p>To do label localization, the tag will look up labels in the 
field resource bundle. If no
             localized label can be found then the value of the label property 
will be used.</p>
 
             <p>All other attributes on the tag (other than map, label, and 
sort) are passed
@@ -1244,6 +1263,17 @@
             ]]></description>
             
<name>group</name><required>false</required><rtexprvalue>true</rtexprvalue>
         </attribute>
+        <attribute>
+            <description>
+                Determines whether attempts to localize labels will occur. If 
set to true (the default), labels will be
+                localized as described above. If set to false, no resource 
bundle lookups will be made, which can
+                improve performance.
+            </description>
+            <name>localizeLabels</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <type>java.lang.Boolean</type>
+        </attribute>
         
 
         <!-- Start: Standard HTML attributes -->
@@ -1279,9 +1309,13 @@
             options will be generated in ordinal value order (i.e. the order 
they are declared in the
             enum).</p>
 
+            <p>Please note that as with the options-collection and options-map 
tags, resource bundle lookups
+            are on by default but can be turned off by setting the 
localizeLabels attribute to false.</p>
+
             <p>The label (the value the user sees) is generated in one of 
three ways: by looking up a
-            localized value, by using the property named by the 'label' tag 
attribute if it is supplied
-            and lastly by toString()'ing the enumeration value.  For example 
the following tag:</p>
+            localized value (unless localizeLabels is set to false), by using 
the property named by the 'label'
+            tag attribute if it is supplied and lastly by toString()'ing the 
enumeration value.
+            For example the following tag:</p>
 
             <pre>&lt;stripes:options-enumeration enum="net.kitty.EyeColor" 
label="description"/&gt;</pre>
 
@@ -1289,8 +1323,8 @@
             following order:</p>
 
             <ul>
-              <li><tt>resource: EyeColor.BLUE</tt></li>
-              <li><tt>resource: net.kitty.EyeColor.BLUE</tt></li>
+              <li><tt>resource: EyeColor.BLUE</tt> (skipped if localizeLabels 
is set to false)</li>
+              <li><tt>resource: net.kitty.EyeColor.BLUE</tt> (skipped if 
localizeLabels is set to false)</li>
               <li><tt>property: EyeColor.BLUE.getDescription()</tt> (because 
of the label="description" above)</li>
               <li><tt>failsafe: EyeColor.BLUE.toString()</tt></li>
             </ul>
@@ -1340,6 +1374,17 @@
             ]]></description>
             
<name>group</name><required>false</required><rtexprvalue>true</rtexprvalue>
         </attribute>
+        <attribute>
+            <description>
+                Determines whether attempts to localize labels will occur. If 
set to true (the default), labels will be
+                localized as described above. If set to false, no resource 
bundle lookups will be made, which can
+                improve performance.
+            </description>
+            <name>localizeLabels</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <type>java.lang.Boolean</type>
+        </attribute>
 
 
         <!-- Start: Standard HTML attributes -->
@@ -1914,9 +1959,9 @@
         </attribute>
         <attribute>
             <description>
-               The (optional) anchor that is appended at the end of the 
generated URL.
-               If the URL specified by the value attribute already contains 
the anchor then
-               the anchor specified by this attribute takes precedence.
+              The (optional) anchor that is appended at the end of the 
generated URL.
+              If the URL specified by the value attribute already contains the 
anchor then
+              the anchor specified by this attribute takes precedence.
             </description>
             
<name>anchor</name><required>false</required><rtexprvalue>true</rtexprvalue>
         </attribute>

Modified: 
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java    
    2010-06-08 20:03:28 UTC (rev 1253)
+++ 
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java    
    2010-06-08 20:35:12 UTC (rev 1254)
@@ -45,8 +45,11 @@
  * scopes and set it on the tag.  The tag would then proceed to iterate 
through that collection
  * calling getCatId() and getName() on each cat to produce HTML option 
tags.</p>
  *
- * <p>The tag will attempt to localize the labels attributes of the option 
tags that are
- * generated. To do this it will look up labels in the field resource bundle 
using:</p>
+ * <p>By default, the tag will attempt to localize the labels attributes of 
the option tags that are
+ * generated. To override this default and turn off this behavior, thus saving 
unnecessary resource
+ * bundle lookups, set the localizeLabels attribute to false.</p>
+ * 
+ * <p>To do label localization, the tag will look up labels in the field 
resource bundle using:</p>
  *
  * <ul>
  *   <li>{className}.{labelPropertyValue}</li>
@@ -66,7 +69,8 @@
  *   <li>com.myco.Gender.M</li>
  * </ul>
  *
- * <p>If no localized label can be found then the value of the label property 
will be used.</p>
+ * <p>If no localized label can be found, or if the localizeLabels attribute 
is set to false,
+ * then the value of the label property will be used.</p>
  *
  * <p>Optionally, the group attribute may be used to generate &lt;optgroup&gt; 
tags. The value of
  * this attribute is used to retrieve the corresponding property on each 
object of the collection.
@@ -95,6 +99,7 @@
     private String label;
     private String sort;
     private String group;
+    private Boolean localizeLabels;
 
     /**
      * A little container class that holds an entry in the collection of items 
being used
@@ -126,7 +131,7 @@
      * @param in either a Collection, an Iterable or an Array
      */
     @SuppressWarnings("unchecked")
-       public void setCollection(Object in) {
+    public void setCollection(Object in) {
         if (in == null) this.collection = null;
         else if (in instanceof Collection) this.collection = (Collection) in;
         else if (in instanceof Iterable) this.collection = 
CollectionUtil.asList((Iterable) in);
@@ -192,6 +197,20 @@
         return sort;
     }
 
+    /** Sets the flag that indicates whether or not attempts to localize 
labels should be made. */
+    public void setLocalizeLabels(Boolean localizeLabels) {
+        this.localizeLabels = localizeLabels;
+    }
+
+    /** Gets the flag that indicates whether or not attempts to localize 
labels should be made. */
+    public Boolean getLocalizeLabels() {
+        return localizeLabels;
+    }
+
+    protected boolean isAttemptToLocalizeLabels() {
+        return (localizeLabels == null) || (localizeLabels != null && 
localizeLabels.booleanValue());
+    }
+
     /**
      * Adds an entry to the internal list of items being used to generate 
options.
      * @param item the object represented by the option
@@ -224,9 +243,9 @@
      */
     @Override
     public int doStartTag() throws JspException {
-       if (this.collection == null)
-               return SKIP_BODY;
-       
+      if (this.collection == null)
+        return SKIP_BODY;
+
         String labelProperty = getLabel();
         String valueProperty = getValue();
         String groupProperty = getGroup();
@@ -234,6 +253,7 @@
 
         try {
             Locale locale = getPageContext().getRequest().getLocale();
+            boolean attemptToLocalizeLabels = isAttemptToLocalizeLabels();
 
             for (Object item : this.collection) {
                 Class<? extends Object> clazz = item.getClass();
@@ -243,24 +263,26 @@
                 Object value = (valueProperty == null) ? item : 
BeanUtil.getPropertyValue(valueProperty, item);
                 Object group = (groupProperty == null) ? null : 
BeanUtil.getPropertyValue(groupProperty, item);
 
-                // Try to localize the label
-                String packageName = clazz.getPackage() == null ? "" : 
clazz.getPackage().getName();
-                String localizedLabel = null;
-                if (label != null) {
-                    localizedLabel = LocalizationUtility.getLocalizedFieldName
-                        (clazz.getSimpleName() + "."  + label, packageName, 
null, locale);
-                }
-                if (localizedLabel == null && value != null) {
-                    localizedLabel = LocalizationUtility.getLocalizedFieldName
-                        (clazz.getSimpleName() + "."  + value, packageName, 
null, locale);
-                }
-                if (localizedLabel != null) label = localizedLabel;
+                if (attemptToLocalizeLabels) {
+                    // Try to localize the label
+                    String packageName = clazz.getPackage() == null ? "" : 
clazz.getPackage().getName();
+                    String localizedLabel = null;
+                    if (label != null) {
+                        localizedLabel = 
LocalizationUtility.getLocalizedFieldName
+                            (clazz.getSimpleName() + "."  + label, 
packageName, null, locale);
+                    }
+                    if (localizedLabel == null && value != null) {
+                        localizedLabel = 
LocalizationUtility.getLocalizedFieldName
+                            (clazz.getSimpleName() + "."  + value, 
packageName, null, locale);
+                    }
+                    if (localizedLabel != null) label = localizedLabel;
 
-                // Try to localize the group
-                if (group != null) {
-                    String localizedGroup = 
LocalizationUtility.getLocalizedFieldName(
-                        clazz.getSimpleName() + "." + group, packageName, 
null, locale);
-                    if (localizedGroup != null) group = localizedGroup;
+                    // Try to localize the group
+                    if (group != null) {
+                        String localizedGroup = 
LocalizationUtility.getLocalizedFieldName(
+                            clazz.getSimpleName() + "." + group, packageName, 
null, locale);
+                        if (localizedGroup != null) group = localizedGroup;
+                    }
                 }
                 addEntry(item, label, value, group);
             }
@@ -299,13 +321,13 @@
         InputOptionTag tag = new InputOptionTag();
         tag.setParent(this);
         tag.setPageContext(getPageContext());
-        
+
         Object lastGroup = null;
 
         for (Entry entry : sortedEntries) {
             // Set properties common to all options
             tag.getAttributes().putAll(getAttributes());
-            
+
             // Set properties for this tag
             tag.setLabel(entry.label == null ? null : entry.label.toString());
             tag.setValue(entry.value);
@@ -316,10 +338,10 @@
                     out.write("<optgroup label=\"");
                     out.write(String.valueOf(entry.group).replaceAll("\"", 
"&quot;"));
                     out.write("\"/>");
-                    
+
                     lastGroup = entry.group;
                 }
-              
+
                 tag.doStartTag();
                 tag.doInitBody();
                 tag.doAfterBody();

Modified: 
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java   
    2010-06-08 20:03:28 UTC (rev 1253)
+++ 
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java   
    2010-06-08 20:35:12 UTC (rev 1254)
@@ -29,9 +29,13 @@
  * options will be generated in ordinal value order (i.e. the order they are 
declared in the
  * enum).</p>
  *
+ * <p>Please note that as with the options-collection and options-map tags, 
resource bundle lookups
+ * are on by default but can be turned off by setting the localizeLabels 
attribute to false.</p>
+ *
  * <p>The label (the value the user sees) is generated in one of three ways: 
by looking up a
- * localized value, by using the property named by the 'label' tag attribute 
if it is supplied
- * and lastly by toString()'ing the enumeration value.  For example the 
following tag:</p>
+ * localized value (unless localizeLabels is set to false), by using the 
property named by the 'label'
+ * tag attribute if it is supplied and lastly by toString()'ing the 
enumeration value.
+ * For example the following tag:</p>
  *
  *<pre>{...@literal <stripes:options-enumeration enum="net.kitty.EyeColor" 
label="description"/>}</pre>
  *
@@ -39,8 +43,8 @@
  * following order:</p>
  *
  * <ul>
- *   <li>resource: EyeColor.BLUE</li>
- *   <li>resource: net.kitty.EyeColor.BLUE</li>
+ *   <li>resource: EyeColor.BLUE (skipped if localizeLabels is set to 
false)</li>
+ *   <li>resource: net.kitty.EyeColor.BLUE (skipped if localizeLabels is set 
to false)</li>
  *   <li>property: EyeColor.BLUE.getDescription() (because of the 
label="description" above)</li>
  *   <li>failsafe: EyeColor.BLUE.toString()</li>
  * </ul>
@@ -80,7 +84,7 @@
      */
     @Override
     @SuppressWarnings("unchecked")
-       public int doStartTag() throws JspException {
+    public int doStartTag() throws JspException {
         Class<Enum> clazz = null;
         try {
             clazz = (Class<Enum>) ReflectUtil.findClass(this.className);
@@ -114,16 +118,20 @@
 
         try {
             Locale locale = getPageContext().getRequest().getLocale();
+            boolean attemptToLocalizeLabels = isAttemptToLocalizeLabels();
 
             for (Enum item : enums) {
                 Object label = null;
-                String packageName = clazz.getPackage() == null ? "" : 
clazz.getPackage().getName();
 
-                // Check for a localized label using class.ENUM_VALUE and 
package.class.ENUM_VALUE
-                label = 
LocalizationUtility.getLocalizedFieldName(clazz.getSimpleName() + "." + 
item.name(),
-                                                                  packageName,
-                                                                  null,
-                                                                  locale);
+                if (attemptToLocalizeLabels) {
+                    String packageName = clazz.getPackage() == null ? "" : 
clazz.getPackage().getName();
+
+                    // Check for a localized label using class.ENUM_VALUE and 
package.class.ENUM_VALUE
+                    label = 
LocalizationUtility.getLocalizedFieldName(clazz.getSimpleName() + "." + 
item.name(),
+                                                                      
packageName,
+                                                                      null,
+                                                                      locale);
+                }
                 if (label == null) {
                     if (getLabel() != null) {
                         label = BeanUtil.getPropertyValue(getLabel(), item);
@@ -132,7 +140,7 @@
                         label = item.toString();
                     }
                 }
-                
+
                 Object group = null;
                 if (getGroup() != null)
                     group = BeanUtil.getPropertyValue(getGroup(), item);

Modified: trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsMapTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsMapTag.java       
2010-06-08 20:03:28 UTC (rev 1253)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsMapTag.java       
2010-06-08 20:35:12 UTC (rev 1254)
@@ -33,16 +33,16 @@
  */
 public class InputOptionsMapTag extends InputOptionsCollectionTag
 {
-       private Map<? extends Object,? extends Object> map;
+    private Map<? extends Object,? extends Object> map;
 
-       /**
-        * <p>Returns the {...@link java.util.Map} that was passed in via 
setMap().</p>
-        * 
-        * @return the {...@link java.util.Map} passed in via setMap().
-        */
-       public Map<? extends Object, ? extends Object> getMap() {
-               return map;
-       }
+    /**
+     * <p>Returns the {...@link java.util.Map} that was passed in via 
setMap().</p>
+     * 
+     * @return the {...@link java.util.Map} passed in via setMap().
+     */
+    public Map<? extends Object, ? extends Object> getMap() {
+        return map;
+    }
 
     /**
      * <p>This function simply passes the result of Map.entrySet()
@@ -51,26 +51,26 @@
      *
      * @param map a Map
      */
-       public void setMap(Map<? extends Object, ? extends Object> map) {
-               this.map = map;
-               
-               setCollection(map.entrySet());
-               
-               if (getValue() == null)
-                       setValue("key");
-               
-               if (getLabel() == null)
-                       setLabel("value");
-       }
-       
-       /**
-        * Calls super.doEndTag() and cleans up instance variables so this 
instance
-        * may be reused.
-        */
+    public void setMap(Map<? extends Object, ? extends Object> map)    {
+        this.map = map;
+
+        setCollection(map.entrySet());
+
+        if (getValue() == null)
+            setValue("key");
+
+        if (getLabel() == null)
+            setLabel("value");
+    }
+
+    /**
+     * Calls super.doEndTag() and cleans up instance variables so this instance
+     * may be reused.
+     */
     @Override
     public int doEndTag() throws JspException {
-       int result = super.doEndTag();
-       
-       return result;
+        int result = super.doEndTag();
+
+        return result;
     }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to