Debian Codegraph @

src/main/java/ezvcard/property/Member.java

raw symbols SCIP
1 package ezvcard.property;
2
3 import java.util.List;
4
5 import ezvcard.SupportedVersions;
6 import ezvcard.VCard;
7 import ezvcard.VCardVersion;
8 import ezvcard.ValidationWarning;
9 import ezvcard.parameter.Pid;
10 import ezvcard.util.TelUri;
11
12 /*
13 Copyright (c) 2012-2023, Michael Angstadt
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18
19 1. Redistributions of source code must retain the above copyright notice, this
20 list of conditions and the following disclaimer.
21 2. Redistributions in binary form must reproduce the above copyright notice,
22 this list of conditions and the following disclaimer in the documentation
23 and/or other materials provided with the distribution.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
29 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36 The views and conclusions contained in the software and documentation are those
37 of the authors and should not be interpreted as representing official policies,
38 either expressed or implied, of the FreeBSD Project.
39 */
40
41 /**
42 * <p>
43 * Defines the members that make up the group. This property can only be used if
44 * the vCard's {@link Kind} property is set to "group".
45 * </p>
46 *
47 * <p>
48 * <b>Code sample</b>
49 * </p>
50 *
51 * <pre class="brush:java">
52 * VCard vcard = new VCard();
53 *
54 * //kind property must be set to "group" in order to add members
55 * vcard.setKind(Kind.group());
56 *
57 * //static factory methods
58 * Member member = Member.email("[email protected]");
59 * vcard.addMember(member);
60 *
61 * //reference another vCard by putting its UID property here
62 * member = new Member("urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af");
63 * vcard.addMember(member);
64 * </pre>
65 *
66 * <p>
67 * <b>Property name:</b> {@code MEMBER}
68 * </p>
69 * <p>
70 * <b>Supported versions:</b> {@code 4.0}
71 * </p>
72 * @author Michael Angstadt
73 * @see <a href="http://tools.ietf.org/html/rfc6350#page-41">RFC 6350 p.41</a>
74 */
75 @SupportedVersions(VCardVersion.V4_0)
76 public class Member extends UriProperty implements HasAltId {
77 /**
78 * Creates a member property.
79 * @param uri the URI representing the member
80 */
81 public Member(String uri) {
82 super(uri);
83 }
84
85 /**
86 * Copy constructor.
87 * @param original the property to make a copy of
88 */
89 public Member(Member original) {
90 super(original);
91 }
92
93 /**
94 * Creates a member property whose value is an email address.
95 * @param email the email address
96 * @return the property
97 */
98 public static Member email(String email) {
99 return new Member("mailto:" + email);
100 }
101
102 /**
103 * Creates a member property whose value is an instant messenger handle.
104 * @param protocol the instant messenger protocol (e.g. "aim")
105 * @param handle the instant messenger handle (e.g. "johndoe")
106 * @return the property
107 */
108 public static Member im(String protocol, String handle) {
109 return new Member(protocol + ":" + handle);
110 }
111
112 /**
113 * Creates a member property whose value is a telephone number.
114 * @param telUri the telephone number
115 * @return the property
116 */
117 public static Member telephone(TelUri telUri) {
118 return new Member(telUri.toString());
119 }
120
121 /**
122 * Gets the URI value.
123 * @return the URI value or null if no URI value is set
124 */
125 public String getUri() {
126 return getValue();
127 }
128
129 /**
130 * Sets the URI.
131 * @param uri the URI
132 */
133 public void setUri(String uri) {
134 setValue(uri);
135 }
136
137 @Override
138 public List<Pid> getPids() {
139 return super.getPids();
140 }
141
142 @Override
143 public Integer getPref() {
144 return super.getPref();
145 }
146
147 @Override
148 public void setPref(Integer pref) {
149 super.setPref(pref);
150 }
151
152 //@Override
153 public String getAltId() {
154 return parameters.getAltId();
155 }
156
157 //@Override
158 public void setAltId(String altId) {
159 parameters.setAltId(altId);
160 }
161
162 /**
163 * Gets the MEDIATYPE parameter.
164 * <p>
165 * <b>Supported versions:</b> {@code 4.0}
166 * </p>
167 * @return the media type or null if not set
168 */
169 public String getMediaType() {
170 return parameters.getMediaType();
171 }
172
173 /**
174 * Sets the MEDIATYPE parameter.
175 * <p>
176 * <b>Supported versions:</b> {@code 4.0}
177 * </p>
178 * @param mediaType the media type or null to remove
179 */
180 public void setMediaType(String mediaType) {
181 parameters.setMediaType(mediaType);
182 }
183
184 @Override
185 protected void _validate(List<ValidationWarning> warnings, VCardVersion version, VCard vcard) {
186 super._validate(warnings, version, vcard);
187
188 if (vcard.getKind() == null || !vcard.getKind().isGroup()) {
189 warnings.add(new ValidationWarning(17));
190 }
191 }
192
193 @Override
194 public Member copy() {
195 return new Member(this);
196 }
197 }