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