1 package org.andromda.cartridges.jsf;
2
3 import java.text.MessageFormat;
4
5 import java.util.MissingResourceException;
6 import java.util.ResourceBundle;
7
8 import javax.faces.context.FacesContext;
9
10
11
12
13 public class Messages
14 {
15
16
17
18 private static final String BUNDLE_NAME = "message-resources";
19
20
21
22
23
24
25
26
27
28 public static String get(
29 String key,
30 Object[] arguments)
31 {
32 FacesContext context = FacesContext.getCurrentInstance();
33 String resourceString;
34 try
35 {
36 final ResourceBundle bundle = ResourceBundle.getBundle(
37 BUNDLE_NAME,
38 context.getViewRoot().getLocale());
39 resourceString = bundle.getString(key);
40 if (arguments != null)
41 {
42 final MessageFormat format = new MessageFormat(resourceString,
43 context.getViewRoot().getLocale());
44 resourceString = format.format(arguments);
45 }
46 }
47 catch (final MissingResourceException exception)
48 {
49 resourceString = key;
50 }
51 return resourceString;
52 }
53 }