aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/PdfASID.java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/PdfASID.java')
-rw-r--r--pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/PdfASID.java222
1 files changed, 222 insertions, 0 deletions
diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/PdfASID.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/PdfASID.java
new file mode 100644
index 0000000..ef9cb87
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/PdfASID.java
@@ -0,0 +1,222 @@
+/**
+ * <copyright> Copyright 2006 by Know-Center, Graz, Austria </copyright>
+ * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
+ * joint initiative of the Federal Chancellery Austria and Graz University of
+ * Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * file for details on the various modules and licenses.
+ * The "NOTICE" text file is part of the distribution. Any derivative works
+ * that you distribute must include a readable copy of the "NOTICE" text file.
+ *
+ * $Id: PdfASID.java,v 1.1 2006/08/25 17:04:16 wprinz Exp $
+ */
+package at.knowcenter.wag.egov.egiz;
+
+import java.io.Serializable;
+
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+
+/**
+ * This class encapsulates the Pdf-AS ID ("Kennzeichnung") urn.
+ *
+ * @author wprinz
+ */
+public class PdfASID implements Serializable
+{
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = 4776635173830445739L;
+
+ /**
+ * The urn word that leads in the identifier.
+ */
+ protected static final String URN = "urn";
+
+ /**
+ * The namespace of the urn.
+ */
+ protected static final String NAMESPACE = "pdfsigfilter";
+
+ /**
+ * The separator between urn blocks.
+ */
+ protected static final String SPLIT_STRING = ":";
+
+ /**
+ * The vendor.
+ */
+ protected String vendor = null;
+
+ /**
+ * The algorithm type.
+ */
+ protected String type = null;
+
+ /**
+ * The version of the algorithm.
+ */
+ protected String version = null;
+
+ /**
+ * Constructor that fills in the parameters directly.
+ *
+ * @param vendor
+ * @param type
+ * @param version
+ */
+ public PdfASID(String vendor, String type, String version)
+ {
+ set(vendor, type, version);
+ }
+
+ /**
+ * Parses the given id String and throws an Exception if it is not valid.
+ *
+ * @param id
+ * The id String to be parsed.
+ */
+ public PdfASID(String id) throws InvalidIDException
+ {
+ String[] tokens = id.split(SPLIT_STRING);
+
+ if (tokens.length != 5)
+ {
+ throw new InvalidIDException(ErrorCode.UNABLE_TO_PARSE_ID, "The method doesn't have enough tokens (" + id + ")");
+ }
+
+ if (!tokens[0].equals(URN))
+ {
+ throw new InvalidIDException(ErrorCode.UNABLE_TO_PARSE_ID, "The method must start with " + URN + " (" + id + ")");
+ }
+
+ if (!tokens[1].equals(NAMESPACE))
+ {
+ throw new InvalidIDException(ErrorCode.UNABLE_TO_PARSE_ID, "The namespace of the method must be " + NAMESPACE + " (" + id + ")");
+ }
+
+ set(tokens[2], tokens[3], tokens[4]);
+ }
+
+ /**
+ * Copy Constructor.
+ *
+ * @param other
+ * The other PdfASID to copy the data from.
+ */
+ public PdfASID(final PdfASID other)
+ {
+ set(other.vendor, other.type, other.version);
+ }
+
+ /**
+ * Auxiliary constructor.
+ *
+ * @param vendor
+ * The vendor.
+ * @param type
+ * The type.
+ * @param version
+ * The version.
+ */
+ private void set(String vendor, String type, String version)
+ {
+ this.vendor = vendor;
+ this.type = type;
+ this.version = version;
+ }
+
+ /**
+ * Returns the type.
+ *
+ * @return Returns the type.
+ */
+ public String getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * Returns the vendor.
+ *
+ * @return Returns the vendor.
+ */
+ public String getVendor()
+ {
+ return this.vendor;
+ }
+
+ /**
+ * Returns the version.
+ *
+ * @return Returns the version.
+ */
+ public String getVersion()
+ {
+ return this.version;
+ }
+
+
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ //@override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (!(obj instanceof PdfASID))
+ {
+ return false;
+ }
+
+ PdfASID other = (PdfASID) obj;
+
+ return this.toString().equals(other.toString());
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ return URN + SPLIT_STRING + NAMESPACE + SPLIT_STRING + this.vendor + SPLIT_STRING + this.type + SPLIT_STRING + this.version;
+ }
+
+ /**
+ * Returns if it is an old textual signature (pre 1.2.0) that used cp1252 encoding for text extraction (mostly)
+ * @return
+ */
+ public boolean isOldCp1252Version() {
+ return this.getVersion().equals(SignatorFactory.VERSION_1_0_0)
+ || this.getVersion().equals(SignatorFactory.VERSION_1_1_0);
+ }
+
+}