Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.util

File MessageManager.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
12% of files have more coverage

Code metrics

0
22
6
1
133
70
10
0.45
3.67
6
1.67

Classes

Class Line # Actions
MessageManager 39 22 10 5
0.821428682.1%
 

Contributing tests

This file is covered by 200 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.util;
22   
23    import java.text.MessageFormat;
24    import java.util.Locale;
25    import java.util.ResourceBundle;
26    import java.util.ResourceBundle.Control;
27    //import java.util.logging.Level;
28    //import java.util.logging.Logger;
29   
30    import org.apache.log4j.Logger;
31   
32    /**
33    *
34    * @author David Roldan Martinez
35    * @author Thomas Abeel
36    *
37    *
38    */
 
39    public class MessageManager
40    {
41   
42    // BH 2018 switched to org.apache.llog4j.Logger
43   
44    private static ResourceBundle rb;
45   
46    private static Logger log = Logger
47    .getLogger(MessageManager.class.getCanonicalName());
48   
49    private static Locale loc;
50   
 
51  1 toggle static
52    {
53  1 try
54    {
55    /* Localize Java dialogs */
56  1 loc = Locale.getDefault();
57    // Locale.setDefault(loc);
58    /* Getting messages for GV */
59  1 log.info("Getting messages for lang: " + loc);
60  1 Control control = Control.getControl(Control.FORMAT_PROPERTIES);
61  1 rb = ResourceBundle.getBundle("lang.Messages", loc, control);
62    // if (log.isLoggable(Level.FINEST))
63    // {
64    // // this might take a while, so we only do it if it will be shown
65    // log.info("Language keys: " + rb.keySet()); // was FINEST
66    // }
67    } catch (Exception q)
68    {
69  0 log.warn("Exception when initting Locale for i18n messages\n"
70    + q.getMessage());
71  0 q.printStackTrace();
72    } catch (Error v)
73    {
74  0 log.warn("Error when initting Locale for i18n messages\n"
75    + v.getMessage());
76  0 v.printStackTrace();
77    }
78   
79    }
80   
 
81  90752 toggle public static String getString(String key)
82    {
83  90753 String value = "[missing key] " + key;
84  90746 try
85    {
86  90746 value = rb.getString(key);
87    } catch (Exception e)
88    {
89  0 log.warn("I18N missing: " + loc + "\t" + key);
90    }
91  90753 return value;
92    }
93   
 
94  40 toggle public static Locale getLocale()
95    {
96  40 return loc;
97    }
98   
 
99  11377 toggle public static String formatMessage(String key, Object... params)
100    {
101  11377 return MessageFormat.format(getString(key), params);
102    }
103   
 
104  17440 toggle public static String formatMessage(String key, String[] params)
105    {
106  17440 return MessageFormat.format(getString(key), (Object[]) params);
107    }
108   
109    /**
110    * Looks up and returns a key given a root and a human-readable(ish) name that
111    * when combined might resolve to an i18n string. If the key doesn't resolve,
112    * then name is returned. Use this for programmatically constructed keys that
113    * have a human readable alternative used in the program (e.g. BLOSUM62 and
114    * label.score_blosum62).
115    *
116    * @param keyroot
117    * @param name
118    * @return
119    */
 
120  3167 toggle public static String getStringOrReturn(String keyroot, String name)
121    {
122  3167 String smkey = keyroot + name.toLowerCase().replaceAll(" ", "");
123  3167 try
124    {
125  3167 name = rb.getString(smkey);
126    } catch (Exception x)
127    {
128  276 log.info("I18N missing key with root " + keyroot + ": " + loc + "\t"
129    + smkey); // was FINEST
130    }
131  3167 return name;
132    }
133    }