KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > i18n > DefaultMapper


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.i18n;
9
10 import java.util.Locale JavaDoc;
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 /**
18  * Maps the locale using the standard Java mapping: en-US would be mapped to
19  * file ending with en_US.
20  *
21  * @author <a HREF="mailto:neeme@apache.org">Neeme Praks</a>
22  * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
23  */

24
25 public class DefaultMapper implements BundleInfoMapper, Component, Configurable {
26
27     public static final class ConfigurationKeys {
28         public static final String JavaDoc PREFIX = "prefix";
29         public static final String JavaDoc SUFFIX = "suffix";
30     }
31
32     private String JavaDoc prefix = null;
33     private String JavaDoc 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 JavaDoc getPrefix() {
41         return prefix;
42     }
43
44     protected String JavaDoc getSuffix() {
45         return suffix;
46     }
47
48     /**
49      * Get the URI for the bundle, based on locale and filename.
50      *
51      * @return the URI
52      */

53     public String JavaDoc map(BundleInfo bundleInfo) {
54         String JavaDoc name = bundleInfo.getName();
55         Locale JavaDoc loc = bundleInfo.getLocale();
56         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(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 JavaDoc result = sb.toString();
78         return result;
79     }
80
81 }
82
Popular Tags