001 package ezvcard.types;
002
003 import java.util.List;
004
005 import ezvcard.VCardSubTypes;
006 import ezvcard.VCardVersion;
007 import ezvcard.util.HCardElement;
008
009 /*
010 Copyright (c) 2012, Michael Angstadt
011 All rights reserved.
012
013 Redistribution and use in source and binary forms, with or without
014 modification, are permitted provided that the following conditions are met:
015
016 1. Redistributions of source code must retain the above copyright notice, this
017 list of conditions and the following disclaimer.
018 2. Redistributions in binary form must reproduce the above copyright notice,
019 this list of conditions and the following disclaimer in the documentation
020 and/or other materials provided with the distribution.
021
022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
023 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
024 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
025 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
026 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
027 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
031 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032
033 The views and conclusions contained in the software and documentation are those
034 of the authors and should not be interpreted as representing official policies,
035 either expressed or implied, of the FreeBSD Project.
036 */
037
038 /**
039 * A list of nicknames the person goes by.
040 *
041 * <pre>
042 * VCard vcard = new VCard();
043 * NicknameType nickname = new NicknameType();
044 * nickname.addValue("Rick");
045 * nickname.addValue("Ricky");
046 * nickname.addValue("Bobby");
047 * vcard.setNickname(nickname);
048 * </pre>
049 *
050 * <p>
051 * vCard property name: NICKNAME
052 * </p>
053 * <p>
054 * vCard versions: 3.0, 4.0
055 * </p>
056 * @author Michael Angstadt
057 */
058 public class NicknameType extends TextListType {
059 public static final String NAME = "NICKNAME";
060
061 public NicknameType() {
062 super(NAME, ',');
063 }
064
065 /**
066 * Gets the TYPE parameter.
067 * <p>
068 * vCard versions: 4.0
069 * </p>
070 * @return the TYPE value (typically, this will be either "work" or "home")
071 * or null if it doesn't exist
072 */
073 public String getType() {
074 return subTypes.getType();
075 }
076
077 /**
078 * Sets the TYPE parameter.
079 * <p>
080 * vCard versions: 4.0
081 * </p>
082 * @param type the TYPE value (this should be either "work" or "home") or
083 * null to remove
084 */
085 public void setType(String type) {
086 subTypes.setType(type);
087 }
088
089 /**
090 * Gets the language the name is written in.
091 * @return the language or null if not set
092 * @see VCardSubTypes#getLanguage
093 */
094 public String getLanguage() {
095 return subTypes.getLanguage();
096 }
097
098 /**
099 * Sets the language the name is written in.
100 * @param language the language or null to remove
101 * @see VCardSubTypes#setLanguage
102 */
103 public void setLanguage(String language) {
104 subTypes.setLanguage(language);
105 }
106
107 /**
108 * Gets all PID parameter values.
109 * <p>
110 * vCard versions: 4.0
111 * </p>
112 * @return the PID values or empty set if there are none
113 * @see VCardSubTypes#getPids
114 */
115 public List<Integer[]> getPids() {
116 return subTypes.getPids();
117 }
118
119 /**
120 * Adds a PID value.
121 * <p>
122 * vCard versions: 4.0
123 * </p>
124 * @param localId the local ID
125 * @param clientPidMapRef the ID used to reference the property's globally
126 * unique identifier in the CLIENTPIDMAP property.
127 * @see VCardSubTypes#addPid(int, int)
128 */
129 public void addPid(int localId, int clientPidMapRef) {
130 subTypes.addPid(localId, clientPidMapRef);
131 }
132
133 /**
134 * Removes all PID values.
135 * <p>
136 * vCard versions: 4.0
137 * </p>
138 * @see VCardSubTypes#removePids
139 */
140 public void removePids() {
141 subTypes.removePids();
142 }
143
144 /**
145 * Gets the preference value.
146 * <p>
147 * vCard versions: 4.0
148 * </p>
149 * @return the preference value or null if it doesn't exist
150 * @see VCardSubTypes#getPref
151 */
152 public Integer getPref() {
153 return subTypes.getPref();
154 }
155
156 /**
157 * Sets the preference value.
158 * <p>
159 * vCard versions: 4.0
160 * </p>
161 * @param pref the preference value or null to remove
162 * @see VCardSubTypes#setPref
163 */
164 public void setPref(Integer pref) {
165 subTypes.setPref(pref);
166 }
167
168 /**
169 * Gets the ALTID.
170 * <p>
171 * vCard versions: 4.0
172 * </p>
173 * @return the ALTID or null if it doesn't exist
174 * @see VCardSubTypes#getAltId
175 */
176 public String getAltId() {
177 return subTypes.getAltId();
178 }
179
180 /**
181 * Sets the ALTID.
182 * <p>
183 * vCard versions: 4.0
184 * </p>
185 * @param altId the ALTID or null to remove
186 * @see VCardSubTypes#setAltId
187 */
188 public void setAltId(String altId) {
189 subTypes.setAltId(altId);
190 }
191
192 @Override
193 public VCardVersion[] getSupportedVersions() {
194 return new VCardVersion[] { VCardVersion.V3_0, VCardVersion.V4_0 };
195 }
196
197 @Override
198 protected void doUnmarshalHtml(HCardElement element, List<String> warnings) {
199 addValue(element.value());
200 }
201 }