You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2005/05/28 03:21:23 UTC

svn commit: r178849 - in /struts/shale/trunk/clay-plugin/src: conf/ java/org/apache/shale/clay/ java/org/apache/shale/clay/component/chain/ java/org/apache/shale/clay/config/ java/org/apache/shale/clay/config/beans/ java/org/apache/shale/clay/config/resources/ java/org/apache/shale/clay/parser/builder/ java/org/apache/shale/clay/utils/ test/org/apache/shale/clay/utils/

Author: craigmcc
Date: Fri May 27 18:21:22 2005
New Revision: 178849

URL: http://svn.apache.org/viewcvs?rev=178849&view=rev
Log:
Apply the proposed patch for Bugzilla ticket #34714 to reduce the cases where
PropUtil.setProperty() would fail silently.  I had to tweak one line
(in ComponentBean.getIsBodyAllowed()) so that it would compile under 1.4
as well as 1.5.

Modified:
    struts/shale/trunk/clay-plugin/src/conf/view-config.dtd
    struts/shale/trunk/clay-plugin/src/conf/view-config.xml
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentBean.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/resources/clay-config_1_0.dtd
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/InputTextareaBuilder.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemBuilder.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemsBuilder.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectManyMenuBuilder.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectOneMenuBuilder.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/PropUtils.java
    struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/PropUtilsTestCase.java

Modified: struts/shale/trunk/clay-plugin/src/conf/view-config.dtd
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/conf/view-config.dtd?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/conf/view-config.dtd (original)
+++ struts/shale/trunk/clay-plugin/src/conf/view-config.dtd Fri May 27 18:21:22 2005
@@ -45,11 +45,11 @@
          resolving inheritance.
          
   useMethodLateBinding - This attribute informs the Clay component to pass a MethodBinding object to
-         to the component.  Currently all the standard method binding events, “action”, “actionListener”, 
-         “validator” and “valueChangeListner” are handled. This attribute is meant to be used by a custom 
+         to the component.  Currently all the standard method binding events, "action", "actionListener", 
+         "validator" and "valueChangeListner" are handled. This attribute is meant to be used by a custom 
          component that has a non-standard attribute name for binding a method event.
 
-  useValueLateBinding - When this attribute is toggled on with a “true” value, the Clay component will pass 
+  useValueLateBinding - When this attribute is toggled on with a "true" value, the Clay component will pass 
          a ValueBinding object to the component; otherwise, the component will receive the resulting value.  
          The resulting value can be a literal or a expression language binding expression. 
   
@@ -87,31 +87,42 @@
 
       
    element - A top-level "component" can contain any number of sub "elements".  Elements define 
-      composition for a complex component.  The element is the glue that pulls in a “top-level” 
+      composition for a complex component.  The element is the glue that pulls in a "top-level" 
       component.  The element is kind of like an inner class in that it can extend the attributes 
-      of the “top-level” component that it's aggregating.
+      of the "top-level" component that it's aggregating.
       
       
    jsfid - A unique identifier defining the component instances as it relates to the 
       componentType.  This is a required attribute.
    
    extends - A jsfid that this component will inherit characteristics from. A jsfid that this 
-      component will inherit characteristics from. By  characteristics we mean parent “elements” 
-      and “attributes”.  This is an optional attribute.
+      component will inherit characteristics from. By  characteristics we mean parent "elements" 
+      and "attributes".  This is an optional attribute.
       
    componentType - The component type will be the JSF registered logical name for Components,
       Validators and Converters in the faces-config.xml file.  For ActionListeners and 
       ValueChangeListeners, the component type will be the fully qualified class name.  The
       componentType will be required when the extends attribute is not specified.  If the 
       extends attribute is specified it will inherit the attribute value from the parent
-      component.  
+      component. 
+      
+   allowBody - This attribute only applies when using the Clay template features and it 
+      is optional.  A "true" value is returned if the HTML child nodes under the node that 
+      this meta component is bound to should be rendered; otherwise, a "false" value is 
+      returned indicating the child nodes should be ignored.  This feature allows you to 
+      override design-time mockup HTML at runtime. 
+      
+   facetName - Use this attribute to register the component in the facets collection rather 
+      than the children collection.  
    
 -->
 <!ELEMENT component (attributes?, converter?, validator*, actionListener*, valueChangeListener*, element*)>
 <!ATTLIST component jsfid CDATA #REQUIRED
 	extends CDATA #IMPLIED
 	componentType CDATA #IMPLIED
-	id CDATA #IMPLIED	
+	id CDATA #IMPLIED
+	allowBody %Boolean; #IMPLIED	
+	facetName CDATA #IMPLIED
 >
 
 <!--
@@ -143,9 +154,9 @@
       enforced at runtime.
       
   element - A "element" can contain any number of sub-elements.  Elements define 
-      composition for a complex component.  The element is the glue that pulls in a “top-level” 
+      composition for a complex component.  The element is the glue that pulls in a "top-level" 
       component.  The element is kind of like an inner class in that it can extend the attributes 
-      of the “top-level” component that it's aggregating.  
+      of the "top-level" component that it's aggregating.  
       
   renderId - A numeric integer value that uniquely defines the element within a owning "component"
       or "element".  It's the "method signature" used to resolve inheritances and also ordering 
@@ -154,6 +165,9 @@
       
    id - This attribute corresponds to a JSF component's id attribute that will be used to derive
       the client id value within the HTML id attribute.
+
+   facetName - Use this attribute to register the component in the facets collection rather 
+      than the children collection.  
      
 -->
 <!ELEMENT element (attributes?, converter?, validator*, actionListener*, valueChangeListener*, element*)>
@@ -161,6 +175,7 @@
 	renderId CDATA #REQUIRED
 	jsfid CDATA #REQUIRED
 	id CDATA #IMPLIED
+	facetName CDATA #IMPLIED	
 >
 <!--
   A "converter" node is the meta component definition for a JSF converter.  This 

Modified: struts/shale/trunk/clay-plugin/src/conf/view-config.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/conf/view-config.xml?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/conf/view-config.xml (original)
+++ struts/shale/trunk/clay-plugin/src/conf/view-config.xml Fri May 27 18:21:22 2005
@@ -25,68 +25,184 @@
       validated (on a subsequent form submit) to catch cases where the
       same form was submitted more than once.
     -->
-   <component jsfid="token" id="token" componentType="org.apache.shale.Token">
-      <attributes>
-         <set name="allowBody" value="false"/>
-      </attributes>   
-   </component>
+  <component jsfid="token" id="token" componentType="org.apache.shale.Token" allowBody="false"/>
 
+  <!-- 
+     Render readonly text
+   -->
   <component jsfid="outputText" componentType="javax.faces.HtmlOutputText">
     <attributes>
       <!-- The current value of this component. -->
       <set name="value" useValueLateBinding="true" />      
     </attributes>
   </component>
-    
+ 
+  <!-- 
+     Render a url query parameter argument
+   -->   
   <component jsfid="parameter" componentType="javax.faces.Parameter"/>
   <component jsfid="param" componentType="javax.faces.Parameter"/>
   
+  <!-- 
+      Render a single html option tag
+   -->
   <component jsfid="selectItem" componentType="javax.faces.SelectItem"/>
+  
+  <!-- 
+      Render an html option tag for each item in the bound collection
+   -->
   <component jsfid="selectItems" componentType="javax.faces.SelectItems">
     <attributes>
       <set name="value" useValueLateBinding="true" />
     </attributes>
   </component>
+  
+  <!-- 
+      Render a set of html "input" elements of type "radio".
+   -->
   <component jsfid="selectOneRadio" componentType="javax.faces.HtmlSelectOneRadio"/>
+
+  <!-- 
+      Render a "select" element without a multiple attribute.
+   -->  
   <component jsfid="selectOneMenu" componentType="javax.faces.HtmlSelectOneMenu"/>
+
+  <!-- 
+      Render a "select" element with a multiple attribute.
+   -->    
   <component jsfid="selectManyMenu" componentType="javax.faces.HtmlSelectManyMenu"/>
+
+  <!-- 
+      Render a set of html "input" elements of type "checkbox".
+   -->  
   <component jsfid="manyCheckbox" componentType="javax.faces.HtmlSelectManyCheckbox"/>
+
+  <!-- 
+      Render a html "input" element of type "checkbox".
+   -->    
   <component jsfid="selectBooleanCheckbox" componentType="javax.faces.HtmlSelectBooleanCheckbox"/>
+
+  <!-- 
+      Render a html "table" element.
+   -->      
   <component jsfid="panelGroup" componentType="javax.faces.HtmlPanelGroup"/>
+
+  <!-- 
+      Render a html "a" element.
+   -->        
   <component jsfid="outputLink" componentType="javax.faces.HtmlOutputLink"/>
+
+  <!-- 
+      Render a html "label" element.
+   -->          
   <component jsfid="outputLabel" componentType="javax.faces.HtmlOutputLabel"/>
+  
+   <!-- 
+      Render a html "textarea" element.
+   -->        
   <component jsfid="inputTextarea" componentType="javax.faces.HtmlInputTextarea"/>
+
+   <!-- 
+      Render a html "input" element of type "password".
+   -->        
   <component jsfid="inputSecret" componentType="javax.faces.HtmlInputSecret"/>
+
+  <!-- 
+      Render a html "input" element of type "hidden".
+   -->          
   <component jsfid="inputHidden" componentType="javax.faces.HtmlInputHidden"/>
+
+  <!-- 
+      Render a html "img" element.
+   -->            
   <component jsfid="image" componentType="javax.faces.HtmlGraphicImage"/>
+
+  <!-- 
+      Render a html "form" element.
+   -->              
   <component jsfid="form" componentType="javax.faces.HtmlForm"/>
+
+  <!-- 
+      Render a html "table" element.
+   -->              
   <component jsfid="dataTable" componentType="javax.faces.HtmlDataTable"/>
+   <!-- 
+      Render a html "input" element of type "button".
+   -->            
   <component jsfid="commandLink" componentType="javax.faces.HtmlCommandLink"/>
+
+   <!-- 
+      Defines a html "td" element within a "dataTable".
+   -->              
   <component jsfid="column" componentType="javax.faces.Column"/>
+
+   <!-- 
+      Render a html "input" element of type "text".
+   -->              
   <component jsfid="inputText" componentType="javax.faces.HtmlInputText"/>
+
+   <!-- 
+      Render a readonly text value substituting inline string parameters.  
+   -->                
   <component jsfid="outputFormat" componentType="javax.faces.HtmlOutputFormat"/>
+  
+   <!-- 
+      Render a set of readonly text messages.  
+   -->                  
   <component jsfid="messages" componentType="javax.faces.HtmlMessages"/>	
+
+   <!-- 
+      Render a readonly text messages associated with an "input" element.   
+   -->                    
   <component jsfid="message" componentType="javax.faces.HtmlMessage"/>	
+
+   <!-- 
+      Render a html "input" element of type "submit".
+   -->                
   <component jsfid="commandButton" componentType="javax.faces.HtmlCommandButton"/>	
+
+   <!-- 
+      Render a html "table" element.
+   -->                  
   <component jsfid="panelGrid" componentType="javax.faces.HtmlPanelGrid" />
+
+   <!-- 
+      Not associated with an html element. 
+   -->                    
   <component jsfid="namingContainer" componentType="javax.faces.NamingContainer" />
+
+   <!-- 
+      Renders a html space. 
+   -->                      
   <component jsfid="space" extends="outputText">
     <attributes>
       <set name="value" value="&amp;nbsp;" />
       <set name="escape" value="false" />
     </attributes>		
   </component>
-  <component jsfid="integerConverter" componentType="javax.faces.Integer"/>   
+
+   <!-- 
+      Converts a string value into a primitive int type and back to a string.
+   -->                        
+  <component jsfid="integerConverter" componentType="javax.faces.Integer"/> 
+
+   <!-- 
+      Converts a string value into a java.util.Date type and back to a string.
+   -->                            
   <component jsfid="dateTimeConverter" componentType="javax.faces.DateTime" >
     <attributes>
       <set name="pattern" value="MM/dd/yyyy" />
     </attributes>	
-    </component>
-    <component jsfid="validateLongRange" componentType="javax.faces.LongRange" >
+  </component>
+
+   <!-- 
+      Converts a string value into a primitive long type and back to a string.
+   -->                            
+  <component jsfid="validateLongRange" componentType="javax.faces.LongRange" >
       <attributes>
         <set name="minimum" value="5" />
         <set name="maximum" value="10" />
       </attributes>	
-    </component>
+  </component>
 
 </view>

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties Fri May 27 18:21:22 2005
@@ -119,3 +119,7 @@
 #org.apache.shale.clay.parser.builder.Builder
 encode.begin=Begin encoding node: {0}
 encode.end=End encoding node: {0}
+
+#org.apache.shale.clay.utils.PropUtils
+unable.to.set.property.error="Could not set property {0} in bean {1}
+

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java Fri May 27 18:21:22 2005
@@ -81,10 +81,8 @@
             id = facesContext.getViewRoot().createUniqueId();
         
         UIComponent child = null;
-        AttributeBean facetName = null;
-        if ((facetName = displayElement
-                .getAttribute(Globals.CLAY_FACET_ATTRIBUTE_NAME)) != null)
-            child = parent.getFacet(facetName.getValue());
+        if (displayElement.getFacetName() != null)
+            child = parent.getFacet(displayElement.getFacetName());
         else
             child = parent.findComponent(id);
         if (child == null) {
@@ -98,8 +96,8 @@
             }
             
             child.setId(id);
-            if (facetName != null)
-                parent.getFacets().put(facetName.getValue(), child);
+            if (displayElement.getFacetName() != null)
+                parent.getFacets().put(displayElement.getFacetName(), child);
             else
                 parent.getChildren().add(parent.getChildren().size(), child);
             

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java Fri May 27 18:21:22 2005
@@ -97,11 +97,6 @@
                     throw e;
         }
         if (converter != null) {
-            Locale locale = facesContext.getViewRoot().getLocale();
-            if (locale == null)
-                locale = facesContext.getApplication().getDefaultLocale();
-            if (locale != null)
-                PropUtils.setProperty(converter, "locale", locale, null);
             parent.setConverter(converter);
             // reassign the child to the converter for the
             // AssignPropertiesCommand

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java Fri May 27 18:21:22 2005
@@ -22,8 +22,6 @@
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
 import org.apache.commons.logging.Log;
@@ -91,11 +89,10 @@
             } else {
                 Object value = binding.getValue(facesContext);
                 try {
-                    BeanUtils
+                    PropUtils
                             .setProperty(child, attributeBean.getName(), value);
                 } catch (Exception e) {
-                    PropUtils.setProperty(child, attributeBean.getName(),
-                            value, null);
+                    log.error(e);
                 }
                 
             }

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java Fri May 27 18:21:22 2005
@@ -24,23 +24,7 @@
  * </p>
  */
 public class Globals {
-    
-    /**
-     * <p>This literal constant is a fabricated name.  In the JSF/JSP specification,
-     * the facet is a parent tag.  In the clay world, we use this identifier for
-     * an attribute name.
-     * </p>
-     */
-    public static final String CLAY_FACET_ATTRIBUTE_NAME = "facetName";
-    
-    /**
-     * <p>A clay attribute used when defining the template style of page
-     * composition where the body of the HTML element is rendered by
-     * the component.  This is used by the abstract
-     * {@link org.apache.shale.clay.parser.builder}.
-     */
-    public static final String COMPONENT_ATTRIBUTE_ALLOW_BODY = "allowBody";
-    
+            
     /**
      *<p>EL properties will replaced the literal value of this constant with the
      * mapped ViewController bean before the expression is evaluated.
@@ -74,7 +58,7 @@
     public static final String CLAY_DEFAULT_TEMPLATE_SUFFIX = ".clay";
     
     /**
-     * <p>The default subiew configuration file containing the base supported
+     * <p>The default subview configuration file containing the base supported
      * components.
      *</p>
      */

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentBean.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentBean.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentBean.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentBean.java Fri May 27 18:21:22 2005
@@ -151,11 +151,79 @@
      */
     private TreeSet actionListeners = new TreeSet();
     
+    /**
+     * <p>This attribute used when defining the template style of page composition where the 
+     * body of the HTML element is rendered by the component ignoring the HTML.  
+     */
+    private String allowBody = null; 
+    
+    
+    /**
+     * <p>Use this property to add the component to the parent's facet collection rather than
+     * the default children collection.</p>
+     */
+    private String facetName = null;
+    
+    
+    /**
+     * <p>This property only applies when using the {@link org.apache.shale.clay.component.Clay}
+     * template features.  A <code>"true"</code> value is returned if the HTML child nodes under
+     * the node that this meta component is bound to should be rendered; otherwise, a <code>"false"</code>
+     * value is returned indicating the child nodes should be ignored.
+     * </p>
+     */
+    public String getAllowBody() {
+        return allowBody;
+    }
+    
+
+    /**
+     * <p>This property only applies when using the {@link org.apache.shale.clay.component.Clay}
+     * template features.  Sets a Boolean string value that indicating if the child HTML nodes 
+     * under the node that this component is bound to should render or ignore its child nodes. 
+     * </p>
+     */
+    public void setAllowBody(String allowBody) {
+        this.allowBody = allowBody;
+    }
+    
+    /**
+     * <p>Returns a boolean representation of the <code>allowBody</code> property.
+     * The default is <code>"true"</code></p>
+     */
+    public boolean getIsBodyAllowed() {
+       boolean f = true;
+       try {
+           if (allowBody != null)
+               f = Boolean.valueOf(allowBody).booleanValue();
+       } catch (Exception e) {}
+       
+       return f;
+    }
+    
+  /**
+   * <p>Returns the facet name that will be used as the identifier when adding the 
+   * component to the parent facets collection.</p>
+   */
+   public String getFacetName() {
+      return facetName;     
+   }
+
+   /**
+    * <p>Sets the facet name that will be used as the identifier when adding the 
+    * component to the parent facets collection.</p>
+    */
+   public void setFacetName(String facetName) {
+      this.facetName = facetName; 
+   }
+    
     public String toString() {
         StringBuffer buff = new StringBuffer();
         buff.append("jsfid=\"").append(jsfid).append(
                 "\" componentType=\"").append(componentType).append(
-                "\" extends=\"").append(extendsElementId).append("\"");
+                "\" extends=\"").append(extendsElementId).append("\"")
+                .append(" allowBody=\"").append(allowBody)
+                .append("\"");
         
         return buff.toString();
     }

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java Fri May 27 18:21:22 2005
@@ -321,6 +321,12 @@
             if (b.getId() == null)
                 b.setId(b.getIsAParent().getId());
             
+            if (b.getAllowBody() == null)
+                b.setAllowBody(b.getIsAParent().getAllowBody());
+
+            if (b.getFacetName() == null)
+                b.setFacetName(b.getIsAParent().getFacetName());
+
             // inherit parents attributes
             Iterator pi = b.getIsAParent().getAttributeIterator();
             while (pi.hasNext()) {

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/resources/clay-config_1_0.dtd
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/resources/clay-config_1_0.dtd?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/resources/clay-config_1_0.dtd (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/resources/clay-config_1_0.dtd Fri May 27 18:21:22 2005
@@ -21,10 +21,41 @@
 
 -->
 
+<!--Boolean enumeration as two values that correspond to a boolean primitive data type-->
 <!ENTITY % Boolean "(true|false)">
 
+<!--
+  The "attributes" node contains all of the attributes that will be applied to the
+  the target "component" or "element".  Individual attributes are specified using the
+  "set" node, a child element.  
+  
+  When using JSF/JSP tags to define composition, the attributes are specified in the body
+  of the being JSP tag.  In clay, all components are represented generically by a top-level
+  "component" or nested "element" node.  The attributes are declared using within the 
+  "attributes" node verses a unique tag for each specific type of component.
+-->
 <!ELEMENT attributes (set+)>
 
+<!--
+  The "set" node represents an individual meta attribute that should be applied to the "component" 
+  or "element" nodes. 
+  
+  name - The attribute name that corresponds to a component property.  The parent "attributes" node
+         container can be inherited.  The "name" attribute acts as the "method signature" when 
+         resolving inheritance.
+         
+  useMethodLateBinding - This attribute informs the Clay component to pass a MethodBinding object to
+         to the component.  Currently all the standard method binding events, "action", "actionListener", 
+         "validator" and "valueChangeListner" are handled. This attribute is meant to be used by a custom 
+         component that has a non-standard attribute name for binding a method event.
+
+  useValueLateBinding - When this attribute is toggled on with a "true" value, the Clay component will pass 
+         a ValueBinding object to the component; otherwise, the component will receive the resulting value.  
+         The resulting value can be a literal or a expression language binding expression. 
+  
+  value - This attribute holds the value of the named attribute. A literal string value or a dynamic bound 
+         expression.  
+-->
 <!ELEMENT set EMPTY>
 <!ATTLIST set
 	name CDATA #REQUIRED
@@ -32,37 +63,179 @@
 	useValueLateBinding %Boolean; #IMPLIED
     value CDATA #IMPLIED
 >
+
 <!--
-  A component represents a single top-level simple component or a subtree of components.
+  A "component" represents a single top-level simple component or a subtree of components.
+  
+  attributes - A container to hold attributes that will be applied to the target component.
+  
+  converter - A component can have a single converter which is the same relationship that 
+      a JSF component would have to a Converter.  JSF has a assumed rule that only components 
+      implementing the ValueHolder interfaces can be assigned converters.  This rule is enforced 
+      at runtime and not through this document type definition.
+         
+  validator - A component can have zero or many associated validators.  Only components that 
+      implement the EditableValueHolder interfaces can be assigned validators.  This rule 
+      is enforced at runtime and not through this document type definition. 
+  
+  actionListener - A component can have zero or many assigned actionListeners.  Action listeners
+      can only be assigned to components implementing the ActionSource interfaces.  This rule is
+      enforced at runtime.
+
+  valueChangeListener - A component can have zero or many assigned valueChangeListeners.  Change listeners
+      can only be assigned to components implementing the EditableValueHolder interfaces.  This rule is
+      enforced at runtime.
+
+      
+   element - A top-level "component" can contain any number of sub "elements".  Elements define 
+      composition for a complex component.  The element is the glue that pulls in a "top-level" 
+      component.  The element is kind of like an inner class in that it can extend the attributes 
+      of the "top-level" component that it's aggregating.
+      
+      
+   jsfid - A unique identifier defining the component instances as it relates to the 
+      componentType.  This is a required attribute.
+   
+   extends - A jsfid that this component will inherit characteristics from. A jsfid that this 
+      component will inherit characteristics from. By  characteristics we mean parent "elements" 
+      and "attributes".  This is an optional attribute.
+      
+   componentType - The component type will be the JSF registered logical name for Components,
+      Validators and Converters in the faces-config.xml file.  For ActionListeners and 
+      ValueChangeListeners, the component type will be the fully qualified class name.  The
+      componentType will be required when the extends attribute is not specified.  If the 
+      extends attribute is specified it will inherit the attribute value from the parent
+      component. 
+      
+   allowBody - This attribute only applies when using the Clay template features and it 
+      is optional.  A "true" value is returned if the HTML child nodes under the node that 
+      this meta component is bound to should be rendered; otherwise, a "false" value is 
+      returned indicating the child nodes should be ignored.  This feature allows you to 
+      override design-time mockup HTML at runtime. 
+      
+   facetName - Use this attribute to register the component in the facets collection rather 
+      than the children collection.  
+   
 -->
 <!ELEMENT component (attributes?, converter?, validator*, actionListener*, valueChangeListener*, element*)>
 <!ATTLIST component jsfid CDATA #REQUIRED
 	extends CDATA #IMPLIED
 	componentType CDATA #IMPLIED
 	id CDATA #IMPLIED	
+	allowBody %Boolean; #IMPLIED
+	facetName CDATA #IMPLIED
 >
 
 <!--
    The element nodes are the composition glue.  The jsfid represents the top-level component that 
-   the nested component will extend.  
+   the nested component will extend.  The jsfid is used in the element like the componentType is 
+   to the "component".  The renderId is the unique namespace within the owning "component" or "element".
+   The key difference between an element and component is that a component can be reused within
+   any number of compositions where an element is the structure for defining the composition.
+   
+  attributes - A container to hold attributes that will be applied to the target component.  These
+       attributes will override and extend attributes in the top-level component which is specified
+       by the "jsfid" attribute.
+
+  converter - A component can have a single converter which is the same relationship that 
+      a JSF component would have to a Converter.  JSF has a assumed rule that only components 
+      implementing the ValueHolder interfaces can be assigned converters.  This rule is enforced 
+      at runtime and not through this document type definition.
+         
+  validator - A component can have zero or many associated validators.  Only components that 
+      implement the EditableValueHolder interfaces can be assigned validators.  This rule 
+      is enforced at runtime and not through this document type definition. 
+  
+  actionListener - A component can have zero or many assigned actionListeners.  Action listeners
+      can only be assigned to components implementing the ActionSource interfaces.  This rule is
+      enforced at runtime.
+
+  valueChangeListener - A component can have zero or many assigned valueChangeListeners.  Change listeners
+      can only be assigned to components implementing the EditableValueHolder interfaces.  This rule is
+      enforced at runtime.
+      
+  element - A "element" can contain any number of sub-elements.  Elements define 
+      composition for a complex component.  The element is the glue that pulls in a "top-level" 
+      component.  The element is kind of like an inner class in that it can extend the attributes 
+      of the "top-level" component that it's aggregating.  
+      
+  renderId - A numeric integer value that uniquely defines the element within a owning "component"
+      or "element".  It's the "method signature" used to resolve inheritances and also ordering 
+      within the parent.  A component that extends another can override or add nested "element"s 
+      by renderId.     
+      
+   id - This attribute corresponds to a JSF component's id attribute that will be used to derive
+      the client id value within the HTML id attribute.
+      
+   facetName - Use this attribute to register the component in the facets collection rather 
+      than the children collection.       
 -->
 <!ELEMENT element (attributes?, converter?, validator*, actionListener*, valueChangeListener*, element*)>
 <!ATTLIST element
 	renderId CDATA #REQUIRED
 	jsfid CDATA #REQUIRED
 	id CDATA #IMPLIED
+	facetName CDATA #IMPLIED
 >
 
+<!--
+  A "converter" node is the meta component definition for a JSF converter.  This 
+  node can exist under a "component" or "element" node.  A converter can only be
+  assigned to a JSF component implementing the ValueHolder interfaces.
+  
+  jsfid - The top-level component that defines a converter. The componentType
+     attribute of this component will should be a converter-id registered in
+     the faces-config.xml file.
+-->
 <!ELEMENT converter (attributes?)>
 <!ATTLIST converter jsfid CDATA #REQUIRED>
 
+<!--
+  A "actionListener" node is the meta component definition for a JSF action listener.  This 
+  node can exist under a "component" or "element" node.  A action listener can only be
+  assigned to a JSF component implementing the ActionSource interfaces.
+  
+  jsfid - The top-level component that defines a converter. The componentType
+     attribute of this component will should be a fully qualified class name
+     of the java class implementing the ActionListener interfaces.
+-->
 <!ELEMENT actionListener (attributes?)>
 <!ATTLIST actionListener jsfid CDATA #REQUIRED>
 
+<!--
+  A "validator" node is the meta component definition for a JSF validator.  This 
+  node can exist under a "component" or "element" node.  A converter can only be
+  assigned to a JSF component implementing the EditableValueHolder interfaces.
+  
+  jsfid - The top-level component that defines a validator. The componentType
+     attribute of this component will should be a validator-id registered in
+     the faces-config.xml file.
+-->
 <!ELEMENT validator (attributes?)>
 <!ATTLIST validator jsfid CDATA #REQUIRED>
 
+<!--
+  A "valueChangeListener" node is the meta component definition for a JSF value change listener. 
+  This node can exist under a "component" or "element" node.  A value change listener can only be
+  assigned to a JSF component implementing the EditableValueHolder interfaces.
+  
+  jsfid - The top-level component that defines a value change listener. The componentType
+     attribute of this component will should be a fully qualified class name
+     of the java class implementing the ValueChangeListener interfaces.
+-->
 <!ELEMENT valueChangeListener (attributes?)>
 <!ATTLIST valueChangeListener jsfid CDATA #REQUIRED>
 
-<!ELEMENT view (component*)>
+<!-- 
+  The "view" node is the root of the document.  This document holds meta data used to 
+  construct a sub component tree.  It's a stand-in for the JSF JSP tags meaning that
+  the same information can be represented here using a very generic structure.
+  
+  component - A top-level meta component definition that can be reused across pages 
+  and subtree compositions. 
+  
+  A component can be directly included from within a clay component by it's unique 
+  jsfid or tied to the view composition indirectly by a HTML template where the HTML 
+  element has a binding jsfid attribute.
+-->
+<!ELEMENT view (component*)>
\ No newline at end of file

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java Fri May 27 18:21:22 2005
@@ -115,20 +115,14 @@
      * <p>
      * Returns <code>true</code> if the builder handles converting the node's
      * children or <code>false</code> if it's handled by the parent. The
-     * <code>Globals.COMPONENT_ATTRIBUTE_ALLOW_BODY</code> attribute can also
+     * <code>isBodyAllowed</code> attribute can also
      * be used to override the default option. This flag allows the HTML to be
      * mocked up but the body ignored when converted into a
      * {@link ComponentBean} graph.
      * <p>
      */
     protected boolean getBuildNodeBody(Node node, ElementBean target) {
-        if (target != null && target.getAttributes().containsKey(Globals.COMPONENT_ATTRIBUTE_ALLOW_BODY)) {
-            AttributeBean allowBody = (AttributeBean) target.getAttributes().get(Globals.COMPONENT_ATTRIBUTE_ALLOW_BODY);
-            if (allowBody != null && allowBody.getValue() != null) {
-                return (allowBody.getValue().equalsIgnoreCase(Boolean.FALSE.toString()));
-            }
-        }
-        return false;
+        return (target != null && !target.getIsBodyAllowed()); 
     }
 
     /**

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/InputTextareaBuilder.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/InputTextareaBuilder.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/InputTextareaBuilder.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/InputTextareaBuilder.java Fri May 27 18:21:22 2005
@@ -45,27 +45,6 @@
 
     /**
      * <p>
-     * The default for this builder is that builder will handle the children
-     * html nodes meaning that the default should be <code>true</code>. The
-     * default can be overridden by the "allowBody" attribute in the component
-     * metadata.
-     * </p>
-     */
-    protected boolean getBuildNodeBody(Node node, ElementBean target) {
-        // if override attribute then let the super sort it out
-        if (target != null
-                && target.getAttributes().containsKey(
-                        Globals.COMPONENT_ATTRIBUTE_ALLOW_BODY))
-            return super.getBuildNodeBody(node, target);
-        else {
-            // default for this HTML element is to let the node build
-            // the body and not each child's builder
-            return true;
-        }
-    }
-
-    /**
-     * <p>
      * Returns the <code>jsfid</code> used to populate the {@link ElementBean}
      * </p>
      */

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemBuilder.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemBuilder.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemBuilder.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemBuilder.java Fri May 27 18:21:22 2005
@@ -47,25 +47,6 @@
     
     /**
      * <p>
-     * The default for this builder is that builder will handle the children
-     * html nodes meaning that the default should be <code>true</code>. The
-     * default can be overridden by the "allowBody" attribute in the component
-     * metadata.
-     * </p>
-     */   
-    protected boolean getBuildNodeBody(Node node, ElementBean target) {
-        // if override attribute then let the super sort it out
-        if (target != null && target.getAttributes().containsKey(Globals.COMPONENT_ATTRIBUTE_ALLOW_BODY))
-            return super.getBuildNodeBody(node, target);
-        else {
-            // default for this HTML element is to let the node build
-            //the body and not each child's builder
-            return true;
-        }
-    }
-
-    /**
-     * <p>
      * Returns a <code>jsfid<code> that will be set on the
      * target {@link ElementBean}. </p>
      */    
@@ -121,5 +102,18 @@
     protected String[] getHtmlAttributes() {
         return new String[0];
     }
+
+    /**
+     * <p>Returns <code>true</code> by default meaning that the
+     * parent will render children.</p> 
+     */
+    protected boolean getBuildNodeBody(Node node, ElementBean target) {
+        if (target.getAllowBody() != null)
+           return super.getBuildNodeBody(node, target);
+        
+        return true;
+    }
+    
+    
     
 }

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemsBuilder.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemsBuilder.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemsBuilder.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectItemsBuilder.java Fri May 27 18:21:22 2005
@@ -43,25 +43,7 @@
     static {
         log = LogFactory.getLog(SelectItemsBuilder.class);
     }
-    
-    /**
-     * <p>
-     * Returns <code>true</code> by default which indicates that the
-     * {@link Builder} will handle the html child elements under the option
-     * {@link Node}.
-     * </p>
-     */   
-    protected boolean getBuildNodeBody(Node node, ElementBean target) {
-        // if override attribute then let the super sort it out
-        if (target != null && target.getAttributes().containsKey(Globals.COMPONENT_ATTRIBUTE_ALLOW_BODY))
-            return super.getBuildNodeBody(node, target);
-        else {
-            // default for this HTML element is to let the node build
-            //the body and not each child's builder
-            return true;
-        }
-    }
- 
+     
     /**
      * <p>
      * Returns a <code>jsfid</code> used to populate the target
@@ -83,6 +65,17 @@
         return "javax.faces.SelectItems";
     }
     
-    
+
+    /**
+     * <p>Returns <code>true</code> by default meaning that the
+     * parent will render children.</p> 
+     */
+    protected boolean getBuildNodeBody(Node node, ElementBean target) {
+        if (target.getAllowBody() != null)
+           return super.getBuildNodeBody(node, target);
+        
+        return true;
+    }
+
     
 }

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectManyMenuBuilder.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectManyMenuBuilder.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectManyMenuBuilder.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectManyMenuBuilder.java Fri May 27 18:21:22 2005
@@ -72,6 +72,14 @@
         return true;
     }
     
-    
+    /**
+     * <p>This method is overridden to return a empty string array.  The 
+     * html Select component should not have any html overrides because
+     * the JSF component properties are not the same as the html element.
+     * </p>
+     */    
+    protected String[] getHtmlAttributes() {
+        return new String[0];
+    }  
     
 }

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectOneMenuBuilder.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectOneMenuBuilder.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectOneMenuBuilder.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/SelectOneMenuBuilder.java Fri May 27 18:21:22 2005
@@ -71,6 +71,16 @@
     public boolean isChildrenAllowed() {
         return true;
     }
+
+    /**
+     * <p>This method is overridden to return a empty string array.  The 
+     * html Select component should not have any html overrides because
+     * the JSF component properties are not the same as the html element.
+     * </p>
+     */    
+    protected String[] getHtmlAttributes() {
+        return new String[0];
+    }
     
     
     

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/PropUtils.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/PropUtils.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/PropUtils.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/PropUtils.java Fri May 27 18:21:22 2005
@@ -20,17 +20,12 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.DecimalFormat;
-import java.text.Format;
-import java.text.MessageFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.commons.beanutils.Converter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.shale.clay.component.chain.PropertyValueCommand;
+import org.apache.shale.util.Messages;
 
 public class PropUtils {
     
@@ -38,313 +33,31 @@
     static {
         log = LogFactory.getLog(PropUtils.class);
     }
-    
+
     /**
-     * <p>A utility method that will format the source object using the pattern.  
-     * The data type of the source object will determine the formatting strategy.
      * <p>
-     * @param source object to format
-     * @param pattern to use or <code>null</code> value will assume a default pattern
-     * @return formated source as a String
-     */
-    public static String formatSimpleProperty(Object source, String pattern) {
-        
-        boolean lhasFormat = false;
-        boolean lisMsgFormat = false;
-        
-        Object lArgs = null;
-        String lPattern = null;
-        String lfmtValue = null;
-        Format lFormat = null;
-        
-        if (source == null)
-            return "";
-        
-        lPattern = pattern;
-        
-        if ((lPattern != null) && (pattern.length() > 0)) {
-            lhasFormat = true;
-            if (pattern.indexOf('{') > -1)
-                lisMsgFormat = true;
-        }
-        
-        if (source instanceof Boolean) {
-            lArgs = new Object[1];
-            ((Object[]) lArgs)[0] =
-                    ((((Boolean) source).booleanValue()) ? "Yes" : "No");
-            lPattern = "{0}";
-            lisMsgFormat = lhasFormat = true;
-            
-        } else if (lisMsgFormat) {
-            //message format requires the value be passed in an array
-            lArgs = new Object[1];
-            ((Object[]) lArgs)[0] = source;
-        } else {
-            lArgs = source;
-        }
-        
-        if (lisMsgFormat) {
-            
-            if (lhasFormat) {
-                lFormat = new MessageFormat(lPattern);
-            }
-            
-        } else if (source instanceof Number) {
-            
-            if ((source instanceof Byte)
-            || (source instanceof Short)
-            || (source instanceof Integer)
-            || (source instanceof Long)
-            || (source instanceof BigInteger)) {
-                
-                if (!lhasFormat) {
-                    lFormat = new DecimalFormat("#0");
-                } else
-                    lFormat = new DecimalFormat(lPattern);
-                
-            } else if (
-                    (source instanceof Float)
-                    || (source instanceof Double)
-                    || (source instanceof BigDecimal)) {
-                
-                if (!lhasFormat) {
-                    lFormat = new DecimalFormat("#0.00");
-                } else
-                    lFormat = new DecimalFormat(lPattern);
-            }
-            
-        } else if (source instanceof java.util.Date) {
-            
-            if (!lhasFormat) {
-                lFormat = new SimpleDateFormat("MM/dd/yyyy");
-            } else
-                lFormat = new SimpleDateFormat(lPattern);
-        } else if (source.getClass().isArray()) {
-            
-            lArgs = source;
-            StringBuffer listPattern = new StringBuffer();
-            int n = ((Object[]) lArgs).length;
-            for (int i = 0; i < n; i++)
-                listPattern.append((i > 0) ? "," : "").append("{").append(
-                        i).append(
-                        "}");
-            lFormat = new MessageFormat(listPattern.toString());
-            listPattern = null;
-        }
-        
-        if (lFormat != null) {
-            try {
-                lfmtValue = lFormat.format(lArgs);
-            } catch (Exception je) {
-                log.error(je);
-            }
-        } else {
-            lfmtValue = source.toString();
-        }
-        
-        lFormat = null;
-        lArgs = null;
-        lPattern = null;
-        
-        return lfmtValue;
-    }
-    
-    /**
-     * <p>A list of numeric patterns that will be applied in sequence when attempting
-     * to decode a number from a string</p>
+     * Message resources for this class.
+     * </p>
      */
-    private final static String[] numberPatterns =
-    { "#0", "#.##", "$#.##", "###,###.00", "$###,###.00", "$ ###,###.00" };
-    /**
-     * <p>A list of date patterns that are used in sequence when attempting to 
-     * decode a date from a string</p>
-     */
-    private final static String[] datePatterns =
-    { "MM/dd/yy", "MM/dd/yyyy", "yyyy/MM/dd", "MM-dd-yyyy", "yyyy-MM-dd" };
+    private static Messages messages = new Messages("org.apache.shale.clay.Bundle", PropUtils.class.getClassLoader());
+
     
     /**
      *  <p>A simple function that tries to convert one type into another<p>
      *  @param source object to convert from
      *  @param targetType object class type to convert the source to
-     *  @param targetPattern that should be used to convert the source to the target
      *  @return an instance of the target object holding the value of the source instance
      */
     public static Object decodeSimpleProperty(
             Object source,
-            Class targetType,
-            String targetPattern) {
-        
-        // if the target type is the same as the source type, return the source
-        if ((source == null) || (source.getClass() == targetType) || (targetType == Object.class))
-            return source;
+            Class targetType) {
         
         Object targetObj = null;
-        Format lFormat = null;
-        
-        if (targetType == String.class) { // converting to a string
-            
-            return formatSimpleProperty(source, targetPattern);
-            
-        } else if (
-                source instanceof String) { // decoding the value of a string
-            
-            if (((String) source).length() == 0)
-                return null; // empty string returns null
-            
-            if ((targetType == java.lang.Boolean.TYPE)
-            || (targetType == java.lang.Boolean.class)) {
-                if ((((String) source).charAt(0) == 'T')
-                || (((String) source).charAt(0) == 'Y')
-                || (((String) source).charAt(0) == 't')
-                || (((String) source).charAt(0) == 'y'))
-                    targetObj = new java.lang.Boolean(true);
-                else
-                    targetObj = new java.lang.Boolean(false);
-                
-                return targetObj;
-                
-            } else if (
-                    (targetType == java.util.Date.class)
-                    || (targetType == java.sql.Date.class)) {
-                
-                if ((targetPattern != null) && (targetPattern.length() > 0))
-                    lFormat = new SimpleDateFormat(targetPattern);
-                else
-                    lFormat = new SimpleDateFormat(datePatterns[0]);
-                
-                for (int i = 0; i < datePatterns.length; ++i) {
-                    
-                    try {
-                        targetObj = lFormat.parseObject((String) source);
-                    } catch (ParseException je) {
-                        //je.printStackTrace();
-                    }
-                    
-                    if (targetObj != null)
-                        break;
-                    
-                    ((SimpleDateFormat) lFormat).applyPattern(datePatterns[i]);
-                    
-                }
-                
-                if ((targetObj != null) && (targetType == java.sql.Date.class))
-                    return new java.sql.Date(
-                            ((java.util.Date) targetObj).getTime());
-                
-                return targetObj;
-                
-            } else if (
-                    (targetType == java.lang.Byte.TYPE)
-                    || (targetType == java.lang.Byte.class)
-                    || (targetType == java.lang.Short.TYPE)
-                    || (targetType == java.lang.Short.class)
-                    || (targetType == java.lang.Integer.TYPE)
-                    || (targetType == java.lang.Integer.class)
-                    || (targetType == java.lang.Long.TYPE)
-                    || (targetType == java.lang.Long.class)
-                    || (targetType == java.math.BigInteger.class)) {
-                
-                if ((targetPattern != null) && (targetPattern.length() > 0))
-                    lFormat = new DecimalFormat(targetPattern);
-                else
-                    lFormat = new DecimalFormat(numberPatterns[0]);
-                
-            } else if (
-                    (targetType == java.lang.Double.TYPE)
-                    || (targetType == java.lang.Double.class)
-                    || (targetType == java.lang.Float.TYPE)
-                    || (targetType == java.lang.Float.class)
-                    || (targetType == java.math.BigDecimal.class)) {
-                
-                if ((targetPattern != null) && (targetPattern.length() > 0))
-                    lFormat = new DecimalFormat(targetPattern);
-                else
-                    lFormat = new DecimalFormat(numberPatterns[2]);
-            }
-            
-            Number numericObj = null;
-            for (int i = 0; i < numberPatterns.length; i++) {
-                try {
-                    numericObj = (Number) lFormat.parseObject((String) source);
-                } catch (Exception je) {
-                    je.printStackTrace();
-                }
-                
-                if (numericObj != null)
-                    break;
-                
-                ((DecimalFormat) lFormat).applyPattern(numberPatterns[i]);
-            }
-            
-            if (numericObj == null)
-                return null;
-            
-            if ((targetType == java.lang.Byte.TYPE)
-            || (targetType == java.lang.Byte.class))
-                targetObj = new java.lang.Byte((byte) numericObj.byteValue());
-            else if (
-                    (targetType == java.lang.Short.TYPE)
-                    || (targetType == java.lang.Short.class))
-                targetObj =
-                        new java.lang.Short((short) numericObj.shortValue());
-            else if (
-                    (targetType == java.lang.Integer.TYPE)
-                    || (targetType == java.lang.Integer.class))
-                targetObj = new java.lang.Integer((int) numericObj.intValue());
-            else if (
-                    (targetType == java.lang.Long.TYPE)
-                    || (targetType == java.lang.Long.class))
-                targetObj = new java.lang.Long((long) numericObj.longValue());
-            else if (
-                    (targetType == java.lang.Double.TYPE)
-                    || (targetType == java.lang.Double.class))
-                targetObj = new java.lang.Double(numericObj.doubleValue());
-            else if (
-                    (targetType == java.lang.Float.TYPE)
-                    || (targetType == java.lang.Float.class))
-                targetObj = new java.lang.Float(numericObj.floatValue());
-            else if (targetType == java.math.BigDecimal.class)
-                targetObj = new java.math.BigDecimal(numericObj.doubleValue());
-            
-            return targetObj;
-            
-        } else if (source instanceof Number) {
-            
-            Number numericObj = (Number) source;
-            
-            if ((targetType == java.lang.Byte.TYPE)
-            || (targetType == java.lang.Byte.class))
-                targetObj = new java.lang.Byte((byte) numericObj.byteValue());
-            else if (
-                    (targetType == java.lang.Short.TYPE)
-                    || (targetType == java.lang.Short.class))
-                targetObj =
-                        new java.lang.Short((short) numericObj.shortValue());
-            else if (
-                    (targetType == java.lang.Integer.TYPE)
-                    || (targetType == java.lang.Integer.class))
-                targetObj = new java.lang.Integer((int) numericObj.intValue());
-            else if (
-                    (targetType == java.lang.Long.TYPE)
-                    || (targetType == java.lang.Long.class))
-                targetObj = new java.lang.Long((long) numericObj.longValue());
-            else if (
-                    (targetType == java.lang.Double.TYPE)
-                    || (targetType == java.lang.Double.class))
-                targetObj = new java.lang.Double(numericObj.doubleValue());
-            else if (
-                    (targetType == java.lang.Float.TYPE)
-                    || (targetType == java.lang.Float.class))
-                targetObj = new java.lang.Float(numericObj.floatValue());
-            else if (targetType == java.math.BigDecimal.class)
-                targetObj = new java.math.BigDecimal(numericObj.doubleValue());
-            
-            return targetObj;
-            
-        } else
-            targetObj = source; // complext type, no conversion
-        
-        lFormat = null;
+        Converter converter = ConvertUtils.lookup(targetType);
+        if (converter != null)
+          targetObj = converter.convert(targetType, source);
+        else
+          targetObj = source;
         
         return targetObj;
     }
@@ -444,22 +157,26 @@
                 break;
             }
         }
-        
-        if (method != null) {
-            // convert the source data type to the target type
-            Object[] paramValues = { decodeSimpleProperty(propValue, paramTypes[0],
-                    pattern) };
-            method.setAccessible(true);
-            
-            try {
-                method.invoke(bean, paramValues);
-            } catch (IllegalArgumentException e) {
-                throw new RuntimeException(e);
-            } catch (IllegalAccessException e) {
-                throw new RuntimeException(e);
-            } catch (InvocationTargetException e) {
-                throw new RuntimeException(e);
-            }
+    
+        if (method == null) {
+            RuntimeException ex = new RuntimeException(messages.getMessage(
+                    "unable.to.set.property.error", new Object[] { propName,
+                            bean.getClass().getName() }));
+            throw ex;
+        }
+
+        // convert the source data type to the target type
+        Object[] paramValues = { decodeSimpleProperty(propValue, paramTypes[0]) };
+        method.setAccessible(true);
+
+        try {
+            method.invoke(bean, paramValues);
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e);
         }
     }
         

Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/PropUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/PropUtilsTestCase.java?rev=178849&r1=178848&r2=178849&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/PropUtilsTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/PropUtilsTestCase.java Fri May 27 18:21:22 2005
@@ -82,7 +82,7 @@
      * <p>Tests setting boolean properties from a String
      * with and without a "is" prefix</p>
      */
-    public void testBoolean() {
+    public void testBoolean() throws Exception {
         MockBean bean = new MockBean();
 
         PropUtils.setProperty(bean, "isGlobal", "true");
@@ -111,12 +111,11 @@
         PropUtils.setProperty(bean, "maximumInt", "0");
         assertTrue("maximumInt equals 0", bean.getMaximumInt() == 0);
 
-        PropUtils.setProperty(bean, "maximumInt", "$999.10");
+        PropUtils.setProperty(bean, "maximumInt", "999");
         assertTrue("maximumInt equals 999", bean.getMaximumInt() == 999);
 
-        PropUtils.setProperty(bean, "maximumInt",
-                "9999999999999999999999999999999999999999999999999.9999999999");
-        assertTrue("maximumInt equals Integer.MAX_VALUE",
+        PropUtils.setProperty(bean, "maximumInt", String.valueOf(Integer.MAX_VALUE));
+        assertTrue("maximumInt equals 9",
                 bean.getMaximumInt() == Integer.MAX_VALUE);
 
     }
@@ -130,18 +129,18 @@
         PropUtils.setProperty(bean, "maximumDouble", "10");
         assertTrue("maximumDouble equals 10", bean.getMaximumDouble() == 10);
 
-        PropUtils.setProperty(bean, "maximumDouble", "$999.10", "$###.00");
-        assertTrue("maximumDouble equals $999.10",
+        PropUtils.setProperty(bean, "maximumDouble", "999.10");
+        assertTrue("maximumDouble equals 999.10",
                 bean.getMaximumDouble() == 999.10);
 
         
-        PropUtils.setProperty(bean, "maximumDouble", ".00001", ".#####");
+        PropUtils.setProperty(bean, "maximumDouble", ".00001");
         assertTrue("maximumDouble equals .00001",
                 bean.getMaximumDouble() == .00001);
        
         PropUtils
-                .setProperty(bean, "maximumDouble", "999,999.99", "###,###.##");
-        assertTrue("maximumDouble equals 999,999.99,",
+                .setProperty(bean, "maximumDouble", "999999.99");
+        assertTrue("maximumDouble equals 999999.99,",
                 bean.getMaximumDouble() == 999999.99);
 
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org