You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by gv...@apache.org on 2005/11/04 05:53:41 UTC

svn commit: r330703 - in /struts/shale/trunk/clay-plugin/src: conf/ java/org/apache/shale/clay/ java/org/apache/shale/clay/component/ java/org/apache/shale/clay/component/chain/ java/org/apache/shale/clay/taglib/

Author: gvanmatre
Date: Thu Nov  3 20:53:21 2005
New Revision: 330703

URL: http://svn.apache.org/viewcvs?rev=330703&view=rev
Log:
Extended replaceable symbol support to the Clay JSP Tag.

Added:
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/SymbolTag.java
Modified:
    struts/shale/trunk/clay-plugin/src/conf/shale-clay.tld
    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/Clay.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
    struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/ClayTag.java

Modified: struts/shale/trunk/clay-plugin/src/conf/shale-clay.tld
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/conf/shale-clay.tld?rev=330703&r1=330702&r2=330703&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/conf/shale-clay.tld (original)
+++ struts/shale/trunk/clay-plugin/src/conf/shale-clay.tld Thu Nov  3 20:53:21 2005
@@ -71,4 +71,23 @@
 
   </tag>
 
+  <tag>
+
+    <name>symbol</name>
+    <tag-class>org.apache.shale.clay.taglib.SymbolTag</tag-class>
+
+    <attribute>
+      <name>name</name>
+      <required>true</required>
+      <rtexprvalue>false</rtexprvalue>
+    </attribute>
+
+    <attribute>
+      <name>value</name>
+      <required>true</required>
+      <rtexprvalue>false</rtexprvalue>
+    </attribute>
+
+  </tag>
+
 </taglib>

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=330703&r1=330702&r2=330703&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 Thu Nov  3 20:53:21 2005
@@ -142,4 +142,7 @@
 invalid.attribute=The "{0}" attribute is required when using the ClayAmalgam.{1}() validator method binding event.
 
 #(ALL)
-clay.null.tagUtils=The utility managed bean "org.apache.shale.TAG_UTILITY_BEAN" registered in the core shale jar cannot be resolved.   
\ No newline at end of file
+clay.null.tagUtils=The utility managed bean "org.apache.shale.TAG_UTILITY_BEAN" registered in the core shale jar cannot be resolved.   
+
+#org.apache.shale.clay.taglib.SymbolTag
+clayparent.notfound=The symbol tag must be nested under a clay tag.
\ No newline at end of file

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java?rev=330703&r1=330702&r2=330703&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java Thu Nov  3 20:53:21 2005
@@ -64,6 +64,19 @@
     private static Messages messages = new Messages(
             "org.apache.shale.clay.Bundle", Clay.class.getClassLoader());
     
+    
+    /**
+     * <p>Holds the symbol table for the component.</p>
+     */
+    private Map symbols = new TreeMap();
+    
+    /**
+     * <p>Returns the symbol table for the component.</p>
+     */
+    public Map getSymbols() {
+        return symbols;
+    }
+    
     /**
      * <p>
      * Loads the chains config using the resource defined by config file
@@ -223,7 +236,7 @@
     
     /**
      * <p>
-     * Sets the logical bean name that replaces any occurance of
+     * Sets the logical bean name that replaces any occurrences of
      * "managed-bean-name" within a binding expression.
      * </p>
      */
@@ -287,6 +300,7 @@
                 
                 Map symbolTable = new TreeMap();
                 symbolTable.put(Globals.MANAGED_BEAN_MNEMONIC, getManagedBeanName());
+                symbolTable.putAll(getSymbols());
                 clayContext.setSymbols(symbolTable);
 
                 //resolve the literal "managed-bean-name"
@@ -323,6 +337,7 @@
         Map symbolTable = new TreeMap();
         symbolTable.putAll(getDisplayElementRoot().getSymbols());
         symbolTable.put(Globals.MANAGED_BEAN_MNEMONIC, getManagedBeanName());
+        symbolTable.putAll(getSymbols());
         clayContext.setSymbols(symbolTable);
         
         clayContext.setRootElement(getDisplayElementRoot());
@@ -438,6 +453,7 @@
         managedBeanName = ((String) aobj[2]);
         shapeValidator = ((String) aobj[3]);
         displayElementRoot = ((ComponentBean) aobj[4]);
+        symbols = ((Map) aobj[5]); 
         
     }
     
@@ -449,12 +465,13 @@
      * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
      */
     public Object saveState(FacesContext context) {
-        Object[] aobj = new Object[5];
+        Object[] aobj = new Object[6];
         aobj[0] = super.saveState(context);
         aobj[1] = jsfid;
         aobj[2] = managedBeanName;
         aobj[3] = shapeValidator;
         aobj[4] = displayElementRoot;
+        aobj[5] = symbols;
         
         return aobj;
     }

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java?rev=330703&r1=330702&r2=330703&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java Thu Nov  3 20:53:21 2005
@@ -92,6 +92,7 @@
             if (parent instanceof Clay) {
                 if (((Clay) parent).getManagedBeanName() != null)
                    symbolTable.put(Globals.MANAGED_BEAN_MNEMONIC, ((Clay) parent).getManagedBeanName());
+                symbolTable.putAll(((Clay) parent).getSymbols());
             }
 
             subContext.setSymbols(symbolTable);

Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/ClayTag.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/ClayTag.java?rev=330703&r1=330702&r2=330703&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/ClayTag.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/ClayTag.java Thu Nov  3 20:53:21 2005
@@ -19,13 +19,13 @@
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
-import javax.faces.webapp.UIComponentTag;
+import javax.faces.webapp.UIComponentBodyTag;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.shale.clay.component.Clay;
 
-public class ClayTag extends UIComponentTag {
+public class ClayTag extends UIComponentBodyTag {
     
     /**
      * <p>Common logging utility instance.</p>

Added: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/SymbolTag.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/SymbolTag.java?rev=330703&view=auto
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/SymbolTag.java (added)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/taglib/SymbolTag.java Thu Nov  3 20:53:21 2005
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.shale.clay.taglib;
+
+import javax.faces.component.UIComponent;
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.shale.clay.component.Clay;
+import org.apache.shale.util.Messages;
+
+/**
+ * <p>This Tag is used to add replacement symbols to the {@link Clay} component.  
+ * Replacement symbols are substituted within the meta-data used to build the subtree 
+ * under the Clay component.  This tag is similar to the standard JSF attribute tag.  
+ * The <code>name</code> attribute will be prepended with an '@' character.  
+ * The "at" character is the symbol identifier.</p>
+ */
+public class SymbolTag extends TagSupport {
+
+    private static final long serialVersionUID = 3977021747121698357L;
+
+    /**
+     * <p>Message resources for this class.</p>
+     */
+    private static Messages messages = new Messages(
+            "org.apache.shale.clay.Bundle", Clay.class.getClassLoader());
+    
+    /**
+     * <p>The <code>name</code> of the symbol.</p>
+     */
+    private String name = null;
+    
+    /**
+     * <p>The <code>value</code> of the symbol.</p>
+     */
+    private String value = null;
+    
+    /**
+     * <p>Returns the name of the symbol.</p>
+     */
+    public String getName() {
+        return name;
+    }
+    
+
+    /**
+     * <p>Sets the <code>name</code> of the symbol.</p>
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+
+    /**
+     * <p>Returns the value for the symbol.</p>
+     */
+    public String getValue() {
+        return value;
+    }
+    
+
+    /**
+     * <p>Sets the <code>value</code> for the symbol.</p>
+     */
+    public void setValue(String value) {
+        this.value = value;
+    }
+    
+
+    /**
+     * <p>Finds the parent component and adds the symbol to the 
+     * Clay component's symbol table.  The parent has to be a {@link Clay} component.
+     * </p>
+     */
+    public int doStartTag() throws JspException {
+          UIComponentTag parentTag = UIComponentTag.getParentUIComponentTag(pageContext);
+          if (parentTag == null) {
+             throw new JspException(messages.getMessage("clayparent.notfound"));    
+          }
+          
+          UIComponent parentComponent = parentTag.getComponentInstance();
+          if (parentComponent == null) {
+              throw new JspException(messages.getMessage("clayparent.notfound"));                        
+          } 
+          
+          if (!(parentComponent instanceof Clay)) {
+              throw new JspException(messages.getMessage("clayparent.notfound"));                                      
+          }
+
+          Clay clayParent = (Clay) parentComponent;
+
+          StringBuffer tmp = new StringBuffer(name);
+          if (tmp.charAt(0) != '@')
+            tmp.insert(0, '@');
+          
+          clayParent.getSymbols().put(tmp.toString(), value);          
+          
+          return super.doStartTag();
+    
+    }
+
+   
+}



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