001package ezvcard; 002 003import com.github.mangstadt.vinnie.SyntaxStyle; 004 005/* 006 * Copyright 2011 George El-Haddad. All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without modification, are 009 * permitted provided that the following conditions are met: 010 * 011 * 1. Redistributions of source code must retain the above copyright notice, this list of 012 * conditions and the following disclaimer. 013 * 014 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 015 * of conditions and the following disclaimer in the documentation and/or other materials 016 * provided with the distribution. 017 * 018 * THIS SOFTWARE IS PROVIDED BY GEORGE EL-HADDAD ''AS IS'' AND ANY EXPRESS OR IMPLIED 019 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 020 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE EL-HADDAD OR 021 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 023 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 024 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 026 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 027 * 028 * The views and conclusions contained in the software and documentation are those of the 029 * authors and should not be interpreted as representing official policies, either expressed 030 * or implied, of George El-Haddad. 031 */ 032 033/* 034 Copyright (c) 2012-2023, Michael Angstadt 035 All rights reserved. 036 037 Redistribution and use in source and binary forms, with or without 038 modification, are permitted provided that the following conditions are met: 039 040 1. Redistributions of source code must retain the above copyright notice, this 041 list of conditions and the following disclaimer. 042 2. Redistributions in binary form must reproduce the above copyright notice, 043 this list of conditions and the following disclaimer in the documentation 044 and/or other materials provided with the distribution. 045 046 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 047 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 048 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 049 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 050 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 051 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 052 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 053 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 054 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 055 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 056 057 The views and conclusions contained in the software and documentation are those 058 of the authors and should not be interpreted as representing official policies, 059 either expressed or implied, of the FreeBSD Project. 060 */ 061 062/** 063 * Contains the vCard versions that this library supports. 064 * @author George El-Haddad 065 * @author Michael Angstadt 066 */ 067public enum VCardVersion { 068 /** 069 * The original vCard specification. 070 * @see <a href="http://www.imc.org/pdi/vcard-21.rtf">2.1 specs</a> 071 */ 072 V2_1("2.1", SyntaxStyle.OLD, null), 073 074 /** 075 * Version 3.0. 076 * @see <a href="http://tools.ietf.org/html/rfc2426">RFC 2426</a> 077 */ 078 V3_0("3.0", SyntaxStyle.NEW, null), 079 080 /** 081 * The lastest specification. 082 * @see <a href="http://tools.ietf.org/html/rfc6350">RFC 6350</a> 083 */ 084 V4_0("4.0", SyntaxStyle.NEW, "urn:ietf:params:xml:ns:vcard-4.0"); 085 086 private final String version; 087 private final SyntaxStyle syntaxStyle; 088 private final String xmlNamespace; 089 090 /** 091 * @param version the text representation 092 * @param xmlNamespace the xCard namespace or null if not defined 093 */ 094 VCardVersion(String version, SyntaxStyle syntaxStyle, String xmlNamespace) { 095 this.version = version; 096 this.syntaxStyle = syntaxStyle; 097 this.xmlNamespace = xmlNamespace; 098 } 099 100 /** 101 * Gets the text representation of this version. 102 * @return the text representation 103 */ 104 public String getVersion() { 105 return version; 106 } 107 108 /** 109 * Gets the syntax style used by this version when writing to a plain-text 110 * data stream. 111 * @return the syntax style 112 */ 113 public SyntaxStyle getSyntaxStyle() { 114 return syntaxStyle; 115 } 116 117 /** 118 * Gets the XML namespace used by this version when writing to an xCard. 119 * @return the XML namespace or null if this version does not support xCard 120 */ 121 public String getXmlNamespace() { 122 return xmlNamespace; 123 } 124 125 /** 126 * Gets a {@link VCardVersion} instance based on the given text 127 * representation. 128 * @param value the text representation 129 * @return the object or null if not found 130 */ 131 public static VCardVersion valueOfByStr(String value) { 132 for (VCardVersion version : VCardVersion.values()) { 133 if (version.getVersion().equals(value)) { 134 return version; 135 } 136 } 137 return null; 138 } 139 140 /** 141 * Gets a {@link VCardVersion} instance based on the given XML namespace. 142 * @param ns the XML namespace 143 * @return the object or null if not found 144 */ 145 public static VCardVersion valueOfByXmlNamespace(String ns) { 146 for (VCardVersion version : VCardVersion.values()) { 147 String versionNs = version.getXmlNamespace(); 148 if (versionNs != null && versionNs.equals(ns)) { 149 return version; 150 } 151 } 152 return null; 153 } 154 155 @Override 156 public String toString() { 157 return version; 158 } 159}