| 1 | package ezvcard.property; |
| 2 | |
| 3 | import java.util.UUID; |
| 4 | |
| 5 | /* |
| 6 | Copyright (c) 2012-2023, Michael Angstadt |
| 7 | All rights reserved. |
| 8 | |
| 9 | Redistribution and use in source and binary forms, with or without |
| 10 | modification, are permitted provided that the following conditions are met: |
| 11 | |
| 12 | 1. Redistributions of source code must retain the above copyright notice, this |
| 13 | list of conditions and the following disclaimer. |
| 14 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | this list of conditions and the following disclaimer in the documentation |
| 16 | and/or other materials provided with the distribution. |
| 17 | |
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
| 29 | The views and conclusions contained in the software and documentation are those |
| 30 | of the authors and should not be interpreted as representing official policies, |
| 31 | either expressed or implied, of the FreeBSD Project. |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * <p> |
| 36 | * Defines a globally unique identifier for this vCard. |
| 37 | * </p> |
| 38 | * |
| 39 | * <p> |
| 40 | * <b>Code sample</b> |
| 41 | * </p> |
| 42 | * |
| 43 | * <pre class="brush:java"> |
| 44 | * VCard vcard = new VCard(); |
| 45 | * |
| 46 | * Uid uid = new Uid("urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519"); |
| 47 | * vcard.setUid(uid); |
| 48 | * |
| 49 | * //or, generate a random UID |
| 50 | * uid = Uid.random(); |
| 51 | * vcard.setUid(uid); |
| 52 | * </pre> |
| 53 | * |
| 54 | * <p> |
| 55 | * <b>Property name:</b> {@code UID} |
| 56 | * </p> |
| 57 | * <p> |
| 58 | * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0} |
| 59 | * </p> |
| 60 | * @author Michael Angstadt |
| 61 | * @see <a href="http://tools.ietf.org/html/rfc6350#page-46">RFC 6350 p.46</a> |
| 62 | * @see <a href="http://tools.ietf.org/html/rfc2426#page-24">RFC 2426 p.24</a> |
| 63 | * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.21</a> |
| 64 | */ |
| 65 | public class Uid extends UriProperty { |
| 66 | /** |
| 67 | * Creates a UID property. |
| 68 | * @param uid the UID |
| 69 | */ |
| 70 | public Uid(String uid) { |
| 71 | super(uid); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Copy constructor. |
| 76 | * @param original the property to make a copy of |
| 77 | */ |
| 78 | public Uid(Uid original) { |
| 79 | super(original); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Creates a UID property that contains a random UUID URI. |
| 84 | * @return the property |
| 85 | */ |
| 86 | public static Uid random() { |
| 87 | String uuid = UUID.randomUUID().toString(); |
| 88 | return new Uid("urn:uuid:" + uuid); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public Uid copy() { |
| 93 | return new Uid(this); |
| 94 | } |
| 95 | } |