001 package ezvcard.types; 002 003 import java.util.List; 004 005 import ezvcard.VCardSubTypes; 006 import ezvcard.VCardVersion; 007 008 /* 009 Copyright (c) 2012, Michael Angstadt 010 All rights reserved. 011 012 Redistribution and use in source and binary forms, with or without 013 modification, are permitted provided that the following conditions are met: 014 015 1. Redistributions of source code must retain the above copyright notice, this 016 list of conditions and the following disclaimer. 017 2. Redistributions in binary form must reproduce the above copyright notice, 018 this list of conditions and the following disclaimer in the documentation 019 and/or other materials provided with the distribution. 020 021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 025 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 026 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 027 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 028 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 029 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 030 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 032 The views and conclusions contained in the software and documentation are those 033 of the authors and should not be interpreted as representing official policies, 034 either expressed or implied, of the FreeBSD Project. 035 */ 036 037 /** 038 * The members that make up the group. This type can only be used if the KIND 039 * type is set to "group". 040 * 041 * <p> 042 * <b>Adding members</b> 043 * </p> 044 * 045 * <pre> 046 * VCard vcard = new VCard(); 047 * 048 * //KIND must be set to "group" in order to add MEMBERs 049 * vcard.setKind(KindType.group()); 050 * 051 * MemberType member = new MemberType(); 052 * member.setUriEmail("funkyjoe@hotmail.com"); 053 * vcard.addMember(member); 054 * member = new MemberType(); 055 * member.setUriIM("aol", "joesmoe@aol.com"); 056 * vcard.addMember(member); 057 * member = new MemberType(); 058 * member.setUriTelephone("+1-123-555-6789"); 059 * vcard.addMember(member); 060 * member = new MemberType(); 061 * member.setUri("urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af"); //references the UID from another vCard 062 * vcard.addMember(member); 063 * </pre> 064 * 065 * <p> 066 * <b>Getting members</b> 067 * </p> 068 * 069 * <pre> 070 * VCard vcard = ... 071 * KindType kind = vcard.getKind(); 072 * if (kind != null){ 073 * if (kind.isGroup()){ 074 * System.out.println("The group's members are:"); 075 * for (MemberType member : vcard.getMembers()){ 076 * System.out.println(member.getUri()); 077 * } 078 * } 079 * } 080 * </pre> 081 * 082 * <p> 083 * vCard property name: MEMBER 084 * </p> 085 * <p> 086 * vCard versions: 4.0 087 * </p> 088 * @author Michael Angstadt 089 */ 090 public class MemberType extends UriType { 091 public static final String NAME = "MEMBER"; 092 093 public MemberType() { 094 super(NAME); 095 } 096 097 /** 098 * @param uri the URI representing the member 099 */ 100 public MemberType(String uri) { 101 super(NAME); 102 setUri(uri); 103 } 104 105 /** 106 * Gets the URI value. 107 * @return the URI value or null if no URI value is set 108 */ 109 public String getUri() { 110 return getValue(); 111 } 112 113 /** 114 * Sets the URI to an email address. 115 * @param email the email address 116 */ 117 public void setUriEmail(String email) { 118 setUri("mailto:" + email); 119 } 120 121 /** 122 * Sets the URI to an instant messaging handle. 123 * @param protocol the IM protocol (e.g. "aim") 124 * @param handle the handle 125 */ 126 public void setUriIM(String protocol, String handle) { 127 setUri(protocol + ":" + handle); 128 } 129 130 /** 131 * Sets the URI to a telephone number. 132 * @param telephone the telephone number 133 */ 134 public void setUriTelephone(String telephone) { 135 setUri("tel:" + telephone); 136 } 137 138 /** 139 * Sets the URI. 140 * @param uri the URI 141 */ 142 public void setUri(String uri) { 143 setValue(uri); 144 } 145 146 /** 147 * Gets all PID parameter values. 148 * <p> 149 * vCard versions: 4.0 150 * </p> 151 * @return the PID values or empty set if there are none 152 * @see VCardSubTypes#getPids 153 */ 154 public List<Integer[]> getPids() { 155 return subTypes.getPids(); 156 } 157 158 /** 159 * Adds a PID value. 160 * <p> 161 * vCard versions: 4.0 162 * </p> 163 * @param localId the local ID 164 * @param clientPidMapRef the ID used to reference the property's globally 165 * unique identifier in the CLIENTPIDMAP property. 166 * @see VCardSubTypes#addPid(int, int) 167 */ 168 public void addPid(int localId, int clientPidMapRef) { 169 subTypes.addPid(localId, clientPidMapRef); 170 } 171 172 /** 173 * Removes all PID values. 174 * <p> 175 * vCard versions: 4.0 176 * </p> 177 * @see VCardSubTypes#removePids 178 */ 179 public void removePids() { 180 subTypes.removePids(); 181 } 182 183 /** 184 * Gets the preference value. 185 * <p> 186 * vCard versions: 4.0 187 * </p> 188 * @return the preference value or null if it doesn't exist 189 * @see VCardSubTypes#getPref 190 */ 191 public Integer getPref() { 192 return subTypes.getPref(); 193 } 194 195 /** 196 * Sets the preference value. 197 * <p> 198 * vCard versions: 4.0 199 * </p> 200 * @param pref the preference value or null to remove 201 * @see VCardSubTypes#setPref 202 */ 203 public void setPref(Integer pref) { 204 subTypes.setPref(pref); 205 } 206 207 /** 208 * Gets the ALTID. 209 * <p> 210 * vCard versions: 4.0 211 * </p> 212 * @return the ALTID or null if it doesn't exist 213 * @see VCardSubTypes#getAltId 214 */ 215 public String getAltId() { 216 return subTypes.getAltId(); 217 } 218 219 /** 220 * Sets the ALTID. 221 * <p> 222 * vCard versions: 4.0 223 * </p> 224 * @param altId the ALTID or null to remove 225 * @see VCardSubTypes#setAltId 226 */ 227 public void setAltId(String altId) { 228 subTypes.setAltId(altId); 229 } 230 231 /** 232 * Gets the MEDIATYPE parameter. 233 * <p> 234 * vCard versions: 4.0 235 * </p> 236 * @return the media type or null if not set 237 */ 238 public String getMediaType() { 239 return subTypes.getMediaType(); 240 } 241 242 /** 243 * Sets the MEDIATYPE parameter. 244 * <p> 245 * vCard versions: 4.0 246 * </p> 247 * @param mediaType the media type or null to remove 248 */ 249 public void setMediaType(String mediaType) { 250 subTypes.setMediaType(mediaType); 251 } 252 253 @Override 254 public VCardVersion[] getSupportedVersions() { 255 return new VCardVersion[] { VCardVersion.V4_0 }; 256 } 257 }