1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.service.protocol;
import java.net.*;
import java.util.*;
import org.jitsi.util.*;
/**
* The ServerStoredDetails class contains a relatively large set of details that
* various protocols may support storing online. Each detail is represented by
* its own inner class that could be instantiated by either the protocol
* provider implementation (for representing details returned by the server) or
* by the using service (e.g. the UIService, when representing details that the
* local user would like to set for the current account).
* <p>
* All detail classes inherit from the GenericDetail class, extending it to
* represent more and more concrete details. The WorkAddressDetail for example,
* meant to represent a postal work address, extends the AddressDetailClass
* which is meant for representing all kinds of postal addresses. The
* AddressDetailClass on its turn extends the StringDetail which itself inherits
* from the GenericDetailClass.
* <p>
* When creating details that do not exist here (which you'll probably have to
* do at one point or another) you are encouraged to extend from the most
* concrete address possible so that your detail could be meaningfully handled
* by the User Interface.
* <p>
* Let's assume for example that we'd like to add a BirthPlaceAddressDetail,
* indicating place of birth. The BirthPlaceAddress detail class should extend
* the AddressDetail class so that the GUI could understand that this is an
* address and visualize it appropriately. The same goes for variations of an
* EmailAddressDetail or any other detail having anything to do with a detail
* represented in this class.
* <p>
* All details have a detailValue and a displayName as well as get methods that
* would give you (read-only) access to them. Most classes extending the
* GenericDetail to something more meaningful would provide additional accessors
* allowing you to retrieve the value casted to its native class.
* <p>
* Detail names may be used when visualizing the detail (however, keep in mind
* that you should leave space for internationalization when doing so).
* <p>
* This class is meant for usage with the OperationSetServerStoredAccountInfo
* and OperationSetServerStoredContactInfo operation sets.
*
* @author Emil Ivov
*/
public class ServerStoredDetails
{
/**
* A generic detail used as the root of all other server stored details.
* This class should be extended or instantiated by implementors with the
* purpose of representing details not defined here.
*/
public static class GenericDetail
{
protected Object value = null;
protected String detailDisplayName = null;
/**
* Instantiates this detail setting its value and display name
* accordingly.
* @param detailDisplayName a display name that may be used as a
* description when visualizing the value of the detail
* @param value the value of the detail.
*/
public GenericDetail(String detailDisplayName, Object value)
{
this.value = value;
this.detailDisplayName = detailDisplayName;
}
/**
* Returns the value of the detail.
* @return the value of the detail.
*/
public Object getDetailValue()
{
return value;
}
/**
* Returns a display name that may be used as a description when
* visualizing the value of the detail (make sure you don't use this
* string in internationalized versions).
* @return the detail's display (descriptive) name.
*/
public String getDetailDisplayName()
{
return detailDisplayName;
}
/**
* Returns a String representation of the detail using both its value
* and display name.
* @return a String representation of the detail using both its value
* and display name.
*/
@Override
public String toString()
{
return value == null ? "": value.toString();
}
/**
* Compares two GenericDetails according
* their DetailDisplayName and Value
*
* @param obj Object expected GenericDetail otherwise return false
* @return <tt>true</tt> if this object has the same display name and
* value as <tt>obj</tt> and false otherwise
*/
@Override
public boolean equals(Object obj)
{
if(!(obj instanceof GenericDetail))
return false;
if(this == obj)
{
return true;
}
GenericDetail other = (GenericDetail)obj;
if(this.detailDisplayName != null // equals DisplayName
&& other.getDetailDisplayName() != null
&& this.detailDisplayName.equals(other.getDetailDisplayName()) &&
// equals not null values
((this.value != null
&& other.getDetailValue() != null
&& this.value.equals(other.getDetailValue()))
||
// or both values are null / empty
(StringUtils.isNullOrEmpty((String)this.value)
&& StringUtils.isNullOrEmpty((String)other.getDetailValue()))))
return true;
else
return false;
}
}
/**
* A generic detail that should be used (extended) when representing details
* with a String content.
*/
public static class StringDetail extends GenericDetail
{
public StringDetail(String detailDisplayName, String value)
{
super(detailDisplayName, value);
}
public String getString()
{
return (String)value;
}
}
//---------------------- physical addresses -----------------------------------
/**
* A detail representing an address (street and street/house number).
*/
public static class AddressDetail extends StringDetail
{
public AddressDetail(String address)
{
super("Address", address);
}
public String getAddress()
{
return getString();
}
}
/**
* A detail representing a street name and number associated with a work
* address.
*/
public static class WorkAddressDetail extends AddressDetail
{
public WorkAddressDetail(String address)
{
super(address);
}
}
/**
* A City name associated with a (home) address.
*/
public static class CityDetail extends StringDetail
{
public CityDetail(String cityName)
{
super("City", cityName);
}
public String getCity()
{
return getString();
}
}
/**
* A City name associated with a work address.
*/
public static class WorkCityDetail extends CityDetail
{
public WorkCityDetail(String cityName)
{
super(cityName);
}
}
/**
* The name of a state/province/region associated with a (home) address.
*/
public static class ProvinceDetail extends StringDetail
{
public ProvinceDetail(String province)
{
super("Region/Province/State", province);
}
public String getProvince()
{
return getString();
}
}
/**
* The name of a state/province/region associated with a work address.
*/
public static class WorkProvinceDetail extends ProvinceDetail
{
public WorkProvinceDetail(String workProvince)
{
super(workProvince);
}
}
/**
* A postal or ZIP code associated with a (home) address.
*/
public static class PostalCodeDetail extends StringDetail
{
public PostalCodeDetail(String postalCode)
{
super("Postal/Zip Code", postalCode);
}
public String getPostalCode()
{
return getString();
}
}
/**
* A postal or ZIP code associated with a work address.
*/
public static class WorkPostalCodeDetail extends PostalCodeDetail
{
public WorkPostalCodeDetail(String postalCode)
{
super(postalCode);
}
}
//------------------------------ LOCALE DETAILS --------------------------------
/**
* A generic detail that should be used (extended) when representing details
* that have anything to do with locales (countries, languages, etc). Most
* of the locales field could be ignored when extending the class. When
* representing a country for example we'd only be using the fields
* concerning the country.
*/
public static class LocaleDetail extends GenericDetail
{
public LocaleDetail(String detailDisplayName, Locale locale)
{
super(detailDisplayName, locale);
}
public Locale getLocale()
{
return (Locale)getDetailValue();
}
}
/**
* A detail representing a country of residence for the corresponding
* subject.
*/
public static class CountryDetail extends LocaleDetail
{
public CountryDetail(Locale locale)
{
super("Country", locale);
}
public CountryDetail(String country)
{
super("Country", null);
value = country;
}
public Locale getLocale()
{
if(value instanceof Locale)
return (Locale)value;
else
return null;
}
}
/**
* The name of a country associated with a work address.
*/
public static class WorkCountryDetail extends CountryDetail
{
public WorkCountryDetail(Locale locale)
{
super(locale);
}
public WorkCountryDetail(String country)
{
super(country);
}
}
//-------------------------------- Language ------------------------------------
/**
* A locale detail indicating a language spoken by the corresponding Contact.
*/
public static class SpokenLanguageDetail extends LocaleDetail
{
public SpokenLanguageDetail(Locale language)
{
super("Language", language);
}
}
//------------------------- phones --------------------------------------------
/**
* A generic detail used for representing a (personal) phone number.
*/
public static class PhoneNumberDetail extends StringDetail
{
public PhoneNumberDetail(String number)
{
super("Phone", number);
}
public String getNumber()
{
return getString();
}
}
/**
* A detail used for representing a work phone number.
*/
public static class WorkPhoneDetail extends PhoneNumberDetail
{
public WorkPhoneDetail(String workPhone)
{
super(workPhone);
super.detailDisplayName = "Work Phone";
}
}
/**
* A detail used for representing a (personal) mobile phone number.
*/
public static class MobilePhoneDetail extends PhoneNumberDetail
{
public MobilePhoneDetail(String privateMobile)
{
super(privateMobile);
super.detailDisplayName = "Mobile Phone";
}
}
/**
* A detail used for representing a work mobile phone number.
*/
public static class WorkMobilePhoneDetail extends MobilePhoneDetail
{
public WorkMobilePhoneDetail(String workMobile)
{
super(workMobile);
}
}
/**
* A Fax number.
*/
public static class FaxDetail extends PhoneNumberDetail
{
public FaxDetail(String number)
{
super(number);
super.detailDisplayName = "Fax";
}
}
/**
* A detail used for representing a video phone number.
*/
public static class VideoDetail extends PhoneNumberDetail
{
public VideoDetail(String number)
{
super(number);
super.detailDisplayName = "Video";
}
}
/**
* A detail used for representing a work video phone number.
*/
public static class WorkVideoDetail extends VideoDetail
{
public WorkVideoDetail(String number)
{
super(number);
}
}
/**
* A Pager number.
*/
public static class PagerDetail extends PhoneNumberDetail
{
public PagerDetail(String number)
{
super(number);
super.detailDisplayName = "Pager";
}
}
//----------------------------- web page ---------------------------------------
/**
* A generic detail representing any url
*/
public static class URLDetail extends GenericDetail
{
public URLDetail(String name, URL url)
{
super(name, url);
}
public URL getURL()
{
return (URL)getDetailValue();
}
/**
* Compares two URLDetails according their name
* and URLs
*
* @param obj Object expected URLDetail otherwise return false
* @return <tt>true</tt> if this object has the same name and
* URL value as <tt>obj</tt> and false otherwise
*/
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof URLDetail))
return false;
if (this == obj)
{
return true;
}
URLDetail other = (URLDetail)obj;
boolean equalsDisplayName =
this.detailDisplayName != null
&& other.getDetailDisplayName() != null
&& this.detailDisplayName.equals(other.getDetailDisplayName());
boolean equalValues =
this.value != null
&& other.getDetailValue() != null
&& this.value.equals(other.getDetailValue());
boolean bothNullValues =
this.value == null && other.value == null;
if (equalsDisplayName && (equalValues || bothNullValues))
return true;
else
return false;
}
}
/**
* A personal web page.
*/
public static class WebPageDetail extends URLDetail
{
public WebPageDetail(URL url)
{
super("Web Page", url);
}
}
/**
* A web page associated with the subject's principal occupation (work).
*/
public static class WorkPageDetail extends WebPageDetail
{
public WorkPageDetail(URL url)
{
super(url);
}
}
//--------------------------- Binary -------------------------------------------
/**
* A generic detail used for representing binary content such as photos
* logos, avatars ....
*/
public static class BinaryDetail extends GenericDetail
{
public BinaryDetail(String displayDetailName, byte[] bytes)
{
super(displayDetailName, bytes);
}
public byte[] getBytes()
{
return (byte[])getDetailValue();
}
/**
* Compares two BinaryDetails according their DetailDisplayName
* and the result of invoking their getBytes() methods.
*
* @param obj Object expected BinaryDetail otherwise return false
* @return <tt>true</tt> if this object has the same display name and
* value as <tt>obj</tt> and false otherwise
*/
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof BinaryDetail))
return false;
if (this == obj)
{
return true;
}
BinaryDetail other = (BinaryDetail)obj;
boolean equalsDisplayName =
this.detailDisplayName != null
&& other.getDetailDisplayName() != null
&& this.detailDisplayName.equals(other.getDetailDisplayName());
boolean equalsNotNull =
this.value != null
&& other.getDetailValue() != null
&& Arrays.equals(this.getBytes(), other.getBytes());
boolean nullOrEmpty =
(this.value == null || this.getBytes().length == 0)
&& (other.getDetailValue() == null
|| other.getBytes().length == 0);
if (equalsDisplayName && (equalsNotNull || nullOrEmpty))
return true;
else
return false;
}
}
/**
* A detail containing any contact related images.
*/
public static class ImageDetail extends BinaryDetail
{
public ImageDetail(String detailDisplayName, byte[] image)
{
super(detailDisplayName, image);
}
}
//-------------------------- Names ---------------------------------------------
/**
* A generic detail representing any kind of name.
*/
public static class NameDetail extends StringDetail
{
public NameDetail(String detailDisplayName, String name)
{
super(detailDisplayName, name);
}
public String getName()
{
return getString();
}
}
/**
* The name of the organization (company, ngo, university, hospital or other)
* employing the corresponding contact.
*/
public static class WorkOrganizationNameDetail extends NameDetail
{
public WorkOrganizationNameDetail(String workOrganizationName)
{
super("Work Organization Name", workOrganizationName);
}
}
/**
* A first, given name.
*/
public static class FirstNameDetail extends NameDetail
{
public FirstNameDetail(String firstName)
{
super("First Name", firstName);
}
}
/**
* A Middle (father's) name.
*/
public static class MiddleNameDetail extends NameDetail
{
public MiddleNameDetail(String middleName)
{
super("Middle Name", middleName);
}
}
/**
* A last (family) name.
*/
public static class LastNameDetail extends NameDetail
{
public LastNameDetail(String lastName)
{
super("Last Name", lastName);
}
}
/**
* The name that should be displayed to identify the information author.
*/
public static class DisplayNameDetail extends NameDetail
{
public DisplayNameDetail(String name)
{
super("Display Name", name);
}
}
/**
* An informal name (nickname) used for referring to the subject.
*/
public static class NicknameDetail extends NameDetail
{
public NicknameDetail(String name)
{
super("Nickname", name);
}
}
/**
* A bi-state detail indicating a gender. Constructor is private and the only
* possible instances are GenderDetail.MALE and GenderDetail.FEMALE
* construction.
*/
public static class GenderDetail extends StringDetail
{
public static final GenderDetail MALE = new GenderDetail("Male");
public static final GenderDetail FEMALE = new GenderDetail("Female");
public GenderDetail(String gender)
{
super("Gender", gender);
}
/**
* Returns a "Male" or "Female" string.
* @return a String with a "Male" or "Female" contents
*/
public String getGender()
{
return getString();
}
}
//-------------------------------- Date & Time ---------------------------------
/**
* A generic detail meant to represent any date (calendar) associated details.
* Protocols that support separate fields for year, month, day and time, or
* even age should try their best to convert to a date (setting to 0
* all unknown details).
*/
public static class CalendarDetail extends GenericDetail
{
public CalendarDetail(String detailDisplayName, Calendar date)
{
super(detailDisplayName, date);
}
public Calendar getCalendar()
{
return (Calendar)getDetailValue();
}
}
/**
* A complete birth date.
*/
public static class BirthDateDetail extends CalendarDetail
{
public BirthDateDetail(Calendar date)
{
super("Birth Date", date);
}
/**
* Compares two BirthDateDetails according to their
* Calender's year, month and day.
*
* @param obj Object expected BirthDateDetail otherwise return false
* @return <tt>true</tt> if this object has the same value as
* <tt>obj</tt> and false otherwise
*/
@Override
public boolean equals(Object obj)
{
if(!(obj instanceof BirthDateDetail))
return false;
if(this == obj)
{
return true;
}
BirthDateDetail other = (BirthDateDetail)obj;
// both null dates
if (this.value == null && other.getDetailValue() == null)
return true;
if (this.value != null && other.getDetailValue() != null)
{
boolean yearEquals =
((Calendar)this.value).get(Calendar.YEAR) ==
((Calendar)other.value).get(Calendar.YEAR);
boolean monthEquals =
((Calendar)this.value).get(Calendar.MONTH) ==
((Calendar)other.value).get(Calendar.MONTH);
boolean dayEquals =
((Calendar)this.value).get(Calendar.DAY_OF_MONTH) ==
((Calendar)other.value).get(Calendar.DAY_OF_MONTH);
return yearEquals && monthEquals && dayEquals;
}
else
return false;
}
}
/**
* A generic detail meant to represent the time zone associated with the
* corresponding contact and that could be extended to represent other
* time zone related details.
*/
public static class TimeZoneDetail extends GenericDetail
{
public TimeZoneDetail(String displayDetailName, TimeZone timeZone)
{
super(displayDetailName, timeZone);
}
public TimeZone getTimeZone()
{
return (TimeZone)getDetailValue();
}
}
//------------------------------- E-Mails ------------------------------------
/**
* Represents a (personal) email address.
*/
public static class EmailAddressDetail extends StringDetail
{
public EmailAddressDetail(String value)
{
this("e-mail", value);
}
protected EmailAddressDetail(String detailDisplayName, String value)
{
super(detailDisplayName, value);
}
public String getEMailAddress()
{
return getString();
}
}
/**
* Represents a (personal) email address.
*/
public static class WorkEmailAddressDetail extends EmailAddressDetail
{
public WorkEmailAddressDetail(String value)
{
super("Work e-mail", value);
}
}
//----------------------------- Interests -------------------------------------
/**
* Represents a personal interest or hobby.
*/
public static class InterestDetail extends StringDetail
{
public InterestDetail(String value)
{
super("Interest", value);
}
public String getInterest()
{
return getString();
}
}
//---------------------------- Numbers -----------------------------------------
/**
* A generic detail that should be used (extended) when representing any
* numbers.
*/
public static class NumberDetail extends GenericDetail
{
public NumberDetail(String detailName, java.math.BigDecimal value)
{
super(detailName, value);
}
public java.math.BigDecimal getNumber()
{
return (java.math.BigDecimal)getDetailValue();
}
}
//---------------------------- Numbers -----------------------------------------
/**
* A generic detail that should be used (extended) when representing any
* boolean values.
*/
public static class BooleanDetail
extends GenericDetail
{
public BooleanDetail(String detailName, boolean value)
{
super(detailName, new Boolean(value));
}
public boolean getBoolean()
{
return ((Boolean)getDetailValue()).booleanValue();
}
}
//---------------------------- Others ------------------------------------------
/**
* A job title.
*/
public static class JobTitleDetail extends StringDetail
{
public JobTitleDetail(String jobTitle)
{
super("Job Title", jobTitle);
}
}
/**
* Represents a (personal) "about me" short description.
*/
public static class AboutMeDetail extends StringDetail
{
public AboutMeDetail(String description)
{
super("Description", description);
}
}
}
|