1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.impl;
18 import java.util.Locale;
19
20 import org.apache.jetspeed.om.common.LocalizedField;
21 import org.apache.jetspeed.util.HashCodeBuilder;
22 import org.apache.jetspeed.util.JetspeedLongObjectID;
23 import org.apache.pluto.om.common.ObjectID;
24
25 /***
26 * LocalizedFieldImpl
27 * <br/>
28 * Implementation that represents a string value and the locale of that string
29 *
30 * @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
31 * @version $Id: LocalizedFieldImpl.java 516448 2007-03-09 16:25:47Z ate $
32 *
33 */
34 public class LocalizedFieldImpl implements LocalizedField
35 {
36 protected String value;
37 protected String name;
38 protected Locale locale;
39
40 protected long parentId;
41 protected JetspeedLongObjectID id;
42
43 public LocalizedFieldImpl()
44 {
45
46 }
47
48 public LocalizedFieldImpl(Locale locale, String value)
49 {
50 this.locale = locale;
51 this.value = value;
52 }
53
54
55
56
57 public Locale getLocale()
58 {
59 return locale;
60 }
61
62
63
64
65 public void setLocale(Locale locale)
66 {
67 this.locale = locale;
68 }
69
70
71
72
73 public String getValue()
74 {
75 return value;
76 }
77
78
79
80
81 public void setValue(String value)
82 {
83 this.value = value;
84 }
85
86 /***
87 *
88 */
89 public ObjectID getId()
90 {
91 return id;
92 }
93
94 public void setLanguage(String language)
95 {
96 if (language != null)
97 {
98 String[] localeArray = language.split("[-|_]");
99 String country = "";
100 String variant = "";
101 for (int i = 0; i < localeArray.length; i++)
102 {
103 if (i == 0)
104 {
105 language = localeArray[i];
106 }
107 else if (i == 1)
108 {
109 country = localeArray[i];
110 }
111 else if (i == 2)
112 {
113 variant = localeArray[i];
114 }
115 }
116
117 this.locale = new Locale(language, country, variant);
118 }
119 }
120
121 public String getLanguage()
122 {
123 if (this.locale != null)
124 {
125 return this.locale.toString();
126 }
127 return null;
128 }
129
130
131
132
133 public String getName()
134 {
135 return name;
136 }
137
138
139
140
141 public void setName(String name)
142 {
143 this.name = name;
144 }
145
146 public String toString()
147 {
148 return "Name: " + name + " Value: " + value + " Locale: " + locale;
149 }
150
151 public boolean equals(Object o)
152 {
153 boolean result = false;
154
155 if(o instanceof LocalizedFieldImpl && o != null)
156 {
157 LocalizedFieldImpl localField = (LocalizedFieldImpl)o;
158
159 result = (this.name == null) ? (localField.name == null) : (this.name.equals(localField.name));
160 result = result && ((this.value == null) ? (localField.value == null) : (this.value.equals(localField.value)));
161 result = result && ((this.locale == null) ? (localField.locale == null) : (this.locale.equals(localField.locale)));
162 }
163
164 return result;
165 }
166
167 /***
168 * @see java.lang.Object#hashCode()
169 */
170 public int hashCode()
171 {
172 HashCodeBuilder hasher = new HashCodeBuilder(27, 101);
173 hasher.append(name).append(value);
174 if(locale != null)
175 {
176 hasher.append(locale.getCountry()).append(locale.getLanguage()).append(locale.getVariant());
177 }
178 return hasher.toHashCode();
179 }
180 }