[Tapestry-commits] CVS: Tapestry/framework/src/net/sf/tapestry Tapestry.java,1.9,1.9.2.1 TapestryStr
Brought to you by:
hship
|
From: Howard L. S. <hs...@us...> - 2002-11-30 03:33:23
|
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry
In directory sc8-pr-cvs1:/tmp/cvs-serv15444/framework/src/net/sf/tapestry
Modified Files:
Tag: hship-2-3
Tapestry.java TapestryStrings.properties IPageSource.java
BaseComponentTemplateLoader.java
Log Message:
Add support for providing expressions in component templates.
Index: Tapestry.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/Tapestry.java,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -C2 -d -r1.9 -r1.9.2.1
*** Tapestry.java 27 Nov 2002 17:58:45 -0000 1.9
--- Tapestry.java 30 Nov 2002 03:33:19 -0000 1.9.2.1
***************
*** 562,565 ****
--- 562,577 ----
/**
+ * Returns true if the Map is null or empty.
+ *
+ * @since NEXT_RELEASE
+ *
+ **/
+
+ public static boolean isEmpty(Map map)
+ {
+ return map == null || map.isEmpty();
+ }
+
+ /**
* Converts a {@link Map} to an even-sized array of key/value
* pairs. This may be useful when using a Map as service parameters
***************
*** 578,582 ****
public static Object[] convertMapToArray(Map map)
{
! if (map == null || map.isEmpty())
return null;
--- 590,594 ----
public static Object[] convertMapToArray(Map map)
{
! if (isEmpty(map))
return null;
Index: TapestryStrings.properties
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/TapestryStrings.properties,v
retrieving revision 1.36.2.1
retrieving revision 1.36.2.2
diff -C2 -d -r1.36.2.1 -r1.36.2.2
*** TapestryStrings.properties 29 Nov 2002 20:58:25 -0000 1.36.2.1
--- TapestryStrings.properties 30 Nov 2002 03:33:19 -0000 1.36.2.2
***************
*** 52,56 ****
BaseComponent.missing-component-spec-multi=Template for component {0} does not reference embedded components:
BaseComponent.and=and
!
BodylessComponentException.message=This component may not have a body.
--- 52,58 ----
BaseComponent.missing-component-spec-multi=Template for component {0} does not reference embedded components:
BaseComponent.and=and
! BaseComponent.dupe-template-expression=An expression for parameter ''{0}'' of component {1} in the template for {2} conflicts with an existing binding in the specification.
! BaseComponent.template-expression-for-informal-parameter=The template for {2} contains an expression for parameter ''{0}'' of component {1}, but {1} does not allow informal parameters.
! BaseComponent.template-expression-for-reserved-parameter=The template for {2} contains an expression for parameter ''{0}'' of component {1}, but ''{0}'' is a reserved parameter name.
BodylessComponentException.message=This component may not have a body.
Index: IPageSource.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/IPageSource.java,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -d -r1.6 -r1.6.2.1
*** IPageSource.java 27 Nov 2002 17:58:45 -0000 1.6
--- IPageSource.java 30 Nov 2002 03:33:19 -0000 1.6.2.1
***************
*** 88,90 ****
--- 88,99 ----
public IAsset getPrivateAsset(String resourcePath);
+
+ /**
+ *
+ * @since NEXT_RELEASE
+ *
+ **/
+
+ public IResourceResolver getResourceResolver();
+
}
Index: BaseComponentTemplateLoader.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/Attic/BaseComponentTemplateLoader.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** BaseComponentTemplateLoader.java 29 Nov 2002 20:58:25 -0000 1.1.2.1
--- BaseComponentTemplateLoader.java 30 Nov 2002 03:33:19 -0000 1.1.2.2
***************
*** 11,14 ****
--- 11,15 ----
import org.apache.commons.logging.LogFactory;
+ import net.sf.tapestry.binding.ExpressionBinding;
import net.sf.tapestry.parse.CloseToken;
import net.sf.tapestry.parse.ComponentTemplate;
***************
*** 231,235 ****
}
! addStaticBindings(component, token.getAttributes());
_stack[_stackx++] = _activeComponent;
--- 232,237 ----
}
! addExpressionBindings(component, token.getExpressionValuesMap());
! addStaticBindings(component, token.getStaticValuesMap());
_stack[_stackx++] = _activeComponent;
***************
*** 265,268 ****
--- 267,345 ----
/**
+ * Adds expression bindings for any expressions in the provided map.
+ *
+ * <p>It is an error to specify expression
+ * bindings in both the specification
+ * and the template.
+ *
+ **/
+
+ private void addExpressionBindings(IComponent component, Map expressionsMap) throws PageLoaderException
+ {
+ if (Tapestry.isEmpty(expressionsMap))
+ return;
+
+ ComponentSpecification spec = component.getSpecification();
+
+ boolean rejectInformal = !spec.getAllowInformalParameters();
+
+ Iterator i = expressionsMap.entrySet().iterator();
+
+ while (i.hasNext())
+ {
+ Map.Entry e = (Map.Entry) i.next();
+
+ String name = (String) e.getKey();
+
+ // If matches a formal parameter name, allow it to be set
+ // unless there's already a binding.
+
+ boolean isFormal = (spec.getParameter(name) != null);
+
+ if (isFormal)
+ {
+ if (component.getBinding(name) != null)
+ throw new PageLoaderException(
+ Tapestry.getString(
+ "BaseComponent.dupe-template-expression",
+ name,
+ component.getExtendedId(),
+ _loadComponent.getExtendedId()),
+ component);
+ }
+ else
+ {
+ if (rejectInformal)
+ throw new PageLoaderException(
+ Tapestry.getString(
+ "BaseComponent.template-expression-for-informal-parameter",
+ name,
+ component.getExtendedId(),
+ _loadComponent.getExtendedId()),
+ component);
+
+ // If the name is reserved (matches a formal parameter
+ // or reserved name, caselessly), then skip it.
+
+ if (spec.isReservedParameterName(name))
+ throw new PageLoaderException(
+ Tapestry.getString(
+ "BaseComponent.template-expression-for-reserved-parameter",
+ name,
+ component.getExtendedId(),
+ _loadComponent.getExtendedId()),
+ component);
+ }
+
+ String expression = (String) e.getValue();
+
+ IBinding binding = new ExpressionBinding(_pageSource.getResourceResolver(), _loadComponent, expression);
+
+ component.setBinding(name, binding);
+ }
+
+ }
+
+ /**
* Adds static bindings for any attrributes specified in the HTML
* template, skipping any that are reserved (explicitly, or
***************
*** 271,277 ****
**/
! private void addStaticBindings(IComponent component, Map attributes)
{
! if (attributes == null || attributes.isEmpty())
return;
--- 348,354 ----
**/
! private void addStaticBindings(IComponent component, Map valuesMap)
{
! if (Tapestry.isEmpty(valuesMap))
return;
***************
*** 280,284 ****
boolean rejectInformal = !spec.getAllowInformalParameters();
! Iterator i = attributes.entrySet().iterator();
while (i.hasNext())
--- 357,361 ----
boolean rejectInformal = !spec.getAllowInformalParameters();
! Iterator i = valuesMap.entrySet().iterator();
while (i.hasNext())
|