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.itext.xmp; 020 021import static io.konik.util.Strings.isNullOrEmpty; 022import io.konik.zugferd.profile.Profile; 023 024/** 025 * ZUGFeRD XMP Info object represents the ZUGFeRD meta data which a part of the PDF/A XMP extension. 026 * 027 * *Example:* 028 * [source,xml] 029 * -- 030 * <zf:ConformanceLevel>BASIC</zf:ConformanceLevel> 031 * <zf:DocumentFileName>ZUGFeRD-invoice.xml</zf:DocumentFileName> 032 * <zf:DocumentType>INVOICE</zf:DocumentType> 033 * <zf:Version>RC</zf:Version> 034 * -- 035 */ 036public class ZfXmpInfo { 037 /** The conformance level. */ 038 private String conformanceLevel; 039 040 /** The document file value. */ 041 private String documentFileName; 042 043 /** The document type. */ 044 private String documentType; 045 046 /** The version. */ 047 private String version; 048 049 /** 050 * Instantiates a empty ZUGFeRD XMP Info Entity 051 */ 052 public ZfXmpInfo() { 053 } 054 055 /** 056 * Instantiates a new zf xmp info. 057 * 058 * @param profile the profile 059 * @param documentFileName the document file name 060 * @param documentType the document type 061 */ 062 public ZfXmpInfo(Profile profile, String documentFileName, String documentType) { 063 this.conformanceLevel = profile.getSimpleName(); 064 this.documentFileName = documentFileName; 065 this.documentType = documentType; 066 this.version = profile.getVersion(); 067 } 068 069 /** 070 * Instantiates a new zf xmp meta data. 071 * 072 * @param conformanceLevel the conformance level 073 * @param documentFileName the document file value 074 * @param documentType the document type 075 * @param version the version 076 */ 077 public ZfXmpInfo(String conformanceLevel, String documentFileName, String documentType, String version) { 078 super(); 079 this.conformanceLevel = conformanceLevel; 080 this.documentFileName = documentFileName; 081 this.documentType = documentType; 082 this.version = version; 083 } 084 085 /** 086 * Gets the conformance level. 087 * 088 * @return the conformance level 089 */ 090 public String getConformanceLevel() { 091 return conformanceLevel; 092 } 093 094 /** 095 * Sets the conformance level. 096 * 097 * @param conformanceLevel the new conformance level 098 */ 099 public void setConformanceLevel(String conformanceLevel) { 100 this.conformanceLevel = conformanceLevel; 101 } 102 103 /** 104 * Gets the document file value. 105 * 106 * @return the document file value 107 */ 108 public String getDocumentFileName() { 109 return documentFileName; 110 } 111 112 /** 113 * Sets the document file value. 114 * 115 * @param documentFileName the new document file value 116 */ 117 public void setDocumentFileName(String documentFileName) { 118 this.documentFileName = documentFileName; 119 } 120 121 /** 122 * Gets the document type. 123 * 124 * @return the document type 125 */ 126 public String getDocumentType() { 127 return documentType; 128 } 129 130 /** 131 * Sets the document type. 132 * 133 * @param documentType the new document type 134 */ 135 public void setDocumentType(String documentType) { 136 this.documentType = documentType; 137 } 138 139 /** 140 * Gets the version. 141 * 142 * @return the version 143 */ 144 public String getVersion() { 145 return version; 146 } 147 148 /** 149 * Sets the version. 150 * 151 * @param version the new version 152 */ 153 public void setVersion(String version) { 154 this.version = version; 155 } 156 157 @Override 158 public int hashCode() { 159 final int prime = 31; 160 int result = 1; 161 result = prime * result + ((conformanceLevel == null) ? 0 : conformanceLevel.hashCode()); 162 result = prime * result + ((documentFileName == null) ? 0 : documentFileName.hashCode()); 163 result = prime * result + ((documentType == null) ? 0 : documentType.hashCode()); 164 result = prime * result + ((version == null) ? 0 : version.hashCode()); 165 return result; 166 } 167 168 @Override 169 public boolean equals(Object obj) { 170 if (this == obj) return true; 171 if (obj == null) return false; 172 if (getClass() != obj.getClass()) return false; 173 ZfXmpInfo other = (ZfXmpInfo) obj; 174 if (conformanceLevel == null) { 175 if (other.conformanceLevel != null) return false; 176 } else if (!conformanceLevel.equals(other.conformanceLevel)) return false; 177 if (documentFileName == null) { 178 if (other.documentFileName != null) return false; 179 } else if (!documentFileName.equals(other.documentFileName)) return false; 180 if (documentType == null) { 181 if (other.documentType != null) return false; 182 } else if (!documentType.equals(other.documentType)) return false; 183 if (version == null) { 184 if (other.version != null) return false; 185 } else if (!version.equals(other.version)) return false; 186 return true; 187 } 188 189 @Override 190 public String toString() { 191 StringBuilder builder = new StringBuilder(); 192 builder.append("ZfXmpInfo [conformanceLevel=").append(conformanceLevel).append(", documentFileName=") 193 .append(documentFileName).append(", documentType=").append(documentType).append(", version=") 194 .append(version).append("]"); 195 return builder.toString(); 196 } 197 198 /** 199 * Checks if content of this entity is valid. 200 * 201 * @return true, if is valid 202 */ 203 public boolean isValid() { 204 return !(isNullOrEmpty(conformanceLevel) && isNullOrEmpty(documentFileName) && isNullOrEmpty(documentType) && isNullOrEmpty(version)); 205 } 206}