1 5 package org.exoplatform.commons.utils; 6 7 import java.util.ResourceBundle ; 8 9 15 public class ExpressionUtil { 16 static public String getExpressionValue(ResourceBundle res, String key) { 17 if (res == null) return key ; 18 if(!isResourceBindingExpression(key)) return key ; 19 String value = key ; 20 key = key.substring(2, key.length() - 1) ; 21 try { 22 value = res.getString(key) ; 23 } catch (java.util.MissingResourceException ex) { } 24 return value ; 25 } 26 27 static public boolean isResourceBindingExpression(String key) { 28 if (key == null || key.length() < 3) return false ; 29 if(key.charAt(0) == '#' && key.charAt(1) == '{' && key.charAt(key.length() - 1) == '}') { 30 return true ; 31 } 32 return false ; 33 } 34 35 static public String getValue(ResourceBundle res, String key) { 36 try { 37 return res.getString(key) ; 38 } catch (java.util.MissingResourceException ex) { } 39 return key ; 40 } 41 42 43 static public boolean isDataBindingExpression(String key) { 44 if (key == null || key.length() < 3) return false ; 45 if(key.charAt(0) == '$' && key.charAt(1) == '{' && key.charAt(key.length() - 1) == '}') { 46 return true ; 47 } 48 return false ; 49 } 50 51 static public String removeBindingExpression(String key) { 52 key = key.substring(2, key.length() - 1) ; 53 return key ; 54 } 55 } | Popular Tags |