Added more Wikipedia configurations
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / actions / mediawiki / config / WikiProperties.java
1 package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config;
2 //Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
3 //http://www.djini.de/software/wikipedia/index.html
4 //
5 //The modified sources are available under the "Common Public License"
6 //with permission from the original author: Daniel Wunsch
7
8 import java.text.MessageFormat;
9 import java.util.MissingResourceException;
10 import java.util.ResourceBundle;
11
12 public class WikiProperties {
13
14   private static final String PACKAGE_NAME = WikiProperties.class.getPackage().getName();
15
16   private String RESOURCE_BUNDLE = null;
17
18   private ResourceBundle fgResourceBundle = null;
19
20   protected WikiProperties(String locale) {
21     RESOURCE_BUNDLE = PACKAGE_NAME + "." + locale;
22     fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
23   }
24
25   public String getString(String key) {
26     try {
27       return fgResourceBundle.getString(key);
28     } catch (MissingResourceException e) {
29       return '!' + key + '!';
30     }
31   }
32
33   /**
34    * Gets a string from the resource bundle and formats it with the argument
35    * 
36    * @param key
37    *          the string used to get the bundle value, must not be null
38    */
39   public String getFormattedString(String key, Object arg) {
40     return MessageFormat.format(getString(key), new Object[] { arg });
41   }
42
43   /**
44    * Gets a string from the resource bundle and formats it with arguments
45    */
46   public String getFormattedString(String key, Object[] args) {
47     return MessageFormat.format(getString(key), args);
48   }
49
50   // test code
51 //    public static void main(String[] args) {
52 //      WikiProperties p = new WikiProperties("EN");
53 //      System.out.println(p.getString("uploadNoLogin"));
54 //    }
55
56 }