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 death.
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     * Deathplace deathplace = new Deathplace();
052     * deathplace.setUri(&quot;geo:46.176502,-122.191658&quot;);
053     * vcard.setDeathplace(deathplace);
054     * 
055     * //text
056     * deathplace = new Deathplace();
057     * deathplace.setText(&quot;Mount St. Helens&quot;);
058     * vcard.setDeathplace(deathplace);
059     * </pre>
060     * 
061     * <p>
062     * <b>Property name:</b> {@code DEATHPLACE}
063     * </p>
064     * <p>
065     * <b>Supported versions:</b> {@code 4.0}
066     * </p>
067     * @author Michael Angstadt
068     * @see <a href="http://tools.ietf.org/html/rfc6474">RFC 6474</a>
069     */
070    public class Deathplace extends VCardProperty implements HasAltId {
071            private String uri;
072            private String text;
073    
074            @Override
075            public Set<VCardVersion> _supportedVersions() {
076                    return EnumSet.of(VCardVersion.V4_0);
077            }
078    
079            /**
080             * Gets the URI value.
081             * @return the URI value or null if no URI value is set
082             */
083            public String getUri() {
084                    return uri;
085            }
086    
087            /**
088             * Sets the value to a URI.
089             * @param uri the URI
090             */
091            public void setUri(String uri) {
092                    this.uri = uri;
093                    text = null;
094            }
095    
096            /**
097             * Gets the text value.
098             * @return the text value or null if no text value is set
099             */
100            public String getText() {
101                    return text;
102            }
103    
104            /**
105             * Sets the value to free-form text.
106             * @param text the text
107             */
108            public void setText(String text) {
109                    this.text = text;
110                    uri = null;
111            }
112    
113            //@Overrde
114            public String getAltId() {
115                    return parameters.getAltId();
116            }
117    
118            //@Override
119            public void setAltId(String altId) {
120                    parameters.setAltId(altId);
121            }
122    
123            @Override
124            public String getLanguage() {
125                    return super.getLanguage();
126            }
127    
128            @Override
129            public void setLanguage(String language) {
130                    super.setLanguage(language);
131            }
132    
133            @Override
134            protected void _validate(List<Warning> warnings, VCardVersion version, VCard vcard) {
135                    if (text == null && uri == null) {
136                            warnings.add(new Warning(8));
137                    }
138            }
139    }