KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > examples > util > GuiUtil


1 package org.apache.myfaces.examples.util;
2
3 import javax.faces.context.FacesContext;
4 import java.util.ResourceBundle JavaDoc;
5 import java.util.MissingResourceException JavaDoc;
6 import java.text.MessageFormat JavaDoc;
7
8 /**
9  * @author Thomas Spiegl (latest modification by $Author: matzew $)
10  * @version $Revision: 1.1 $ $Date: 2005/03/24 16:47:11 $
11  */

12 public class GuiUtil
13 {
14     private static String JavaDoc BUNDLE_NAME = "org.apache.myfaces.examples.resource.example_messages";
15
16     public static String JavaDoc getMessageResource(String JavaDoc key, Object JavaDoc[] arguments)
17     {
18         FacesContext context = FacesContext.getCurrentInstance();
19         String JavaDoc resourceString;
20         try
21         {
22             ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(BUNDLE_NAME, context.getViewRoot().getLocale());
23             resourceString = bundle.getString(key);
24         }
25         catch (MissingResourceException JavaDoc e)
26         {
27             return key;
28         }
29
30         if (arguments == null) return resourceString;
31
32         MessageFormat JavaDoc format = new MessageFormat JavaDoc(resourceString, context.getViewRoot().getLocale());
33         return format.format(arguments);
34     }
35
36 }
37
Popular Tags