Skip to content

Commit bd9662f

Browse files
Removed duplicated code, added code to empty catch block and change variable name
1 parent 5a75db1 commit bd9662f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

java/src/main/java/com/genexus/reports/PDFReportItext8.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,7 @@ else if (valign == VerticalAlign.BOTTOM.value())
635635
Rectangle htmlRectangle = new Rectangle(llx, lly, urx - llx, ury - lly);
636636
YPosition yPosition = new YPosition(htmlRectangle.getTop());
637637

638-
Canvas htmlCanvas = new Canvas(cb, htmlRectangle);
639-
htmlCanvas.setFontProvider(fontProvider);
638+
Canvas htmlCanvas = getNewCanvas(cb, htmlRectangle, fontProvider);
640639

641640
//Iterate over the elements (a.k.a the parsed HTML string) and handle each case accordingly
642641
List<IElement> elements = HtmlConverter.convertToElements(sTxt, converterProperties);
@@ -659,8 +658,7 @@ else if (valign == VerticalAlign.BOTTOM.value())
659658
cb.setFontAndSize(this.baseFont, fontSize);
660659
cb.setFillColor(new DeviceRgb(foreColor));
661660

662-
htmlCanvas = new Canvas(cb, htmlRectangle);
663-
htmlCanvas.setFontProvider(fontProvider);
661+
htmlCanvas = getNewCanvas(cb, htmlRectangle, fontProvider);
664662
}
665663
processHTMLElement((IBlockElement)element, alignment, htmlCanvas);
666664
yPosition.setCurrentYPosition(yPosition.getCurrentYPosition() - blockElementHeight);
@@ -788,6 +786,12 @@ else if (valign == VerticalAlign.BOTTOM.value())
788786
}
789787
}
790788

789+
private Canvas getNewCanvas(PdfCanvas pdfCanvas, Rectangle rectangle, FontProvider fontProvider) {
790+
Canvas canvas = new Canvas(pdfCanvas, rectangle);
791+
canvas.setFontProvider(fontProvider);
792+
return canvas;
793+
}
794+
791795
void processHTMLElement(IBlockElement blockElement, int alignment, Canvas htmlCanvas){
792796
if (blockElement instanceof Paragraph) {
793797
Paragraph p = (Paragraph) blockElement;

java/src/main/java/com/genexus/reports/PDFReportPDFBox.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ else if (valign == PDFReportPDFBox.VerticalAlign.BOTTOM.value())
637637

638638
loadSupportedHTMLTags();
639639

640-
Document document = Jsoup.parse(sTxt);
641-
Elements allElements = document.getAllElements();
640+
Document htmlDocument = Jsoup.parse(sTxt);
641+
Elements allElements = htmlDocument.getAllElements();
642642
for (Element element : allElements){
643643
if (pageHeightExceeded(bottomMargin, spaceHandler.getCurrentYPosition())) {
644644
llx = leftAux + leftMargin;
@@ -652,7 +652,7 @@ else if (valign == PDFReportPDFBox.VerticalAlign.BOTTOM.value())
652652
GxStartPage();
653653

654654
cb.close();
655-
cb = new PDPageContentStream(this.document, this.document.getPage(page - 1),PDPageContentStream.AppendMode.APPEND,false);
655+
cb = new PDPageContentStream(document, document.getPage(page - 1),PDPageContentStream.AppendMode.APPEND,false);
656656
}
657657
if (this.supportedHTMLTags.contains(element.normalName()))
658658
processHTMLElement(cb, htmlRectangle, spaceHandler, element);
@@ -870,7 +870,12 @@ else if (valign == PDFReportPDFBox.VerticalAlign.BOTTOM.value())
870870
} catch (Exception ioe){
871871
log.error("GxDrawText failed: ", ioe);
872872
} finally {
873-
try {if (cb != null) cb.close();} catch (IOException ioe) {}
873+
try {
874+
if (cb != null) cb.close();
875+
}
876+
catch (IOException ioe) {
877+
log.error("GxDrawText failed to close a content stream to one of it's pages: ", ioe);
878+
}
874879
}
875880
}
876881

@@ -1324,8 +1329,8 @@ public void GxEndDocument() {
13241329
try {
13251330
document.save(outputStream);
13261331
document.close();
1327-
} catch (IOException ioe) {
1328-
log.error("GxEndDocument: failed to save document to the output stream", ioe);
1332+
} catch (IOException | IllegalStateException e) {
1333+
log.error("GxEndDocument: failed to save document to the output stream", e);
13291334
}
13301335

13311336
log.debug("GxEndDocument!");

0 commit comments

Comments
 (0)