KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
13  * Maps the locale using the standard Java mapping: en-US would be mapped to
14  * file ending with en_US.
15  *
16  * @author <a HREF="mailto:neeme@apache.org">Neeme Praks</a>
17  * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
18  */

19
20 public class DirectoryMapper extends DefaultMapper {
21
22     /**
23      * Get the URI for the bundle, based on locale and filename.
24      *
25      * @return the URI
26      */

27     public String JavaDoc map(BundleInfo bundleInfo) {
28         String JavaDoc name = bundleInfo.getName();
29         Locale JavaDoc loc = bundleInfo.getLocale();
30         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(getPrefix());
31         if (loc != null) {
32             String JavaDoc lang = loc.getLanguage();
33             String JavaDoc country = loc.getCountry();
34             String JavaDoc variant = loc.getVariant();
35
36             if (lang.length() > 0) sb.append("/").append(lang);
37             if (country.length() > 0) sb.append("/").append(country);
38             if (variant.length() > 0) sb.append("/").append(variant);
39         }
40         sb.append("/").append(name).append(getSuffix());
41
42         String JavaDoc result = sb.toString();
43         return result;
44     }
45
46 }
47
Popular Tags