From 77dd3fcc4d85088b15ab859c4438521d9cd6ed10 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Wed, 15 Apr 2026 13:49:22 +0200 Subject: pdf-as-5 (#82) - JDK 17 - PDFBox 3 - PDF-AS Web moved to Spring Boot - MOA Integration tests w/ new error code --------- Co-authored-by: Gerald Palfinger Co-authored-by: kathrin.resek --- .../at/knowcenter/wag/egov/egiz/table/Style.java | 27 ++++++++++++++---- .../at/knowcenter/wag/egov/egiz/table/Table.java | 32 ++++++++++------------ 2 files changed, 35 insertions(+), 24 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/knowcenter') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java index e2fa7062..d575b6bd 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java @@ -54,6 +54,7 @@ import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; import java.awt.color.ICC_ProfileRGB; import java.io.Serializable; +import java.util.Set; /** * This class implements an abstract style definiton used in tables or table entrys. Predefined @@ -202,6 +203,20 @@ public class Style implements Serializable { */ public final static String STRIKETHRU = "STRIKETHRU"; + /** + * Valid horizontal alignment values + */ + private static final Set VALID_HALIGN_VALUES = Set.of(LEFT, CENTER, RIGHT); + + /** + * Valid vertical alignment values + */ + private static final Set VALID_VALIGN_VALUES = Set.of(TOP, MIDDLE, BOTTOM); + + /** + * Valid value horizontal alignment values (includes LINECENTER) + */ + private static final Set VALID_VALUE_HALIGN_VALUES = Set.of(LEFT, CENTER, RIGHT, LINECENTER); /** * all paddings initialized with the default padding value (1) @@ -286,33 +301,33 @@ public class Style implements Serializable { } if (HALIGN.equals(id)) { - if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { + if (VALID_HALIGN_VALUES.contains(value)) { hAlign_ = value; } } if (VALIGN.equals(id)) { - if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + if (VALID_VALIGN_VALUES.contains(value)) { vAlign_ = value; } } //Set new align for horziontal valign of lineCenter if (VALUEHALIGN.equals(id)) { - if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)||LINECENTER.equals(value)) { + if (VALID_VALUE_HALIGN_VALUES.contains(value)) { valueHAlign_ = value; } } if (VALUEVALIGN.equals(id)) { - if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + if (VALID_VALIGN_VALUES.contains(value)) { valueVAlign_ = value; } } if (IMAGEHALIGN.equals(id)) { - if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { + if (VALID_HALIGN_VALUES.contains(value)) { imageHAlign_ = value; } } if (IMAGEVALIGN.equals(id)) { - if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + if (VALID_VALIGN_VALUES.contains(value)) { imageVAlign_ = value; } } diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java index 12d0e2ee..77266488 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java @@ -51,7 +51,6 @@ package at.knowcenter.wag.egov.egiz.table; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException; @@ -81,7 +80,7 @@ public class Table implements Serializable /** * The row definitions. */ - private Map> rows_ = new HashMap>(); + private Map> rows_ = new HashMap<>(); /** * The table width. @@ -197,7 +196,7 @@ public class Table implements Serializable */ public ArrayList> getRows() { - ArrayList> rows = new ArrayList>(); + ArrayList> rows = new ArrayList<>(); for (int row_idx = 1; row_idx <= rows_.size(); row_idx++) { ArrayList row = rows_.get(String.valueOf(row_idx)); @@ -232,16 +231,14 @@ public class Table implements Serializable private int calculateRowSize(ArrayList newrow) { int colCount = 0; - for(int i = 0; i < newrow.size(); i++) { - colCount += newrow.get(i).getColSpan(); + for (Entry entry : newrow) { + colCount += entry.getColSpan(); } return colCount; } private void recalculateMaxCol() { - Iterator> rowIt = getRows().iterator(); - while(rowIt.hasNext()) { - ArrayList row = rowIt.next(); + for (ArrayList row : getRows()) { calculateMaxCols(row); } } @@ -253,9 +250,7 @@ public class Table implements Serializable * @throws PdfAsSettingsException */ public void normalize() throws PdfAsSettingsException { - Iterator> rowIt = getRows().iterator(); - while(rowIt.hasNext()) { - ArrayList row = rowIt.next(); + for (ArrayList row : getRows()) { // This row fits just fine if(row.size() == maxCols_) { @@ -293,20 +288,21 @@ public class Table implements Serializable */ public String toString() { - String the_string = "\n#### TABLE " + name_ + " BEGIN #####"; - the_string += " Width:" + width_ + " max cols:" + maxCols_ + " cols:" + colsRelativeWith_; - the_string += "\nStyle:" + style_; + StringBuilder sb = new StringBuilder(); + sb.append("\n#### TABLE ").append(name_).append(" BEGIN #####"); + sb.append(" Width:").append(width_).append(" max cols:").append(maxCols_).append(" cols:").append(colsRelativeWith_); + sb.append("\nStyle:").append(style_); ArrayList> rows = getRows(); for (int row_idx = 0; row_idx < rows.size(); row_idx++) { ArrayList row = rows.get(row_idx); String row_prefix = "\n ++ ROW " + row_idx + " ++ "; - for (int entry_idx = 0; entry_idx < row.size(); entry_idx++) + for (Entry entry : row) { - the_string += row_prefix + row.get(entry_idx).toString(); + sb.append(row_prefix).append(entry.toString()); } } - the_string += "\n#### TABLE " + name_ + " END #####"; - return the_string; + sb.append("\n#### TABLE ").append(name_).append(" END #####"); + return sb.toString(); } } -- cgit v1.2.3