Generates code to coerce a string to an Integer object. @param s The string expression @param isNamedAttribute Whether the value comes from a named attribute @return the generated coercion code
(String s, boolean isNamedAttribute)
| 603 | * @return the generated coercion code |
| 604 | */ |
| 605 | public static String coerceToInteger(String s, boolean isNamedAttribute) { |
| 606 | if (isNamedAttribute) { |
| 607 | return "(java.lang.Integer) org.apache.jasper.runtime.JspRuntimeLibrary.coerce(" + s + |
| 608 | ", java.lang.Integer.class)"; |
| 609 | } else { |
| 610 | if (s == null || s.isEmpty()) { |
| 611 | return "java.lang.Integer.valueOf(0)"; |
| 612 | } else { |
| 613 | // Detect format error at translation time |
| 614 | return "java.lang.Integer.valueOf(" + Generator.quote(s) + ")"; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Generates code to coerce a string to a primitive short value. |
no test coverage detected