001 package ezvcard.property; 002 003 import java.util.EnumSet; 004 import java.util.List; 005 import java.util.Set; 006 007 import ezvcard.VCard; 008 import ezvcard.VCardVersion; 009 import ezvcard.Warning; 010 011 /* 012 Copyright (c) 2013, Michael Angstadt 013 All rights reserved. 014 015 Redistribution and use in source and binary forms, with or without 016 modification, are permitted provided that the following conditions are met: 017 018 1. Redistributions of source code must retain the above copyright notice, this 019 list of conditions and the following disclaimer. 020 2. Redistributions in binary form must reproduce the above copyright notice, 021 this list of conditions and the following disclaimer in the documentation 022 and/or other materials provided with the distribution. 023 024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 025 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 028 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 034 035 The views and conclusions contained in the software and documentation are those 036 of the authors and should not be interpreted as representing official policies, 037 either expressed or implied, of the FreeBSD Project. 038 */ 039 040 /** 041 * Defines the location of the person's birth. 042 * 043 * <p> 044 * <b>Code sample</b> 045 * </p> 046 * 047 * <pre class="brush:java"> 048 * VCard vcard = new VCard(); 049 * 050 * //URI (geo) 051 * Birthplace birthplace = new Birthplace(); 052 * birthplace.setUri("geo:39.970806,-75.174809"); 053 * vcard.setBirthplace(birthplace); 054 * 055 * //URI (website) 056 * birthplace = new Birthplace(); 057 * birthplace.setUri("http://www.chop.edu"); 058 * vcard.setBirthplace(birthplace); 059 * 060 * //text 061 * birthplace = new Birthplace(); 062 * birthplace.setText("The Children's Hospital of Philadelphia"); 063 * vcard.setBirthplace(birthplace); 064 * 065 * //text 066 * birthplace = new Birthplace(); 067 * birthplace.setText("Philadelphia, PA"); 068 * vcard.setBirthplace(birthplace); 069 * </pre> 070 * 071 * <p> 072 * <b>Property name:</b> {@code BIRTHPLACE} 073 * </p> 074 * <p> 075 * <b>Supported versions:</b> {@code 4.0} 076 * </p> 077 * @author Michael Angstadt 078 * @see <a href="http://tools.ietf.org/html/rfc6474">RFC 6474</a> 079 */ 080 public class Birthplace extends VCardProperty implements HasAltId { 081 private String uri; 082 private String text; 083 084 @Override 085 public Set<VCardVersion> _supportedVersions() { 086 return EnumSet.of(VCardVersion.V4_0); 087 } 088 089 /** 090 * Gets the URI value. 091 * @return the URI value or null if no URI value is set 092 */ 093 public String getUri() { 094 return uri; 095 } 096 097 /** 098 * Sets the value to a URI. 099 * @param uri the URI 100 */ 101 public void setUri(String uri) { 102 this.uri = uri; 103 text = null; 104 } 105 106 /** 107 * Gets the text value. 108 * @return the text value or null if no text value is set 109 */ 110 public String getText() { 111 return text; 112 } 113 114 /** 115 * Sets the value to free-form text. 116 * @param text the text 117 */ 118 public void setText(String text) { 119 this.text = text; 120 uri = null; 121 } 122 123 //@Override 124 public String getAltId() { 125 return parameters.getAltId(); 126 } 127 128 //@Override 129 public void setAltId(String altId) { 130 parameters.setAltId(altId); 131 } 132 133 @Override 134 public String getLanguage() { 135 return super.getLanguage(); 136 } 137 138 @Override 139 public void setLanguage(String language) { 140 super.setLanguage(language); 141 } 142 143 @Override 144 protected void _validate(List<Warning> warnings, VCardVersion version, VCard vcard) { 145 if (uri == null && text == null) { 146 warnings.add(new Warning(8)); 147 } 148 } 149 }