KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > model > core > ContentLocale


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.model.core;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 /**
25  * <p>Locale for content. This represents some language for which application
26  * will have support. For each localized content (like {@link ContentFieldValue})
27  * Content Locale is specified. It's also attached to {@link ContentDocument}s.
28  * </p>
29  * <p>
30  * Each content locale may be <em>active</em> or <em>inactive</em>. Active
31  * content locale is one that is actually used. Content field values with content
32  * locale which is inactive are not displayed to user. It's convenient when you
33  * need to add some language: until everything is ready, it will be invisible.
34  * </p>
35  * <p>
36  * One of content locales is default. It's used when nothing was found for
37  * requested content locale.
38  * </p>
39  * <p><a HREF="ContentLocale.java.htm"><i>View Source</i></a>
40  * </p>
41  * <p/>
42  *
43  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
44  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
45  * @version $Revision: 1.34 $ $Date: 2005/12/18 16:43:42 $
46  * @struts.form include-all="false" extends="BaseForm"
47  * @hibernate.class table="`al_core_locale`" lazy="false"
48  * @hibernate.cache usage="read-write"
49  */

50 public class ContentLocale extends BaseObject implements Comparable JavaDoc {
51
52     /**
53      * Identifier of this content locale. It's based on standart. Examples are
54      * en, ru, es.
55      */

56     protected String JavaDoc identifier;
57     /**
58      * Is this locale default
59      */

60     protected Boolean JavaDoc defaultInstance;
61     /**
62      * Is this locale active (may be used in application)
63      */

64     protected Boolean JavaDoc active;
65     /**
66      * List of CFVs with this locale
67      */

68     protected List JavaDoc contentFieldValues = new ArrayList JavaDoc();
69     /**
70      * List of content documents with this locale
71      */

72     protected List JavaDoc contentDocuments = new ArrayList JavaDoc();
73     /**
74      * List of application resources with this locale
75      */

76     protected List JavaDoc applicationResources = new ArrayList JavaDoc();
77     /**
78      * Version of this locale (used in optimistic locking)
79      */

80     protected Long JavaDoc version;
81
82     /**
83      * Localized title of this locale
84      */

85     protected Map JavaDoc title = new HashMap JavaDoc();
86
87     //~ Methods
88

89     /**
90      * Returns the identifier of locale based on standard (for example, en, ru, es, ...)
91      *
92      * @return locale identifier
93      * @struts.validator type="required"
94      * @struts.validator type="mask" msgkey="core.commons.errors.contentLocaleIdentifier"
95      * @struts.validator-args arg0resource="core.contentLocale.form.identifier"
96      * @struts.validator-var name="mask" value="^[a-z]{2}$"
97      * @struts.form-field
98      * @hibernate.id column="`identifier`" generator-class="assigned" unsaved-value="null" length="10"
99      */

100     public String JavaDoc getIdentifier() {
101         return identifier;
102     }
103
104     /**
105      * Sets the identifier of locale
106      *
107      * @param identifier the identifier of locale
108      * @see ContentLocale#getIdentifier()
109      */

110     public void setIdentifier(String JavaDoc identifier) {
111         this.identifier = identifier;
112     }
113
114     /**
115      * Returns a mapping from locales to titles of this locale (title per each locale)
116      *
117      * @return mapping from locales to titles
118      * @struts.form-field
119      * @hibernate.map table="`al_core_locale_title`" lazy="true" cascade="all" outer-join="false"
120      * @hibernate.collection-key column="`identifier`"
121      * @hibernate.collection-index column="`title_identifier`" type="string" length="10"
122      * @hibernate.collection-element type="string" column="`title`" not-null="false" length="252"
123      */

124     public Map JavaDoc getTitle() {
125         return title;
126     }
127
128     /**
129      * Sets a mapping from locales to titles of this locale (title per each locale)
130      *
131      * @param title mapping from locales to titles
132      */

133     public void setTitle(Map JavaDoc title) {
134         this.title = title;
135     }
136
137     /**
138      * Returns version of this content locale
139      *
140      * @return the version
141      * @struts.form-field
142      * @hibernate.version column="`version`" type="long" unsaved-value="null"
143      */

144     public Long JavaDoc getVersion() {
145         return version;
146     }
147
148     /**
149      * Sets version of this content locale
150      *
151      * @param version new version
152      */

153     public void setVersion(Long JavaDoc version) {
154         this.version = version;
155     }
156
157
158     /**
159      * Returns the list of content field values that correspond to this content locale
160      *
161      * @return the list of CFVs
162      * @hibernate.bag name="contentFieldValues" inverse="true" lazy="true" cascade="delete" outer-join="false"
163      * @hibernate.collection-key column="`locale_identifier`"
164      * @hibernate.collection-one-to-many class="com.blandware.atleap.model.core.ContentFieldValue"
165      */

166     protected List JavaDoc getContentFieldValues() {
167         return contentFieldValues;
168     }
169
170     /**
171      * Sets list of content field values that correspond to this content locale
172      *
173      * @param contentFieldValues the list of CFVs
174      */

175     protected void setContentFieldValues(List JavaDoc contentFieldValues) {
176         this.contentFieldValues = contentFieldValues;
177     }
178
179     /**
180      * Returns the list of content documents that correspond to this content locale
181      *
182      * @return the list of content documents
183      * @hibernate.bag name="contentDocuments" inverse="true" lazy="true" cascade="delete" outer-join="false"
184      * @hibernate.collection-key column="`locale_identifier`"
185      * @hibernate.collection-one-to-many class="com.blandware.atleap.model.core.ContentDocument"
186      */

187     protected List JavaDoc getContentDocuments() {
188         return contentDocuments;
189     }
190
191     /**
192      * Sets list of content documents that correspond to this content locale
193      *
194      * @param contentDocuments the list of content documents
195      */

196     protected void setContentDocuments(List JavaDoc contentDocuments) {
197         this.contentDocuments = contentDocuments;
198     }
199
200     /**
201      * Returns the list of application resources that correspond to this content locale
202      *
203      * @return the list of application resources
204      * @hibernate.bag name="applicationResources" inverse="true" lazy="true" cascade="delete" outer-join="false"
205      * @hibernate.collection-key column="`locale_identifier`"
206      * @hibernate.collection-one-to-many class="com.blandware.atleap.model.core.ApplicationResource"
207      */

208     protected List JavaDoc getApplicationResources() {
209         return applicationResources;
210     }
211
212     /**
213      * Sets list of application resources that correspond to this content locale
214      *
215      * @param applicationResources the list of application resources
216      */

217     protected void setApplicationResources(List JavaDoc applicationResources) {
218         this.applicationResources = applicationResources;
219     }
220
221     /**
222      * Returns <code>Boolean.TRUE</code> if this locale is default
223      *
224      * @return whether this locale is default
225      * @hibernate.property column="`default_instance`" not-null="true" type="true_false"
226      */

227     public Boolean JavaDoc getDefaultInstance() {
228         return defaultInstance;
229     }
230
231     /**
232      * Sets whether this content locale is default
233      *
234      * @param defaultInstance whether this locale will be default
235      */

236     public void setDefaultInstance(Boolean JavaDoc defaultInstance) {
237         this.defaultInstance = defaultInstance;
238     }
239
240     /**
241      * Returns <code>Boolean.TRUE</code> if this locale is active (and can be
242      * used)
243      *
244      * @return whether this locale is active
245      * @hibernate.property column="`active`" not-null="true" type="true_false"
246      */

247     public Boolean JavaDoc getActive() {
248         return active;
249     }
250
251     /**
252      * Returns <code>true</code> if this locale is active (and can be used)
253      *
254      * @return whether this locale is active
255      */

256     public boolean isActive() {
257         return active.booleanValue();
258     }
259
260     /**
261      * Sets whether this locale will be active
262      *
263      * @param active whether this locale will be active
264      */

265     public void setActive(Boolean JavaDoc active) {
266         this.active = active;
267     }
268
269     public boolean equals(Object JavaDoc o) {
270         if ( this == o ) {
271             return true;
272         }
273         if ( !(o instanceof ContentLocale) ) {
274             return false;
275         }
276
277         final ContentLocale contentLocale = (ContentLocale) o;
278
279         if ( identifier != null ? !identifier.equals(contentLocale.identifier) : contentLocale.identifier != null ) {
280             return false;
281         }
282
283         return true;
284     }
285
286     public int hashCode() {
287         return (identifier != null ? identifier.hashCode() : 0);
288     }
289
290     /**
291      * Compares this locale to another
292      *
293      * @param o Object to compare with. If this object is not an instance of ContentLocale, <code>java.lang.ClassCastException</code> will be thrown
294      * @return a negative integer, zero, or a positive integer as this locale identifier is less than,
295      * equal to, or greater than the identifier of specified locale.
296      * @see java.lang.Comparable#compareTo(Object)
297      */

298     public int compareTo(Object JavaDoc o) {
299         if ( o instanceof ContentLocale ) {
300             ContentLocale locale = (ContentLocale) o;
301             return this.identifier.compareToIgnoreCase(locale.getIdentifier());
302         } else {
303             throw new ClassCastException JavaDoc("Cannot compare instance of " + getClass().getName() + " to the instance of " + o.getClass().getName());
304         }
305     }
306
307     /**
308      * Returns shallow copy of this object
309      *
310      * @return Copy of this locale without linked collections
311      */

312     public ContentLocale shallowCopy() {
313         ContentLocale locale = new ContentLocale();
314         locale.setIdentifier(this.identifier);
315         // copy title
316
Map JavaDoc title = new HashMap JavaDoc();
317         for ( Iterator JavaDoc i = this.title.entrySet().iterator(); i.hasNext(); ) {
318             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
319             String JavaDoc key = (String JavaDoc) entry.getKey();
320             String JavaDoc value = (String JavaDoc) entry.getValue();
321             title.put(key, value);
322         }
323         locale.setTitle(title);
324         locale.setActive(this.active);
325         locale.setDefaultInstance(this.defaultInstance);
326         locale.setVersion(this.version);
327         return locale;
328     }
329 }
330
Popular Tags