001package ezvcard.property;
002
003import java.util.List;
004
005import ezvcard.SupportedVersions;
006import ezvcard.VCard;
007import ezvcard.VCardVersion;
008import ezvcard.ValidationWarning;
009import ezvcard.parameter.Pid;
010import ezvcard.util.TelUri;
011
012/*
013 Copyright (c) 2012-2023, Michael Angstadt
014 All rights reserved.
015
016 Redistribution and use in source and binary forms, with or without
017 modification, are permitted provided that the following conditions are met: 
018
019 1. Redistributions of source code must retain the above copyright notice, this
020 list of conditions and the following disclaimer. 
021 2. Redistributions in binary form must reproduce the above copyright notice,
022 this list of conditions and the following disclaimer in the documentation
023 and/or other materials provided with the distribution. 
024
025 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
026 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
028 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
029 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
031 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
032 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
033 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
034 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
035
036 The views and conclusions contained in the software and documentation are those
037 of the authors and should not be interpreted as representing official policies, 
038 either expressed or implied, of the FreeBSD Project.
039 */
040
041/**
042 * <p>
043 * Defines the members that make up the group. This property can only be used if
044 * the vCard's {@link Kind} property is set to "group".
045 * </p>
046 * 
047 * <p>
048 * <b>Code sample</b>
049 * </p>
050 * 
051 * <pre class="brush:java">
052 * VCard vcard = new VCard();
053 * 
054 * //kind property must be set to "group" in order to add members
055 * vcard.setKind(Kind.group());
056 * 
057 * //static factory methods
058 * Member member = Member.email("johndoe@hotmail.com");
059 * vcard.addMember(member);
060 * 
061 * //reference another vCard by putting its UID property here
062 * member = new Member("urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af");
063 * vcard.addMember(member);
064 * </pre>
065 * 
066 * <p>
067 * <b>Property name:</b> {@code MEMBER}
068 * </p>
069 * <p>
070 * <b>Supported versions:</b> {@code 4.0}
071 * </p>
072 * @author Michael Angstadt
073 * @see <a href="http://tools.ietf.org/html/rfc6350#page-41">RFC 6350 p.41</a>
074 */
075@SupportedVersions(VCardVersion.V4_0)
076public class Member extends UriProperty implements HasAltId {
077        /**
078         * Creates a member property.
079         * @param uri the URI representing the member
080         */
081        public Member(String uri) {
082                super(uri);
083        }
084
085        /**
086         * Copy constructor.
087         * @param original the property to make a copy of
088         */
089        public Member(Member original) {
090                super(original);
091        }
092
093        /**
094         * Creates a member property whose value is an email address.
095         * @param email the email address
096         * @return the property
097         */
098        public static Member email(String email) {
099                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}