You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用LotusScript识别并替换富文本字段中的热点链接

解决Notes富文本项中热点文件链接路径替换问题

要批量替换Notes文档RichTextItem中指向文件服务器的热点链接路径,可以通过Domino开发API实现,以下是两种常用方案:

LotusScript 实现方案

LotusScript是Domino环境下最常用的脚本语言,适合快速编写代理或工具处理这类需求:

  1. 核心思路
    遍历RichTextItem中的所有元素,识别热点链接类型元素,提取其目标URL,替换旧服务器路径后重新赋值,最后保存文档。

  2. 代码示例

Sub ReplaceHotspotLinks()
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    Dim rtItem As NotesRichTextItem
    Dim nav As NotesRichTextNavigator
    Dim elem As NotesRichTextElement
    Dim oldPath As String, newPath As String
    Dim currentURL As String, updatedURL As String
    
    ' 配置旧路径和新路径
    oldPath = "\\old-server\share\"
    newPath = "\\new-server\share\"
    
    Set db = session.CurrentDatabase
    Set view = db.GetView("YourViewName") ' 替换为目标视图名
    Set doc = view.GetFirstDocument()
    
    While Not(doc Is Nothing)
        Set rtItem = doc.GetFirstItem("Body") ' 替换为目标富文本项名称
        If Not(rtItem Is Nothing) And rtItem.Type = RICHTEXT Then
            Set nav = rtItem.CreateNavigator()
            Set elem = nav.FindFirstElement(RTELEM_TYPE_HOTSPOTLINK)
            
            While Not(elem Is Nothing)
                currentURL = elem.HotspotLink
                ' 仅处理文件服务器路径的链接
                If InStr(currentURL, oldPath) > 0 Then
                    updatedURL = Replace(currentURL, oldPath, newPath)
                    elem.HotspotLink = updatedURL
                    Call doc.Save(True, False)
                End If
                Set elem = nav.FindNextElement(RTELEM_TYPE_HOTSPOTLINK)
            Wend
        End If
        Set doc = view.GetNextDocument(doc)
    Wend
End Sub
  1. 注意事项
  • 先在测试环境验证,操作前务必备份目标文档
  • 替换YourViewName和Body为实际的视图名和富文本项字段名
  • 若需处理file://格式的URL,调整路径匹配规则即可

Java 实现方案

如果偏好Java开发,可使用Domino Java API实现类似逻辑:

import lotus.domino.*;

public class ReplaceHotspotLinks {
    public static void main(String[] args) {
        Session session = null;
        Database db = null;
        View view = null;
        Document doc = null;
        
        String oldPath = "\\\\old-server\\share\\";
        String newPath = "\\\\new-server\\share\\";
        
        try {
            session = NotesFactory.createSession();
            db = session.getCurrentDatabase();
            view = db.getView("YourViewName");
            doc = view.getFirstDocument();
            
            while (doc != null) {
                RichTextItem rtItem = (RichTextItem) doc.getFirstItem("Body");
                if (rtItem != null && rtItem.getType() == Item.RICHTEXT) {
                    RichTextNavigator nav = rtItem.createNavigator();
                    RichTextElement elem = nav.findFirstElement(RichTextItem.RTELEM_TYPE_HOTSPOTLINK);
                    
                    while (elem != null) {
                        String currentURL = elem.getHotspotLink();
                        if (currentURL.contains(oldPath)) {
                            String updatedURL = currentURL.replace(oldPath, newPath);
                            elem.setHotspotLink(updatedURL);
                            doc.save(true, false);
                        }
                        elem = nav.findNextElement(RichTextItem.RTELEM_TYPE_HOTSPOTLINK);
                    }
                }
                Document nextDoc = view.getNextDocument(doc);
                doc.recycle();
                doc = nextDoc;
            }
        } catch (NotesException e) {
            e.printStackTrace();
        } finally {
            try {
                if (view != null) view.recycle();
                if (db != null) db.recycle();
                if (session != null) session.recycle();
            } catch (NotesException e) {
                e.printStackTrace();
            }
        }
    }
}

额外提示

  • 若需处理批量文档,可将代码封装为Domino代理,定时或手动执行
  • 对于复杂的富文本结构,可增加对链接类型的判断(如仅处理文件链接,排除网页链接)

内容的提问来源于stack exchange,提问作者Tom Van Aken

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 04:02:41