tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mck <m...@semb.wever.org>
Subject Re: wildcarding works in put-attribute@value but not in put-attribute@expression
Date Wed, 10 Mar 2010 14:08:22 GMT
On Wed, 2010-03-10 at 09:54 +0100, Mck wrote:
> Otherwise, Will a patch to implement it be accepted?

For example this patch works for me...


--- tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java	(revision
921279)
+++ tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java	(working
copy)
@@ -157,7 +157,9 @@
         nuattr.setRenderer(attr.getRenderer());
         Expression expressionObject = attr.getExpressionObject();
         if (expressionObject != null) {
-            nuattr.setExpressionObject(new Expression(expressionObject));
+            Expression newExpressionObject = Expression
+                    .createExpression(replace(expressionObject.getExpression(), vars), expressionObject.getLanguage());
+            nuattr.setExpressionObject(newExpressionObject);
         }
 
         Object value = attr.getValue();
@@ -207,6 +209,7 @@
      */
     private static String replace(String st, Object... vars) {
         if (st != null && st.indexOf('{') >= 0) {
+            st = st.replaceAll("'", "'''").replaceAll("\\Q${\\E", "\\$'{'");
             MessageFormat format = new MessageFormat(st, ROOT_LOCALE);
             return format.format(vars, new StringBuffer(), null).toString();
         }



Albeit that 
      st = st.replaceAll("'", "'''").replaceAll("\\Q${\\E", "\\$'{'");
definitely should be improved with something from javax.el that escapes
the el before pushing it through the MessageFormat.
But going down this path it should be made pluggable so that the various
registered attributeEvaluators are called to do the appropriate
escaping.

~mck

Mime
View raw message