EPMDocument和WTDocument主内容下载的API
一、说明
多用于系统集成的数据外发
二、相关代码
2.1 对象主内容数据的获取
import java.beans.PropertyVetoException;
import java.io.File;
import java.io.IOException;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentHolder;
import wt.content.ContentRoleType;
import wt.content.ContentServerHelper;
import wt.doc.WTDocument;
import wt.epm.EPMDocument;
import wt.fc.Persistable;
import wt.fc.QueryResult;
import wt.fv.master.RedirectDownload;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
public class Test {
/**
*
* @MethodName: getApplicationData
* @Description: 获取对象的数据
* @param persistable 对象
* @return
* @throws WTException
* @throws WTPropertyVetoException
* @return: ApplicationData 数据
* @throws
* @date: 2025-01-09 04:27:56
*/
public static ApplicationData getApplicationData(Persistable persistable)
throws WTException, WTPropertyVetoException {
ApplicationData data = null;
QueryResult queryResult = null;
String cadName = "";
if (persistable instanceof EPMDocument) {
EPMDocument epm = (EPMDocument)persistable;
queryResult = ContentHelper.service.getContentsByRole(epm, ContentRoleType.PRIMARY);
cadName = epm.getCADName();
} else if (persistable instanceof WTDocument) {
WTDocument doc = (WTDocument)persistable;
queryResult = ContentHelper.service.getContentsByRole(doc, ContentRoleType.PRIMARY);
}
if (queryResult != null) {
while (queryResult.hasMoreElements()) {
Object element = queryResult.nextElement();
if (element instanceof ApplicationData) {
data = (ApplicationData)element;
if (data.getFileName().equals("{$CAD_NAME}") && !cadName.isEmpty()) {
data.setFileName(cadName);
}
}
}
}
return data;
}
}
2.2 将对象主内容下载到服务器的方法
/**
*
* @MethodName: downloadContent
* @Description: 将对象主内容下载到服务器
* @param persistable 对象
* @param dir 服务器文件目录
* @throws WTException
* @throws IOException
* @throws PropertyVetoException
* @return: void
* @throws
* @date: 2025-01-09 04:02:07
*/
public static void downloadContent(Persistable persistable, File dir)
throws WTException, IOException, PropertyVetoException {
ApplicationData data = getApplicationData(persistable);
if (data != null) {
File file = new File(dir, data.getFileName());
ContentServerHelper.service.writeContentStream(data, file.getCanonicalPath());
}
}
2.3 获取对象的下载地址的方法
/**
*
* @MethodName: getDownLoadURL
* @Description: 获取对象的下载地址
* @param persistable 对象
* @return
* @throws WTPropertyVetoException
* @throws WTException
* @throws IOException
* @return: String 下载地址
* @throws
* @date: 2025-01-09 04:38:07
*/
public static String getDownLoadURL(Persistable persistable)
throws WTPropertyVetoException, WTException, IOException {
String url = "";
ApplicationData data = getApplicationData(persistable);
ContentHolder contentHolder = null;
if (persistable instanceof EPMDocument) {
EPMDocument epm = (EPMDocument)persistable;
contentHolder = epm;
} else if (persistable instanceof WTDocument) {
WTDocument doc = (WTDocument)persistable;
contentHolder = doc;
}
if (data != null && contentHolder != null) {
/**
* 方式一:直接下载的链接,一次或30分钟失效
*/
url = RedirectDownload.getPreferredURL(data, contentHolder).toExternalForm();
/**
* 方式二:不是直接的下载链接,页面上有下载选项
*/
url = ContentHelper.getDownloadURL(contentHolder, data).toExternalForm();
}
return url;
}