001 package ezvcard.types; 002 003 import java.util.List; 004 005 import ezvcard.VCardSubTypes; 006 import ezvcard.util.HCardElement; 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 * A list of organizations the person belongs to. The list is ordered. It starts 039 * with the broadest organization and ends with the most specific. 040 * 041 * <pre> 042 * VCard vcard = new VCard(); 043 * OrganizationType org = new OrganizationType(); 044 * org.addValue("Google"); 045 * org.addValue("GMail Team"); 046 * org.addValue("Spam Detection Team"); 047 * vcard.setOrganizations(org); 048 * </pre> 049 * 050 * <p> 051 * vCard property name: ORG 052 * </p> 053 * <p> 054 * vCard versions: 2.1, 3.0, 4.0 055 * </p> 056 * @author Michael Angstadt 057 */ 058 public class OrganizationType extends TextListType { 059 public static final String NAME = "ORG"; 060 061 public OrganizationType() { 062 super(NAME, ';'); 063 } 064 065 /** 066 * Gets the language that the address is written in. 067 * @return the language or null if not set 068 * @see VCardSubTypes#getLanguage 069 */ 070 public String getLanguage() { 071 return subTypes.getLanguage(); 072 } 073 074 /** 075 * Sets the language that the address is written in. 076 * @param language the language or null to remove 077 * @see VCardSubTypes#setLanguage 078 */ 079 public void setLanguage(String language) { 080 subTypes.setLanguage(language); 081 } 082 083 /** 084 * Gets the TYPE parameter. 085 * <p> 086 * vCard versions: 4.0 087 * </p> 088 * @return the TYPE value (typically, this will be either "work" or "home") 089 * or null if it doesn't exist 090 */ 091 public String getType() { 092 return subTypes.getType(); 093 } 094 095 /** 096 * Sets the TYPE parameter. 097 * <p> 098 * vCard versions: 4.0 099 * </p> 100 * @param type the TYPE value (this should be either "work" or "home") or 101 * null to remove 102 */ 103 public void setType(String type) { 104 subTypes.setType(type); 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 /** 193 * Gets the string(s) that define how to sort the vCard. 194 * <p> 195 * 2.1 and 3.0 vCards should use the {@link SortStringType SORT-STRING} 196 * property instead. 197 * </p> 198 * <p> 199 * vCard versions: 4.0 200 * </p> 201 * @return the sort string(s) or empty list if there are none 202 * @see VCardSubTypes#getSortAs 203 */ 204 public List<String> getSortAs() { 205 return subTypes.getSortAs(); 206 } 207 208 /** 209 * Sets the string(s) that define how to sort the vCard. These strings 210 * correspond to the values that are in this property. 211 * <p> 212 * 2.1 and 3.0 vCards should use the {@link SortStringType SORT-STRING} 213 * property instead. 214 * </p> 215 * <p> 216 * vCard versions: 4.0 217 * </p> 218 * @param names the names or empty parameter list to remove 219 * @see VCardSubTypes#setSortAs 220 */ 221 public void setSortAs(String... names) { 222 subTypes.setSortAs(names); 223 } 224 225 @Override 226 protected void doUnmarshalHtml(HCardElement element, List<String> warnings) { 227 String orgName = element.firstValue("organization-name"); 228 if (orgName != null) { 229 addValue(orgName); 230 } 231 232 String orgUnit = element.firstValue("organization-unit"); 233 if (orgUnit != null) { 234 addValue(orgUnit); 235 } 236 237 if (getValues().isEmpty()) { 238 addValue(element.value()); 239 } 240 } 241 }