我可以在不实际提取 Lotus Notes 嵌入文件的情况下访问它们吗? [英] Can I get access to Lotus Notes embedded files without actually extracting them?

查看:37
本文介绍了我可以在不实际提取 Lotus Notes 嵌入文件的情况下访问它们吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种以编程方式访问 Lotus Notes 数据库的方法,以收集有关特定时期内记录的嵌入附件的信息.

I'm working on a way of programatically accessing a Lotus Notes database to gather information on embedded attachments of records over a given period.

我的目标是查找给定时间段内的记录,然后使用 Apache-POI 获取有关文档大小、字符数等的元数据.

My goal is to find records over a given period, then use Apache-POI to get metadata about document size, character count, etc.

POI 部分运行良好,到目前为止,由于此帮助,我已经能够访问 Lotus Notes 记录:

The POI part works fine, and so far, I've been able to access the Lotus Notes records thanks to this help:

lotus notes 使用 Java api 按日期搜索

这个答案还告诉我如何下载/复制附件:

and this answer also shows me how to download/copy the attachments:

如何使用 java 从 .nsf(lotus notes) 文件中获取所有附件

从那里我可以使用我的 POI 代码完成我的工作,最后,只需删除复制的附件即可.这种方法基本上有效,但我想避免复制、保存然后最后从数据库中删除这些附加文档的副本的开销.

from there I could use my POI code do my job and at the end, just delete the copied attachments. This approach, basically works, but I want to avoid the overhead of copying, saving and then at the end deleting my copy of these attached documents from the database.

我尝试将 EmbeddedObject getSource() 方法的结果作为输入传递给我的 POI 代码,并在 POI 代码中得到一个 FileNotFoundException ,它需要一个字符串来创建一个文件.

I tried passing the result of the EmbeddedObject getSource() method as an input to my POI code and got a FileNotFoundException in the POI code that was expecting a String to make a File.

有没有办法在不复制和保存附件的情况下获取可以传递给 POI 的文件引用?或者,我的意思是,它是否像获取 Lotus Notes EmbeddedObject 附件的文件(+路径)一样简单,我该怎么做?

Is there a way of getting a File reference I can pass to POI, without copying and saving the attachment? Or, what I mean is, is it as simple as getting a File (+path) for the Lotus Notes EmbeddedObject attachment, and how do I do this?

我找到了答案并将其发布在下面.

I found the answer and posted it below.

推荐答案

回答我自己的问题...

Answering my own question...

...这是我在发布上述问题后找到的解决方案:

...here's the solution I found a little while after posting the question above:

EmbeddedObject 的 getInputStream 来救援...

EmbeddedObject's getInputStream to the rescue...

  //from the answer in the link in the question above 
  Database db = agentContext.getCurrentDatabase();
  DocumentCollection dc = db.getAllDocuments();
  Document doc = dc.getFirstDocument();
  boolean saveFlag = false;
  while (doc != null) {
    RichTextItem body = 
    (RichTextItem)doc.getFirstItem("Body");
    System.out.println(doc.getItemValueString("Subject"));
    Vector v = body.getEmbeddedObjects();
    Enumeration e = embeddedObjs.elements();
    while(e.hasMoreElements()){
        EmbeddedObject eo = (EmbeddedObject)e.nextElement();
        if(eo.getType() == EmbeddedObject.EMBED_ATTACHMENT){

    //this next line gives Apache-POI access to the InputStream

                        InputStream is = eo.getInputStream();
            POIFSFileSystem POIfs = 
                              HWPFDocument.verifyAndBuildPOIFS(is);
            POIOLE2TextExtractor extractor = 
                              ExtractorFactory.createExtractor(POIfs);
            System.out.println("extracted text: " + extractor.getText());
                        is.close();  //closing InputStream 
                     }
                     eo.recycle();  //recycling EmbeddedObject

   //thanks to rhsatrhs for the close() and recycle() tip!

这篇关于我可以在不实际提取 Lotus Notes 嵌入文件的情况下访问它们吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆