1 8 package org.apache.avalon.excalibur.i18n; 9 10 import java.util.Locale ; 11 12 import org.apache.avalon.framework.configuration.Configurable; 13 import org.apache.avalon.framework.configuration.Configuration; 14 import org.apache.avalon.framework.configuration.ConfigurationException; 15 import org.apache.avalon.framework.component.Component; 16 17 24 25 public class DefaultMapper implements BundleInfoMapper, Component, Configurable { 26 27 public static final class ConfigurationKeys { 28 public static final String PREFIX = "prefix"; 29 public static final String SUFFIX = "suffix"; 30 } 31 32 private String prefix = null; 33 private String suffix = null; 34 35 public void configure(Configuration configuration) throws ConfigurationException { 36 if (prefix == null) prefix = configuration.getChild(ConfigurationKeys.PREFIX).getValue(); 37 if (suffix == null) suffix = configuration.getChild(ConfigurationKeys.SUFFIX).getValue(); 38 } 39 40 protected String getPrefix() { 41 return prefix; 42 } 43 44 protected String getSuffix() { 45 return suffix; 46 } 47 48 53 public String map(BundleInfo bundleInfo) { 54 String name = bundleInfo.getName(); 55 Locale loc = bundleInfo.getLocale(); 56 StringBuffer sb = new StringBuffer (getPrefix()); 57 sb.append('/').append(name); 58 if (loc != null) 59 { 60 if (! loc.getLanguage().equals("")) 61 { 62 sb.append("_"); 63 sb.append(loc.getLanguage()); 64 } 65 if (! loc.getCountry().equals("")) 66 { 67 sb.append("_"); 68 sb.append(loc.getCountry()); 69 } 70 if (! loc.getVariant().equals("")) 71 { 72 sb.append("_"); 73 sb.append(loc.getVariant()); 74 } 75 } 76 sb.append(getSuffix()); 77 String result = sb.toString(); 78 return result; 79 } 80 81 } 82 | Popular Tags |