From c6a7f5c43c968e76ee9411337dc0257b6050aae7 Mon Sep 17 00:00:00 2001 From: j-dimension Date: Tue, 2 Jan 2024 23:48:02 +0100 Subject: [PATCH] ignore whitespace for table placeholders. close #2261. --- .../jlawyer/documents/LibreOfficeAccess.java | 15 ++++++++++++--- .../documents/MicrosoftOfficeAccess.java | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/LibreOfficeAccess.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/LibreOfficeAccess.java index ec5eb1683..2f72c2ca3 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/LibreOfficeAccess.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/LibreOfficeAccess.java @@ -1114,7 +1114,10 @@ public static void setPlaceHolders(String caseId, String fileInFileSystem, Strin CalculationTable tab = (CalculationTable) values.get(key); for (Table t : allTables) { if (t.getColumnCount() == 1 && t.getRowCount() == 1) { - if (key.equals(t.getCellByPosition(0, 0).getStringValue())) { + String cellContent=t.getCellByPosition(0, 0).getStringValue(); + if(cellContent!=null) + cellContent=cellContent.trim(); + if (key.equals(cellContent)) { Border border = new Border(Color.WHITE, 1.0, SupportedLinearMeasure.PT); for (int i = 0; i < tab.getData()[0].length - 1; i++) { t.appendColumn(); @@ -1173,7 +1176,10 @@ public static void setPlaceHolders(String caseId, String fileInFileSystem, Strin StyledCalculationTable tab = (StyledCalculationTable) values.get(key); for (Table t : allTables) { if (t.getColumnCount() == 1 && t.getRowCount() == 1) { - if (key.equals(t.getCellByPosition(0, 0).getStringValue())) { + String cellContent=t.getCellByPosition(0, 0).getStringValue(); + if(cellContent!=null) + cellContent=cellContent.trim(); + if (key.equals(cellContent)) { Border border = new Border(Color.BLACK, 0.05, SupportedLinearMeasure.PT); border.setColor(new org.odftoolkit.odfdom.type.Color(tab.getBorderColor())); for (int i = 0; i < tab.getColumnCount() - 1; i++) { @@ -1423,7 +1429,10 @@ public static java.util.List getPlaceHolders(String file, List a for (String r : PlaceHolders.ALLTABLEPLACEHOLDERS) { for (Table t : allTables) { if (t.getColumnCount() == 1 && t.getRowCount() == 1) { - if (r.equals(t.getCellByPosition(0, 0).getStringValue())) { + String cellContent=t.getCellByPosition(0, 0).getStringValue(); + if(cellContent!=null) + cellContent=cellContent.trim(); + if (r.equals(cellContent)) { resultList.add(r); } } diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/MicrosoftOfficeAccess.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/MicrosoftOfficeAccess.java index c5c59123f..299d9b7ac 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/MicrosoftOfficeAccess.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/MicrosoftOfficeAccess.java @@ -757,7 +757,10 @@ public static void setPlaceHolders(String caseId, String fileInFileSystem, Strin CalculationTable tab = (CalculationTable) values.get(key); for (XWPFTable t : allTables) { if (t.getRow(0).getTableCells().size() == 1 && t.getNumberOfRows() == 1) { - if (key.equals(t.getRow(0).getCell(0).getText())) { + String cellContent=t.getRow(0).getCell(0).getText(); + if(cellContent!=null) + cellContent=cellContent.trim(); + if (key.equals(cellContent)) { for (int i = 0; i < tab.getData()[0].length - 1; i++) { t.addNewCol(); @@ -766,7 +769,7 @@ public static void setPlaceHolders(String caseId, String fileInFileSystem, Strin t.createRow(); } int firstDataRow = 0; - if (tab.getColumnLabels().size() > 0) { + if (!tab.getColumnLabels().isEmpty()) { firstDataRow = 1; t.createRow(); for (int i = 0; i < tab.getColumnLabels().size(); i++) { @@ -788,7 +791,10 @@ public static void setPlaceHolders(String caseId, String fileInFileSystem, Strin XWPFTable t = null; for (XWPFTable tableCandidate : allTables) { if (tableCandidate.getRow(0).getTableCells().size() == 1 && tableCandidate.getNumberOfRows() == 1) { - if (key.equals(tableCandidate.getRow(0).getCell(0).getText())) { + String cellContent=tableCandidate.getRow(0).getCell(0).getText(); + if(cellContent!=null) + cellContent=cellContent.trim(); + if (key.equals(cellContent)) { t = tableCandidate; break; @@ -924,7 +930,10 @@ public static java.util.List getPlaceHolders(String file, List a for (XWPFTable t : allTables) { try { if (t.getRow(0).getTableCells().size() == 1 && t.getNumberOfRows() == 1) { - if (r.equals(t.getRow(0).getCell(0).getText())) { + String cellContent=t.getRow(0).getCell(0).getText(); + if(cellContent!=null) + cellContent=cellContent.trim(); + if (r.equals(cellContent)) { resultList.add(r); } }