001/* 002 * Copyright (C) 2014 konik.io 003 * 004 * This file is part of Konik library. 005 * 006 * Konik library is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Konik library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with Konik library. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package io.konik.zugferd.profile; 020 021/** 022 * The Invoice Profiles. 023 */ 024public enum ProfileType { 025 /** The basic profile */ 026 BASIC, 027 /** The comfort profile */ 028 COMFORT, 029 /** The extended profile */ 030 EXTENDED; 031 032 /** The ZUGFeRD name space prefix */ 033 public final static String NS = "urn:ferd:invoice"; 034 035 /** The ZUGFeRD VERSION. */ 036 public final static String VERSION = "rc"; 037 038 /** The full name. with namespace:version:profileName*/ 039 public final String fullName; 040 041 /** The simple name. */ 042 public final String simpleName; 043 044 /** The conformance level is simple name in capital letters */ 045 public final String conformanceLevel; 046 047 /** 048 * Instantiates a new profile type. 049 */ 050 ProfileType() { 051 conformanceLevel = name(); 052 simpleName = conformanceLevel.toLowerCase(); 053 fullName = NS + ":" + VERSION + ":" + simpleName; 054 } 055 056 /** 057 * Get a profile by full name. 058 * 059 * @param fullName the full name 060 * @return the profile 061 */ 062 public static ProfileType getProfile(String fullName) { 063 for (ProfileType v : values()) { 064 if(v.fullName.equals(fullName)) { 065 return v; 066 } 067 } 068 throw new EnumConstantNotPresentException(ProfileType.class, fullName); 069 } 070 071 /** 072 * Gets the profile by name. 073 * 074 * @param name the simple name 075 * @return the profile by name case independent 076 */ 077 public static ProfileType getProfileByName(String name) { 078 for (ProfileType v : values()) { 079 if(v.simpleName.equals(name.toLowerCase())) { 080 return v; 081 } 082 } 083 throw new EnumConstantNotPresentException(ProfileType.class, name); 084 } 085 086 /** 087 * Checks if is basic. 088 * 089 * @param fullName the full name 090 * @return true, if is basic 091 */ 092 public static boolean isBasic(String fullName) { 093 return fullName.endsWith(BASIC.simpleName); 094 } 095 096 /** 097 * Checks if is comfort. 098 * 099 * @param fullName the full name 100 * @return true, if is comfort 101 */ 102 public static boolean isComfort(String fullName) { 103 return fullName.endsWith(COMFORT.simpleName); 104 } 105 106 /** 107 * Checks if is extended. 108 * 109 * @param fullName the full name 110 * @return true, if is extended 111 */ 112 public static boolean isExtended(String fullName) { 113 return fullName.endsWith(EXTENDED.simpleName); 114 } 115 116 /** 117 * Extract version from full name. 118 * 119 * @param fullName the full name 120 * @return the version of provided in the full name or empty string 121 */ 122 public static String extractVersion(String fullName) { 123 if (fullName==null || fullName.isEmpty()) { 124 return ""; 125 } 126 String[] tokens = fullName.split(":"); 127 if (tokens.length<4) { 128 return ""; 129 } 130 return tokens[3]; 131 132 133 } 134}