From 89a45b322b16d3c3a949b552f4fb4f07f2914817 Mon Sep 17 00:00:00 2001 From: pdanner Date: Thu, 4 Nov 2010 16:35:10 +0000 Subject: - Added image[valign|halign] config parameters to allow separate alignment of images. - Normalization of value cell values does not remove multiple newlines any more git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@601 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../impl/signator/binary/BinarySignator_1_0_0.java | 5 +- .../java/at/knowcenter/wag/egov/egiz/PdfAS.java | 2 +- .../wag/egov/egiz/pdf/PDFSignatureObjectIText.java | 21 ++++--- .../wag/egov/egiz/sig/SignatureObject.java | 5 +- .../at/knowcenter/wag/egov/egiz/table/Style.java | 66 +++++++++++++++++++++- .../knowcenter/wag/egov/egiz/tools/Normalize.java | 3 +- .../wag/egov/egiz/tools/NormalizeV01.java | 26 ++++++--- .../knowcenter/wag/egov/egiz/tools/Normalizer.java | 34 +++++------ 8 files changed, 122 insertions(+), 40 deletions(-) diff --git a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java index bdb5fdb..e1257dc 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/signator/binary/BinarySignator_1_0_0.java @@ -17,7 +17,6 @@ */ package at.gv.egiz.pdfas.impl.signator.binary; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -42,7 +41,6 @@ import at.gv.egiz.pdfas.framework.signator.SignatorInformation; import at.gv.egiz.pdfas.impl.input.CompoundPdfDataSourceImpl; import at.gv.egiz.pdfas.impl.signator.IncrementalUpdateHelper; import at.gv.egiz.pdfas.utils.OgnlUtil; -import at.gv.egiz.pdfas.utils.PDFASUtils; import at.knowcenter.wag.egov.egiz.PdfAS; import at.knowcenter.wag.egov.egiz.PdfASID; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; @@ -87,6 +85,7 @@ import com.lowagie.text.pdf.PdfPTable; */ public class BinarySignator_1_0_0 implements Signator { +// 04.11.2010 changed by exthex - fillReplacesWithValue no longer removes multiple newlines from values private static Log log = LogFactory.getLog(BinarySignator_1_0_0.class); @@ -338,7 +337,7 @@ public class BinarySignator_1_0_0 implements Signator // evaluate expression String res = ognl.compileMessage(ri.sfd.value); - ri.value = this.normalizer.normalize(res); + ri.value = this.normalizer.normalize(res, true); } else { ri.value = iui.signed_signature_object.retrieveStringValue(ri.sfd.field_name); diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index 431f7b2..57868d0 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -1175,7 +1175,7 @@ public abstract class PdfAS public static String normalizeText(final String text) throws NormalizeException { Normalizer normalizer = new Normalizer(); - String normalized_text = normalizer.normalize(text); + String normalized_text = normalizer.normalize(text, false); // fix #331 ?? //normalized_text = normalized_text.replaceAll("\n", ""); return normalized_text; diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java index 85abd73..5c1cddb 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java @@ -66,6 +66,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject // 03.11.2010 changed by exthex to allow setting separate hAlign and vAlign for value and non-value cells. // If no value for valuevalign or valuehalign is set the values from valign and halign are taken. // Also fixed a minor bug which prevented proper style inheritment (Bug Nr. #534). +// 04.11.2010 changed by exthex - allow setting separate hAlign and vAlign for image cells analog to value cells. private static final String SIG_PDFA1_B_VALID = "SIG_PDFA1B_VALID"; @@ -182,12 +183,12 @@ public class PDFSignatureObjectIText implements PDFSignatureObject * the pdf cell to be styled * @param cellStyle * the abstract style definition - * @param isValue - * true if the pdfCell is a value cell - the appropriate style will be set + * @param type + * type of the cell to render - the appropriate style will be set * @see com.lowagie.text.pdf.PdfPCell * @see at.knowcenter.wag.egov.egiz.table.Style */ - private void setCellStyle(PdfPCell pdfCell, Style cellStyle, boolean isValue) + private void setCellStyle(PdfPCell pdfCell, Style cellStyle, int type) { if (cellStyle != null) { @@ -205,16 +206,20 @@ public class PDFSignatureObjectIText implements PDFSignatureObject pdfCell.setBorder(0); } int align = -1; - if (isValue && cellStyle.getValueVAlign() != null) + if (type == Entry.TYPE_VALUE && cellStyle.getValueVAlign() != null) align = ((Integer) alignMap_.get(cellStyle.getValueVAlign())).intValue(); + else if (type == Entry.TYPE_IMAGE && cellStyle.getImageVAlign() != null) + align = ((Integer) alignMap_.get(cellStyle.getImageVAlign())).intValue(); else if (cellStyle.getVAlign() != null) align = ((Integer) alignMap_.get(cellStyle.getVAlign())).intValue(); if (align != -1) pdfCell.setVerticalAlignment(align); align = -1; - if (isValue && cellStyle.getValueHAlign() != null) + if (type == Entry.TYPE_VALUE && cellStyle.getValueHAlign() != null) align = ((Integer) alignMap_.get(cellStyle.getValueHAlign())).intValue(); + else if (type == Entry.TYPE_IMAGE && cellStyle.getImageHAlign() != null) + align = ((Integer) alignMap_.get(cellStyle.getImageHAlign())).intValue(); else if (cellStyle.getHAlign() != null) align = ((Integer) alignMap_.get(cellStyle.getHAlign())).intValue(); if (align != -1) @@ -375,7 +380,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject } Phrase text_phrase = new Phrase(text, cell_font); pdf_cell = new PdfPCell(text_phrase); - setCellStyle(pdf_cell, cell_style, isValue); + setCellStyle(pdf_cell, cell_style, (isValue?Entry.TYPE_VALUE:Entry.TYPE_CAPTION)); break; case Entry.TYPE_IMAGE: try @@ -408,7 +413,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject fit = false; } pdf_cell = new PdfPCell(image, fit); - setCellStyle(pdf_cell, cell_style, false); + setCellStyle(pdf_cell, cell_style, Entry.TYPE_IMAGE); } catch (BadElementException e) { @@ -490,7 +495,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject pdf_table = new PdfPTable(cols); pdf_table.setWidthPercentage(abstractTable.getWidth()); Style table_style = abstractTable.getStyle(); - setCellStyle(pdf_table.getDefaultCell(), table_style, false); + setCellStyle(pdf_table.getDefaultCell(), table_style, Entry.TYPE_TABLE); ArrayList rows = abstractTable.getRows(); for (int row_idx = 0; row_idx < rows.size(); row_idx++) diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java index 859e54e..24d1411 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java @@ -73,6 +73,7 @@ public class SignatureObject implements Serializable { // 03.11.2010 changed by exthex - added default for defaultValueStyle_.hAlign since we had to remove the hardcoded default in Style +// 04.11.2010 changed by exthex - setSigValue no longer removes multiple newlines from value /** * SVUID. @@ -369,7 +370,7 @@ public class SignatureObject implements Serializable sigEntries_.put(key, sig_entry); is_new = true; } - value = normalizer_.normalize(value); + value = normalizer_.normalize(value, true); if (SignatureTypes.SIG_VALUE.equals(key) || SignatureTypes.SIG_ID.equals(key) || SignatureTypes.SIG_NUMBER.equals(key)) { value = removeAllWhiteSpaces(value); @@ -1090,7 +1091,7 @@ public class SignatureObject implements Serializable * @author tknall */ private String normalizeIssuer(String issuer) { - issuer = normalizer_.normalize(issuer); + issuer = normalizer_.normalize(issuer, false); issuer = removeAllWhiteSpaces(issuer); return issuer; } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java b/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java index 5b3db7d..d26570c 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java @@ -39,6 +39,7 @@ public class Style implements Serializable { // 03.11.2010 changed by exthex - added valuevalign and valuehalign to allow separate layout for value and non-value cells. // Also the hardcoded default values for halign and valign were removed to allow proper inheritment. +// 04.11.2010 changed by exthex - added imagevalign and imagehalign analog to valuevalign/valuehalign /** * SVUID. @@ -84,13 +85,22 @@ public class Style implements Serializable { public final static String VALIGN = "valign"; /** - * halign key + * value halign key */ public final static String VALUEHALIGN = "valuehalign"; /** - * valign key + * value valign key */ public final static String VALUEVALIGN = "valuevalign"; + + /** + * image halign key + */ + public final static String IMAGEHALIGN = "imagehalign"; + /** + * image valign key + */ + public final static String IMAGEVALIGN = "imagevalign"; /** * padding key, default padding = 1 */ @@ -187,6 +197,14 @@ public class Style implements Serializable { * The current valuevalign value */ private String valueVAlign_ = null; + /** + * The current imagehalign value + */ + private String imageHAlign_ = null; + /** + * The current imagevalign value + */ + private String imageVAlign_ = null; /** * The current border value -> initialized with the default border value */ @@ -248,6 +266,16 @@ public class Style implements Serializable { valueVAlign_ = value; } } + if (IMAGEHALIGN.equals(id)) { + if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { + imageHAlign_ = value; + } + } + if (IMAGEVALIGN.equals(id)) { + if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + imageVAlign_ = value; + } + } if (PADDING.equals(id)) { padding_ = Float.parseFloat(value); } @@ -399,6 +427,36 @@ public class Style implements Serializable { public String getValueVAlign() { return valueVAlign_; } + + /** + * @param align The imageHAlign to set. + */ + public void setImageHAlign(String align) { + imageHAlign_ = align; + } + + /** + * Returns the image halign + * @return Returns the image halign + */ + public String getImageHAlign() { + return imageHAlign_; + } + + /** + * @param align The imageVAlign to set. + */ + public void setImageVAlign(String align) { + imageVAlign_ = align; + } + + /** + * Returns the image valign + * @return Returns the image valign + */ + public String getImageVAlign() { + return imageVAlign_; + } /** * Returns the scaleToFit dimensions to be applied for image-cells. @@ -449,6 +507,8 @@ public class Style implements Serializable { newStyle.setBorder(baseStyle.getBorder()); newStyle.setFont(baseStyle.getFont()); newStyle.setHAlign(baseStyle.getHAlign()); + newStyle.setImageHAlign(baseStyle.getImageHAlign()); + newStyle.setImageVAlign(baseStyle.getImageVAlign()); newStyle.setPadding(baseStyle.getPadding()); newStyle.setVAlign(baseStyle.getVAlign()); newStyle.setValueFont(baseStyle.getValueFont()); @@ -463,6 +523,8 @@ public class Style implements Serializable { if (newStyle.getBorder() == DEFAULT_BORDER) { newStyle.setBorder(inheritStyle.getBorder()); } if (newStyle.getFont() == null) { newStyle.setFont(inheritStyle.getFont()); } if (newStyle.getHAlign() == null) { newStyle.setHAlign(inheritStyle.getHAlign()); } + if (newStyle.getImageHAlign() == null) { newStyle.setImageHAlign(inheritStyle.getImageHAlign()); } + if (newStyle.getImageVAlign() == null) { newStyle.setImageVAlign(inheritStyle.getImageVAlign()); } if (newStyle.getPadding() == DEFAULT_PADDING) { newStyle.setPadding(inheritStyle.getPadding()); } if (newStyle.getVAlign() == null) { newStyle.setVAlign(inheritStyle.getVAlign()); } if (newStyle.getValueFont() == null) { newStyle.setValueFont(inheritStyle.getValueFont()); } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalize.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalize.java index a2df327..80cb286 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalize.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalize.java @@ -30,9 +30,10 @@ public interface Normalize { /** * Normalize a given text. * @param rawText the raw text to normalize + * @param keepMultipleLineBreaks if true multiple line breaks in a row will not be normalized to a single line break * @return the normalized string */ - public String normalize(String rawText); + public String normalize(String rawText, boolean keepMultipleLineBreaks); /** * Return the current normalizer version string. * @return the version string diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/NormalizeV01.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/NormalizeV01.java index d3af9b5..c8f10d9 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/tools/NormalizeV01.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/NormalizeV01.java @@ -28,7 +28,8 @@ import java.io.Serializable; * @author wlackner */ public class NormalizeV01 implements Normalize, Serializable { - +// 04.11.2010 change by exthex - added keepMultipleLineBreaks parameter to normalize method +// to allow multiple line breaks to not be normalized to a single one /** * SVUID. */ @@ -72,7 +73,7 @@ public class NormalizeV01 implements Normalize, Serializable { *
  • code all multiple line breaks as \n\n
  • *
  • replace all Tabs and form feeds with spaces
  • *
  • code line breaks as \n
  • - *
  • reduce all multiple line breaks into one line break, code line break as \r
  • + *
  • reduce all multiple line breaks into one line break (only if keepMultipleLineBreaks == false), code line break as \r
  • *
  • replace all single line breaks with space
  • *
  • normalize spaces
  • *
  • remove spaces before and after a line break
  • @@ -83,9 +84,11 @@ public class NormalizeV01 implements Normalize, Serializable { *
  • normalize hypens
  • * * + * @param rawText the text to normalize + * @param keepMultipleLineBreaks if true, multiple newlines in a row will not be normalized to a single line break * @see at.knowcenter.wag.egov.egiz.tools.Normalize#normalize(java.lang.String) */ - public String normalize(String rawText) { + public String normalize(String rawText, boolean keepMultipleLineBreaks) { if (rawText == null || rawText.equals("null") || rawText.length() == 0) { return ""; } @@ -106,8 +109,11 @@ public class NormalizeV01 implements Normalize, Serializable { // code all mac line breaks as \n normText = normText.replace('\r', '\n'); - // reduce all multiple line breaks into two line breaks, code muliple line break as \r\r - normText = normText.replaceAll("\n[\\s\n]*\n", "\r\r"); + if (!keepMultipleLineBreaks) + { + // reduce all multiple line breaks into two line breaks, code muliple line break as \r\r + normText = normText.replaceAll("\n[\\s\n]*\n", "\r\r"); + } // replace all single line breaks with one line break normText = normText.replace('\n', '\r'); @@ -118,8 +124,14 @@ public class NormalizeV01 implements Normalize, Serializable { // remove spaces before and after a single line break normText = normText.replaceAll(" ?\r ?", "\r"); - // remove spaces before and after a multiple line breaks - normText = normText.replaceAll(" ?\r\r ?", "\r"); + if (keepMultipleLineBreaks) + { + // remove spaces before and after a multiple line breaks + normText = normText.replaceAll(" ?\r\r ?", "\r\r"); + } else + { + normText = normText.replaceAll(" ?\r\r ?", "\r"); + } // remove leading and trailing space or line break in the string int start_idx = (normText.charAt(0) == ' ' || normText.charAt(0) == '\r' ? 1 : 0); diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalizer.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalizer.java index 3dafb31..d5550f8 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalizer.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/Normalizer.java @@ -42,6 +42,7 @@ import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; * @see at.knowcenter.wag.egov.egiz.cfg.SettingsReader */ public class Normalizer implements Serializable { +// 04.11.2010 changed by exthex - normalize methods use and propagate the keepMultipleNewlines parameter /** * SVUID. @@ -187,18 +188,18 @@ public class Normalizer implements Serializable { rawString_ = rawString; } - /** - * Return the normalized string. If the chached value does not exist the normalize method from the - * current normalizer implementation is called. - * - * @return the normalized string - */ - public String getNormalizedString() { - if (normString_ == null) { - normalize(); - } - return normString_; - } +// /** +// * Return the normalized string. If the chached value does not exist the normalize method from the +// * current normalizer implementation is called. +// * +// * @return the normalized string +// */ +// public String getNormalizedString() { +// if (normString_ == null) { +// normalize(); +// } +// return normString_; +// } /** * Set a normalizer version. This activity load the new requested normalizer implementation. @@ -224,11 +225,12 @@ public class Normalizer implements Serializable { * Wrapper method. Call the normalizer implementation method. * * @param rawString the raw string to normalize + * @param keepMultipleNewlines * @return the normalized string * @see NormalizeV01 */ - public String normalize(String rawString) { - return normalize_.normalize(rawString); + public String normalize(String rawString, boolean keepMultipleNewlines) { + return normalize_.normalize(rawString, keepMultipleNewlines); } /** @@ -237,9 +239,9 @@ public class Normalizer implements Serializable { * @return the normalized string * @see NormalizeV01 */ - public String normalize() { + public String normalize(boolean keepMultipleNewlines) { if (normString_ == null) { - normString_ = normalize(rawString_); + normString_ = normalize(rawString_, keepMultipleNewlines); } return normString_; } -- cgit v1.2.3