KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > entities > management > LanguageVO


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.entities.management;
25
26 import java.util.Locale JavaDoc;
27
28 import org.infoglue.cms.entities.kernel.BaseEntityVO;
29 import org.infoglue.cms.entities.management.impl.simple.LanguageImpl;
30 import org.infoglue.cms.exception.ConstraintException;
31 import org.infoglue.cms.util.ConstraintExceptionBuffer;
32 import org.infoglue.cms.util.validators.ValidatorFactory;
33 import org.infoglue.deliver.controllers.kernel.impl.simple.LanguageDeliveryController;
34
35 /**
36  * This entity represents a language
37  */

38
39 public class LanguageVO implements BaseEntityVO
40 {
41     private java.lang.Integer JavaDoc languageId;
42     private java.lang.String JavaDoc name;
43     private java.lang.String JavaDoc languageCode;
44     private java.lang.String JavaDoc charset = "ISO-8859-1";
45     
46     public String JavaDoc toString()
47     {
48         return getName();
49     }
50
51     /**
52      * @see org.infoglue.cms.entities.kernel.BaseEntityVO#getId()
53      */

54     public Integer JavaDoc getId() {
55         return getLanguageId();
56     }
57
58     public java.lang.Integer JavaDoc getLanguageId()
59     {
60         return this.languageId;
61     }
62                 
63     public void setLanguageId(java.lang.Integer JavaDoc languageId)
64     {
65         this.languageId = languageId;
66     }
67     
68     public java.lang.String JavaDoc getName()
69     {
70         return this.name;
71     }
72
73     public java.lang.String JavaDoc getLanguageCode()
74     {
75         return this.languageCode;
76     }
77
78     public java.lang.String JavaDoc getCharset()
79     {
80         return this.charset;
81     }
82                 
83     public void setName(java.lang.String JavaDoc name) throws ConstraintException
84     {
85         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
86         ValidatorFactory.createStringValidator("Language.name", true, 4, 20).validate(name, ceb);
87  
88
89         ceb.throwIfNotEmpty();
90         this.name = name;
91     }
92       
93     public void setLanguageCode(java.lang.String JavaDoc languageCode) throws ConstraintException
94     {
95         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
96         ValidatorFactory.createStringValidator("Language.languageCode", true, 2, 6).validate(languageCode, ceb);
97
98         ceb.throwIfNotEmpty();
99         this.languageCode = languageCode;
100     }
101     
102     public void setCharset(java.lang.String JavaDoc charset)
103     {
104         this.charset = charset;
105     }
106
107     /**
108      * @see org.infoglue.cms.entities.kernel.BaseEntityVO#validate()
109      */

110
111     public ConstraintExceptionBuffer validate()
112     {
113         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
114         if (name != null) ValidatorFactory.createStringValidator("Language.name", true, 4, 20, true, LanguageImpl.class, this.getId(), null).validate(name, ceb);
115         if (languageCode != null) ValidatorFactory.createStringValidator("Language.languageCode", true, 2, 6, true, LanguageImpl.class, this.getId(), null).validate(languageCode, ceb);
116         return ceb;
117     }
118    
119     public boolean equals(Object JavaDoc o)
120     {
121         boolean equals = false;
122         
123         if(o instanceof LanguageVO)
124         {
125             LanguageVO languageVO = (LanguageVO)o;
126             if(languageVO != null && languageVO.getLanguageId().equals(this.languageId))
127                 equals = true;
128         }
129         
130         return equals;
131     }
132     
133     public int hashCode()
134     {
135         return this.languageId.intValue();
136     }
137
138     /**
139      * Returns the locale matching this language languageCode.
140      * @return java.util.Locale
141      */

142
143     public Locale JavaDoc getLocale()
144     {
145         return LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithCode(this.languageCode);
146     }
147
148     /**
149      * Returns the display name for this language
150      * @return
151      */

152     
153     public String JavaDoc getDisplayLanguage()
154     {
155         Locale JavaDoc locale = getLocale();
156         return locale.getDisplayLanguage();
157     }
158
159     /**
160      * Returns the localized display name for this language
161      * @return
162      */

163
164     public String JavaDoc getLocalizedDisplayLanguage()
165     {
166         Locale JavaDoc locale = getLocale();
167         return locale.getDisplayLanguage(locale);
168     }
169
170 }
171         
172
Popular Tags