[seam-commits] Seam SVN: r12011 - in branches/community/Seam_2_2/src: main/org/jboss/seam/log and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Feb 4 13:23:14 EST 2010
Author: manaRH
Date: 2010-02-04 13:23:13 -0500 (Thu, 04 Feb 2010)
New Revision: 12011
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java
branches/community/Seam_2_2/src/main/org/jboss/seam/log/LogImpl.java
branches/community/Seam_2_2/src/test/unit/org/jboss/seam/test/unit/InterpolatorTest.java
Log:
JBSEAM-4203
Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java 2010-02-04 17:50:16 UTC (rev 12010)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java 2010-02-04 18:23:13 UTC (rev 12011)
@@ -73,125 +73,119 @@
{
StringTokenizer tokens = new StringTokenizer(string, "#{}", true);
StringBuilder builder = new StringBuilder(string.length());
- try
+
+ while (tokens.hasMoreTokens())
{
- while (tokens.hasMoreTokens())
+ String tok = tokens.nextToken();
+
+ if ("#".equals(tok) && tokens.hasMoreTokens())
{
- String tok = tokens.nextToken();
+ String nextTok = tokens.nextToken();
- if ("#".equals(tok) && tokens.hasMoreTokens())
+ while (nextTok.equals("#") && tokens.hasMoreTokens())
{
- String nextTok = tokens.nextToken();
-
- while (nextTok.equals("#") && tokens.hasMoreTokens())
+ builder.append(tok);
+ nextTok = tokens.nextToken();
+ }
+
+ if ("{".equals(nextTok))
+ {
+ String expression = "#{" + tokens.nextToken() + "}";
+ try
{
- builder.append(tok);
- nextTok = tokens.nextToken();
+ Object value = Expressions.instance().createValueExpression(expression).getValue();
+ if (value != null)
+ builder.append(value);
}
+ catch (Exception e)
+ {
+ log.debug("exception interpolating string: " + string, e);
+ }
+ tokens.nextToken(); // the trailing "}"
- if ("{".equals(nextTok))
+ }
+ else if (nextTok.equals("#"))
+ {
+ // could be trailing #
+ builder.append("#");
+
+ }
+ else
+ {
+ int index;
+ try
{
- String expression = "#{" + tokens.nextToken() + "}";
- try
+ index = Integer.parseInt(nextTok.substring(0, 1));
+ if (index >= params.length)
{
- Object value = Expressions.instance().createValueExpression(expression).getValue();
- if (value != null)
- builder.append(value);
+ // log.warn("parameter index out of bounds: " + index +
+ // " in: " + string);
+ builder.append("#").append(nextTok);
}
- catch (Exception e)
+ else
{
- log.debug("exception interpolating string: " + string, e);
+ builder.append(params[index]).append(nextTok.substring(1));
}
- tokens.nextToken(); // the trailing "}"
-
}
- else if (nextTok.equals("#"))
+ catch (NumberFormatException nfe)
{
- // could be trailing #
- builder.append("#");
-
+ builder.append("#").append(nextTok);
}
- else
- {
- int index;
- try
- {
- index = Integer.parseInt(nextTok.substring(0, 1));
- if (index >= params.length)
- {
- // log.warn("parameter index out of bounds: " + index +
- // " in: " + string);
- builder.append("#").append(nextTok);
- }
- else
- {
- builder.append(params[index]).append(nextTok.substring(1));
- }
- }
- catch (NumberFormatException nfe)
- {
- builder.append("#").append(nextTok);
- }
- }
}
- else if ("{".equals(tok))
+ }
+ else if ("{".equals(tok))
+ {
+ StringBuilder expr = new StringBuilder();
+
+ expr.append(tok);
+ int level = 1;
+
+ while (tokens.hasMoreTokens())
{
- StringBuilder expr = new StringBuilder();
+ String nextTok = tokens.nextToken();
+ expr.append(nextTok);
- expr.append(tok);
- int level = 1;
-
- while (tokens.hasMoreTokens())
+ if (nextTok.equals("{"))
{
- String nextTok = tokens.nextToken();
- expr.append(nextTok);
-
- if (nextTok.equals("{"))
+ ++level;
+ }
+ else if (nextTok.equals("}"))
+ {
+ if (--level == 0)
{
- ++level;
- }
- else if (nextTok.equals("}"))
- {
- if (--level == 0)
+ try
{
- try
+ if (params.length == 0)
{
- if (params.length == 0)
- {
- builder.append(expr.toString());
- }
- else
- {
- String value = new MessageFormat(expr.toString(), Locale.instance()).format(params);
- builder.append(value);
- }
+ builder.append(expr.toString());
}
- catch (Exception e)
+ else
{
- // if it is a bad message, use the expression itself
- builder.append(expr);
+ String value = new MessageFormat(expr.toString(), Locale.instance()).format(params);
+ builder.append(value);
}
- expr = null;
- break;
}
+ catch (Exception e)
+ {
+ // if it is a bad message, use the expression itself
+ builder.append(expr);
+ }
+ expr = null;
+ break;
}
}
-
- if (expr != null)
- {
- builder.append(expr);
- }
}
- else
+
+ if (expr != null)
{
- builder.append(tok);
+ builder.append(expr);
}
}
+ else
+ {
+ builder.append(tok);
+ }
}
- catch (Exception e)
- {
- log.debug("exception interpolating string: " + string, e);
- }
return builder.toString();
}
Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/log/LogImpl.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/log/LogImpl.java 2010-02-04 17:50:16 UTC (rev 12010)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/log/LogImpl.java 2010-02-04 18:23:13 UTC (rev 12011)
@@ -140,7 +140,14 @@
{
if (object instanceof String)
{
- return Interpolator.instance().interpolate( (String) object, params );
+ try {
+ return Interpolator.instance().interpolate( (String) object, params );
+ } catch (Exception e) {
+ log.error("exception interpolating string: " + object, e);
+ } finally {
+ return object;
+ }
+
}
else
{
Modified: branches/community/Seam_2_2/src/test/unit/org/jboss/seam/test/unit/InterpolatorTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/unit/org/jboss/seam/test/unit/InterpolatorTest.java 2010-02-04 17:50:16 UTC (rev 12010)
+++ branches/community/Seam_2_2/src/test/unit/org/jboss/seam/test/unit/InterpolatorTest.java 2010-02-04 18:23:13 UTC (rev 12011)
@@ -57,9 +57,10 @@
try
{
interpolator.interpolate("hello #{", (Object) null);
+ Assert.fail("interpolator not raised an exception");
} catch (Throwable t)
{
- Assert.fail("interpolator raised an exception");
+
}
}
More information about the seam-commits
mailing list