001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.model.Address;
021 import com.liferay.portal.model.User;
022
023 import java.util.Calendar;
024 import java.util.GregorianCalendar;
025
026
029 public class UserAttributes {
030
031
032
033 public static final String LIFERAY_COMPANY_ID = "liferay.company.id";
034
035 public static final String LIFERAY_USER_ID = "liferay.user.id";
036
037 public static final String USER_NAME_FULL = "user.name.full";
038
039
040
041 public static final String USER_BDATE = "user.bdate";
042
043 public static final String USER_BDATE_DAY = "user.bdate.ymd.day";
044
045 public static final String USER_BDATE_FRACTIONSECOND = "user.bdate.fractionsecond";
046
047 public static final String USER_BDATE_HOUR = "user.bdate.hms.hour";
048
049 public static final String USER_BDATE_MINUTE = "user.bdate.hms.minute";
050
051 public static final String USER_BDATE_MONTH = "user.bdate.ymd.month";
052
053 public static final String USER_BDATE_SECOND = "user.bdate.hms.second";
054
055 public static final String USER_BDATE_TIMEZONE = "user.bdate.timezone";
056
057 public static final String USER_BDATE_YEAR = "user.bdate.ymd.year";
058
059 public static final String USER_GENDER = "user.gender";
060
061 public static final String USER_EMPLOYER = "user.employer";
062
063 public static final String USER_DEPARTMENT = "user.department";
064
065 public static final String USER_JOBTITLE = "user.jobtitle";
066
067 public static final String USER_NAME_PREFIX = "user.name.prefix";
068
069 public static final String USER_NAME_GIVEN = "user.name.given";
070
071 public static final String USER_NAME_FAMILY = "user.name.family";
072
073 public static final String USER_NAME_MIDDLE = "user.name.middle";
074
075 public static final String USER_NAME_SUFFIX = "user.name.suffix";
076
077 public static final String USER_NAME_NICKNAME = "user.name.nickName";
078
079 public static final String USER_HOME_INFO_POSTAL_NAME = "user.home-info.postal.name";
080
081 public static final String USER_HOME_INFO_POSTAL_STREET = "user.home-info.postal.street";
082
083 public static final String USER_HOME_INFO_POSTAL_CITY = "user.home-info.postal.city";
084
085 public static final String USER_HOME_INFO_POSTAL_STATEPROV = "user.home-info.postal.stateprov";
086
087 public static final String USER_HOME_INFO_POSTAL_POSTALCODE = "user.home-info.postal.postalcode";
088
089 public static final String USER_HOME_INFO_POSTAL_COUNTRY = "user.home-info.postal.country";
090
091 public static final String USER_HOME_INFO_POSTAL_ORGANIZATION = "user.home-info.postal.organization";
092
093 public static final String USER_HOME_INFO_TELECOM_TELEPHONE_INTCODE = "user.home-info.telecom.telephone.intcode";
094
095 public static final String USER_HOME_INFO_TELECOM_TELEPHONE_LOCCODE = "user.home-info.telecom.telephone.loccode";
096
097 public static final String USER_HOME_INFO_TELECOM_TELEPHONE_NUMBER = "user.home-info.telecom.telephone.number";
098
099 public static final String USER_HOME_INFO_TELECOM_TELEPHONE_EXT = "user.home-info.telecom.telephone.ext";
100
101 public static final String USER_HOME_INFO_TELECOM_TELEPHONE_COMMENT = "user.home-info.telecom.telephone.comment";
102
103 public static final String USER_HOME_INFO_TELECOM_FAX_INTCODE = "user.home-info.telecom.fax.intcode";
104
105 public static final String USER_HOME_INFO_TELECOM_FAX_LOCCODE = "user.home-info.telecom.fax.loccode";
106
107 public static final String USER_HOME_INFO_TELECOM_FAX_NUMBER = "user.home-info.telecom.fax.number";
108
109 public static final String USER_HOME_INFO_TELECOM_FAX_EXT = "user.home-info.telecom.fax.ext";
110
111 public static final String USER_HOME_INFO_TELECOM_FAX_COMMENT = "user.home-info.telecom.fax.comment";
112
113 public static final String USER_HOME_INFO_TELECOM_MOBILE_INTCODE = "user.home-info.telecom.mobile.intcode";
114
115 public static final String USER_HOME_INFO_TELECOM_MOBILE_LOCCODE = "user.home-info.telecom.mobile.loccode";
116
117 public static final String USER_HOME_INFO_TELECOM_MOBILE_NUMBER = "user.home-info.telecom.mobile.number";
118
119 public static final String USER_HOME_INFO_TELECOM_MOBILE_EXT = "user.home-info.telecom.mobile.ext";
120
121 public static final String USER_HOME_INFO_TELECOM_MOBILE_COMMENT = "user.home-info.telecom.mobile.comment";
122
123 public static final String USER_HOME_INFO_TELECOM_PAGER_INTCODE = "user.home-info.telecom.pager.intcode";
124
125 public static final String USER_HOME_INFO_TELECOM_PAGER_LOCCODE = "user.home-info.telecom.pager.loccode";
126
127 public static final String USER_HOME_INFO_TELECOM_PAGER_NUMBER = "user.home-info.telecom.pager.number";
128
129 public static final String USER_HOME_INFO_TELECOM_PAGER_EXT = "user.home-info.telecom.pager.ext";
130
131 public static final String USER_HOME_INFO_TELECOM_PAGER_COMMENT = "user.home-info.telecom.pager.comment";
132
133 public static final String USER_HOME_INFO_ONLINE_EMAIL = "user.home-info.online.email";
134
135 public static final String USER_HOME_INFO_ONLINE_URI = "user.home-info.online.uri";
136
137 public static final String USER_BUSINESS_INFO_POSTAL_NAME = "user.business-info.postal.name";
138
139 public static final String USER_BUSINESS_INFO_POSTAL_STREET = "user.business-info.postal.street";
140
141 public static final String USER_BUSINESS_INFO_POSTAL_CITY = "user.business-info.postal.city";
142
143 public static final String USER_BUSINESS_INFO_POSTAL_STATEPROV = "user.business-info.postal.stateprov";
144
145 public static final String USER_BUSINESS_INFO_POSTAL_POSTALCODE = "user.business-info.postal.postalcode";
146
147 public static final String USER_BUSINESS_INFO_POSTAL_COUNTRY = "user.business-info.postal.country";
148
149 public static final String USER_BUSINESS_INFO_POSTAL_ORGANIZATION = "user.business-info.postal.organization";
150
151 public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_INTCODE = "user.business-info.telecom.telephone.intcode";
152
153 public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_LOCCODE = "user.business-info.telecom.telephone.loccode";
154
155 public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_NUMBER = "user.business-info.telecom.telephone.number";
156
157 public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_EXT = "user.business-info.telecom.telephone.ext";
158
159 public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_COMMENT = "user.business-info.telecom.telephone.comment";
160
161 public static final String USER_BUSINESS_INFO_TELECOM_FAX_INTCODE = "user.business-info.telecom.fax.intcode";
162
163 public static final String USER_BUSINESS_INFO_TELECOM_FAX_LOCCODE = "user.business-info.telecom.fax.loccode";
164
165 public static final String USER_BUSINESS_INFO_TELECOM_FAX_NUMBER = "user.business-info.telecom.fax.number";
166
167 public static final String USER_BUSINESS_INFO_TELECOM_FAX_EXT = "user.business-info.telecom.fax.ext";
168
169 public static final String USER_BUSINESS_INFO_TELECOM_FAX_COMMENT = "user.business-info.telecom.fax.comment";
170
171 public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_INTCODE = "user.business-info.telecom.mobile.intcode";
172
173 public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_LOCCODE = "user.business-info.telecom.mobile.loccode";
174
175 public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER = "user.business-info.telecom.mobile.number";
176
177 public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_EXT = "user.business-info.telecom.mobile.ext";
178
179 public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_COMMENT = "user.business-info.telecom.mobile.comment";
180
181 public static final String USER_BUSINESS_INFO_TELECOM_PAGER_INTCODE = "user.business-info.telecom.pager.intcode";
182
183 public static final String USER_BUSINESS_INFO_TELECOM_PAGER_LOCCODE = "user.business-info.telecom.pager.loccode";
184
185 public static final String USER_BUSINESS_INFO_TELECOM_PAGER_NUMBER = "user.business-info.telecom.pager.number";
186
187 public static final String USER_BUSINESS_INFO_TELECOM_PAGER_EXT = "user.business-info.telecom.pager.ext";
188
189 public static final String USER_BUSINESS_INFO_TELECOM_PAGER_COMMENT = "user.business-info.telecom.pager.comment";
190
191 public static final String USER_BUSINESS_INFO_ONLINE_EMAIL = "user.business-info.online.email";
192
193 public static final String USER_BUSINESS_INFO_ONLINE_URI = "user.business-info.online.uri";
194
195 public static final String USER_LOGIN_ID = "user.login.id";
196
197 public UserAttributes(User user) {
198 _user = user;
199
200
212 }
213
214 public String getValue(String name)
215 throws PortalException, SystemException {
216
217 if (name == null) {
218 return null;
219 }
220
221 if (name.equals(LIFERAY_COMPANY_ID)) {
222 return String.valueOf(_user.getCompanyId());
223 }
224 else if (name.equals(LIFERAY_USER_ID)) {
225 return String.valueOf(_user.getUserId());
226 }
227 else if (name.equals(USER_NAME_FULL)) {
228 return _user.getFullName();
229 }
230 else if (name.equals(USER_BDATE)) {
231 return _user.getBirthday().toString();
232 }
233 else if (name.equals(USER_BDATE_DAY)) {
234 String returnValue = null;
235
236 if (_user.getBirthday() != null) {
237 _calendar.setTime(_user.getBirthday());
238
239 returnValue = String.valueOf(_calendar.get(Calendar.DATE));
240 }
241
242 return returnValue;
243 }
244 else if (name.equals(USER_BDATE_FRACTIONSECOND)) {
245 String returnValue = null;
246
247 if (_user.getBirthday() != null) {
248 _calendar.setTime(_user.getBirthday());
249
250 returnValue = String.valueOf(
251 _calendar.get(Calendar.MILLISECOND));
252 }
253
254 return returnValue;
255 }
256 else if (name.equals(USER_BDATE_HOUR)) {
257 String returnValue = null;
258
259 if (_user.getBirthday() != null) {
260 _calendar.setTime(_user.getBirthday());
261
262 returnValue = String.valueOf(_calendar.get(Calendar.HOUR));
263 }
264
265 return returnValue;
266 }
267 else if (name.equals(USER_BDATE_MINUTE)) {
268 String returnValue = null;
269
270 if (_user.getBirthday() != null) {
271 _calendar.setTime(_user.getBirthday());
272
273 returnValue = String.valueOf(_calendar.get(Calendar.MINUTE));
274 }
275
276 return returnValue;
277 }
278 else if (name.equals(USER_BDATE_MONTH)) {
279 String returnValue = null;
280
281 if (_user.getBirthday() != null) {
282 _calendar.setTime(_user.getBirthday());
283
284 returnValue = String.valueOf(_calendar.get(Calendar.MONTH) + 1);
285 }
286
287 return returnValue;
288 }
289 else if (name.equals(USER_BDATE_SECOND)) {
290 String returnValue = null;
291
292 if (_user.getBirthday() != null) {
293 _calendar.setTime(_user.getBirthday());
294
295 returnValue = String.valueOf(_calendar.get(Calendar.SECOND));
296 }
297
298 return returnValue;
299 }
300 else if (name.equals(USER_BDATE_TIMEZONE)) {
301 String returnValue = null;
302
303 if (_user.getBirthday() != null) {
304 _calendar.setTime(_user.getBirthday());
305
306 returnValue = String.valueOf(
307 _calendar.get(Calendar.ZONE_OFFSET));
308 }
309 return returnValue;
310 }
311 else if (name.equals(USER_BDATE_YEAR)) {
312 String returnValue = null;
313
314 if (_user.getBirthday() != null) {
315 _calendar.setTime(_user.getBirthday());
316
317 returnValue = String.valueOf(_calendar.get(Calendar.YEAR));
318 }
319
320 return returnValue;
321 }
322 else if (name.equals(USER_GENDER)) {
323 return _user.isMale() ? "male" : "female";
324 }
325 else if (name.equals(USER_EMPLOYER)) {
326 return StringPool.BLANK;
327 }
328 else if (name.equals(USER_DEPARTMENT)) {
329 return StringPool.BLANK;
330 }
331 else if (name.equals(USER_JOBTITLE)) {
332 return _user.getJobTitle();
333 }
334 else if (name.equals(USER_NAME_PREFIX)) {
335 return StringPool.BLANK;
336 }
337 else if (name.equals(USER_NAME_GIVEN)) {
338 return _user.getFirstName();
339 }
340 else if (name.equals(USER_NAME_FAMILY)) {
341 return _user.getLastName();
342 }
343 else if (name.equals(USER_NAME_MIDDLE)) {
344 return _user.getMiddleName();
345 }
346 else if (name.equals(USER_NAME_SUFFIX)) {
347 return StringPool.BLANK;
348 }
349 else if (name.equals(USER_NAME_NICKNAME)) {
350 return _user.getScreenName();
351 }
352 else if (name.equals(USER_LOGIN_ID)) {
353 return _user.getScreenName();
354 }
355 else if (name.equals(USER_HOME_INFO_POSTAL_NAME)) {
356 return StringPool.BLANK;
357 }
358 else if (name.equals(USER_HOME_INFO_POSTAL_STREET)) {
359 if (_homeAddress != null) {
360 return _homeAddress.getStreet1();
361 }
362 else {
363 return StringPool.BLANK;
364 }
365 }
366 else if (name.equals(USER_HOME_INFO_POSTAL_CITY)) {
367 if (_homeAddress != null) {
368 return _homeAddress.getCity();
369 }
370 else {
371 return StringPool.BLANK;
372 }
373 }
374 else if (name.equals(USER_HOME_INFO_POSTAL_STATEPROV)) {
375 return StringPool.BLANK;
376 }
377 else if (name.equals(USER_HOME_INFO_POSTAL_POSTALCODE)) {
378 if (_homeAddress != null) {
379 return _homeAddress.getZip();
380 }
381 else {
382 return StringPool.BLANK;
383 }
384 }
385 else if (name.equals(USER_HOME_INFO_POSTAL_COUNTRY)) {
386 return StringPool.BLANK;
387 }
388 else if (name.equals(USER_HOME_INFO_POSTAL_ORGANIZATION)) {
389 return StringPool.BLANK;
390 }
391 else if (name.equals(USER_HOME_INFO_TELECOM_TELEPHONE_INTCODE)) {
392 return StringPool.BLANK;
393 }
394 else if (name.equals(USER_HOME_INFO_TELECOM_TELEPHONE_LOCCODE)) {
395 return StringPool.BLANK;
396 }
397 else if (name.equals(USER_HOME_INFO_TELECOM_TELEPHONE_NUMBER)) {
398 return StringPool.BLANK;
399 }
400 else if (name.equals(USER_HOME_INFO_TELECOM_TELEPHONE_EXT)) {
401 return StringPool.BLANK;
402 }
403 else if (name.equals(USER_HOME_INFO_TELECOM_TELEPHONE_COMMENT)) {
404 return StringPool.BLANK;
405 }
406 else if (name.equals(USER_HOME_INFO_TELECOM_FAX_INTCODE)) {
407 return StringPool.BLANK;
408 }
409 else if (name.equals(USER_HOME_INFO_TELECOM_FAX_LOCCODE)) {
410 return StringPool.BLANK;
411 }
412 else if (name.equals(USER_HOME_INFO_TELECOM_FAX_NUMBER)) {
413 return StringPool.BLANK;
414 }
415 else if (name.equals(USER_HOME_INFO_TELECOM_FAX_EXT)) {
416 return StringPool.BLANK;
417 }
418 else if (name.equals(USER_HOME_INFO_TELECOM_FAX_COMMENT)) {
419 return StringPool.BLANK;
420 }
421 else if (name.equals(USER_HOME_INFO_TELECOM_MOBILE_INTCODE)) {
422 return StringPool.BLANK;
423 }
424 else if (name.equals(USER_HOME_INFO_TELECOM_MOBILE_LOCCODE)) {
425 return StringPool.BLANK;
426 }
427 else if (name.equals(USER_HOME_INFO_TELECOM_MOBILE_NUMBER)) {
428 return StringPool.BLANK;
429 }
430 else if (name.equals(USER_HOME_INFO_TELECOM_MOBILE_EXT)) {
431 return StringPool.BLANK;
432 }
433 else if (name.equals(USER_HOME_INFO_TELECOM_MOBILE_COMMENT)) {
434 return StringPool.BLANK;
435 }
436 else if (name.equals(USER_HOME_INFO_TELECOM_PAGER_INTCODE)) {
437 return StringPool.BLANK;
438 }
439 else if (name.equals(USER_HOME_INFO_TELECOM_PAGER_LOCCODE)) {
440 return StringPool.BLANK;
441 }
442 else if (name.equals(USER_HOME_INFO_TELECOM_PAGER_NUMBER)) {
443 return StringPool.BLANK;
444 }
445 else if (name.equals(USER_HOME_INFO_TELECOM_PAGER_EXT)) {
446 return StringPool.BLANK;
447 }
448 else if (name.equals(USER_HOME_INFO_TELECOM_PAGER_COMMENT)) {
449 return StringPool.BLANK;
450 }
451 else if (name.equals(USER_HOME_INFO_ONLINE_EMAIL)) {
452 return _user.getEmailAddress();
453 }
454 else if (name.equals(USER_HOME_INFO_ONLINE_URI)) {
455 return StringPool.BLANK;
456 }
457 else if (name.equals(USER_BUSINESS_INFO_POSTAL_NAME)) {
458 return StringPool.BLANK;
459 }
460 else if (name.equals(USER_BUSINESS_INFO_POSTAL_STREET)) {
461 if (_bizAddress != null) {
462 return _bizAddress.getStreet1();
463 }
464 else {
465 return StringPool.BLANK;
466 }
467 }
468 else if (name.equals(USER_BUSINESS_INFO_POSTAL_CITY)) {
469 if (_bizAddress != null) {
470 return _bizAddress.getCity();
471 }
472 else {
473 return StringPool.BLANK;
474 }
475 }
476 else if (name.equals(USER_BUSINESS_INFO_POSTAL_STATEPROV)) {
477 return StringPool.BLANK;
478 }
479 else if (name.equals(USER_BUSINESS_INFO_POSTAL_POSTALCODE)) {
480 if (_bizAddress != null) {
481 return _bizAddress.getZip();
482 }
483 else {
484 return StringPool.BLANK;
485 }
486 }
487 else if (name.equals(USER_BUSINESS_INFO_POSTAL_COUNTRY)) {
488 return StringPool.BLANK;
489 }
490 else if (name.equals(USER_BUSINESS_INFO_POSTAL_ORGANIZATION)) {
491 return StringPool.BLANK;
492 }
493 else if (name.equals(USER_BUSINESS_INFO_TELECOM_TELEPHONE_INTCODE)) {
494 return StringPool.BLANK;
495 }
496 else if (name.equals(USER_BUSINESS_INFO_TELECOM_TELEPHONE_LOCCODE)) {
497 return StringPool.BLANK;
498 }
499 else if (name.equals(USER_BUSINESS_INFO_TELECOM_TELEPHONE_NUMBER)) {
500 return StringPool.BLANK;
501 }
502 else if (name.equals(USER_BUSINESS_INFO_TELECOM_TELEPHONE_EXT)) {
503 return StringPool.BLANK;
504 }
505 else if (name.equals(USER_BUSINESS_INFO_TELECOM_TELEPHONE_COMMENT)) {
506 return StringPool.BLANK;
507 }
508 else if (name.equals(USER_BUSINESS_INFO_TELECOM_FAX_INTCODE)) {
509 return StringPool.BLANK;
510 }
511 else if (name.equals(USER_BUSINESS_INFO_TELECOM_FAX_LOCCODE)) {
512 return StringPool.BLANK;
513 }
514 else if (name.equals(USER_BUSINESS_INFO_TELECOM_FAX_NUMBER)) {
515 return StringPool.BLANK;
516 }
517 else if (name.equals(USER_BUSINESS_INFO_TELECOM_FAX_EXT)) {
518 return StringPool.BLANK;
519 }
520 else if (name.equals(USER_BUSINESS_INFO_TELECOM_FAX_COMMENT)) {
521 return StringPool.BLANK;
522 }
523 else if (name.equals(USER_BUSINESS_INFO_TELECOM_MOBILE_INTCODE)) {
524 return StringPool.BLANK;
525 }
526 else if (name.equals(USER_BUSINESS_INFO_TELECOM_MOBILE_LOCCODE)) {
527 return StringPool.BLANK;
528 }
529 else if (name.equals(USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER)) {
530 return StringPool.BLANK;
531 }
532 else if (name.equals(USER_BUSINESS_INFO_TELECOM_MOBILE_EXT)) {
533 return StringPool.BLANK;
534 }
535 else if (name.equals(USER_BUSINESS_INFO_TELECOM_MOBILE_COMMENT)) {
536 return StringPool.BLANK;
537 }
538 else if (name.equals(USER_BUSINESS_INFO_TELECOM_PAGER_INTCODE)) {
539 return StringPool.BLANK;
540 }
541 else if (name.equals(USER_BUSINESS_INFO_TELECOM_PAGER_LOCCODE)) {
542 return StringPool.BLANK;
543 }
544 else if (name.equals(USER_BUSINESS_INFO_TELECOM_PAGER_NUMBER)) {
545 return StringPool.BLANK;
546 }
547 else if (name.equals(USER_BUSINESS_INFO_TELECOM_PAGER_EXT)) {
548 return StringPool.BLANK;
549 }
550 else if (name.equals(USER_BUSINESS_INFO_TELECOM_PAGER_COMMENT)) {
551 return StringPool.BLANK;
552 }
553 else if (name.equals(USER_BUSINESS_INFO_ONLINE_EMAIL)) {
554 return _user.getEmailAddress();
555 }
556 else if (name.equals(USER_BUSINESS_INFO_ONLINE_URI)) {
557 return StringPool.BLANK;
558 }
559 else {
560 return null;
561 }
562 }
563
564 private User _user;
565 private Address _homeAddress;
566 private Address _bizAddress;
567 private Calendar _calendar = new GregorianCalendar();
568
569 }