diff --git a/README.md b/README.md
index 199776e..b2a8932 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,13 @@
文书服务
-api下为调用的接口,在需要处理文书的项目中引用,以`fegin方式`配置Service后进行调用
++ api下为调用的接口,在需要处理文书的项目中引用,以`Http Invoker`配置Service后进行调用
+ + 参考[在Spring Boot中使用Http Invoker](https://codeleading.com/article/15413828287/) 的`Client`部分
-server下为使用jacob处理word文书,使用openoffice来进行pdf转换,`java -jar xxx.jar`启动
++ [jod-document-server](document-server/jod-document-server)下使用poi-tl处理word文件,使用jacob处理调用[LibreOffice](https://zh-cn.libreoffice.org/)来进行格式转换,`java -jar xxx.jar`启动
+ + 参考:[springboot整合libreoffice(两种方式,使用本地和远程的libreoffice);docker中同时部署应用和libreoffice](https://blog.csdn.net/qq_42882229/article/details/140917550)
+ + 在Linux下,需要注意word文件的字体,必须在Linux中存在
+ + 若出现格式问题,需先使用LibreOffice打开修复后,在进行转换
-tl-server下仅进行word转pdf,使用的docto调用office来转换,`java -jar xxx.jar`启动
\ No newline at end of file
++ [docto-document-server](document-server/docto-document-server)下使用poi-tl处理word文件,使用docto调用`Microsoft Office`来转换格式,`java -jar xxx.jar`启动
+ + 仅能运行在Windows,兼容性最好,比较慢
\ No newline at end of file
diff --git a/api/pom.xml b/api/pom.xml
deleted file mode 100644
index fdeb470..0000000
--- a/api/pom.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- 4.0.0
- com.optima
- document-api
- 2.0.0
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 8
- 8
-
-
-
-
- document api
- 文档操作api
-
- 1.8
-
-
-
- org.projectlombok
- lombok
- 1.16.20
- provided
-
-
-
diff --git a/api/src/main/java/com/optima/document/api/LegacyDocumentService.java b/api/src/main/java/com/optima/document/api/LegacyDocumentService.java
deleted file mode 100644
index f4c9610..0000000
--- a/api/src/main/java/com/optima/document/api/LegacyDocumentService.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.optima.document.api;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * 文档接口,此类中用的jacob生成word文档,插入图片等,使用openoffice进行格式转换
- *
- * @author Elias
- * @since 2021-09-28 16:00
- */
-public interface LegacyDocumentService extends BaseDocumentService {
- /**
- * 通过jacob向文档中插入图片,仅server模块下实现
- *
- * @param source 文档流
- * @param toFindText 需要替换的文本
- * @param imgSource 图片流
- * @param width 宽度
- * @param height 高度
- * @return word文档流
- */
- default byte[] insertJpeg(byte[] source, String toFindText, byte[] imgSource, int width, int height) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * 通过jacob向文档中插入多张图片,仅server模块下实现
- *
- * @param source 文档流
- * @param toFindText 需要替换的文本
- * @param imgSource 图片流列表
- * @param width 宽度
- * @param height 高度
- * @return word文档流
- */
- default byte[] insertJpeg(byte[] source, String toFindText, List imgSource, int width, int height) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * 通过jacob向word填充属性字段,仅server模块下实现
- *
- * @param source 文档流
- * @param infoMap 字段集合,${key}为占位字符,value为对应替换内容
- * @return word文档流
- */
- default byte[] fieldToWord(byte[] source, Map infoMap) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/document-api/pom.xml b/document-api/pom.xml
new file mode 100644
index 0000000..6c71a4c
--- /dev/null
+++ b/document-api/pom.xml
@@ -0,0 +1,58 @@
+
+
+ 4.0.0
+
+ com.optima
+ document
+ 2.0.0
+
+ document-api
+ Document API
+ 文档操作api
+
+
+
+
+ org.projectlombok
+ lombok
+ 1.16.20
+ provided
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.3.0
+
+
+
+
+ com.example.MyApp
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.1
+
+
+ attach-sources
+ package
+
+ jar-no-fork
+
+
+
+
+
+
+
diff --git a/api/src/main/java/com/optima/document/api/BaseDocumentService.java b/document-api/src/main/java/com/optima/document/api/BaseDocumentService.java
similarity index 59%
rename from api/src/main/java/com/optima/document/api/BaseDocumentService.java
rename to document-api/src/main/java/com/optima/document/api/BaseDocumentService.java
index 71be642..f7a4de2 100644
--- a/api/src/main/java/com/optima/document/api/BaseDocumentService.java
+++ b/document-api/src/main/java/com/optima/document/api/BaseDocumentService.java
@@ -1,17 +1,34 @@
package com.optima.document.api;
+import java.util.Map;
+
/**
* @author yanghuanglin
* @since 2022/12/28
*/
public interface BaseDocumentService {
/**
- * 格式转换,server和tl-server下均实现
+ * 格式转换
*
- * @param source 源文件流,tl-server下仅支持docx格式
+ * @param source 源文件流,仅支持docx格式
* @param sourceExtension 源文件后缀名,不包含"."
* @param targetExtension 目标文件后缀名,不包含"."
- * @param targetFormat 目标文件格式,需与目标文件后缀名匹配,server下此参数无效。,tl-server下参考: word格式
+ * @return 转换后的文件流
+ */
+ default byte[] convert(byte[] source, String sourceExtension, String targetExtension) {
+ return convert(source, sourceExtension, targetExtension, null);
+ }
+
+ /**
+ * 格式转换
+ *
+ * @param source 源文件流,仅支持docx格式
+ * @param sourceExtension 源文件后缀名,不包含"."
+ * @param targetExtension 目标文件后缀名,不包含"."
+ * @param targetFormat 目标文件格式,需与目标文件后缀名匹配。
+ * server下此参数无效。
+ * tl-server下参考:
+ * word格式
* 或 excel格式
* 或 powerpoint格式
* @return 转换后的文件流
@@ -21,9 +38,20 @@ public interface BaseDocumentService {
}
/**
- * word转为pdf,server和tl-server下均实现
+ * 通过调用poi生成word
*
- * @param source word文件流,tl-server下仅支持docx格式
+ * @param sourceTemplate word模版流,仅支持docx格式
+ * @param dataModel 数据模型
+ * @return word文档流
+ */
+ default byte[] generateWord(byte[] sourceTemplate, Map dataModel) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * word转为pdf
+ *
+ * @param source word文件流,仅支持docx格式
* @param sourceFormat 源文件后缀名,不包含".",tl-server下此参数无效
* @param clear 是否清除占位符,如果为true,则在tl-server下源文件只支持docx格式
* @return pdf文档流
@@ -35,7 +63,7 @@ public interface BaseDocumentService {
/**
* 通过pdfbox将word转图片
*
- * @param source word文件流,tl-server下仅支持docx格式
+ * @param source word文件流,仅支持docx格式
* @param sourceExtension 源文件后缀名,不包含".",server下此参数无效
* @param targetExtension 目标格式 支持jpeg, jpg, gif, tiff or png
* @return 图片流
@@ -45,7 +73,7 @@ public interface BaseDocumentService {
}
/**
- * doc转为docx,server和tl-server下均实现
+ * doc转为docx
*
* @param source doc文档流
* @return docx文档流
@@ -55,7 +83,7 @@ public interface BaseDocumentService {
}
/**
- * xls转为xlsx,server和tl-server下均实现
+ * xls转为xlsx
*
* @param source xls文档流
* @return xlsx文档流
diff --git a/api/src/main/java/com/optima/document/api/DocumentService.java b/document-api/src/main/java/com/optima/document/api/DocumentService.java
similarity index 62%
rename from api/src/main/java/com/optima/document/api/DocumentService.java
rename to document-api/src/main/java/com/optima/document/api/DocumentService.java
index 81b6d47..a86b261 100644
--- a/api/src/main/java/com/optima/document/api/DocumentService.java
+++ b/document-api/src/main/java/com/optima/document/api/DocumentService.java
@@ -1,7 +1,5 @@
package com.optima.document.api;
-import java.util.Map;
-
/**
* 文档接口,此类中用的poi2生成word文档,使用docto进行格式转换
*
@@ -10,18 +8,7 @@ import java.util.Map;
*/
public interface DocumentService extends BaseDocumentService {
/**
- * 通过调用poi生成word,仅tl-server模块下实现,仅支持docx格式
- *
- * @param sourceTemplate word模版流,仅支持docx格式
- * @param dataModel 数据模型
- * @return word文档流
- */
- default byte[] generateWord(byte[] sourceTemplate, Map dataModel) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * 通过调用poi将word转pdf,仅tl-server模块下实现,如果clear为true,则仅支持docx格式
+ * 通过调用poi将word转pdf,如果clear为true,则仅支持docx格式
*
* @param source word模版流,仅支持docx格式
* @param clear 是否清除占位符
diff --git a/document-server/docto-document-server/pom.xml b/document-server/docto-document-server/pom.xml
new file mode 100644
index 0000000..542217e
--- /dev/null
+++ b/document-server/docto-document-server/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ com.optima
+ document-server
+ 2.0.0
+
+ docto-document-server
+ 2.0.0
+ Docto Document server
+ Docto 文档操作服务
+
+
+
+
+
+
+
diff --git a/tl-server/src/main/java/com/optima/document/tl/server/DocumentServer.java b/document-server/docto-document-server/src/main/java/com/optima/document/server/DoctoDocumentServer.java
similarity index 60%
rename from tl-server/src/main/java/com/optima/document/tl/server/DocumentServer.java
rename to document-server/docto-document-server/src/main/java/com/optima/document/server/DoctoDocumentServer.java
index 30f27a1..c627082 100644
--- a/tl-server/src/main/java/com/optima/document/tl/server/DocumentServer.java
+++ b/document-server/docto-document-server/src/main/java/com/optima/document/server/DoctoDocumentServer.java
@@ -1,13 +1,13 @@
-package com.optima.document.tl.server;
+package com.optima.document.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
-public class DocumentServer {
+public class DoctoDocumentServer {
public static void main(String[] args) {
- SpringApplication.run(DocumentServer.class, args);
+ SpringApplication.run(DoctoDocumentServer.class, args);
}
}
diff --git a/tl-server/src/main/java/com/optima/document/tl/server/api/DocumentServiceImpl.java b/document-server/docto-document-server/src/main/java/com/optima/document/server/api/DocumentServiceImpl.java
similarity index 92%
rename from tl-server/src/main/java/com/optima/document/tl/server/api/DocumentServiceImpl.java
rename to document-server/docto-document-server/src/main/java/com/optima/document/server/api/DocumentServiceImpl.java
index bc068d0..c77d154 100644
--- a/tl-server/src/main/java/com/optima/document/tl/server/api/DocumentServiceImpl.java
+++ b/document-server/docto-document-server/src/main/java/com/optima/document/server/api/DocumentServiceImpl.java
@@ -1,4 +1,4 @@
-package com.optima.document.tl.server.api;
+package com.optima.document.server.api;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
@@ -11,7 +11,7 @@ import com.deepoove.poi.template.run.RunTemplate;
import com.deepoove.poi.xwpf.BodyContainer;
import com.deepoove.poi.xwpf.BodyContainerFactory;
import com.optima.document.api.DocumentService;
-import com.optima.document.tl.server.config.DocumentConfig;
+import com.optima.document.server.config.DocumentConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
@@ -42,11 +42,13 @@ import java.util.UUID;
@Slf4j
@Service
public class DocumentServiceImpl implements DocumentService {
+ @Resource
+ private DocumentConfig documentConfig;
/**
* word模版引擎配置
*/
- private static final Configure wtlConfig = Configure.builder().buildGramer("${", "}")
+ Configure wtlConfig = Configure.builder().buildGramer("${", "}")
.setValidErrorHandler(new Configure.DiscardHandler())
.addPlugin('%', new ListRenderPolicy() {
@Override
@@ -84,9 +86,6 @@ public class DocumentServiceImpl implements DocumentService {
})
.build();
- @Resource
- private DocumentConfig documentConfig;
-
public byte[] convert(byte[] source, String sourceExtension, String targetExtension, String targetFormat) {
try {
sourceExtension = sourceExtension.replace(".", "");
@@ -108,17 +107,17 @@ public class DocumentServiceImpl implements DocumentService {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
long end = System.currentTimeMillis();
- log.info("docto convert {} to {} take time in millis:{}", sourceExtension, targetExtension, (end - begin));
+ log.info("convert {} to {} take time in millis:{}", sourceExtension, targetExtension, (end - begin));
return Files.readAllBytes(targetPath);
} catch (Exception e) {
- e.printStackTrace();
+ log.error("convert {} to {} error", sourceExtension, targetExtension, e);
return null;
} finally {
Files.delete(sourcePath);
Files.delete(targetPath);
}
} catch (IOException e) {
- log.error("docto convert error", e);
+ log.error("convert error", e);
}
return null;
}
@@ -155,9 +154,9 @@ public class DocumentServiceImpl implements DocumentService {
});
template.writeAndClose(bos);
source = bos.toByteArray();
- log.info("清空占位符=======耗时:{} 毫秒", System.currentTimeMillis() - start);
+ log.info("clear placeholder take time in millis:{}", System.currentTimeMillis() - start);
} catch (Exception e) {
- log.error("清空标签失败:", e);
+ log.error("clear placeholder error", e);
return null;
}
}
diff --git a/tl-server/src/main/java/com/optima/document/tl/server/config/DocumentConfig.java b/document-server/docto-document-server/src/main/java/com/optima/document/server/config/DocumentConfig.java
similarity index 91%
rename from tl-server/src/main/java/com/optima/document/tl/server/config/DocumentConfig.java
rename to document-server/docto-document-server/src/main/java/com/optima/document/server/config/DocumentConfig.java
index a0ebf0a..3a9c27e 100644
--- a/tl-server/src/main/java/com/optima/document/tl/server/config/DocumentConfig.java
+++ b/document-server/docto-document-server/src/main/java/com/optima/document/server/config/DocumentConfig.java
@@ -1,4 +1,4 @@
-package com.optima.document.tl.server.config;
+package com.optima.document.server.config;
import com.optima.document.api.DocumentService;
import lombok.Data;
@@ -13,7 +13,7 @@ import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
* @author Elias
* @since 2021-09-28 16:12
*/
-@SuppressWarnings("VulnerableCodeUsages")
+@SuppressWarnings("deprecation")
@Configuration
@ConfigurationProperties(prefix = "document")
@Data
diff --git a/document-server/docto-document-server/src/main/resources/application.yml b/document-server/docto-document-server/src/main/resources/application.yml
new file mode 100644
index 0000000..7eddcf7
--- /dev/null
+++ b/document-server/docto-document-server/src/main/resources/application.yml
@@ -0,0 +1,5 @@
+server:
+ port: 9004
+
+document:
+ doc-to-program: C:\\DocumentServer\\docto.exe
\ No newline at end of file
diff --git a/server/src/main/resources/banner.txt b/document-server/docto-document-server/src/main/resources/banner.txt
similarity index 100%
rename from server/src/main/resources/banner.txt
rename to document-server/docto-document-server/src/main/resources/banner.txt
diff --git a/document-server/jod-document-server/pom.xml b/document-server/jod-document-server/pom.xml
new file mode 100644
index 0000000..5395f6e
--- /dev/null
+++ b/document-server/jod-document-server/pom.xml
@@ -0,0 +1,32 @@
+
+
+ 4.0.0
+
+ com.optima
+ document-server
+ 2.0.0
+
+ jod-document-server
+ 2.0.0
+ Jod Document Server
+ Jod 文档操作服务
+
+
+ 4.4.9
+
+
+
+
+ org.jodconverter
+ jodconverter-local
+ ${jodconverter.version}
+
+
+
+ org.jodconverter
+ jodconverter-spring-boot-starter
+ ${jodconverter.version}
+
+
+
diff --git a/server/src/main/java/com/optima/document/server/DocumentServer.java b/document-server/jod-document-server/src/main/java/com/optima/document/server/JodDocumentServer.java
similarity index 72%
rename from server/src/main/java/com/optima/document/server/DocumentServer.java
rename to document-server/jod-document-server/src/main/java/com/optima/document/server/JodDocumentServer.java
index 437ed56..581fc53 100644
--- a/server/src/main/java/com/optima/document/server/DocumentServer.java
+++ b/document-server/jod-document-server/src/main/java/com/optima/document/server/JodDocumentServer.java
@@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
-public class DocumentServer {
+public class JodDocumentServer {
public static void main(String[] args) {
- SpringApplication.run(DocumentServer.class, args);
+ SpringApplication.run(JodDocumentServer.class, args);
}
}
diff --git a/document-server/jod-document-server/src/main/java/com/optima/document/server/api/DocumentServiceImpl.java b/document-server/jod-document-server/src/main/java/com/optima/document/server/api/DocumentServiceImpl.java
new file mode 100644
index 0000000..b1e53c1
--- /dev/null
+++ b/document-server/jod-document-server/src/main/java/com/optima/document/server/api/DocumentServiceImpl.java
@@ -0,0 +1,196 @@
+package com.optima.document.server.api;
+
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.data.PictureRenderData;
+import com.deepoove.poi.data.TextRenderData;
+import com.deepoove.poi.policy.ListRenderPolicy;
+import com.deepoove.poi.policy.PictureRenderPolicy;
+import com.deepoove.poi.render.RenderContext;
+import com.deepoove.poi.template.run.RunTemplate;
+import com.deepoove.poi.xwpf.BodyContainer;
+import com.deepoove.poi.xwpf.BodyContainerFactory;
+import com.optima.document.api.DocumentService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.rendering.ImageType;
+import org.apache.pdfbox.rendering.PDFRenderer;
+import org.apache.pdfbox.tools.imageio.ImageIOUtil;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.jodconverter.core.DocumentConverter;
+import org.jodconverter.core.document.DefaultDocumentFormatRegistry;
+import org.jodconverter.core.document.DocumentFormat;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 服务接口实现
+ *
+ * @author Elias
+ * @since 2021-09-28 16:18
+ */
+@Slf4j
+@Service
+public class DocumentServiceImpl implements DocumentService {
+ @Resource
+ private DocumentConverter documentConverter;
+
+ /**
+ * word模版引擎配置
+ */
+ private static final Configure wtlConfig = Configure.builder().buildGramer("${", "}")
+ .setValidErrorHandler(new Configure.DiscardHandler())
+ .addPlugin('%', new ListRenderPolicy() {
+ @Override
+ public void doRender(RenderContext> context) throws Exception {
+ XWPFRun run = context.getRun();
+ List> dataList = context.getData();
+ Iterator> var5 = dataList.iterator();
+ while (var5.hasNext()) {
+ Object data = var5.next();
+ if (data instanceof TextRenderData) {
+ run.setText(((TextRenderData) data).getText());
+ if (var5.hasNext()) {
+ run.setText(",");
+ }
+ } else if (data instanceof PictureRenderData) {
+ PictureRenderPolicy.Helper.renderPicture(run, (PictureRenderData) data);
+ }
+
+ }
+ }
+
+ })
+ .setRenderDataComputeFactory(envModel ->
+ el -> {
+ Object data = envModel.getRoot();
+ if ("#this".equals(el)) {
+ return data;
+ } else if (data instanceof Map) {
+ Map dataMap = ((Map) data);
+ if (dataMap.containsKey(el)) {
+ return dataMap.get(el);
+ }
+ }
+ return null;
+ })
+ .build();
+
+ /**
+ * 文件格式转换
+ *
+ * @param source 源文件流
+ * @param sourceExtension 源文件后缀名,不包含"."
+ * @param targetExtension 目标文件后缀名
+ * @return 转换后的文件流
+ */
+ public byte[] convert(byte[] source, String sourceExtension, String targetExtension) {
+ try {
+ sourceExtension = sourceExtension.replace(".", "");
+ targetExtension = targetExtension.replace(".", "");
+ long start = System.currentTimeMillis();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DocumentFormat sourceFormat = DefaultDocumentFormatRegistry.getFormatByExtension(sourceExtension);
+ DocumentFormat targetFormat = DefaultDocumentFormatRegistry.getFormatByExtension(targetExtension);
+ assert sourceFormat != null;
+ assert targetFormat != null;
+ documentConverter.convert(new ByteArrayInputStream(source))
+ .as(sourceFormat)
+ .to(bos)
+ .as(targetFormat)
+ .execute();
+ log.info("convert {} to {} take time in millis:{}", sourceExtension, targetExtension, System.currentTimeMillis() - start);
+ return bos.toByteArray();
+ } catch (Exception e) {
+ log.error("convert {} to {} error", sourceExtension, targetExtension, e);
+ }
+ return null;
+ }
+
+ public byte[] convert(byte[] source, String sourceExtension, String targetExtension, String targetFormat) {
+ return convert(source, sourceExtension, targetExtension);
+ }
+
+ public byte[] generateWord(byte[] sourceTemplate, Map dataModel) {
+ long start = System.currentTimeMillis();
+ XWPFTemplate template = XWPFTemplate.compile(new ByteArrayInputStream(sourceTemplate), wtlConfig).render(dataModel);
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
+ template.write(bos);
+ log.info("word generate take time in millis:{}", System.currentTimeMillis() - start);
+ return bos.toByteArray();
+ } catch (Exception e) {
+ log.error("word generate error", e);
+ return null;
+ }
+ }
+
+ public byte[] wordToPdf(byte[] source, String sourceFormat, boolean clear) {
+ return wordToPdf(source, clear);
+ }
+
+ public byte[] wordToPdf(byte[] source, boolean clear) {
+ try {
+ long start = System.currentTimeMillis();
+ if (clear) {
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
+ XWPFTemplate template = XWPFTemplate.compile(new ByteArrayInputStream(source), wtlConfig);
+ BodyContainer bodyContainer = BodyContainerFactory.getBodyContainer(template.getXWPFDocument());
+ template.getElementTemplates().forEach(it -> {
+ if (it instanceof RunTemplate) {
+ RunTemplate rt = (RunTemplate) it;
+ bodyContainer.clearPlaceholder(rt.getRun());
+ }
+ });
+ template.writeAndClose(bos);
+ source = bos.toByteArray();
+ log.info("clear placeholder take time in millis:{}", System.currentTimeMillis() - start);
+ } catch (Exception e) {
+ log.error("clear placeholder error", e);
+ return null;
+ }
+ }
+ return convert(source, "docx", "pdf");
+ } catch (Exception e) {
+ log.error("word to pdf error", e);
+ return null;
+ }
+ }
+
+ public byte[] wordToImage(byte[] source, String targetExtension) {
+ try {
+ byte[] pdfBytes = wordToPdf(source, true);
+ long start = System.currentTimeMillis();
+ PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfBytes));
+ PDFRenderer pdfRenderer = new PDFRenderer(document);
+ BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.RGB);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ImageIOUtil.writeImage(bim, targetExtension, bos, 300);
+ document.close();
+ log.info("word to image take time in millis:{}", System.currentTimeMillis() - start);
+ return bos.toByteArray();
+ } catch (Exception e) {
+ log.error("word to image error", e);
+ }
+ return null;
+ }
+
+ public byte[] wordToImage(byte[] source, String sourceExtension, String targetExtension) {
+ return wordToImage(source, targetExtension);
+ }
+
+ public byte[] docToDocx(byte[] source) {
+ return convert(source, "doc", "docx");
+ }
+
+ public byte[] xlsToXlsx(byte[] source) {
+ return convert(source, "xls", "xlsx");
+ }
+
+}
diff --git a/server/src/main/java/com/optima/document/server/config/DocumentConfig.java b/document-server/jod-document-server/src/main/java/com/optima/document/server/config/DocumentConfig.java
similarity index 66%
rename from server/src/main/java/com/optima/document/server/config/DocumentConfig.java
rename to document-server/jod-document-server/src/main/java/com/optima/document/server/config/DocumentConfig.java
index 9e3b9d5..effd536 100644
--- a/server/src/main/java/com/optima/document/server/config/DocumentConfig.java
+++ b/document-server/jod-document-server/src/main/java/com/optima/document/server/config/DocumentConfig.java
@@ -1,6 +1,6 @@
package com.optima.document.server.config;
-import com.optima.document.api.LegacyDocumentService;
+import com.optima.document.api.DocumentService;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -13,26 +13,21 @@ import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
* @author Elias
* @since 2021-09-28 16:12
*/
-@SuppressWarnings("VulnerableCodeUsages")
+@SuppressWarnings("deprecation")
@Configuration
@ConfigurationProperties(prefix = "document")
@Data
public class DocumentConfig {
-
- private String tempDir;
-
- private String openOfficeHome;
-
/**
* 文档接口
*
* @return httpinvoker
*/
@Bean(name = "/document-service")
- HttpInvokerServiceExporter wordService(LegacyDocumentService legacyDocumentService) {
+ HttpInvokerServiceExporter wordService(DocumentService documentService) {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
- exporter.setService(legacyDocumentService);
- exporter.setServiceInterface(LegacyDocumentService.class);
+ exporter.setService(documentService);
+ exporter.setServiceInterface(DocumentService.class);
return exporter;
}
diff --git a/document-server/jod-document-server/src/main/resources/application.yml b/document-server/jod-document-server/src/main/resources/application.yml
new file mode 100644
index 0000000..a44f16b
--- /dev/null
+++ b/document-server/jod-document-server/src/main/resources/application.yml
@@ -0,0 +1,16 @@
+server:
+ port: 9005
+
+jodconverter:
+ local:
+ # 启动本地转换
+ enabled: true
+ # macOS下:program/soffice 的 program 所在目录 或 MacOS/soffice 的 MacOS 所在目录
+ # windows下:program/soffice.exe 的 program 所在目录
+ # linux下:program/soffice.bin 的 program 所在目录
+ # 如果不配置,则自动查找
+ office-home: /Applications/LibreOffice.app/Contents
+ # 一个端口表示一个常驻进程,默认只有一个进程,端口为2002
+ port-numbers: [ 2002 ]
+ # 每个进程最多处理多个任务,默认为200
+ max-tasks-per-process: 200
diff --git a/tl-server/src/main/resources/banner.txt b/document-server/jod-document-server/src/main/resources/banner.txt
similarity index 100%
rename from tl-server/src/main/resources/banner.txt
rename to document-server/jod-document-server/src/main/resources/banner.txt
diff --git a/document-server/jod-document-server/src/test/java/com/optima/document/server/JodDocumentServerTest.java b/document-server/jod-document-server/src/test/java/com/optima/document/server/JodDocumentServerTest.java
new file mode 100644
index 0000000..8088311
--- /dev/null
+++ b/document-server/jod-document-server/src/test/java/com/optima/document/server/JodDocumentServerTest.java
@@ -0,0 +1,42 @@
+package com.optima.document.server;
+
+import com.optima.document.api.DocumentService;
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.HashMap;
+import java.util.Map;
+
+@Disabled
+public class JodDocumentServerTest {
+
+ @Test
+ public void test() throws IOException {
+ DocumentService documentService = buildDocumentService();
+
+ File sourceDocx = new File("/Users/yanghuanglin/Downloads/test.docx");
+ File targetPdf = new File("/Users/yanghuanglin/Downloads/test.pdf");
+
+ Map params = new HashMap<>();
+ params.put("callerName", "张三");
+ byte[] sourceBytes = documentService.generateWord(Files.readAllBytes(sourceDocx.toPath()), params);
+
+ byte[] bytes = documentService.wordToPdf(sourceBytes, false);
+ FileUtils.writeByteArrayToFile(targetPdf, bytes);
+ }
+
+ private static DocumentService buildDocumentService() {
+ // 创建客户端代理
+ HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
+ factoryBean.setServiceUrl("http://10.211.55.13:9005/document-service");
+ factoryBean.setServiceInterface(DocumentService.class);
+ factoryBean.afterPropertiesSet();
+
+ return (DocumentService) factoryBean.getObject();
+ }
+}
diff --git a/document-server/pom.xml b/document-server/pom.xml
new file mode 100644
index 0000000..e664496
--- /dev/null
+++ b/document-server/pom.xml
@@ -0,0 +1,163 @@
+
+
+ 4.0.0
+
+ com.optima
+ document
+ 2.0.0
+
+ document-server
+ pom
+ Document Server
+ 文档操作模块
+
+ docto-document-server
+ jod-document-server
+
+
+
+ 2.0.25
+ 2.17.2
+ 1.16.20
+ 1.12.1
+
+
+
+
+ com.optima
+ document-api
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.apache.pdfbox
+ pdfbox-tools
+
+
+
+ com.deepoove
+ poi-tl
+
+
+
+ org.apache.logging.log4j
+ log4j-to-slf4j
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ 2.7.18
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+ 2.7.18
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ 2.7.18
+ test
+
+
+
+ com.optima
+ document-api
+ 2.0.0
+
+
+
+ org.apache.pdfbox
+ pdfbox-tools
+ ${pdfbox-tools.version}
+
+
+
+ com.deepoove
+ poi-tl
+ ${poi-tl.version}
+
+
+
+ org.apache.logging.log4j
+ log4j-to-slf4j
+ ${log4j.version}
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+ ${log4j.version}
+
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+
+
+
+ document-server-${version}
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.3.1
+
+
+ copy-resources
+ process-resources
+
+ copy-resources
+
+
+ ${project.build.directory}
+
+
+ src/main/resources
+
+ application.yml
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 08296c9..f2a85ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,16 +1,40 @@
- 4.0.0
- com.optima
- document
- 2.0.0
- pom
- document
- 文档操作模块
-
- api
- server
- tl-server
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ com.optima
+ document
+ 2.0.0
+ pom
+ Document
+ 文档操作模块
+
+ document-api
+ document-server
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 2.7.18
+
+
+
+ repackage
+
+
+
+
+
+
diff --git a/server/pom.xml b/server/pom.xml
deleted file mode 100644
index 6110b38..0000000
--- a/server/pom.xml
+++ /dev/null
@@ -1,136 +0,0 @@
-
-
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.0.3.RELEASE
-
-
- com.optima
- document-server
- 2.0.0
- document server
- 文档操作服务
-
- 1.8
- 8.5.100
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- com.optima
- document-api
- 2.0.0
-
-
-
- org.apache.commons
- commons-lang3
- 3.3.2
-
-
-
- net.sf.jacob-project
- jacob
- 1.18
- system
- ${basedir}/src/main/resources/libs/jacob.jar
-
-
- com.artofsolving
- jodconverter
- 2.2.2
- system
- ${basedir}/src/main/resources/libs/jodconverter-2.2.2.jar
-
-
-
- apache
- poi2
- 1.0
- system
- ${basedir}/src/main/resources/libs/poi2-1.0.jar
-
-
-
- org.apache.poi
- poi
- 3.14
-
-
- org.apache.poi
- poi-ooxml
- 3.14
-
-
-
- org.apache.poi
- poi-scratchpad
- 3.14
-
-
- joda-time
- joda-time
- 2.1
-
-
- org.projectlombok
- lombok
- 1.16.20
- provided
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
- org.jodconverter
- jodconverter-core
- 4.0.0-RELEASE
-
-
- commons-io
- commons-io
-
-
- commons-lang3
- org.apache.commons
-
-
- json
- org.json
-
-
-
-
- org.apache.commons
- commons-io
- 1.3.2
-
-
- org.apache.pdfbox
- pdfbox-tools
- 2.0.25
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
- true
-
-
-
-
-
-
diff --git a/server/src/main/java/com/optima/document/server/api/LegacyDocumentServiceImpl.java b/server/src/main/java/com/optima/document/server/api/LegacyDocumentServiceImpl.java
deleted file mode 100644
index f01cdd9..0000000
--- a/server/src/main/java/com/optima/document/server/api/LegacyDocumentServiceImpl.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package com.optima.document.server.api;
-
-import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
-import com.artofsolving.jodconverter.DocumentConverter;
-import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
-import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
-import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
-import com.optima.document.api.LegacyDocumentService;
-import com.optima.document.server.config.DocumentConfig;
-import com.optima.document.server.utils.DocToPdfUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.rendering.ImageType;
-import org.apache.pdfbox.rendering.PDFRenderer;
-import org.apache.pdfbox.tools.imageio.ImageIOUtil;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 服务接口实现
- *
- * @author Elias
- * @since 2021-09-28 16:18
- */
-@Slf4j
-@Service
-public class LegacyDocumentServiceImpl implements LegacyDocumentService {
- @Resource
- private DocumentConfig documentConfig;
-
- /**
- * 文件格式转换
- *
- * @param source 源文件流
- * @param sourceExtension 源文件后缀名,不包含"."
- * @param targetExtension 目标文件后缀名
- * @return 转换后的文件流
- */
- private byte[] convert(byte[] source, String sourceExtension, String targetExtension) {
- try {
- sourceExtension = sourceExtension.replace(".","");
- targetExtension = targetExtension.replace(".","");
- long start = System.currentTimeMillis();
- String command = "%s -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
- Process p = Runtime.getRuntime().exec(String.format(command, documentConfig.getOpenOfficeHome()));
- OpenOfficeConnection connection = new SocketOpenOfficeConnection();
- connection.connect();
- DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DefaultDocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
- converter.convert(new ByteArrayInputStream(source), formatRegistry.getFormatByFileExtension(sourceExtension), bos, formatRegistry.getFormatByFileExtension(targetExtension));
- connection.disconnect();
- p.destroy();
- log.info("openoffice convert {} to {} take time in millis:{}", sourceExtension, targetExtension, System.currentTimeMillis() - start);
- return bos.toByteArray();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public byte[] fieldToWord(byte[] source, Map infoMap) {
- return DocToPdfUtil.fieldToWord(source, infoMap);
- }
-
- public byte[] insertJpeg(byte[] source, String toFindText, byte[] imgSource, int width, int height) {
- return DocToPdfUtil.insertJpeg(source, toFindText, imgSource, width, height);
- }
-
- public byte[] insertJpeg(byte[] source, String toFindText, List imgSource, int width, int height) {
- return DocToPdfUtil.insertJpeg(source, toFindText, imgSource, width, height);
- }
-
- public byte[] wordToPdf(byte[] source, String sourceExtension, boolean clear) {
- try {
- if (clear) {
- source = DocToPdfUtil.clearPlaceholder(source);
- }
- return convert(source, sourceExtension, "pdf");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public byte[] convert(byte[] source, String sourceExtension, String targetExtension, String targetFormat) {
- return convert(source, sourceExtension, targetExtension);
- }
-
- public byte[] wordToImage(byte[] source, String sourceExtension, String targetExtension) {
- try {
- byte[] pdfBytes = wordToPdf(source, sourceExtension, true);
- PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfBytes));
- PDFRenderer pdfRenderer = new PDFRenderer(document);
- BufferedImage bim = pdfRenderer.renderImageWithDPI(
- 0, 300, ImageType.RGB);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ImageIOUtil.writeImage(bim, targetExtension, bos, 300);
- document.close();
- return bos.toByteArray();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public byte[] docToDocx(byte[] source) {
- return convert(source, "doc", "docx");
- }
-
- public byte[] xlsToXlsx(byte[] source) {
- return convert(source, "xls", "xlsx");
- }
-}
diff --git a/server/src/main/java/com/optima/document/server/utils/CastUtil.java b/server/src/main/java/com/optima/document/server/utils/CastUtil.java
deleted file mode 100644
index 5192f39..0000000
--- a/server/src/main/java/com/optima/document/server/utils/CastUtil.java
+++ /dev/null
@@ -1,493 +0,0 @@
-package com.optima.document.server.utils;
-
-
-
-import org.apache.commons.lang3.StringUtils;
-import org.joda.time.DateTime;
-
-import java.math.BigDecimal;
-import java.text.DateFormat;
-import java.text.DecimalFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Created by xianjun on 2016/6/17.
- */
-
-/**
- * 转型操作工具类
- */
-public final class CastUtil {
-
- /**
- * 转为String 型 默认为空
- */
- public static String castString(Object obj) {
- return CastUtil.castString(obj, "");
- }
-
- /**
- * 转为String 型(提供默认值)
- */
- public static String castString(Object obj, String defaultValue) {
- return obj != null ? String.valueOf(obj) : defaultValue;
- }
-
- /**
- * 转为double型 默认为0
- */
- public static double castDouble(Object obj) {
- return CastUtil.castDouble(obj, 0);
- }
-
- /**
- * 转为double型(提供默认值)
- */
- public static double castDouble(Object obj, double defaultValue) {
- double doubleValue = defaultValue;
- if (obj != null) {
- String strValue = castString(obj);
- if (StringUtils.isNotEmpty(strValue)) {
- try {
- doubleValue = Double.parseDouble(strValue);
- } catch (NumberFormatException e) {
- doubleValue = defaultValue;
- }
- }
- }
- return doubleValue;
- }
-
- /**
- * 转为long型,默认值为0
- */
- public static long castLong(Object obj) {
- return CastUtil.castLong(obj, 0);
- }
-
- /**
- * 转换为long型(提供默认值)
- */
- public static long castLong(Object obj, long defaultValue) {
- long longValue = defaultValue;
- if (obj != null) {
- String strValue = castString(obj);
- if (!StringUtils.isEmpty(strValue)) {
- try {
- longValue = Long.parseLong(strValue);
- } catch (NumberFormatException e) {
- longValue = defaultValue;
- }
- }
- }
- return longValue;
- }
-
- /**
- * 转为int型 默认值为0
- */
- public static int castInt(Object obj) {
- return CastUtil.castInt(obj, 0);
- }
-
- /**
- * 转为int型(提供默认值)
- */
- public static int castInt(Object obj, int defaultValue) {
- int intValue = defaultValue;
- if (obj != null) {
- String strValue = castString(obj);
- if (StringUtils.isNotEmpty(strValue)) {
- try {
- intValue = Integer.parseInt(strValue);
- } catch (NumberFormatException e) {
- intValue = defaultValue;
- }
- }
- }
- return intValue;
- }
-
- /**
- * 转为double型,默认值为false
- */
- public static boolean castBoolean(Object obj) {
- return CastUtil.castBoolean(obj, false);
- }
-
- /**
- * 转为double型,提供默认值
- */
- public static boolean castBoolean(Object obj, boolean defaultValue) {
- boolean booleanValue = defaultValue;
- if (obj != null) {
- booleanValue = Boolean.parseBoolean(castString(obj));
- }
- return booleanValue;
- }
-
- /**
- * 转时间戳为date类型
- *
- * @param time
- * @param defaultValue
- * @return
- */
- public static Date castDate(long time, Date defaultValue) {
- Date dateValue = defaultValue;
- if (time != 0) {
- DateTime dateTime = new DateTime(time);
- dateValue = dateTime.toDate();
- }
-
- return dateValue;
- }
-
- public static Date castDateNo(long time) {
- return castDate(time, new Date(0));
- }
-
- /**
- * 转时间戳为date类型
- */
- public static Date castDate(long time) {
- return castDate(time, new Date());
- }
-
- /**
- * 获取开始时间
- *
- * @Title: getStartTime
- * @author: xianjun
- * @Description: TODO
- * @param date
- * @param monthTime
- * @param dateTime
- * @param hour
- * @return
- * @throws
- */
- public static Date getStartTime(Date date, int monthTime, int dateTime, int hour) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(CastUtil.castInt(CastUtil.castStringByDate(date, "yyyy")), date.getMonth() + monthTime, date.getDate() + dateTime, 0 + hour, 0, 0);
- return calendar.getTime();
- }
-
- /**
- * 获取结束时间
- *
- * @Title: getEndTime
- * @author: xianjun
- * @Description: TODO
- * @param date
- * @param monthTime
- * @param dateTime
- * @param hour
- * @return
- * @throws
- */
- public static Date getEndTime(Date date, int monthTime, int dateTime, int hour) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(CastUtil.castInt(CastUtil.castStringByDate(date, "yyyy")), date.getMonth() + monthTime, date.getDate() + dateTime, 23 + hour, 59, 59);
- return calendar.getTime();
- }
-
- /**
- * 转日期格式为字符串
- */
- public static String castStringDate(Date date, Date defaultValue) {
- SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date dateValue = defaultValue;
- String dateString = "";
- if (date != null) {
- dateString = fmt.format(date);
- } else {
- dateString = fmt.format(dateValue);
- }
-
- return dateString;
- }
-
- /**
- * 转换日期格式为年-月-日
- * @Title: castStringIntegerDate
- * @author: xianjun
- * @Description: TODO
- * @param date
- * @return
- * @throws
- */
- public static String castStringIntegerDate(Date date) {
- return castStringIntegerDate(date, new Date());
- }
-
- /**
- * 转换格式为年-月-日
- * @Title: castStringIntegerDate
- * @author: xianjun
- * @Description: TODO
- * @param date
- * @param defaultValue
- * @return
- * @throws
- */
- public static String castStringIntegerDate(Date date, Date defaultValue) {
- SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
- Date dateValue = defaultValue;
- String dateString = "";
- if (date != null) {
- dateString = fmt.format(date);
- } else {
- dateString = fmt.format(dateValue);
- }
-
- return dateString;
- }
-
- /**
- * 根据传入的格式,转换为不同的日期
- *
- * @Title: castStringByDate
- * @author: xianjun
- * @Description: TODO
- * @param date
- * @param pattern
- * @return
- * @throws
- */
- public static String castStringByDate(Date date, String pattern) {
- SimpleDateFormat fmt = new SimpleDateFormat(pattern);
- Date dateValue = new Date();
- String dateString = "";
- if (date != null) {
- dateString = fmt.format(date);
- } else {
- dateString = fmt.format(dateValue);
- }
- return dateString;
- }
-
- /**
- * 转日期格式为字符串
- */
- public static String castStringDate(Date date) {
- return castStringDate(date, new Date());
- }
-
- /**
- * 转 字符串为日期格式
- */
- public static Date castDateByString(String defaultDate){
- SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- Date date = fmt.parse(defaultDate);
- return date;
- } catch (ParseException e) {
- e.printStackTrace();
- return new Date();
- }
- }
-
- /**
- * 转BigDecimal为字符串
- */
- public static String castStringByDecimal(BigDecimal value, String pattern) {
- DecimalFormat fmt = new DecimalFormat(pattern);
- try {
- String tempValue = fmt.format(value.stripTrailingZeros());
- return tempValue;
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- return "0";
- }
- }
-
- /**
- * 转换字符串,判断是否非空
- * @Title: castStringByString
- * @author: xianjun
- * @Description: TODO
- * @param defaultString
- * @return
- * @throws
- */
- public static String castStringByString(String defaultString) {
- String value = defaultString == null ? "" : defaultString;
- return value;
- }
-
- /**
- * 去除html标签
- * @Title: delHTMLTag
- * @author: xianjun
- * @Description: TODO
- * @param htmlStr
- * @return
- * @throws
- */
- public static String delHTMLTag(String htmlStr){
- String regEx_script="