OSDN Git Service

83bf050952082924fffc28cf4df0226fb9b7adc2
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / utils / LocalizedDescriptionManager.java
1 package jp.sourceforge.stigmata.utils;
2
3 /*
4  * $Id$
5  */
6
7 import java.util.HashMap;
8 import java.util.Locale;
9 import java.util.Map;
10 import java.util.MissingResourceException;
11 import java.util.ResourceBundle;
12
13 /**
14  * @author Haruaki TAMADA
15  */
16 public class LocalizedDescriptionManager{
17     public static enum ServiceCategory{
18         comparator, extractor, birthmark, formatter, filter,
19     };
20     private Map<Locale, ResourceBundle> resources = new HashMap<Locale, ResourceBundle>();
21
22     /**
23      * only one instance of singleton pattern.
24      */
25     private static LocalizedDescriptionManager manager = new LocalizedDescriptionManager();
26
27     private LocalizedDescriptionManager(){
28     }
29
30     public String getDisplayType(Locale locale, String type){
31         return getDisplayType(locale, type, ServiceCategory.birthmark);
32     }
33
34     public String getDisplayType(Locale locale, String type, ServiceCategory category){
35         try{
36             return getBundle(locale).getString(category.name() + "." + type + ".display.type");
37         } catch(MissingResourceException e){
38             return null;
39         }
40     }
41
42     public String getDescription(Locale locale, String birthmarkType){
43         return getDescription(locale, birthmarkType, ServiceCategory.birthmark);
44     }
45
46     public String getDescription(Locale locale, String type, ServiceCategory category){
47         try{
48             return getBundle(locale).getString(category.name() + "." + type + ".description");
49         } catch(MissingResourceException e){
50             return null;
51         }
52     }
53
54     private ResourceBundle getBundle(Locale locale){
55         ResourceBundle bundle = resources.get(locale);
56         if(bundle == null){
57             bundle = ResourceBundle.getBundle("resources.description", locale);
58             resources.put(locale, bundle);
59         }
60         return bundle;
61     }
62
63     public static LocalizedDescriptionManager getInstance(){
64         return manager;
65     }
66 }