aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java82
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java71
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java162
3 files changed, 172 insertions, 143 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java b/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java
index d5545e6..a490327 100644
--- a/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java
+++ b/src/main/java/at/gv/egiz/pdfas/api/commons/SignatureProfile.java
@@ -3,59 +3,45 @@
*/
package at.gv.egiz.pdfas.api.commons;
-import java.util.Set;
+import java.util.Properties;
/**
* Definition of a signature profile.
*
* @author wprinz
*/
-public interface SignatureProfile
-{
- // TODO: the full profile information will be implemented in future
-
- /**
- * Returns the profile id.
- *
- * @return Returns the profile id.
- */
- public String getProfileId();
-
- /**
- * Returns the MOA KeyIdentifier.
- *
- * @return Returns the MOA KeyIdentifier.
- */
- public String getMOAKeyIdentifier();
-
- // start - modified by tknall
-
- /**
- * Returns the value of a field with a given key for the current profile.
- * <p>
- * e.g.<br/><code>signaturProfile.getField(SignatureTypes.SIG_ISSUER)</code><br/>
- * returns <code>"Issuer-Certificate"</code>
- * </p>
- * <code>null</code> is returned if a field with key <code>key</code>
- * could not be found.
- *
- * @param key
- * The key for the field to be returned or <code>null</code> if
- * there is not such field.
- * @return The value of the field with key <code>key</key>.
- * @see at.knowcenter.wag.egov.egiz.sig.SignatureTypes
- */
- public String getField(String key);
-
- // added by tknall
-
- /**
- * Returns a set containing all field keys (properties starting with
- * <code>sig_obj.CURRENT_PROFILE.key.</code> of the current profiles. The
- * set should be unmodifiable.
- */
- public Set getFieldKeys();
-
- // stop - modified by tknall
+public interface SignatureProfile {
+ // TODO: the full profile information will be implemented in future
+
+ /**
+ * Returns the profile id.
+ *
+ * @return Returns the profile id.
+ */
+ public String getProfileId();
+
+ /**
+ * Returns the MOA KeyIdentifier.
+ *
+ * @return Returns the MOA KeyIdentifier.
+ */
+ public String getMOAKeyIdentifier();
+
+ // start - modified by tknall
+
+ /**
+ * Returns the entries relevant to the search algorithm for signature blocks.<br/>
+ * e.g. properties starting with <code>sig_obj.PROFILE.key.</code> and
+ * properties of the form <code>sig_obj.PROFILE.table.TABLENAME.NUMBER</code>
+ * where <code>PROFILE</code> is the name of the current profile,
+ * <code>TABLENAME</code> is the name of a table and <code>NUMBER</code>
+ * is the number of the specific row within the table <code>TABLENAME</code>.
+ *
+ * @return The entries relevant to the signature block search algorithm as
+ * Java properties.
+ */
+ public Properties getSignatureBlockEntries();
+
+ // stop - modified by tknall
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
index 39b4aff..f0c85d4 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
@@ -8,13 +8,18 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.api.PdfAs;
import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters;
import at.gv.egiz.pdfas.api.analyze.AnalyzeResult;
import at.gv.egiz.pdfas.api.commons.Constants;
import at.gv.egiz.pdfas.api.commons.SignatureInformation;
-import at.gv.egiz.pdfas.api.commons.SignatureProfile;
import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.api.sign.SignParameters;
import at.gv.egiz.pdfas.api.sign.SignResult;
@@ -65,6 +70,11 @@ public class PdfAsObject implements PdfAs
protected File workDirectory = null;
/**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(CheckHelper.class);
+
+ /**
* This constructor is for internal use only - use
* {@link at.gv.egiz.pdfas.PdfAsFactory} instead.
*
@@ -104,6 +114,7 @@ public class PdfAsObject implements PdfAs
*/
public List getProfileInformation() throws PdfAsException
{
+ log.debug("Collecting profile information.");
final String MOA_SIGN_KEY_IDENTIFIER_KEY = "moa.sign.KeyIdentifier";
SettingsReader settings = SettingsReader.getInstance();
@@ -120,6 +131,7 @@ public class PdfAsObject implements PdfAs
SignatureTypeDefinition profile = (SignatureTypeDefinition) it.next();
final String profileId = profile.getType();
+ log.debug("Processing profile \"" + profileId + "\".");
final String moaKeyIdentifier = settings.getSetting("sig_obj." + profileId + "." + MOA_SIGN_KEY_IDENTIFIER_KEY, defaultMoaKeyIdentifiert);
// modified by tknall
@@ -127,21 +139,60 @@ public class PdfAsObject implements PdfAs
// start - added by tknall
- // add key values
- final String parentProperty = "sig_obj." + profileId + ".key.";
- ArrayList keys = settings.getKeys(parentProperty);
- if (keys != null) {
- Iterator keyIt = keys.iterator();
+ // signature entries relevant to the search algorithm
+ Properties signatureEntries = new Properties();
+
+ // search for table entries
+ String parentPropertyKey = "sig_obj." + profileId + ".table";
+ log.debug("Looking for subkeys of \"" + parentPropertyKey + "\".");
+ Vector keysVector = settings.getSettingKeys(parentPropertyKey);
+ if (keysVector != null) {
+ Iterator keyIt = keysVector.iterator();
+ while (keyIt.hasNext()) {
+ String subKey = (String) keyIt.next();
+ if (subKey != null && subKey.length() > 0) {
+ String fullKey = parentPropertyKey + "." + subKey;
+ String value = settings.getValueFromKey(fullKey);
+ int lastIndex = fullKey.lastIndexOf(".");
+ if (lastIndex != -1) {
+ String endsWith = fullKey.substring(lastIndex + 1);
+ if (value != null && value.length() > 0) {
+ if (NumberUtils.isDigits(endsWith)) {
+ signatureEntries.setProperty(fullKey, value);
+ } else {
+ log.debug("Ignoring table entry \"" + fullKey + "\" because it does not end with a digit. Therefore it is not relevant for the seach algorithm.");
+ }
+ } else {
+ log.warn("Problem detected with key \"" + fullKey + "\". The value is empty.");
+ }
+ }
+ }
+ }
+ }
+
+ // search for table entries
+ parentPropertyKey = "sig_obj." + profileId + ".key";
+ log.debug("Looking for subkeys of \"" + parentPropertyKey + "\".");
+ keysVector = settings.getSettingKeys(parentPropertyKey);
+ if (keysVector != null) {
+ Iterator keyIt = keysVector.iterator();
while (keyIt.hasNext()) {
- String key = (String) keyIt.next();
- if (key != null && key.length() > 0) {
- String value = settings.getValueFromKey(parentProperty + key);
+ String subKey = (String) keyIt.next();
+ if (subKey != null && subKey.length() > 0) {
+ String fullKey = parentPropertyKey + "." + subKey;
+ String value = settings.getValueFromKey(fullKey);
if (value != null && value.length() > 0) {
- signatureProfile.setField(key, value);
+ signatureEntries.setProperty(fullKey, value);
+ } else {
+ log.warn("Problem detected with key \"" + fullKey + "\". The value is empty.");
}
}
}
}
+
+ // set properties
+ signatureProfile.setSignatureBlockEntries(signatureEntries);
+
// stop - added by tknall
profileInformation.add(signatureProfile);
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java
index f0422f6..fb78564 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/api/commons/SignatureProfileImpl.java
@@ -3,9 +3,7 @@
*/
package at.gv.egiz.pdfas.impl.api.commons;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.Set;
+import java.util.Properties;
import at.gv.egiz.pdfas.api.commons.SignatureProfile;
@@ -14,87 +12,81 @@ import at.gv.egiz.pdfas.api.commons.SignatureProfile;
*
* @author wprinz
*/
-public class SignatureProfileImpl implements SignatureProfile
-{
-
- /**
- * The profile identifier.
- */
- protected String profileId = null;
-
- /**
- * The MOA key identifiert of this profile.
- */
- protected String moaKeyIdentifier = null;
-
- // start - added by tknall
-
- /**
- * A Hashtable containing all field values (as String) for the current profiles
- * (<code>sig_obj.PROFILE.key.*</code>).
- */
- protected Hashtable fields = new Hashtable();
-
- // stop - added by tknall
-
- /**
- * Constructor.
- *
- * @param profileId
- * The profile identifier.
- * @param moaKeyIdentifier
- * The MOA key identifiert of this profile.
- */
- public SignatureProfileImpl(String profileId, String moaKeyIdentifier)
- {
- this.profileId = profileId;
- this.moaKeyIdentifier = moaKeyIdentifier;
- }
-
- /**
- * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getProfileId()
- */
- public String getProfileId()
- {
- return this.profileId;
- }
-
- /**
- * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getMOAKeyIdentifier()
- */
- public String getMOAKeyIdentifier()
- {
- return this.moaKeyIdentifier;
- }
-
- // start - added by tknall
-
- /**
- * Returns the value of a field with a given key for the current profile.
- * <p>e.g.<br/><code>signaturProfile.getField(SignatureTypes.SIG_ISSUER)</code><br/>
- * returns <code>"Issuer-Certificate"</code></p>
- * <code>null</code> is returned if a field with key <code>key</code> could not be found.
- * @param key The key for the field to be returned or <code>null</code> if there is not such field.
- * @return The value of the field with key <code>key</key>.
- * @see at.knowcenter.wag.egov.egiz.sig.SignatureTypes
- */
- public String getField(String key) {
- return (String) this.fields.get(key);
- }
-
- /**
- * Sets the value <code>value</code> for a certain field with key <code>key</code>.
- * @param key The key of the field.
- * @param value The value of the field with key <code>key</code>.
- */
- public void setField(String key, String value) {
- this.fields.put(key, value);
- }
-
- public Set getFieldKeys() {
- return Collections.unmodifiableSet(this.fields.keySet());
- }
-
- // stop - added by tknall
+public class SignatureProfileImpl implements SignatureProfile {
+
+ /**
+ * The profile identifier.
+ */
+ protected String profileId = null;
+
+ /**
+ * The MOA key identifiert of this profile.
+ */
+ protected String moaKeyIdentifier = null;
+
+ // start - added by tknall
+
+ /**
+ * Properties containing the layout settings relevant to the search algorithm
+ * for signature blocks.
+ */
+ protected Properties signatureBlockEntries;
+
+ // stop - added by tknall
+
+ /**
+ * Constructor.
+ *
+ * @param profileId
+ * The profile identifier.
+ * @param moaKeyIdentifier
+ * The MOA key identifiert of this profile.
+ */
+ public SignatureProfileImpl(String profileId, String moaKeyIdentifier) {
+ this.profileId = profileId;
+ this.moaKeyIdentifier = moaKeyIdentifier;
+ this.signatureBlockEntries = new Properties();
+ }
+
+ /**
+ * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getProfileId()
+ */
+ public String getProfileId() {
+ return this.profileId;
+ }
+
+ /**
+ * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getMOAKeyIdentifier()
+ */
+ public String getMOAKeyIdentifier() {
+ return this.moaKeyIdentifier;
+ }
+
+ // start - added by tknall
+
+ /**
+ * @see at.gv.egiz.pdfas.api.commons.SignatureProfile#getSignatureBlockEntries()
+ */
+ public Properties getSignatureBlockEntries() {
+ return this.signatureBlockEntries;
+ }
+
+ /**
+ * Sets the entries relevant to the search algorithm for signature blocks.<br/>
+ * e.g. properties starting with <code>sig_obj.PROFILE.key.</code> and
+ * properties of the form <code>sig_obj.PROFILE.table.TABLENAME.NUMBER</code>
+ * where <code>PROFILE</code> is the name of the current profile,
+ * <code>TABLENAME</code> is the name of a table and <code>NUMBER</code>
+ * is the number of the specific row within the table <code>TABLENAME</code>.
+ *
+ * @param signatureBlockEntries
+ * The entries relevant to the signature block search algorithm as
+ * Java properties.
+ */
+ public void setSignatureBlockEntries(Properties signatureBlockEntries) {
+ this.signatureBlockEntries = signatureBlockEntries;
+ }
+
+ // stop - added by tknall
}