(Object o, String formatString, Locale locale)
| 45 | public class StringRenderer implements AttributeRenderer { |
| 46 | // trim(s) and strlen(s) built-in funcs; these are format options |
| 47 | @Override |
| 48 | public String toString(Object o, String formatString, Locale locale) { |
| 49 | String s = (String)o; |
| 50 | if ( formatString==null ) return s; |
| 51 | if ( formatString.equals("upper") ) return s.toUpperCase(locale); |
| 52 | if ( formatString.equals("lower") ) return s.toLowerCase(locale); |
| 53 | if ( formatString.equals("cap") ) { |
| 54 | return (s.length()>0) ? Character.toUpperCase(s.charAt(0)) +s.substring(1) : s; |
| 55 | } |
| 56 | if ( formatString.equals("url-encode") ) { |
| 57 | try { |
| 58 | return URLEncoder.encode(s, "UTF-8"); |
| 59 | } |
| 60 | catch (UnsupportedEncodingException ex) { |
| 61 | // UTF-8 is standard, should always be available |
| 62 | } |
| 63 | } |
| 64 | if ( formatString.equals("xml-encode") ) { |
| 65 | return escapeHTML(s); |
| 66 | } |
| 67 | return String.format(locale, formatString, s); |
| 68 | } |
| 69 | |
| 70 | public static String escapeHTML(String s) { |
| 71 | if ( s==null ) { |
nothing calls this directly
no test coverage detected