Windchill开发-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;
    }

2.4 打开方式二获得下载链接截图

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值