1 16 package org.apache.jetspeed.services.customlocalization; 17 18 import java.util.Locale ; 19 import java.util.ResourceBundle ; 20 import java.util.MissingResourceException ; 21 22 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 23 import org.apache.jetspeed.services.logging.JetspeedLogger; 24 25 import org.apache.turbine.services.pull.ApplicationTool; 26 import org.apache.turbine.util.RunData; 27 28 29 30 38 public class CustomLocalizationTool implements ApplicationTool 39 { 40 43 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(CustomLocalizationTool.class.getName()); 44 45 public CustomLocalizationTool() 46 { 47 refresh(); 48 } 49 50 public String get(String key) 51 { 52 try 53 { 54 String s = CustomLocalization.getString(getBundleName(null), getLocale(), key); 55 return s; 56 } 57 catch (MissingResourceException noKey) 58 { 59 logger.error("Exception", noKey); 60 } 61 return null; 62 } 63 64 72 public String get(String key, Locale locale) 73 { 74 if (locale == null) 75 { 76 locale = getLocale(); 77 } 78 79 String s = null; 80 try 81 { 82 s = CustomLocalization.getString(getBundleName(null), locale, key); 83 } 84 catch (MissingResourceException noKey) 85 { 86 logger.error("Exception", noKey); 87 } 88 89 return s; 90 } 91 92 93 public Locale getLocale() 94 { 95 return locale; 96 } 97 98 protected String getBundleName(Object data) 99 { 100 return CustomLocalization.getDefaultBundleName(); 101 } 102 103 public final void init(Object data) 104 { 105 if (data instanceof RunData) 106 { 107 locale = CustomLocalization.getLocale((RunData)data); 108 bundleName = getBundleName(data); 109 } 110 } 111 112 public void refresh() 113 { 114 locale = null; 115 bundle = null; 116 bundleName = null; 117 } 118 119 protected Locale locale; 120 private ResourceBundle bundle; 121 private String bundleName; 122 boolean debug; 123 } 124 | Popular Tags |