KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Used to map locale information to URI space, to find the relevant bundle.
14  *
15  * @author <a HREF="mailto:neeme@apache.org">Neeme Praks</a>
16  * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
17  */

18 public class BundleInfo {
19
20     private String JavaDoc name;
21     private Locale JavaDoc locale;
22     private String JavaDoc ext;
23
24     public BundleInfo() {
25         this(null, null, null);
26     }
27
28     public BundleInfo(String JavaDoc name, Locale JavaDoc locale) {
29         this(name, locale, null);
30     }
31
32     public BundleInfo(String JavaDoc name, Locale JavaDoc locale, String JavaDoc ext) {
33         this.name = name;
34         this.locale = locale;
35         this.ext = ext;
36     }
37
38     protected void setName(String JavaDoc name) {
39         this.name = name;
40     }
41
42     protected void setLocale(Locale JavaDoc locale) {
43         this.locale = locale;
44     }
45
46     protected void setExtensionParameter(String JavaDoc ext) {
47         this.ext = ext;
48     }
49
50     public String JavaDoc getName()
51     {
52         return this.name;
53     }
54
55     public Locale JavaDoc getLocale()
56     {
57         return this.locale;
58     }
59
60     public String JavaDoc getExtensionParameter()
61     {
62         return this.ext;
63     }
64
65     public String JavaDoc toString()
66     {
67         return "BundleInfo(" + this.name + "," + this.locale + "," + this.ext + ")";
68     }
69
70     public BundleInfo getParent()
71     {
72         if (this.locale != null && !this.locale.getLanguage().equals(""))
73             return new BundleInfo(this.name, this.getParentLocale(), this.ext);
74         else
75             return null;
76     }
77
78     /**
79      * Returns the next locale up the parent hierarchy.
80      * E.g. the parent of new Locale("en","us","mac") would be
81      * new Locale("en", "us", "").
82      *
83      * @param locale the locale
84      * @return the parent locale
85      */

86     protected Locale JavaDoc getParentLocale()
87     {
88         Locale JavaDoc newloc;
89         if (this.locale.getVariant().equals(""))
90         {
91             if (this.locale.getCountry().equals(""))
92                 newloc = new Locale JavaDoc("","","");
93             else
94                 newloc = new Locale JavaDoc(this.locale.getLanguage(), "", "");
95         }
96         else
97             newloc = new Locale JavaDoc(this.locale.getLanguage(), this.locale.getCountry(), "");
98
99         return newloc;
100     }
101
102 }
103
Popular Tags