!24 修改启动配置问题,合并闭源版wiki模块生成doc的代码

Merge pull request !24 from sh1yu/master
This commit is contained in:
暮光:城中城
2023-06-20 09:17:13 +00:00
committed by Gitee
3 changed files with 141 additions and 136 deletions

View File

@@ -29,8 +29,8 @@ public class ModuleMissingInterceptor implements HandlerInterceptor {
public ModuleMissingInterceptor(ZyplayerModuleKeeper zyplayerModuleKeeper){ public ModuleMissingInterceptor(ZyplayerModuleKeeper zyplayerModuleKeeper){
enableWiki= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class); enableWiki= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class);
enableDb= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class); enableDb= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableDb.class);
enableApi= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableWiki.class); enableApi= zyplayerModuleKeeper.ismoduleStarted(ZyplayerDocConfig.enableApi.class);
} }
@Override @Override

View File

@@ -49,33 +49,24 @@
<groupId>com.zyplayer</groupId> <groupId>com.zyplayer</groupId>
<artifactId>zyplayer-doc-core</artifactId> <artifactId>zyplayer-doc-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.4</version>
</dependency>
<!--docx4j-->
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-core</artifactId>
<version>8.3.9</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
<version>8.3.9</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>8.3.8</version>
</dependency>
<dependency> <dependency>
<groupId>com.atlassian.commonmark</groupId> <groupId>com.atlassian.commonmark</groupId>
<artifactId>commonmark</artifactId> <artifactId>commonmark</artifactId>

View File

@@ -27,8 +27,10 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.docx4j.XmlUtils;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -37,6 +39,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -337,18 +340,29 @@ public class WikiPageController {
return DocResponseJson.warn("文档内容为空,不能导出!"); return DocResponseJson.warn("文档内容为空,不能导出!");
} }
try { try {
ByteArrayInputStream bais = new ByteArrayInputStream(pageContent.getContent().getBytes("GBK")); String content = pageContent.getContent();
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
directory.createDocument("WordDocument", bais);
// 写入流
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(wikiPageSel.getName(), "UTF-8"); String fileName = URLEncoder.encode(wikiPageSel.getName(), "UTF-8");
content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" +
"<html lang=\"zh\">\n" +
"<head>\n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
"<title>" + fileName + "</title>\n" +
"</head>\n" +
"<body>" +
content +
"</body>\n" +
"</html>";
// 写入流
response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx"); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx");
ServletOutputStream outputStream = response.getOutputStream(); ServletOutputStream outputStream = response.getOutputStream();
poifs.writeFilesystem(outputStream); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
bais.close(); MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
mdp.addAltChunk(AltChunkType.Xhtml, content.getBytes(StandardCharsets.UTF_8));
mdp.convertAltChunks();
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true);
wordMLPackage.save(outputStream);
outputStream.close(); outputStream.close();
return DocResponseJson.ok(); return DocResponseJson.ok();
} catch (Exception e) { } catch (Exception e) {