Skip to content

Commit eb12c61

Browse files
committed
refactor: sync null-check guards and engine comments from 3.0.x
1 parent 4e08126 commit eb12c61

13 files changed

Lines changed: 30 additions & 11 deletions

File tree

easypdf-beetl/src/main/java/io/github/easy4j/pdf/beetl/BeetlPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
2929

3030
/**
31-
* Implementation of wordprocessing m l beetl template extending WordprocessingMLTemplate.
31+
* Beetl 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3232
*
3333
* @author <a href="https://github.com/loong10k">Loong Wan</a>
3434
*/

easypdf-core/src/main/java/io/github/easy4j/pdf/PdfTemplate.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.ByteArrayOutputStream;
44
import java.io.OutputStream;
55
import java.util.Map;
6+
import java.util.Objects;
67

78
/**
89
* PDF 模板抽象:引擎适配器渲染模板为 HTML 后输出 PDF。
@@ -13,15 +14,17 @@ public abstract class PdfTemplate {
1314
/**
1415
* 渲染模板并输出 PDF。
1516
*
16-
* @param template 模板内容/路径
17-
* @param variables 模板变量
18-
* @param out PDF 输出流
17+
* @param template 模板内容/路径,不能为 null
18+
* @param variables 模板变量,不能为 null
19+
* @param out PDF 输出流,不能为 null
1920
* @throws Exception 渲染或转换异常
2021
*/
2122
public abstract void process(String template, Map<String, Object> variables, OutputStream out) throws Exception;
2223

2324
/** 便捷方法:渲染模板并返回 PDF 字节。 */
2425
public ByteArrayOutputStream process(String template, Map<String, Object> variables) throws Exception {
26+
Objects.requireNonNull(template, "template must not be null");
27+
Objects.requireNonNull(variables, "variables must not be null");
2528
ByteArrayOutputStream out = new ByteArrayOutputStream();
2629
process(template, variables, out);
2730
return out;

easypdf-core/src/main/java/io/github/easy4j/pdf/core/convert/HtmlPdfConverter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.io.OutputStream;
6+
import java.util.Objects;
67

78
import com.itextpdf.html2pdf.ConverterProperties;
89
import com.itextpdf.html2pdf.HtmlConverter;
@@ -28,18 +29,22 @@ private HtmlPdfConverter() {
2829

2930
/** 追加注册字体文件(服务器缺少系统字体时的扩展点)。 */
3031
public static void registerFont(String fontPath) {
32+
Objects.requireNonNull(fontPath, "fontPath must not be null");
3133
FONT_PROVIDER.addFont(fontPath);
3234
}
3335

3436
/** 将 HTML 字符串渲染为 PDF 写入输出流(自动处理中文字体)。 */
3537
public static void htmlToPdf(String html, OutputStream out) throws IOException {
38+
Objects.requireNonNull(html, "html must not be null");
39+
Objects.requireNonNull(out, "out must not be null");
3640
ConverterProperties props = new ConverterProperties();
3741
props.setFontProvider(FONT_PROVIDER);
3842
HtmlConverter.convertToPdf(html, out, props);
3943
}
4044

4145
/** 从 PDF 文件逐页提取纯文本。 */
4246
public static String pdfToText(File pdf) throws IOException {
47+
Objects.requireNonNull(pdf, "pdf must not be null");
4348
StringBuilder sb = new StringBuilder();
4449
try (PdfDocument doc = new PdfDocument(new PdfReader(pdf))) {
4550
for (int i = 1; i <= doc.getNumberOfPages(); i++) {

easypdf-core/src/main/java/io/github/easy4j/pdf/template/AbstractStringTemplateWrappingPdfTemplate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.OutputStream;
44
import java.util.Map;
5+
import java.util.Objects;
56

67
import io.github.easy4j.pdf.PdfTemplate;
78
import io.github.easy4j.pdf.core.convert.HtmlPdfConverter;
@@ -17,6 +18,9 @@ protected AbstractStringTemplateWrappingPdfTemplate() {
1718

1819
@Override
1920
public void process(String template, Map<String, Object> variables, OutputStream out) throws Exception {
21+
Objects.requireNonNull(template, "template must not be null");
22+
Objects.requireNonNull(variables, "variables must not be null");
23+
Objects.requireNonNull(out, "out must not be null");
2024
String html = render(template, variables);
2125
HtmlPdfConverter.htmlToPdf(html, out);
2226
}

easypdf-httl/src/main/java/io/github/easy4j/pdf/httl/HttlPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
3030

3131
/**
32-
* Implementation of wordprocessing m l httl template extending WordprocessingMLTemplate.
32+
* Httl 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3333
*
3434
* @author <a href="https://github.com/loong10k">Loong Wan</a>
3535
*/

easypdf-jetbrick/src/main/java/io/github/easy4j/pdf/jetbrick/JetbrickPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
3333

3434
/**
35-
* Implementation of wordprocessing m l jetbrick template extending WordprocessingMLTemplate.
35+
* Jetbrick 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3636
*
3737
* @author <a href="https://github.com/loong10k">Loong Wan</a>
3838
*/

easypdf-jsp/src/main/java/io/github/easy4j/pdf/jsp/JspPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
3535

3636
/**
37-
* Implementation of wordprocessing m l jsp template extending WordprocessingMLTemplate.
37+
* Jsp 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3838
*
3939
* @author <a href="https://github.com/loong10k">Loong Wan</a>
4040
*/

easypdf-rythm/src/main/java/io/github/easy4j/pdf/rythm/RythmPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
3030

3131
/**
32-
* Implementation of wordprocessing m l rythm template extending WordprocessingMLTemplate.
32+
* Rythm 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3333
*
3434
* @author <a href="https://github.com/loong10k">Loong Wan</a>
3535
*/

easypdf-thymeleaf/src/main/java/io/github/easy4j/pdf/thymeleaf/ThymeleafPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
3333

3434
/**
35-
* Implementation of wordprocessing m l thymeleaf template extending WordprocessingMLTemplate.
35+
* Thymeleaf 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3636
*
3737
* @author <a href="https://github.com/loong10k">Loong Wan</a>
3838
*/

easypdf-velocity/src/main/java/io/github/easy4j/pdf/velocity/VelocityPdfTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import io.github.easy4j.pdf.template.AbstractStringTemplateWrappingPdfTemplate;
3030

3131
/**
32-
* Implementation of wordprocessing m l velocity template extending WordprocessingMLTemplate.
32+
* Velocity 模板引擎适配器:渲染模板为 HTML 后输出 PDF。
3333
*
3434
* @author <a href="https://github.com/loong10k">Loong Wan</a>
3535
*/

0 commit comments

Comments
 (0)