Author: manaRH
Date: 2010-02-04 12:34:49 -0500 (Thu, 04 Feb 2010)
New Revision: 12009
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java
Log:
fixed white spaces
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
08:30:37 UTC (rev 12008)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java 2010-02-04
17:34:49 UTC (rev 12009)
@@ -63,96 +63,131 @@
return string;
}
- private String interpolateExpressions(String string, Object... params)
- {
- StringTokenizer tokens = new StringTokenizer(string, "#{}", true);
- StringBuilder builder = new StringBuilder(string.length());
- try {
- while (tokens.hasMoreTokens()) {
- String tok = tokens.nextToken();
-
- if ("#".equals(tok) && 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 {
- Object value =
Expressions.instance().createValueExpression(expression).getValue();
- if (value!=null) builder.append(value);
- } catch (Exception e) {
- log.debug("exception interpolating string: " +
string, e);
+ private String interpolateExpressions(String string, Object... params)
+ {
+ StringTokenizer tokens = new StringTokenizer(string, "#{}", true);
+ StringBuilder builder = new StringBuilder(string.length());
+ try
+ {
+ while (tokens.hasMoreTokens())
+ {
+ String tok = tokens.nextToken();
+
+ if ("#".equals(tok) && 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
+ {
+ 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 "}"
+
+ }
+ else if (nextTok.equals("#"))
+ {
+ // could be trailing #
+ builder.append("#");
+
+ }
+ 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))
+ {
+ StringBuilder expr = new StringBuilder();
+
+ expr.append(tok);
+ int level = 1;
+
+ while (tokens.hasMoreTokens())
+ {
+ String nextTok = tokens.nextToken();
+ expr.append(nextTok);
+
+ if (nextTok.equals("{"))
+ {
+ ++level;
+ }
+ else if (nextTok.equals("}"))
+ {
+ if (--level == 0)
+ {
+ try
+ {
+ if (params.length == 0)
+ {
+ builder.append(expr.toString());
+ }
+ else
+ {
+ String value = new MessageFormat(expr.toString(),
Locale.instance()).format(params);
+ builder.append(value);
+ }
}
- tokens.nextToken(); // the trailing "}"
-
- } else if (nextTok.equals("#")) {
- // could be trailing #
- builder.append("#");
-
- } 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);
+ catch (Exception e)
+ {
+ // if it is a bad message, use the expression itself
+ builder.append(expr);
}
- }
- } else if ("{".equals(tok)) {
- StringBuilder expr = new StringBuilder();
-
- expr.append(tok);
- int level = 1;
-
- while (tokens.hasMoreTokens()) {
- String nextTok = tokens.nextToken();
- expr.append(nextTok);
-
- if (nextTok.equals("{")) {
- ++level;
- } else if (nextTok.equals("}")) {
- if (--level == 0) {
- try {
- if (params.length == 0)
- {
- builder.append(expr.toString());
- }
- else
- {
- String value = new MessageFormat(expr.toString(),
Locale.instance()).format(params);
- builder.append(value);
- }
- } 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 {
- builder.append(tok);
- }
+ expr = null;
+ break;
+ }
+ }
+ }
+
+ if (expr != null)
+ {
+ builder.append(expr);
+ }
}
- } catch (Exception e) {
- log.debug("exception interpolating string: " + string, e);
- }
+ else
+ {
+ builder.append(tok);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.debug("exception interpolating string: " + string, e);
+ }
+
+ return builder.toString();
+ }
- return builder.toString();
- }
-
}
Show replies by date