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