我创建了一个 10 旧应用程序的 XPages 版本,该应用程序将富文本(输入)添加到现有字段。这段代码听起来可能会对您有所帮助:
var moveAddBody = function(doc:NotesDocument){
var addRt:NotesMIMEEntity = doc.getMIMEEntity("addBody");
var attFiles:NotesRichTextItem = doc.getFirstItem("attachedFiles");
if(addRt == null && attFiles == null) return;
if(attFiles != null) {
// println("attFiles: " + attFiles.getText() + ", length=" + attFiles.getValueLength());
}
// if(addRt != null && @Length(addRt.getContentAsText().trim()) <= 28) return; // The standard tags in an empty field fills 28 chars
// Something to move...
var tmpDoc:NotesDocument = doc.getParentDatabase().createDocument(); // Never saved - just left in the wind...
var mime:NotesMIMEEntity = tmpDoc.createMIMEEntity("myBody");
var stream:NotesStream = session.createStream();
var formatter = java.text.SimpleDateFormat('yyyy-MM-dd HH:mm');
var time = formatter.format(@Now());
var logLine:String = '<font size="2" color="#008080" face="sans-serif"><b>' + time + " - " + @Name("[Abbreviate]",@UserName()) + '</b></font>';
stream.writeText(logLine);
if(addRt != null && @Length(addRt.getContentAsText().trim()) > 28) {
stream.writeText('<font size="2" face="sans-serif">'); // Enforce "simiilar" font type/size...
stream.writeText(addRt.getContentAsText());
stream.writeText('</font>');
}
mime.setContentFromText(stream, "text/html", NotesMIMEEntity.ENC_NONE);
var prevMime = session.isConvertMime();
session.setConvertMime(true);
tmpDoc.closeMIMEEntities(true,"myBody");
var rt:NotesRichTextItem = doc.getFirstItem("Body");
var body = null;
if (rt != null) {
body = rt.copyItemToDocument(tmpDoc,"Body");
rt.remove();
}
rt = doc.createRichTextItem("Body");
var rtMime:NotesRichTextItem = tmpDoc.getFirstItem("myBody");
rt.appendRTItem(rtMime);
if(attFiles != null) {
if(addRt == null) rt.addNewLine(1);
rt.appendRTItem(attFiles);
attFiles.remove();
}
if(body != null) {
rt.addNewLine(2);
rt.appendRTItem(body);
}
if(addRt != null) {
addRt.remove();
addRt.recycle();
}
session.setConvertMime(prevMime);
return true;
}
您将需要取出上面的一些代码,因为它还添加了日期/时间和一些格式(在有人低语“css ...”之前与 Notes 版本兼容 ;-))。它还处理附件。
希望你能用它来解决你的问题?
/约翰