| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.el.impl; |
| 17 | |
|
| 18 | |
import javax.faces.el.ReferenceSyntaxException; |
| 19 | |
|
| 20 | |
import org.seasar.framework.exception.EmptyRuntimeException; |
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
public class JspELParserUtil { |
| 26 | |
|
| 27 | |
private static final String JSP_OPEN_BRACE = "${"; |
| 28 | |
|
| 29 | |
private static final String JSP_CLOSE_BRACE = "}"; |
| 30 | |
|
| 31 | 0 | private JspELParserUtil() { |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
public static String convertToJspExpression(final String expression) { |
| 35 | 201 | return convertToJspExpression(expression, "#{", "}"); |
| 36 | |
} |
| 37 | |
|
| 38 | |
public static String convertToJspExpression(final String expression, |
| 39 | |
final String openBrace, final String closeBrace) { |
| 40 | 201 | if (expression == null) { |
| 41 | 1 | throw new EmptyRuntimeException("expression"); |
| 42 | |
} |
| 43 | 200 | if (openBrace == null || closeBrace == null) { |
| 44 | 0 | throw new ReferenceSyntaxException(); |
| 45 | |
} |
| 46 | 200 | String str = expression; |
| 47 | 200 | if (str.startsWith(openBrace) && str.indexOf(closeBrace) > 0) { |
| 48 | 77 | int pos = str.indexOf(closeBrace); |
| 49 | 77 | String s = str.substring(JSP_OPEN_BRACE.length(), pos); |
| 50 | 77 | String postfix = str.substring(pos + 1); |
| 51 | 77 | str = JSP_OPEN_BRACE + s + JSP_CLOSE_BRACE |
| 52 | |
+ convertToJspExpression(postfix); |
| 53 | |
} else { |
| 54 | 123 | int pos1 = str.indexOf(openBrace); |
| 55 | 123 | int pos2 = str.indexOf(closeBrace); |
| 56 | 123 | if (pos1 > 0) { |
| 57 | 28 | if (pos2 > pos1) { |
| 58 | 24 | String prefix = str.substring(0, pos1); |
| 59 | 24 | String s = str.substring(pos1 + openBrace.length(), pos2); |
| 60 | 24 | String postfix = str.substring(pos2 + 1); |
| 61 | 24 | str = prefix + JSP_OPEN_BRACE + s + JSP_CLOSE_BRACE |
| 62 | |
+ convertToJspExpression(postfix); |
| 63 | 4 | } else if (pos2 >= 0 && pos2 <= pos1) { |
| 64 | 4 | String prefix = str.substring(0, pos2 + 1); |
| 65 | 4 | String s = str.substring(pos2 + 1); |
| 66 | 4 | str = prefix + convertToJspExpression(s); |
| 67 | |
} |
| 68 | |
} |
| 69 | |
} |
| 70 | 200 | return str; |
| 71 | |
} |
| 72 | |
|
| 73 | |
} |