aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings
diff options
context:
space:
mode:
authorThomas <>2023-06-26 21:11:26 +0200
committerThomas <>2023-06-26 21:11:26 +0200
commit8e0ccca7cfd1680e33737e0db8d6e1091661568c (patch)
tree33ae7a462976eecbda355921706412a1ff60131a /pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings
parent203eaa42d83da699ed9cc6c7e286906b5aeb6d44 (diff)
downloadpdf-as-4-8e0ccca7cfd1680e33737e0db8d6e1091661568c.tar.gz
pdf-as-4-8e0ccca7cfd1680e33737e0db8d6e1091661568c.tar.bz2
pdf-as-4-8e0ccca7cfd1680e33737e0db8d6e1091661568c.zip
refact(placeholder): clean-up, bugfix and optimize QR-Code placeholder detection
Major re-factoring of QR-Code detection with huge clean-up of code.
Diffstat (limited to 'pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings')
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java442
1 files changed, 211 insertions, 231 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
index 7f047278..65722f88 100644
--- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
@@ -3,19 +3,19 @@
* 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
@@ -24,7 +24,6 @@
package at.gv.egiz.pdfas.common.settings;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.slf4j.Logger;
@@ -35,241 +34,222 @@ import at.gv.egiz.pdfas.common.exceptions.PDFASError;
public class SignatureProfileSettings implements IProfileConstants {
- private static final Logger logger = LoggerFactory
- .getLogger(SignatureProfileSettings.class);
+ private static final Logger logger = LoggerFactory
+ .getLogger(SignatureProfileSettings.class);
- private Map<String, SignatureProfileEntry> profileInformations = new HashMap<String, SignatureProfileEntry>();
+ private final Map<String, SignatureProfileEntry> profileInformations =
+ new HashMap<>();
- private Map<String, String> profileSettings = new HashMap<String, String>();
+ private final Map<String, String> profileSettings = new HashMap<>();
- private String profileID;
+ private final String profileID;
- private String pdfAVersion = null;
+ private String pdfAVersion = null;
- private ISettings configuration;
+ private final ISettings configuration;
- public SignatureProfileSettings(String profileID, ISettings configuration) throws PDFASError {
-
- if (!configuration.hasPrefix(SIG_OBJ + profileID)) {
+ public SignatureProfileSettings(String profileID, ISettings configuration) throws PDFASError {
+
+ if (!configuration.hasPrefix(SIG_OBJ + profileID)) {
throw new PDFASError(ErrorConstants.ERROR_SIG_INVALID_PROFILE,
PDFASError.buildInfoString(ErrorConstants.ERROR_SIG_INVALID_PROFILE,
profileID));
}
-
- this.profileID = profileID;
- String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR;
- String keysPrefix = profilePrefix + PROFILE_KEY;
- String valuesPrefix = profilePrefix + PROFILE_VALUE;
- String tablePrefix = profilePrefix + TABLE;
- this.configuration = configuration;
-
- logger.debug("Reading Profile: " + profileID);
- logger.debug("Keys Prefix: " + keysPrefix);
- logger.debug("Values Prefix: " + valuesPrefix);
- logger.debug("Table Prefix: " + tablePrefix);
-
- Map<String, String> keys = configuration.getValuesPrefix(keysPrefix);
- Map<String, String> values = configuration.getValuesPrefix(valuesPrefix);
-
- if (keys != null) {
- Iterator<String> keyIterator = keys.keySet().iterator();
-
- while (keyIterator.hasNext()) {
- String key = keyIterator.next();
- key = key.substring(key.lastIndexOf('.') + 1);
- String valueKey = keys.get(keysPrefix + KEY_SEPARATOR + key);
-
- String valueValue = values.get(valuesPrefix + KEY_SEPARATOR
- + key);
-
- // Lookup default values
- if(valueKey == null) {
- valueKey = DefaultSignatureProfileSettings.getDefaultKeyCaption(key);
- }
-
- if(valueValue == null) {
- valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key);
- }
-
- SignatureProfileEntry entry = new SignatureProfileEntry();
- entry.setKey(key);
- entry.setCaption(valueKey);
- entry.setValue(valueValue);
- profileInformations.put(key, entry);
- logger.debug(" " + entry.toString());
- }
- }
-
- if (values != null) {
- // Find entries where only values exists
- Iterator<String> valuesIterator = values.keySet().iterator();
-
- while (valuesIterator.hasNext()) {
- String key = valuesIterator.next();
- key = key.substring(key.lastIndexOf('.') + 1);
-
- String valueValue = values.get(valuesPrefix + KEY_SEPARATOR
- + key);
-
- // Lookup default values
- if(valueValue == null) {
- valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key);
- }
-
- SignatureProfileEntry entry = profileInformations.get(key);
- if (entry == null) {
- entry = new SignatureProfileEntry();
- entry.setKey(key);
- entry.setCaption(null);
- entry.setValue(valueValue);
- profileInformations.put(key, entry);
- }
-
- logger.debug(" " + entry.toString());
- }
- }
-
- Map<String, String> others = configuration
- .getValuesPrefix(profilePrefix);
-
- if(others != null) {
- Iterator<String> otherIterator = others.keySet().iterator();
-
- while (otherIterator.hasNext()) {
- String key = otherIterator.next();
-
- logger.trace("Checking key " + key);
- if (key.startsWith(keysPrefix) || key.startsWith(valuesPrefix)
- || key.startsWith(tablePrefix)) {
- continue;
- }
-
- String value = others.get(key);
- key = key.substring(key.lastIndexOf('.') + 1);
-
- profileSettings.put(key, value);
-
- logger.debug(" Settings: " + key + " : " + value);
- }
- }
-
- Iterator<SignatureProfileEntry> dumpIterator =
- profileInformations.values().iterator();
-
- logger.debug("Settings for profile {}", profileID);
- while(dumpIterator.hasNext()) {
- SignatureProfileEntry entry = dumpIterator.next();
- logger.debug(" " + entry.toString());
- }
- }
-
- public String getCaption(String key) {
- SignatureProfileEntry entry = profileInformations.get(key);
- if (entry != null) {
- return entry.getCaption();
- }
- return null;
- }
-
- protected String getDefaultValue(String key) {
- String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR;
- logger.debug("Searching default value for: " + key);
- if (key.startsWith(profilePrefix)) {
- key = key.substring(profilePrefix.length());
- }
- key = "default." + key;
- logger.debug("Searching default value for: " + key);
- return this.configuration.getValue(key);
- }
-
- public String getValue(String key) {
- logger.debug("Searching: " + key);
- SignatureProfileEntry entry = profileInformations.get(key);
- if (entry != null) {
- String value = entry.getValue();
-
- if (value == null) {
- return getDefaultValue(key);
- }
-
- return value;
- }
- String v = profileSettings.get(key);
- if (v != null) {
- return v;
- }
- return getDefaultValue(key);
- }
-
- public String getProfileID() {
- return profileID;
- }
-
- public String getSigningReason() {
- return this.getValue(SIGNING_REASON);
- }
-
- public String getSignFieldValue() {
- return this.getValue(SIGNFIELD_VALUE);
- }
-
- public String getProfileTimeZone() {
- return this.getValue(TIMEZONE_BASE);
- }
-
- public void setPDFAVersion(String version) {
- this.pdfAVersion = version;
- }
-
- public boolean isPDFA() {
-
- if(this.pdfAVersion != null) {
- return "1".equals(this.pdfAVersion);
- }
-
- SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID);
- if (entry != null) {
- String value = entry.getCaption();
- return "true".equals(value);
- }
-
- entry = profileInformations.get(SIG_PDFA1B_VALID);
- if (entry != null) {
- String value = entry.getCaption();
- return "true".equals(value);
- }
- return false;
- }
-
- public boolean isPDFUA() {
- SignatureProfileEntry entry = profileInformations.get(SIG_PDFUA_FORCE);
- if (entry != null) {
- String value = entry.getCaption();
- return "true".equals(value);
- }
- return false;
- }
-
-
- public boolean isLatin1Encoding() {
- SignatureProfileEntry entry = profileInformations.get(LATIN1_ENCODING);
- if (entry != null) {
- String value = entry.getCaption();
- return "true".equals(value);
- }
- return false;
- }
-
- public boolean isPDFA3() {
- if(this.pdfAVersion != null) {
- return "3".equals(this.pdfAVersion);
- }
-
- SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID);
- if (entry != null) {
- String value = entry.getCaption();
- return "true".equals(value);
- }
- return false;
- }
+
+ this.profileID = profileID;
+ final String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR;
+ final String keysPrefix = profilePrefix + PROFILE_KEY;
+ final String valuesPrefix = profilePrefix + PROFILE_VALUE;
+ final String tablePrefix = profilePrefix + TABLE;
+ this.configuration = configuration;
+
+ logger.debug("Reading Profile: " + profileID);
+ logger.debug("Keys Prefix: " + keysPrefix);
+ logger.debug("Values Prefix: " + valuesPrefix);
+ logger.debug("Table Prefix: " + tablePrefix);
+
+ final Map<String, String> keys = configuration.getValuesPrefix(keysPrefix);
+ final Map<String, String> values = configuration.getValuesPrefix(valuesPrefix);
+
+ for (String key : keys.keySet()) {
+ key = key.substring(key.lastIndexOf('.') + 1);
+ String valueKey = keys.get(keysPrefix + KEY_SEPARATOR + key);
+
+ String valueValue = values.get(valuesPrefix + KEY_SEPARATOR
+ + key);
+
+ // Lookup default values
+ if (valueKey == null) {
+ valueKey = DefaultSignatureProfileSettings.getDefaultKeyCaption(key);
+ }
+
+ if (valueValue == null) {
+ valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key);
+ }
+
+ final SignatureProfileEntry entry = new SignatureProfileEntry();
+ entry.setKey(key);
+ entry.setCaption(valueKey);
+ entry.setValue(valueValue);
+ profileInformations.put(key, entry);
+ logger.debug(" " + entry.toString());
+ }
+
+ for (String key : values.keySet()) {
+ key = key.substring(key.lastIndexOf('.') + 1);
+
+ String valueValue = values.get(valuesPrefix + KEY_SEPARATOR
+ + key);
+
+ // Lookup default values
+ if (valueValue == null) {
+ valueValue = DefaultSignatureProfileSettings.getDefaultKeyValue(key);
+ }
+
+ SignatureProfileEntry entry = profileInformations.get(key);
+ if (entry == null) {
+ entry = new SignatureProfileEntry();
+ entry.setKey(key);
+ entry.setCaption(null);
+ entry.setValue(valueValue);
+ profileInformations.put(key, entry);
+ }
+
+ logger.debug(" " + entry.toString());
+ }
+
+ final Map<String, String> others = configuration
+ .getValuesPrefix(profilePrefix);
+
+ if (others != null) {
+ for (String key : others.keySet()) {
+ logger.trace("Checking key " + key);
+ if (key.startsWith(keysPrefix) || key.startsWith(valuesPrefix)
+ || key.startsWith(tablePrefix)) {
+ continue;
+ }
+
+ final String value = others.get(key);
+ key = key.substring(key.lastIndexOf('.') + 1);
+
+ profileSettings.put(key, value);
+
+ logger.debug(" Settings: " + key + " : " + value);
+ }
+ }
+
+ logger.debug("Settings for profile {}", profileID);
+ for (final SignatureProfileEntry entry : profileInformations.values()) {
+ logger.debug(" " + entry.toString());
+ }
+ }
+
+ public String getCaption(String key) {
+ final SignatureProfileEntry entry = profileInformations.get(key);
+ if (entry != null) {
+ return entry.getCaption();
+ }
+ return null;
+ }
+
+ protected String getDefaultValue(String key) {
+ final String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR;
+ logger.debug("Searching default value for: " + key);
+ if (key.startsWith(profilePrefix)) {
+ key = key.substring(profilePrefix.length());
+ }
+ key = "default." + key;
+ logger.debug("Searching default value for: " + key);
+ return this.configuration.getValue(key);
+ }
+
+ public String getValue(String key) {
+ logger.debug("Searching: " + key);
+ final SignatureProfileEntry entry = profileInformations.get(key);
+ if (entry != null) {
+ final String value = entry.getValue();
+
+ if (value == null) {
+ return getDefaultValue(key);
+ }
+
+ return value;
+ }
+ final String v = profileSettings.get(key);
+ if (v != null) {
+ return v;
+ }
+ return getDefaultValue(key);
+ }
+
+ public String getProfileID() {
+ return profileID;
+ }
+
+ public String getSigningReason() {
+ return this.getValue(SIGNING_REASON);
+ }
+
+ public String getSignFieldValue() {
+ return this.getValue(SIGNFIELD_VALUE);
+ }
+
+ public String getProfileTimeZone() {
+ return this.getValue(TIMEZONE_BASE);
+ }
+
+ public void setPDFAVersion(String version) {
+ this.pdfAVersion = version;
+ }
+
+ public boolean isPDFA() {
+
+ if (this.pdfAVersion != null) {
+ return "1".equals(this.pdfAVersion);
+ }
+
+ SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID);
+ if (entry != null) {
+ final String value = entry.getCaption();
+ return "true".equals(value);
+ }
+
+ entry = profileInformations.get(SIG_PDFA1B_VALID);
+ if (entry != null) {
+ final String value = entry.getCaption();
+ return "true".equals(value);
+ }
+ return false;
+ }
+
+ public boolean isPDFUA() {
+ final SignatureProfileEntry entry = profileInformations.get(SIG_PDFUA_FORCE);
+ if (entry != null) {
+ final String value = entry.getCaption();
+ return "true".equals(value);
+ }
+ return false;
+ }
+
+ public boolean isLatin1Encoding() {
+ final SignatureProfileEntry entry = profileInformations.get(LATIN1_ENCODING);
+ if (entry != null) {
+ final String value = entry.getCaption();
+ return "true".equals(value);
+ }
+ return false;
+ }
+
+ public boolean isPDFA3() {
+ if (this.pdfAVersion != null) {
+ return "3".equals(this.pdfAVersion);
+ }
+
+ final SignatureProfileEntry entry = profileInformations.get(SIG_PDFA_VALID);
+ if (entry != null) {
+ final String value = entry.getCaption();
+ return "true".equals(value);
+ }
+ return false;
+ }
}