Skip to content

Commit e16b4f5

Browse files
committed
fix(xhtml,io): align landscape, writeToStream, and file-exists checks with 1.0/3.0
- HtmlTemplate.process(String,Map): pass landscape to buildWhithXhtml (3-arg overload); 2-arg ignored it (always portrait) - TemplateWriter.writeToStream: save the full .docx ZIP via wmlPackage.save(output) instead of writing document.xml text (was not a valid docx) - PackageWriter.writeToDocx/Html/PDF(File): drop the inverted Assert.isTrue(outFile.exists()) so writing a NEW file succeeds (was failing on fresh output files) 338 core + 33 xhtml tests green.
1 parent b55dddc commit e16b4f5

3 files changed

Lines changed: 6 additions & 19 deletions

File tree

easydoc-core/src/main/java/io/github/easy4j/doc/io/WordprocessingMLPackageWriter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public File writeToDocx(WordprocessingMLPackage wmlPackage, String outPath) thro
106106
* @throws Docx4JException : Docx4j异常
107107
*/
108108
public File writeToDocx(WordprocessingMLPackage wmlPackage, File outFile) throws IOException, Docx4JException {
109-
Assert.isTrue( outFile.exists() , " outFile is not founded !");
110109
writeToDocx(wmlPackage, new FileOutputStream(outFile));
111110
return outFile;
112111
}
@@ -165,7 +164,6 @@ public File writeToHtml(WordprocessingMLPackage wmlPackage, String outPath) thro
165164
*/
166165
public File writeToHtml(WordprocessingMLPackage wmlPackage,File outFile) throws IOException, Docx4JException {
167166
Assert.notNull(wmlPackage, " wmlPackage is not specified!");
168-
Assert.isTrue( outFile.exists() , " outFile is not founded !");
169167
OutputStream output = null;
170168
try {
171169
String imageTargetUri = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_HTML_IMAGETARGETURI, "images");
@@ -238,7 +236,6 @@ public File writeToPDF(WordprocessingMLPackage wmlPackage,String outPath) throws
238236
* @throws Docx4JException : Docx4j异常
239237
*/
240238
public File writeToPDF(WordprocessingMLPackage wmlPackage,File outFile) throws IOException, Docx4JException {
241-
Assert.isTrue( outFile.exists() , " outFile is not founded !");
242239
writeToPDF(wmlPackage, new FileOutputStream(outFile));
243240
return outFile;
244241
}

easydoc-core/src/main/java/io/github/easy4j/doc/io/WordprocessingMLTemplateWriter.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,11 @@ public static void writeToFile(WordprocessingMLPackage wmlPackage,File outFile)
7979
writeToStream(wmlPackage, new FileOutputStream(outFile));
8080
}
8181

82-
public static void writeToStream(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException {
82+
public static void writeToStream(WordprocessingMLPackage wmlPackage, OutputStream output) throws IOException, Docx4JException {
8383
Assert.notNull(wmlPackage, " wmlPackage is not specified!");
8484
Assert.notNull(output, " output is not specified!");
85-
InputStream input = null;
86-
try {
87-
//Document对象
88-
MainDocumentPart document = wmlPackage.getMainDocumentPart();
89-
//Document XML
90-
String documentXML = XmlUtils.marshaltoString(wmlPackage);
91-
//转成字节输入流
92-
input = IOUtils.toBufferedInputStream(new ByteArrayInputStream(documentXML.getBytes()));
93-
//输出模板
94-
IOUtils.copy(input, output);
95-
} finally {
96-
IOUtils.closeQuietly(input);
97-
}
85+
// .docx 是 ZIP 容器:保存整个包而不是把 XML 文本写入文件(与 1.0.x/3.0.x 对齐)
86+
wmlPackage.save(output);
9887
}
9988

10089
public void writeToWriter(WordprocessingMLPackage wmlPackage,Writer output) throws IOException, Docx4JException {

easydoc-xhtml/src/main/java/io/github/easy4j/doc/xhtml/WordprocessingMLHtmlTemplate.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ public WordprocessingMLPackage process(InputStream template, Map<String, Object>
128128
*/
129129
@Override
130130
public WordprocessingMLPackage process(String template, Map<String, Object> variables) throws Exception {
131-
// 返回WordprocessingMLPackage对象
132-
return wordMLPackageBuilder.buildWhithXhtml(template, altChunk);
131+
// 返回WordprocessingMLPackage对象(3 参重载传入 landscape,与 3.0.x 行为一致;
132+
// 原 2 参重载忽略 landscape,String 路径总产出纵向文档)
133+
return wordMLPackageBuilder.buildWhithXhtml(template, landscape, altChunk);
133134
}
134135

135136
public DocumentHandler getDocHandler() {

0 commit comments

Comments
 (0)