Skip to content

Commit 3addacd

Browse files
authored
Merge pull request #716 from syjer/715-replace-printstacktrace
Fixes #715 replace printStacktrace()
2 parents 1afd265 + 046975b commit 3addacd

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

openhtmltopdf-core/src/main/java/com/openhtmltopdf/resource/FSEntityResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public InputSource resolveEntity(String publicID,
8484
try {
8585
is = realUrl.openStream();
8686
} catch (IOException e) {
87-
e.printStackTrace();
87+
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.EXCEPTION_IO_PROBLEM_FOR_URI, url, e);
8888
}
8989

9090
if (is == null) {

openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/LogMessageId.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ enum LogMessageId1Param implements LogMessageId {
149149
EXCEPTION_FONT_METRICS_NOT_AVAILABLE(XRLog.EXCEPTION, "Font metrics not available for font-description: {}"),
150150
EXCEPTION_URI_SYNTAX_WHILE_LOADING_EXTERNAL_SVG_RESOURCE(XRLog.EXCEPTION, "URI syntax exception while loading external svg resource: {}"),
151151
EXCEPTION_SVG_ERROR_HANDLER(XRLog.EXCEPTION, "SVG {}"),
152+
EXCEPTION_SVG_CREATE_FONT(XRLog.EXCEPTION, "Error while creating a font with family: {}"),
152153
EXCEPTION_PDF_IN_WRITING_METHOD(XRLog.EXCEPTION, "Exception in PDF writing method: {}"),
153154
EXCEPTION_CANT_READ_IMAGE_FILE_FOR_URI(XRLog.EXCEPTION, "Can't read image file; unexpected problem for URI '{}'"),
154155
EXCEPTION_CANT_READ_IMAGE_FILE_FOR_URI_NOT_FOUND(XRLog.EXCEPTION, "Can't read image file; image at URI '{}' not found"),

openhtmltopdf-objects/src/main/java/com/openhtmltopdf/objects/pdf/ForegroundPdfDrawer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.openhtmltopdf.extend.OutputDevice;
44
import com.openhtmltopdf.pdfboxout.PdfBoxOutputDevice;
55
import com.openhtmltopdf.render.RenderingContext;
6+
import com.openhtmltopdf.util.LogMessageId;
7+
import com.openhtmltopdf.util.XRLog;
68
import org.apache.pdfbox.cos.COSArray;
79
import org.apache.pdfbox.cos.COSName;
810
import org.apache.pdfbox.cos.COSStream;
@@ -16,6 +18,7 @@
1618
import java.io.OutputStream;
1719
import java.nio.charset.StandardCharsets;
1820
import java.util.Map;
21+
import java.util.logging.Level;
1922

2023
public class ForegroundPdfDrawer extends PdfDrawerBase
2124
{
@@ -60,7 +63,7 @@ public Map<Shape, String> drawObject(Element e, double x, double y, double width
6063
}
6164
catch (IOException e1)
6265
{
63-
e1.printStackTrace();
66+
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.GENERAL_MESSAGE, "Error while drawing with the ForegroundPdfDrawer ", e1);
6467
}
6568
return null;
6669
}

openhtmltopdf-objects/src/main/java/com/openhtmltopdf/objects/pdf/MergeBackgroundPdfDrawer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import java.io.OutputStream;
66
import java.nio.charset.StandardCharsets;
77
import java.util.Map;
8+
import java.util.logging.Level;
89

10+
import com.openhtmltopdf.util.LogMessageId;
11+
import com.openhtmltopdf.util.XRLog;
912
import org.apache.pdfbox.cos.COSArray;
1013
import org.apache.pdfbox.cos.COSName;
1114
import org.apache.pdfbox.cos.COSStream;
@@ -64,7 +67,7 @@ public Map<Shape, String> drawObject(Element e, double x, double y, double width
6467
}
6568
catch (IOException e1)
6669
{
67-
e1.printStackTrace();
70+
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.GENERAL_MESSAGE, "Error while drawing with the MergeBackgroundPdfDrawer ", e1);
6871
}
6972
return null;
7073
}

openhtmltopdf-svg-support/src/main/java/com/openhtmltopdf/svgsupport/OpenHtmlGvtFont.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import java.io.File;
99
import java.io.IOException;
1010
import java.text.CharacterIterator;
11+
import java.util.logging.Level;
1112

13+
import com.openhtmltopdf.util.LogMessageId;
14+
import com.openhtmltopdf.util.XRLog;
1215
import org.apache.batik.gvt.font.GVTFont;
1316
import org.apache.batik.gvt.font.GVTFontFamily;
1417
import org.apache.batik.gvt.font.GVTGlyphVector;
@@ -56,7 +59,7 @@ public OpenHtmlGvtFont(byte[] fontBytes, GVTFontFamily family, float size, Float
5659
font = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(fontBytes)).deriveFont(toFontWeight(fontWeight) | toStyle(fontStyle) , size);
5760
} catch (IOException e) {
5861
// Shouldn't happen
59-
e.printStackTrace();
62+
XRLog.log(Level.WARNING, LogMessageId.LogMessageId1Param.EXCEPTION_SVG_CREATE_FONT, family != null ? family.getFamilyName() : "", e);
6063
font = null;
6164
}
6265

0 commit comments

Comments
 (0)