aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-02-15 13:55:12 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-02-15 13:55:12 +0100
commitaa99f5b7512a5019b71616f9589a7a5bbfc403da (patch)
tree5fad8be42ae22f433beb61ae31d08b24ff8112d9
parentdfde0e5bcde5ab48940ee91b72c8251492ffdc21 (diff)
downloadpdf-as-4-aa99f5b7512a5019b71616f9589a7a5bbfc403da.tar.gz
pdf-as-4-aa99f5b7512a5019b71616f9589a7a5bbfc403da.tar.bz2
pdf-as-4-aa99f5b7512a5019b71616f9589a7a5bbfc403da.zip
placeholder sorted mode
-rw-r--r--pdf-as-lib/src/configuration/cfg/advancedconfig.properties1
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java3
-rw-r--r--pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java36
3 files changed, 39 insertions, 1 deletions
diff --git a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties
index ec88b448..ade378df 100644
--- a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties
+++ b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties
@@ -31,6 +31,7 @@
# MATCH_MODE_STRICT = 0
# MATCH_MODE_MODERATE = 1
# MATCH_MODE_LENIENT = 2
+# MATCH_MODE_SORTED = 3
#placeholder_mode=
##################
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java
index 2d898dd5..5aa93609 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderExtractorConstants.java
@@ -5,7 +5,8 @@ public interface PlaceholderExtractorConstants {
public static final int PLACEHOLDER_MATCH_MODE_STRICT = 0;
public static final int PLACEHOLDER_MATCH_MODE_MODERATE = 1;
public static final int PLACEHOLDER_MATCH_MODE_LENIENT = 2;
+ public static final int PLACEHOLDER_MATCH_MODE_SORTED = 3;
public static final int PLACEHOLDER_MODE_MIN = 0;
- public static final int PLACEHOLDER_MODE_MAX = 2;
+ public static final int PLACEHOLDER_MODE_MAX = 3;
}
diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java
index db16d212..54922864 100644
--- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java
+++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox/placeholder/SignaturePlaceholderExtractor.java
@@ -192,6 +192,38 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl
if (placeholders.size() == 0)
return null;
+ if (matchMode == PLACEHOLDER_MATCH_MODE_SORTED) {
+ // sort all placeholders by the id string if all ids are null do nothing
+ SignaturePlaceholderData currentFirstSpd = null;
+ for (int i = 0; i < placeholders.size(); i++) {
+ SignaturePlaceholderData spd = placeholders.get(i);
+ if (spd.getId() != null) {
+ if(currentFirstSpd == null) {
+ currentFirstSpd = spd;
+ logger.debug("Setting new current ID: {}",
+ currentFirstSpd.getId());
+ } else {
+ String currentID = currentFirstSpd.getId();
+ String testID = spd.getId();
+ logger.debug("Testing placeholder current: {} compare to {}",
+ currentID, testID);
+ if(testID.compareToIgnoreCase(currentID) < 0) {
+ currentFirstSpd = spd;
+ logger.debug("Setting new current ID: {}",
+ testID);
+ }
+ }
+ }
+ }
+
+ if(currentFirstSpd != null) {
+ logger.info("Running Placeholder sorted mode: using id: {}", currentFirstSpd.getId());
+ return currentFirstSpd;
+ } else {
+ logger.info("Running Placeholder sorted mode: no placeholder with id found, fallback to first placeholder");
+ }
+ }
+
for (int i = 0; i < placeholders.size(); i++) {
SignaturePlaceholderData spd = placeholders.get(i);
if (spd.getId() == null)
@@ -207,6 +239,10 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl
private static SignaturePlaceholderData matchPlaceholderPage(
List<SignaturePlaceholderData> placeholders, String placeholderId,
int matchMode) {
+
+ if(matchMode == PLACEHOLDER_MATCH_MODE_SORTED)
+ return null;
+
if (placeholders.size() == 0)
return null;
for (int i = 0; i < placeholders.size(); i++) {