| 1 | package ezvcard.property; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import ezvcard.SupportedVersions; |
| 6 | import ezvcard.VCard; |
| 7 | import ezvcard.VCardVersion; |
| 8 | import ezvcard.parameter.AddressType; |
| 9 | |
| 10 | /* |
| 11 | Copyright (c) 2012-2023, Michael Angstadt |
| 12 | All rights reserved. |
| 13 | |
| 14 | Redistribution and use in source and binary forms, with or without |
| 15 | modification, are permitted provided that the following conditions are met: |
| 16 | |
| 17 | 1. Redistributions of source code must retain the above copyright notice, this |
| 18 | list of conditions and the following disclaimer. |
| 19 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 20 | this list of conditions and the following disclaimer in the documentation |
| 21 | and/or other materials provided with the distribution. |
| 22 | |
| 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 27 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | |
| 34 | The views and conclusions contained in the software and documentation are those |
| 35 | of the authors and should not be interpreted as representing official policies, |
| 36 | either expressed or implied, of the FreeBSD Project. |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * <p> |
| 41 | * Defines the exact text to put on the mailing label when sending snail mail to |
| 42 | * the person. Note that instances of this class should NEVER be added to a |
| 43 | * vCard! Instead, use the {@link Address#setLabel} method to assign a mailing |
| 44 | * label to an {@link Address} property. |
| 45 | * </p> |
| 46 | * |
| 47 | * <p> |
| 48 | * <b>Version interoperability</b> |
| 49 | * </p> |
| 50 | * |
| 51 | * <p> |
| 52 | * The label property is not supported in vCard version 4.0. Instead, labels are |
| 53 | * included as <i>parameters</i> to their corresponding {@link Address} |
| 54 | * properties. When marshalling a vCard, ez-vcard will use either the label |
| 55 | * property or the LABEL parameter, depending on the requested vCard version. |
| 56 | * </p> |
| 57 | * |
| 58 | * <p> |
| 59 | * <b>Orphaned labels</b> |
| 60 | * </p> |
| 61 | * |
| 62 | * <p> |
| 63 | * ez-vcard defines an "orphaned label" as a label property that could not be |
| 64 | * assigned to an address (a label is assigned to an address if its list of TYPE |
| 65 | * parameters is identical to the address's list of TYPE parameters). The |
| 66 | * {@link VCard#addOrphanedLabel} method can be used to add such labels to a |
| 67 | * vCard, but its use is strongly discouraged. The |
| 68 | * {@link VCard#getOrphanedLabels} method can be useful when parsing version 2.1 |
| 69 | * or 3.0 vCards in order to retrieve any label properties that the parser could |
| 70 | * not assign to an address. |
| 71 | * </p> |
| 72 | * |
| 73 | * <p> |
| 74 | * <b>Property name:</b> {@code LABEL} |
| 75 | * </p> |
| 76 | * <p> |
| 77 | * <b>Supported versions:</b> {@code 2.1, 3.0} |
| 78 | * </p> |
| 79 | * @author Michael Angstadt |
| 80 | * @see <a href="http://tools.ietf.org/html/rfc2426#page-13">RFC 2426 p.13</a> |
| 81 | * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.12</a> |
| 82 | */ |
| 83 | @SupportedVersions({ VCardVersion.V2_1, VCardVersion.V3_0 }) |
| 84 | public class Label extends TextProperty { |
| 85 | /** |
| 86 | * Creates a label property. |
| 87 | * @param label the label value |
| 88 | */ |
| 89 | public Label(String label) { |
| 90 | super(label); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Copy constructor. |
| 95 | * @param original the property to make a copy of |
| 96 | */ |
| 97 | public Label(Label original) { |
| 98 | super(original); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Gets the list that stores this property's address types (TYPE |
| 103 | * parameters). |
| 104 | * @return the address types (e.g. "HOME", "WORK") (this list is mutable) |
| 105 | */ |
| 106 | public List<AddressType> getTypes() { |
| 107 | return parameters.new TypeParameterList<AddressType>() { |
| 108 | @Override |
| 109 | protected AddressType _asObject(String value) { |
| 110 | return AddressType.get(value); |
| 111 | } |
| 112 | }; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public String getLanguage() { |
| 117 | return super.getLanguage(); |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void setLanguage(String language) { |
| 122 | super.setLanguage(language); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public Label copy() { |
| 127 | return new Label(this); |
| 128 | } |
| 129 | } |