Source code: nectar/view/PersonView.java
1 /*
2 Copyright (C) 2003 Kai Schutte
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 * PersonView.java
19 *
20 * Created on March 19, 2003, 4:27 PM
21 */
22
23 package nectar.view;
24
25 import nectar.record.PersonRecord;
26 import nectar.record.RecordInvalidInputException;
27 import java.util.Date;
28 import java.text.SimpleDateFormat;
29 import java.util.Locale;
30 import java.util.Calendar;
31 import java.text.ParseException;
32
33
34 /**
35 *
36 * @author Kai Schutte skander@skander.com
37 */
38 public class PersonView extends RecordView {
39 /** Creates a new instance of PersonView */
40 public PersonView(PersonRecord record) {
41 super(record);
42 }
43
44 public String getAuthlevel() {
45 return ((PersonRecord)record).getAuthlevel();
46 }
47
48 public void setAuthlevel(String value) throws RecordInvalidInputException {
49 ((PersonRecord)record).setAuthlevel(value);
50 }
51
52 public String getNameFirst() {
53 String s = ((PersonRecord)record).getNameFirst();
54 if (s == null)
55 return new String();
56 else
57 return s;
58 }
59
60 public void setNameFirst(String value) throws RecordInvalidInputException {
61 ((PersonRecord)record).setNameFirst(value);
62 }
63
64 public String getNameInitial() {
65 String s = ((PersonRecord)record).getNameInitial();
66 if (s == null)
67 return new String();
68 else
69 return s;
70 }
71
72 public void setNameInitial(String value) throws RecordInvalidInputException {
73 ((PersonRecord)record).setNameInitial(value);
74 }
75
76 public String getNamePublic() {
77 String s = ((PersonRecord)record).getNamePublic();
78 if (s == null)
79 return new String();
80 else
81 return s;
82 }
83
84 public void setNameLast(String value) throws RecordInvalidInputException {
85 ((PersonRecord)record).setNameLast(value);
86 }
87
88 public String getNameLast() {
89 String s = ((PersonRecord)record).getNameLast();
90 if (s == null)
91 return new String();
92 else
93 return s;
94 }
95
96 public void setNamePublic(String value) throws RecordInvalidInputException {
97 ((PersonRecord)record).setNamePublic(value);
98 }
99
100
101 public String getLogin() {
102 String s = ((PersonRecord)record).getLogin();
103 if (s == null)
104 return new String();
105 else
106 return s;
107 }
108
109 public void setLogin(String value) throws RecordInvalidInputException {
110 ((PersonRecord)record).setLogin(value);
111 }
112
113 public String getLastLogin() {
114 Date date = ((PersonRecord)record).getLastLogin();
115 if (date == null) {
116 return new String();
117 }
118 if (locale == null) {
119 locale = Locale.getDefault();
120 }
121 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm ZZ", locale);
122 return sdf.format(date);
123 }
124
125 public String[] getLastLoginAgo() {
126 Date date = ((PersonRecord)record).getLastLogin();
127 if (date == null) {
128 return durationToString(-1);
129 }
130
131 long now = Calendar.getInstance().getTimeInMillis();
132 long duration = (now - date.getTime())/1000;
133 return durationToString(duration);
134 }
135
136 public void setLastLogin(String value) throws RecordInvalidInputException {
137 throw new RecordInvalidInputException("The LastLogin field is an internal value and cannot be modified by View-based calls.");
138 }
139
140 public String getLastHost() {
141 String s = ((PersonRecord)record).getLastHost();
142 if (s == null)
143 return new String();
144 else
145 return s;
146 }
147
148 public void setLastHost() throws RecordInvalidInputException {
149 throw new RecordInvalidInputException("The LastHost field is an internal value and cannot be modified by View-based calls.");
150 }
151
152 public String getPhone() {
153 String s = ((PersonRecord)record).getPhone();
154 if (s == null)
155 return new String();
156 else
157 return s;
158 }
159
160 public void setPhone(String value) throws RecordInvalidInputException {
161 ((PersonRecord)record).setPhone(value);
162 }
163
164 public String getFax() {
165 String s = ((PersonRecord)record).getFax();
166 if (s == null)
167 return new String();
168 else
169 return s;
170 }
171
172 public void setFax(String value) throws RecordInvalidInputException {
173 ((PersonRecord)record).setFax(value);
174 }
175
176 public String getEmail() {
177 String s = ((PersonRecord)record).getEmail();
178 if (s == null)
179 return new String();
180 else
181 return s;
182 }
183
184 public void setEmail(String value) throws RecordInvalidInputException {
185 ((PersonRecord)record).setEmail(value);
186 }
187
188 public String getPrefContactMe() {
189 return ((PersonRecord)record).getPrefContactMe();
190 }
191
192 public void setPrefContactMe(String value) throws RecordInvalidInputException {
193 ((PersonRecord)record).setPrefContactMe(value);
194 }
195
196 public String getPrefWantNewsletter() {
197 Boolean b = ((PersonRecord)record).getPrefWantNewsletter();
198 if (b == null) {
199 return null;
200 } else if (b.booleanValue()) {
201 return "yes";
202 } else {
203 return "no";
204 }
205 }
206
207 public void setPrefWantNewsletter(String value) throws RecordInvalidInputException {
208 if (value != null) {
209 if (value == "yes")
210 ((PersonRecord)record).setPrefWantNewsletter(new Boolean(true));
211 else if (value == "no")
212 ((PersonRecord)record).setPrefWantNewsletter(new Boolean(false));
213 else
214 throw new RecordInvalidInputException();
215 } else {
216 throw new RecordInvalidInputException();
217 }
218 }
219
220 public String getPrefCurrency() {
221 return ((PersonRecord)record).getPrefCurrency();
222 }
223
224 public void setPrefCurrency(String value) throws RecordInvalidInputException {
225 ((PersonRecord)record).setPrefCurrency(value);
226 }
227
228 public final String getPrefUnit() {
229 return ((PersonRecord)record).getPrefUnit();
230 }
231
232 public final void setPrefUnit(String s) throws RecordInvalidInputException {
233 ((PersonRecord)record).setPrefUnit(s);
234 }
235
236 public final String getPrefLanguage() {
237 return ((PersonRecord)record).getPrefLanguage();
238 }
239
240 public final void setPrefLanguage(String s) throws RecordInvalidInputException {
241 ((PersonRecord)record).setPrefLanguage(s);
242 }
243
244 public final String getPrefShowInPublic() {
245 Boolean b = ((PersonRecord)record).getPrefShowInPublic();
246 if (b == null) {
247 return null;
248 } else if (b.booleanValue()) {
249 return "yes";
250 } else {
251 return "no";
252 }
253 }
254
255 public final void setPrefShowInPublic(String value) throws RecordInvalidInputException {
256 if (value != null) {
257 if (value == "yes")
258 ((PersonRecord)record).setPrefShowInPublic(new Boolean(true));
259 else if (value == "no")
260 ((PersonRecord)record).setPrefShowInPublic(new Boolean(false));
261 else
262 throw new RecordInvalidInputException();
263 } else {
264 throw new RecordInvalidInputException();
265 }
266 }
267
268 public String getBirthday() {
269 Date d = ((PersonRecord)record).getBirthday();
270 if (d == null) {
271 return new String();
272 }
273 SimpleDateFormat sdf;
274 if (locale == null) {
275 sdf = new SimpleDateFormat("dd MMMM yyyy");
276 } else {
277 sdf = new SimpleDateFormat("dd MMMM yyyy", locale);
278 }
279 return sdf.format(d);
280 }
281
282 public void setBirthday(String s) throws RecordInvalidInputException {
283 Date d;
284 try {
285 SimpleDateFormat sdf;
286 if (locale == null) {
287 sdf = new SimpleDateFormat("dd MMMM yyyy");
288 } else {
289 sdf = new SimpleDateFormat("dd MMMM yyyy", locale);
290 }
291 d = sdf.parse(s);
292 } catch (ParseException e) {
293 throw new RecordInvalidInputException();
294 }
295 ((PersonRecord)record).setBirthday(d);
296 }
297
298 public final String getDescription() {
299 return ((PersonRecord)record).getDescription();
300 }
301
302 public final void setDescription(String s) throws RecordInvalidInputException {
303 ((PersonRecord)record).setDescription(s);
304 }
305 }