You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
6.9 KiB
Java
187 lines
6.9 KiB
Java
package weaver.wps.doccenter.convert;
|
|
|
|
import net.sf.json.JSONArray;
|
|
import net.sf.json.JSONObject;
|
|
import weaver.file.Prop;
|
|
import weaver.general.Util;
|
|
import weaver.hrm.User;
|
|
import weaver.wps.doccenter.utils.Config;
|
|
import weaver.wps.doccenter.utils.FileInfoUtil;
|
|
import weaver.wps.doccenter.utils.Tools;
|
|
import weaver.wps.logging.Logger;
|
|
import weaver.wps.logging.LoggerFactory;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class OfficeWrapheader {
|
|
private Logger log = LoggerFactory.getLogger(OfficeWrapheader.class);
|
|
private User user;
|
|
|
|
// 书签内容类型,文本
|
|
public final static String BOOKMARK_TYPE_TEXT = "TEXT";
|
|
// 书签内容类型, 文档
|
|
public final static String BOOKMARK_TYPE_DOCUMENT = "DOCUMENT";
|
|
// 书签内容类型,图片
|
|
public final static String BOOKMARK_TYPE_IMAGE = "IMAGE";
|
|
|
|
// 书签,正文
|
|
public final static String BOOKMARK_CONTENT = "Content";
|
|
|
|
public OfficeWrapheader(){
|
|
}
|
|
|
|
/**
|
|
* 构造函数,用户基本上是用于获取多语言
|
|
* @param user
|
|
*/
|
|
public OfficeWrapheader(User user){
|
|
this.user = user;
|
|
}
|
|
|
|
public User getUser() {
|
|
return user;
|
|
}
|
|
|
|
public OfficeWrapheader setUser(User user) {
|
|
this.user = user;
|
|
return this;
|
|
}
|
|
|
|
public Logger getLog() {
|
|
return log;
|
|
}
|
|
|
|
public OfficeWrapheader setLog(Logger log) {
|
|
this.log = log;
|
|
return this;
|
|
}
|
|
|
|
public Map<String, String> convert(Map<String, String> params, JSONArray sampleList) throws Exception {
|
|
Map<String, String> result = new HashMap<String, String>();
|
|
JSONObject requestParams = new JSONObject();
|
|
|
|
String ecfileid = params.get("imagefileid");
|
|
// 判断模块。目前应该只有知识管理的
|
|
String fromMould = Tools.null2String(params.get("fromMould"));
|
|
fromMould = Tools.getFromMould(fromMould);
|
|
|
|
String targetFileFormat = Tools.null2String(params.get("targetFileFormat"));
|
|
String apiUrl = ""; // Config.getCpsV1OfficeWrapheader();
|
|
if(6 == Config.getProductVersion()) {
|
|
apiUrl = Config.getV6CpsV1OfficeWrapheader();
|
|
} else if(5 == Config.getProductVersion()) {
|
|
apiUrl = Config.getCpsV1OfficeWrapheader();
|
|
}
|
|
|
|
FileInfoUtil fileInfoUtil = new FileInfoUtil();
|
|
Map<String,String> fileInfo = fileInfoUtil.getFileInfo(ecfileid, user, fromMould);
|
|
|
|
String filename = fileInfo.get("filename");
|
|
|
|
requestParams = new JSONObject();
|
|
requestParams.put("template_filename", Tools.getFileNameWithLowerCaseSuffix(filename));
|
|
requestParams.put("template_url", fileInfo.get("download"));
|
|
// String flatten_source_style = Prop.getPropValue("doc_wps_custom", "flatten_source_style");
|
|
// requestParams.put("flatten_source_style", "1".equals(flatten_source_style));
|
|
requestParams.put("sample_list", sampleList);
|
|
|
|
//套红页边距问题修改
|
|
requestParams.put("use_template_section_property",true);
|
|
|
|
// 结果文件的文件名
|
|
String targetFilename = params.containsKey("targetFilename") ? params.get("targetFilename"): "";
|
|
targetFilename = Tools.isEmptyOrNull(targetFilename) ? filename : params.get("targetFilename");
|
|
|
|
BaseConvert baseConvert = new BaseConvert(user);
|
|
if(!params.containsKey("comefrom")) params.put("comefrom", "OfficeWrapheader");
|
|
result = baseConvert.convert(apiUrl, requestParams, targetFilename, params);
|
|
// 处理其他的事务
|
|
return result;
|
|
}
|
|
|
|
public Map<String, String> replaceBookmark(Map<String, String> params, Map<String,String> bookmarkMap) throws Exception {
|
|
int newimagefileid = -1;
|
|
|
|
if(Config.isLogInfo()) {
|
|
log.info("paramsMap:" + params.toString());
|
|
log.info("bookmarkMap:" + bookmarkMap.toString());
|
|
}
|
|
|
|
//1,获取参数
|
|
//模板类型
|
|
String mouldType = params.get("mouldType");
|
|
//模板Id
|
|
int mouldId = Util.getIntValue(params.get("mouldId"));
|
|
//模板后缀名
|
|
// String doctype = (String)params.get("doctype");
|
|
//正文imageFileId
|
|
String imagefileId = params.get("imagefileId");
|
|
int imagefileIdInt = Util.getIntValue(imagefileId);
|
|
//正文后缀名
|
|
// String zwDocType = (String)params.get("zwDocType");
|
|
//生成的替换书签后的文档名称
|
|
String fileName = params.get("fileName");
|
|
|
|
Map<String, String> convertParams = new HashMap<String, String>();
|
|
convertParams.put("imagefileid", mouldId+"");
|
|
convertParams.put("fromMould", params.get("mouldType"));
|
|
convertParams.put("targetFilename", fileName);
|
|
|
|
JSONArray sampleList = new JSONArray();
|
|
JSONObject markItem = new JSONObject();
|
|
|
|
//普通书签
|
|
for(Map.Entry<String,String> entry : bookmarkMap.entrySet()){
|
|
markItem = new JSONObject();
|
|
markItem.put("bookmark",entry.getKey());
|
|
markItem.put("text",entry.getValue());
|
|
markItem.put("type", BOOKMARK_TYPE_TEXT);
|
|
sampleList.add(markItem);
|
|
}
|
|
|
|
//如果为显示模板才替换正文书签
|
|
if("showMould".equals(mouldType)){
|
|
//正文
|
|
markItem = new JSONObject();
|
|
markItem.put("bookmark", BOOKMARK_CONTENT);
|
|
markItem.put("type", BOOKMARK_TYPE_DOCUMENT);
|
|
|
|
// 获取正文文件数据
|
|
FileInfoUtil fileInfoUtil = new FileInfoUtil();
|
|
Map<String,String> fileInfo = fileInfoUtil.getFileInfo(imagefileId, user, "ecology");
|
|
markItem.put("sample_url", fileInfo.get("download"));
|
|
markItem.put("sample_filename", getTempFileName(Tools.getFileNameWithLowerCaseSuffix(fileName)));
|
|
|
|
sampleList.add(markItem);
|
|
}
|
|
|
|
Map<String, String> result = convert(convertParams, sampleList);
|
|
|
|
// 如果是显示模板,执行一次清稿
|
|
if("showMould".equals(mouldType)){
|
|
String newImagefileid = result.get("imagefileid");
|
|
Map<String, String> clearDocParam = new HashMap<String, String>();
|
|
clearDocParam.put("imagefileId", newImagefileid);
|
|
clearDocParam.put("fileName", Tools.getFileNameWithLowerCaseSuffix(fileName));
|
|
clearDocParam.put("fromMould", "ecology");
|
|
|
|
OfficeOperate officeOperate = new OfficeOperate(user);
|
|
Map<String, String> clearDocResult = officeOperate.clearDoc(clearDocParam);
|
|
if("0".equals(clearDocResult.get("status"))){
|
|
return clearDocResult;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static String getTempFileName(String filename) {
|
|
if(Tools.isEmptyOrNull(filename) || !filename.contains(".")){
|
|
return filename;
|
|
}
|
|
int idx = filename.lastIndexOf(".");
|
|
return"1" + filename.substring(idx).toLowerCase();
|
|
}
|
|
}
|