在Java文档中获取附件文件名的最简单方法是什么?
在我的情况下,文档总是包含最多1个文件,并存储在名为Body的富文本字段中。
答案 0 :(得分:0)
在你自己的java类中尝试这个,它应该可以工作:
import com.ibm.xsp.model.domino.DominoUtils;
@SuppressWarnings("unchecked")
public List<String> getAttachmentsNames(RichTextItem richTextItem) {
List<String> attachmentsNames = new ArrayList<String>();
try {
Vector v = richTextItem.getEmbeddedObjects();
Enumeration e = v.elements();
while (e.hasMoreElements()) {
EmbeddedObject eo = (EmbeddedObject) e.nextElement();
if (eo.getType() == EmbeddedObject.EMBED_ATTACHMENT) attachmentsNames.add(eo.getName());
}
} catch (NotesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return attachmentsNames;
}
@SuppressWarnings("unchecked")
public List<String> getFileNames(Document document, String richTextFieldName) {
List<String> fileNames = new ArrayList<String>();
try {
if (document.hasEmbedded()) {
Vector<String> docFileNames = DominoUtils.getCurrentSession().evaluate("@AttachmentNames" , document);
RichTextItem rtitem = (RichTextItem) document.getFirstItem(richTextFieldName); // Body
for (int i = 0; i < docFileNames.size(); i++) {
if (!docFileNames.get(i).equals("") && getAttachmentsNames(rtitem).contains(docFileNames.get(i))) {
fileNames.add(fileNames.get(i));
}
}
}
} catch (NotesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fileNames;
}