Author: gvanmatre
Date: Wed Oct 26 22:34:15 2005
New Revision: 328794
URL: http://svn.apache.org/viewcvs?rev=328794&view=rev
Log:
Added use of replacement symbols within the Clay component attribute
definitions.
Modified:
struts/shale/trunk/clay-plugin/src/conf/clay-config.xml
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/AbstractCommand.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/component/chain/ClayContext.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/beans/ComponentBean.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
Modified: struts/shale/trunk/clay-plugin/src/conf/clay-config.xml
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/conf/clay-config.xml?rev=328794&r1=328793&r2=328794&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/conf/clay-config.xml (original)
+++ struts/shale/trunk/clay-plugin/src/conf/clay-config.xml Wed Oct 26 22:34:15
2005
@@ -66,7 +66,8 @@
<set name="readonly" bindingType="VB" />
<set name="onselect" bindingType="VB" />
<set name="tabindex" bindingType="VB" />
-
+
+ <set name="required" bindingType="VB" />
<set name="value" bindingType="VB" />
<set name="converter" bindingType="VB" />
<set name="immediate" bindingType="VB" />
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=328794&r1=328793&r2=328794&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
Wed Oct 26 22:34:15 2005
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
import javax.faces.component.UIComponent;
import javax.faces.component.UINamingContainer;
@@ -290,7 +292,10 @@
ClayContext clayContext = new ClayContext();
clayContext.setAttribute(attr);
- clayContext.setManagedBeanName(getManagedBeanName());
+
+ Map symbolTable = new TreeMap();
+ symbolTable.put(Globals.MANAGED_BEAN_MNEMONIC,
getManagedBeanName());
+ clayContext.setSymbols(symbolTable);
String expr = AbstractCommand.replaceMnemonic(clayContext);
Class[] methodSignature = {
@@ -321,7 +326,12 @@
clayContext.setDisplayElement(getDisplayElementRoot());
clayContext.setJsfid(getJsfid());
clayContext.setFacesContext(getFacesContext());
- clayContext.setManagedBeanName(getManagedBeanName());
+
+ Map symbolTable = new TreeMap();
+ symbolTable.putAll(getDisplayElementRoot().getSymbols());
+ symbolTable.put(Globals.MANAGED_BEAN_MNEMONIC, getManagedBeanName());
+ clayContext.setSymbols(symbolTable);
+
clayContext.setRootElement(getDisplayElementRoot());
clayContext.setParent(this);
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AbstractCommand.java
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AbstractCommand.java?rev=328794&r1=328793&r2=328794&view=diff
==============================================================================
---
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AbstractCommand.java
(original)
+++
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AbstractCommand.java
Wed Oct 26 22:34:15 2005
@@ -19,6 +19,8 @@
package org.apache.shale.clay.component.chain;
import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.CatalogFactory;
@@ -77,25 +79,40 @@
/**
* <p>
* This call is used to substitue an attribute binding expression
containing
- * the literal string <strong>managed-bean-name</strong> with the
- * <code>managedBeanName</code> property value in the [EMAIL PROTECTED]
ClayContext}.
+ * the <code>symbols</code> with the target property value in the [EMAIL
PROTECTED] ClayContext}.
* </p>
*/
public static String replaceMnemonic(ClayContext context) {
StringBuffer buff = new
StringBuffer(context.getAttribute().getValue());
+ Map symbols = context.getSymbols();
+ Iterator si = symbols.entrySet().iterator();
- for (int i = 0; i < (buff.length() - Globals.MANAGED_BEAN_MNEMONIC
- .length()); i++) {
- String token = buff.substring(i, i
- + Globals.MANAGED_BEAN_MNEMONIC.length());
- if (token.compareToIgnoreCase(Globals.MANAGED_BEAN_MNEMONIC) == 0)
{
- buff.delete(i, i + Globals.MANAGED_BEAN_MNEMONIC.length());
- buff.insert(i, context.getManagedBeanName());
+ while (si.hasNext()) {
+ Map.Entry e = (Map.Entry) si.next();
+ String key = (String) e.getKey();
+ String value = (String) e.getValue();
+
+ int i = 0;
+ while (i <= (buff.length() - key.length())) {
+ String token = buff.substring(i, i + key.length());
+ if (token.compareToIgnoreCase(key) == 0) {
+ buff.delete(i, i + key.length());
+ buff.insert(i, value);
+ i = i + value.length();
+ } else {
+ i++;
+ }
+
+ token = null;
}
- token = null;
+ e = null;
+ key = null;
+ value = null;
}
+ symbols = null;
+ si = null;
return buff.toString();
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=328794&r1=328793&r2=328794&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
Wed Oct 26 22:34:15 2005
@@ -19,6 +19,8 @@
package org.apache.shale.clay.component.chain;
import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
import javax.faces.component.UIComponent;
@@ -73,12 +75,7 @@
.getMessage("clay.null.componentBean"));
Iterator vi = displayElement.getChildrenIterator();
- String managedBeanName = clayContext.getManagedBeanName();
- if (parent instanceof Clay) {
- if (((Clay) parent).getManagedBeanName() != null)
- managedBeanName = ((Clay) parent).getManagedBeanName();
- }
-
+
int childIndex = 0;
while (vi.hasNext()) {
ComponentBean childDisplayElement = (ComponentBean) vi.next();
@@ -88,7 +85,16 @@
subContext.setParent(parent);
subContext.setChild(null);
subContext.setChildIndex(childIndex);
- subContext.setManagedBeanName(managedBeanName);
+
+ Map symbolTable = new TreeMap();
+ symbolTable.putAll(clayContext.getSymbols());
+ symbolTable.putAll(childDisplayElement.getSymbols());
+ if (parent instanceof Clay) {
+ if (((Clay) parent).getManagedBeanName() != null)
+ symbolTable.put(Globals.MANAGED_BEAN_MNEMONIC, ((Clay)
parent).getManagedBeanName());
+ }
+
+ subContext.setSymbols(symbolTable);
Catalog catalog = getCatalog();
Command command = catalog
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java?rev=328794&r1=328793&r2=328794&view=diff
==============================================================================
---
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
(original)
+++
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
Wed Oct 26 22:34:15 2005
@@ -18,6 +18,9 @@
package org.apache.shale.clay.component.chain;
+import java.util.Map;
+import java.util.TreeMap;
+
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -37,30 +40,30 @@
private static final long serialVersionUID = 3618132372818901298L;
/**
- * <p>The name of the ViewController or back bean that
- * is bound to the [EMAIL PROTECTED] org.apache.shale.clay.component.Clay}
component.
- * </p>
+ * <p>Symbol table that holds literal strings that
+ * will be replaced within the value of an attribute.</p>
*/
- private String managedBeanName = null;
+ private Map symbols = null;
/**
- * <p>Returns the managed bean name that will replace the
- * literal string <strong>managed-bean-name</strong> in
- * value and action component expressions.
- * </p>
+ * <p>Returns a Map containing replacement symbols
+ * within meta-component attributes.</p>
*/
- public String getManagedBeanName() {
- return managedBeanName;
+ public Map getSymbols() {
+ if (symbols == null)
+ symbols = new TreeMap();
+
+ return symbols;
}
-
+
/**
- * <p>Sets the managed bean name that the [EMAIL PROTECTED]
org.apache.shale.clay.component.Clay} component
- * and all sub components are bound to.
- * </p>
+ * <p>Sets a Map containing replacement symbols
+ * within meta-component attributes.</p>
*/
- public void setManagedBeanName(String managedBeanName) {
- this.managedBeanName = managedBeanName;
+ public void setSymbols(Map symbols) {
+ this.symbols = symbols;
}
+
/**
* <p>Unique identifier for a component metadata definition.</p>
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=328794&r1=328793&r2=328794&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
Wed Oct 26 22:34:15 2005
@@ -109,11 +109,7 @@
boolean isEarly =
bindingType.equals(AttributeBean.BINDING_TYPE_EARLY);
- String expr = null;
- if (isEL)
- expr = replaceMnemonic(clayContext);
- else
- expr = attributeBean.getValue();
+ String expr = replaceMnemonic(clayContext);
if (isEL && isVB)
tagUtils.setValueBinding((UIComponentBase) child,
attributeBean.getName(), expr);
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=328794&r1=328793&r2=328794&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
Wed Oct 26 22:34:15 2005
@@ -218,6 +218,13 @@
/**
+ * <p>The replacement symbol table for the component meta-data.</p>
+ */
+ private Map symbols = new TreeMap();
+
+
+
+ /**
* <p>This property only applies when using the [EMAIL PROTECTED]
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>
@@ -686,6 +693,24 @@
*/
public void setId(String string) {
id = string;
+ }
+
+ /**
+ * <p>Adds a symbol identified by the <code>key</code>
+ * and replacement <code>value</code> to the symbols
+ * collection.</p>
+ */
+ public void addSymbol(String key, String value) {
+ symbols.put(key, value);
+ }
+
+ /**
+ * <p>Returns the replacement symbols assigned to the component.
+ * The key value represents the literal replacement string.
+ * The value Map property represents target string.</p>
+ */
+ public Map getSymbols() {
+ return symbols;
}
}
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=328794&r1=328793&r2=328794&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
Wed Oct 26 22:34:15 2005
@@ -287,15 +287,24 @@
next: while (ai.hasNext()) {
Map.Entry e = (Map.Entry) ai.next();
- if (e.getKey().equals("jsfid"))
+ if (e.getKey().equals("id") ||
+ e.getKey().equals("jsfid") ||
+ e.getKey().equals("allowbody") ||
+ e.getKey().equals("facetname"))
continue next;
AttributeBean original = null;
- Token valueToken = null;
- if (((original = (AttributeBean) target.getAttribute((String)
e.getKey())) != null) &&
- ((valueToken = (Token) e.getValue()) != null))
- createAttribute(original, valueToken.getRawText(), target);
-
+ Token valueToken = (Token) e.getValue();
+ if (valueToken != null) {
+ if ((original = (AttributeBean) target.getAttribute((String)
e.getKey())) != null) {
+ createAttribute(original, valueToken.getRawText(), target);
+ } else {
+ //any token that is not an attribute in the target becomes
a symbol
+ StringBuffer identifier = new StringBuffer((String)
e.getKey());
+ identifier.insert(0, '@');
+ target.addSymbol(identifier.toString(),
valueToken.getRawText());
+ }
+ }
}
if (node.getAttributes().containsKey("allowbody"))
Modified:
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java?rev=328794&r1=328793&r2=328794&view=diff
==============================================================================
---
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
(original)
+++
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
Wed Oct 26 22:34:15 2005
@@ -604,6 +604,42 @@
}
+
+ // test symbolic property replacement
+ public void testSymbolicProperties() throws Exception {
+ javax.faces.component.html.HtmlOutputText child =
(javax.faces.component.html.HtmlOutputText)
facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
+ assertNotNull("javax.faces.HtmlOutputText", child);
+
+
+ AttributeBean attr = new AttributeBean();
+ attr.setName("value");
+ attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
+ attr.setValue("@value"); //symbolic attribute
+
+ ComponentBean displayElement = new ComponentBean();
+ displayElement.setJsfid("inputText");
+ displayElement.setComponentType("javax.faces.HtmlOutputText");
+ displayElement.setId("testId");
+ displayElement.addAttribute(attr);
+ displayElement.addSymbol("@value", "10");
+
+ ClayContext clayContext = new ClayContext();
+ clayContext.setFacesContext(facesContext);
+ clayContext.setChild(child);
+ clayContext.setAttribute(attr);
+ clayContext.setDisplayElement(displayElement);
+ // normally done in the AssignChildrenCommand
+ clayContext.setSymbols(displayElement.getSymbols());
+
+ //shale core utility class
+ servletContext.setAttribute(ShaleConstants.TAG_UTILITY_BEAN, new
Tags());
+
+ Command command = new PropertyValueCommand();
+ boolean isFinal = command.execute(clayContext);
+ assertEquals("command finished", isFinal, true);
+ assertEquals("value = 10", child.getValue(), "10");
+
+ }
// test duplicate id check
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]