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