KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > language > Language


1 package com.sslexplorer.language;
2
3 import java.util.Locale JavaDoc;
4
5 /**
6  * Encapsulates a single language supported by a language pack.
7  *
8  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
9  * @see LanguagePackDefinition
10  */

11 public class Language implements Comparable JavaDoc {
12
13     // Private instance variables
14

15     private String JavaDoc code;
16     private String JavaDoc description;
17     private Locale JavaDoc locale;
18     private LanguagePackDefinition pack;
19
20     /**
21      * Constructor
22      *
23      * @param pack
24      * the language pack the language is contained in or
25      * <code>null</code> if language is in the core
26      * @param code
27      * language code
28      * @param description
29      * description of language (as presented in the language itself)
30      */

31     public Language(LanguagePackDefinition pack, String JavaDoc code, String JavaDoc description) {
32         this.code = code;
33         this.pack = pack;
34         this.description = description;
35         String JavaDoc language = code;
36         String JavaDoc country = "";
37         String JavaDoc variant = "";
38         int idx = language.indexOf('_');
39         if (idx != -1) {
40             country = language.substring(idx + 1);
41             language = language.substring(0, idx);
42         }
43         idx = country.indexOf('_');
44         if (idx != -1) {
45             variant = country.substring(idx + 1);
46             country = country.substring(0, idx);
47         }
48         locale = new Locale JavaDoc(language, country, variant);
49     }
50     
51     /**
52      * Get the language pack definition or <code>null</code>
53      * if the language is part of the core
54      *
55      * @return language pack
56      */

57     public LanguagePackDefinition getPack() {
58         return pack;
59     }
60
61     /**
62      * Get a locale object appropriate for this language
63      *
64      * @return locale
65      */

66     public Locale JavaDoc getLocale() {
67         return locale;
68     }
69
70     /**
71      * Get the code for this language
72      *
73      * @return code
74      */

75     public String JavaDoc getCode() {
76         return code;
77     }
78
79     /**
80      * Get the description for this language.
81      *
82      * @return description
83      */

84     public String JavaDoc getDescription() {
85         return description;
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see java.lang.Comparable#compareTo(T)
92      */

93     public int compareTo(Object JavaDoc o) {
94         return getDescription().compareTo(((Language) o).getDescription());
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see java.lang.Object#equals(java.lang.Object)
101      */

102     public boolean equals(Object JavaDoc o) {
103         return getCode().equals(((Language) o).getCode());
104     }
105
106     /**
107      * Test if the {@link Locale} appropriate for this language equals another
108      * locale
109      *
110      * @param locale
111      * locale
112      * @return is same locale
113      */

114     public boolean isLocale(Locale JavaDoc locale) {
115         return getLocale().equals(locale);
116     }
117 }
Popular Tags