挂载附件~解析word内的文件名
This commit is contained in:
parent
5b418056e8
commit
7efe804fa8
@ -23,10 +23,7 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.usermodel.*;
|
import org.apache.poi.hwpf.usermodel.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,30 +95,42 @@ public class ReadTable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//解析文档附件
|
DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
|
||||||
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(wsId, docxname.replace(".docx", ""));
|
|
||||||
if (palRepositoryModel == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String id = palRepositoryModel.getId();
|
|
||||||
|
|
||||||
|
|
||||||
//进行文件解析 写基本信息
|
//进行文件解析 写基本信息
|
||||||
DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
|
//DCPluginProfile dcProfilepdfdoc = DCProfileManager.getDCProfile("com.actionsoft.apps.coe.pal.datamigration", "migration");
|
||||||
DCContext dcContextpdfdoc = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docname);
|
DCContext dcContextpdfdoc = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docname);
|
||||||
InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc);
|
InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc);
|
||||||
//画一个图形 并返回图形ID
|
//画一个图形 并返回图形ID
|
||||||
String shapId = createOneMap(wsId, docname.replace(".doc", ""), userContext, docfile);
|
String shapId = createOneMap(wsId, docname.replace(".doc", ""), userContext, docfile);
|
||||||
|
if(shapId.isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String title = fileFieldMap.get("标题").getData().toString();
|
||||||
|
//解析文档附件
|
||||||
|
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(wsId, title);
|
||||||
|
if (palRepositoryModel == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String id = palRepositoryModel.getId();
|
||||||
|
//将文件挂载到附件里面
|
||||||
|
DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
|
||||||
|
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
|
||||||
|
try {
|
||||||
|
new ReadWordUtil().writeFileTodisk(userContext, "", fileName, originfile, palRepositoryModel.getId(),"f");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
//先把默认属性给他弄上~~~然后再赋值
|
//先把默认属性给他弄上~~~然后再赋值
|
||||||
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palRepositoryModel.getId(), 0);
|
/*BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palRepositoryModel.getId(), 0);
|
||||||
if (defineModel == null) {
|
if (defineModel == null) {
|
||||||
defineModel = CoeDesignerUtil.createModel(palRepositoryModel.getId(), 0);
|
defineModel = CoeDesignerUtil.createModel(palRepositoryModel.getId(), 0);
|
||||||
defineModel.setCreateHistory(false);
|
defineModel.setCreateHistory(false);
|
||||||
}
|
}*/
|
||||||
String define = defineModel.getDefinition();
|
/*String define = defineModel.getDefinition();
|
||||||
JSONObject definition = JSONObject.parseObject(define);
|
JSONObject definition = JSONObject.parseObject(define);
|
||||||
JSONObject elements = definition.getJSONObject("elements");
|
JSONObject elements = definition.getJSONObject("elements");
|
||||||
Map<String, Map<String, JSONObject>> methodAttrsMap = new HashMap<>();
|
Map<String, Map<String, JSONObject>> methodAttrsMap = new HashMap<>();*/
|
||||||
//handleShapeDefaultAttr("", palRepositoryModel, elements, methodAttrsMap, docfile);
|
//handleShapeDefaultAttr("", palRepositoryModel, elements, methodAttrsMap, docfile);
|
||||||
//writeAttrbute(userContext, docfile, docname.replace(".doc", ""), elements.getJSONObject(shapId));
|
//writeAttrbute(userContext, docfile, docname.replace(".doc", ""), elements.getJSONObject(shapId));
|
||||||
//解析附件进行复制
|
//解析附件进行复制
|
||||||
@ -169,7 +178,15 @@ public class ReadTable {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String createOneMap(String plId, String name, UserContext userContext, InputStream docfile) {
|
public String createOneMap(String plId, String name, UserContext userContext, InputStream docfile) {
|
||||||
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(plId, name);
|
boolean result = analysisWordTable(docfile);
|
||||||
|
String title = fileFieldMap.get("标题").getData().toString();
|
||||||
|
if(title.isEmpty()){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
PALRepositoryModel palRepositoryModel = ReadWordUtil.getRepositoryByName(plId, title);
|
||||||
|
if(palRepositoryModel == null){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palRepositoryModel.getId(), 0);
|
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palRepositoryModel.getId(), 0);
|
||||||
if (defineModel == null) {
|
if (defineModel == null) {
|
||||||
defineModel = CoeDesignerUtil.createModel(palRepositoryModel.getId(), 0);
|
defineModel = CoeDesignerUtil.createModel(palRepositoryModel.getId(), 0);
|
||||||
@ -185,7 +202,7 @@ public class ReadTable {
|
|||||||
//增加一个表单图形
|
//增加一个表单图形
|
||||||
JSONObject shapeze = ShapeUtil.getProcessShapeDefinitionByName("data.form", "form");
|
JSONObject shapeze = ShapeUtil.getProcessShapeDefinitionByName("data.form", "form");
|
||||||
String shapeIdz = UUIDGener.getObjectId();
|
String shapeIdz = UUIDGener.getObjectId();
|
||||||
shapeze.put("text", name);//不生效
|
shapeze.put("text", title);//不生效
|
||||||
shapeze.put("level", 0);
|
shapeze.put("level", 0);
|
||||||
JSONObject props1 = shapeze.getJSONObject("props");// 位置大小
|
JSONObject props1 = shapeze.getJSONObject("props");// 位置大小
|
||||||
shapeze.put("id", shapeIdz);
|
shapeze.put("id", shapeIdz);
|
||||||
@ -212,6 +229,7 @@ public class ReadTable {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean analysisWordTable(InputStream file) {
|
public boolean analysisWordTable(InputStream file) {
|
||||||
|
boolean ischeck = false;
|
||||||
try {
|
try {
|
||||||
HWPFDocument doc = new HWPFDocument(file);
|
HWPFDocument doc = new HWPFDocument(file);
|
||||||
//XWPFDocument doc = new XWPFDocument(file);
|
//XWPFDocument doc = new XWPFDocument(file);
|
||||||
@ -222,6 +240,22 @@ public class ReadTable {
|
|||||||
if (StringUtils.isEmpty(text)) {
|
if (StringUtils.isEmpty(text)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(nowPara.text().contains("文件编码")){
|
||||||
|
ischeck = true;
|
||||||
|
}
|
||||||
|
if(ischeck){
|
||||||
|
boolean isTitle = isTitle(nowPara);
|
||||||
|
if(isTitle){
|
||||||
|
String title = "";
|
||||||
|
if(fieldMap.get("标题") != null){
|
||||||
|
title = fieldMap.get("标题").toString();
|
||||||
|
}
|
||||||
|
title = title+nowPara.text().replace("\r","");
|
||||||
|
fieldMap.put("标题", title);
|
||||||
|
fileFieldMap.put("标题", new WordField<>(title));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
/*WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
||||||
if (null == wordAttribute) {
|
if (null == wordAttribute) {
|
||||||
continue;
|
continue;
|
||||||
@ -316,7 +350,6 @@ public class ReadTable {
|
|||||||
* @param methodAttrsMap
|
* @param methodAttrsMap
|
||||||
*/
|
*/
|
||||||
public void handleShapeDefaultAttr(String wsId, PALRepositoryModel palModel, JSONObject elements, Map<String, Map<String, JSONObject>> methodAttrsMap, InputStream file) {
|
public void handleShapeDefaultAttr(String wsId, PALRepositoryModel palModel, JSONObject elements, Map<String, Map<String, JSONObject>> methodAttrsMap, InputStream file) {
|
||||||
boolean result = analysisWordTable(file);
|
|
||||||
for (String key : elements.keySet()) {
|
for (String key : elements.keySet()) {
|
||||||
JSONObject shape = elements.getJSONObject(key);
|
JSONObject shape = elements.getJSONObject(key);
|
||||||
if ("linker".equals(shape.getString("name"))) {
|
if ("linker".equals(shape.getString("name"))) {
|
||||||
@ -395,4 +428,25 @@ public class ReadTable {
|
|||||||
object2.put("value", "");
|
object2.put("value", "");
|
||||||
return object2;
|
return object2;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 判断是否为文档标题
|
||||||
|
* 标志:黑体一号
|
||||||
|
* @param paragraph
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isTitle(Paragraph paragraph){
|
||||||
|
int size = paragraph.numCharacterRuns();
|
||||||
|
String fontName = "";
|
||||||
|
int fontSize = 0;
|
||||||
|
boolean bold ;
|
||||||
|
for (int j = 0; j < size; j++) {
|
||||||
|
CharacterRun characterRun = paragraph.getCharacterRun(j);
|
||||||
|
fontName = characterRun.getFontName();
|
||||||
|
if (fontName.contains("黑体")){
|
||||||
|
//与文档fontsize标号2倍关系 ,黑体一号 等于 26号size
|
||||||
|
return characterRun.getFontSize() == 44;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,6 +82,10 @@ public class ReadWordUtil {
|
|||||||
public void writeAttrbute(UserContext userContext, InputStream file, String name, String wsdl) {
|
public void writeAttrbute(UserContext userContext, InputStream file, String name, String wsdl) {
|
||||||
boolean result = analysisWordTable(file);
|
boolean result = analysisWordTable(file);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
String title = fileFieldMap.get("标题").getData().toString();
|
||||||
|
if(title.isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
//根据名称获取PAL制度模型
|
//根据名称获取PAL制度模型
|
||||||
PALRepositoryModel palRepositoryModel = getRepositoryByName(wsdl, name);
|
PALRepositoryModel palRepositoryModel = getRepositoryByName(wsdl, name);
|
||||||
if (palRepositoryModel != null) {
|
if (palRepositoryModel != null) {
|
||||||
@ -171,28 +175,37 @@ public class ReadWordUtil {
|
|||||||
//将文件挂载到附件里面
|
//将文件挂载到附件里面
|
||||||
DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
|
DCContext dcContextorigin = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, fileName);
|
||||||
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
|
InputStream originfile = SDK.getDCAPI().read(dcContextorigin);
|
||||||
PALRepositoryModel palRepositoryModel = getRepositoryByName(wsId, docname.replace(".doc", ""));
|
|
||||||
|
|
||||||
|
//进行文件解析
|
||||||
|
DCContext dcContextpdfdoc = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docname);
|
||||||
|
InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc);
|
||||||
|
//ReadWordUtil tmp = new ReadWordUtil();
|
||||||
|
writeAttrbute(userContext, docfile, fileName, wsId);
|
||||||
|
String title = fileFieldMap.get("标题").getData().toString();
|
||||||
|
if(title.isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PALRepositoryModel palRepositoryModel = getRepositoryByName(wsId, title);
|
||||||
if (palRepositoryModel != null) {
|
if (palRepositoryModel != null) {
|
||||||
try {
|
try {
|
||||||
writeFileTodisk(userContext, "", fileName, originfile, palRepositoryModel.getId(), "f");
|
writeFileTodisk(userContext, "", fileName, originfile, palRepositoryModel.getId(), "f");
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//进行文件解析
|
|
||||||
DCContext dcContextpdfdoc = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docname);
|
|
||||||
InputStream docfile = SDK.getDCAPI().read(dcContextpdfdoc);
|
|
||||||
ReadWordUtil tmp = new ReadWordUtil();
|
|
||||||
tmp.writeAttrbute(userContext, docfile, docname.replace(".doc", ""), wsId);
|
|
||||||
//创建图形
|
//创建图形
|
||||||
DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docxname);
|
DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docxname);
|
||||||
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
|
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
|
||||||
new CreateMaps().updateMaps(userContext, wsId, docxfile, docxname.replace(".docx", ""));
|
new CreateMaps().updateMaps(userContext, wsId, docxfile, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean analysisWordTable(InputStream file) {
|
public boolean analysisWordTable(InputStream file) {
|
||||||
|
fileFieldMap.clear();
|
||||||
|
fieldMap.clear();
|
||||||
try {
|
try {
|
||||||
HWPFDocument doc = new HWPFDocument(file);
|
HWPFDocument doc = new HWPFDocument(file);
|
||||||
//XWPFDocument doc = new XWPFDocument(file);
|
//XWPFDocument doc = new XWPFDocument(file);
|
||||||
@ -203,6 +216,16 @@ public class ReadWordUtil {
|
|||||||
if (StringUtils.isEmpty(text)) {
|
if (StringUtils.isEmpty(text)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
boolean isTitle = isTitle(nowPara);
|
||||||
|
if(isTitle){
|
||||||
|
String title = "";
|
||||||
|
if(fieldMap.get("标题") != null){
|
||||||
|
title = fieldMap.get("标题").toString();
|
||||||
|
}
|
||||||
|
title = title+nowPara.text().replace("\r","");
|
||||||
|
fieldMap.put("标题", title);
|
||||||
|
fileFieldMap.put("标题", new WordField<>(title));
|
||||||
|
}
|
||||||
WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
||||||
if ("目的".equals(text.trim())) {
|
if ("目的".equals(text.trim())) {
|
||||||
int index = i + 1 > range.numParagraphs() ? i : i + 1;
|
int index = i + 1 > range.numParagraphs() ? i : i + 1;
|
||||||
@ -429,6 +452,7 @@ public class ReadWordUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将文件挂载到附件
|
* 将文件挂载到附件
|
||||||
|
*
|
||||||
* @param me
|
* @param me
|
||||||
* @param reid
|
* @param reid
|
||||||
* @param filename
|
* @param filename
|
||||||
@ -460,6 +484,28 @@ public class ReadWordUtil {
|
|||||||
new UpFileDao().create(model);
|
new UpFileDao().create(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为文档标题
|
||||||
|
* 标志:黑体一号
|
||||||
|
* @param paragraph
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isTitle(Paragraph paragraph){
|
||||||
|
int size = paragraph.numCharacterRuns();
|
||||||
|
String fontName = "";
|
||||||
|
int fontSize = 0;
|
||||||
|
boolean bold ;
|
||||||
|
for (int j = 0; j < size; j++) {
|
||||||
|
CharacterRun characterRun = paragraph.getCharacterRun(j);
|
||||||
|
fontName = characterRun.getFontName();
|
||||||
|
if (fontName.contains("黑体")){
|
||||||
|
//与文档fontsize标号2倍关系 ,黑体一号 等于 26号size
|
||||||
|
return characterRun.isBold() && characterRun.getFontSize() == 52;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据名字寻找palmode
|
* 根据名字寻找palmode
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user