KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > commons > utils > ExpressionUtil


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.commons.utils;
6
7 import java.util.ResourceBundle JavaDoc;
8
9 /**
10  * Jul 18, 2004
11  * @author: Tuan Nguyen
12  * @email: tuan08@users.sourceforge.net
13  * @version: $Id: ExpressionUtil.java,v 1.1 2004/07/21 19:59:11 tuan08 Exp $
14  */

15 public class ExpressionUtil {
16     static public String JavaDoc getExpressionValue(ResourceBundle JavaDoc res, String JavaDoc key) {
17         if (res == null) return key ;
18         if(!isResourceBindingExpression(key)) return key ;
19         String JavaDoc value = key ;
20         key = key.substring(2, key.length() - 1) ;
21         try {
22             value = res.getString(key) ;
23         } catch (java.util.MissingResourceException JavaDoc ex) { }
24         return value ;
25     }
26   
27   static public boolean isResourceBindingExpression(String JavaDoc 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 JavaDoc getValue(ResourceBundle JavaDoc res, String JavaDoc key) {
36     try {
37       return res.getString(key) ;
38     } catch (java.util.MissingResourceException JavaDoc ex) { }
39     return key ;
40   }
41   
42   
43   static public boolean isDataBindingExpression(String JavaDoc 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 JavaDoc removeBindingExpression(String JavaDoc key) {
52     key = key.substring(2, key.length() - 1) ;
53     return key ;
54   }
55 }
Popular Tags