Author: manaRH
Date: 2010-04-26 09:32:53 -0400 (Mon, 26 Apr 2010)
New Revision: 12647
Modified:
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/core/Interpolator.java
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/log/LogImpl.java
Log:
JBPAPP-4006
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/core/Interpolator.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/core/Interpolator.java 2010-04-26
13:07:26 UTC (rev 12646)
+++
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/core/Interpolator.java 2010-04-26
13:32:53 UTC (rev 12647)
@@ -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/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/log/LogImpl.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/log/LogImpl.java 2010-04-26
13:07:26 UTC (rev 12646)
+++ branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/log/LogImpl.java 2010-04-26
13:32:53 UTC (rev 12647)
@@ -136,11 +136,23 @@
}
}
+ @SuppressWarnings("finally")
private Object interpolate(Object object, Object... params)
{
if (object instanceof String)
{
- return Interpolator.instance().interpolate( (String) object, params );
+ try
+ {
+ object = Interpolator.instance().interpolate((String) object, params);
+ }
+ catch (Exception e)
+ {
+ log.error("exception interpolating string: " + object, e);
+ }
+ finally
+ {
+ return object;
+ }
}
else
{