我可以访问Lotus Notes中嵌入的文件,而无需实际解压呢? [英] Can I get access to Lotus Notes embedded files without actually extracting them?

查看:273
本文介绍了我可以访问Lotus Notes中嵌入的文件,而无需实际解压呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的编程访问Lotus Notes数据库在给定的时间来收集记录嵌入附件信息的方法。

我的目标是要找到在给定的时间记录,然后使用Apache的POI,以获取有关文件的大小,字符数等元数据。

的POI部分工作正常,到目前为止,我已经能够访问Lotus Notes记录感谢这个帮助:

荷花注意到日期的Java API <搜索/ p>

和这个答案也说明我如何下载/复制附件:

<一个href=\"http://stackoverflow.com/questions/7850189/how-do-i-get-all-the-attachments-from-a-nsflotus-notes-file-using-java/7854740#7854740\">How我从一个.NSF用java 所有附件(Lotus Notes)中的文件

从那里我可以用我的POI code做我的工作,到了最后,只是删除复制的附件。这种做法,基本上工作,但我想避免复制的开销,节约然后在最后删除我对这些附加文件副本从数据库中。

我试图传递EmbeddedObject的getSource()方法的结果作为输入到我的POI code和得到了在POI code,它期待一个字符串,使文件出现FileNotFoundException。

有没有得到一个文件引用我可以传递给POI,而不复制并保存附件的方式吗?或者说,我的意思是,它是那样简单获得对Lotus Notes附件EmbeddedObject文件(+路径),以及如何做到这一点?


我找到了答案,并张贴在下面。


解决方案

回答我的问题...

...这里是我发现了一小会儿张贴上面的问题后的解决方案:

EmbeddedObject的的getInputStream救援...

  //从上面的问题的链接答案
  数据库DB = agentContext.getCurrentDatabase();
  DocumentCollection直流= db.getAllDocuments();
  文档的文档= dc.getFirstDocument();
  布尔saveFlag = FALSE;
  而(DOC!= NULL){
    RichTextItem体=
    (RichTextItem)doc.getFirstItem(身体);
    的System.out.println(doc.getItemValueString(主题));
    矢量v = body.getEmbeddedObjects();
    枚举E = embeddedObjs.elements();
    而(e.hasMoreElements()){
        EmbeddedObject EO =(EmbeddedObject)e.nextElement();
        如果(eo.getType()== EmbeddedObject.EMBED_ATTACHMENT){    //这个下一行给予InputStream的Apache的POI访问                        InputStream为= eo.getInputStream();
            POIFSFileSystem POIFS =
                              HWPFDocument.verifyAndBuildPOIFS(是);
            POIOLE2TextExtractor提取=
                              ExtractorFactory.createExtractor(POIFS);
            的System.out.println(提取的文本:+ extractor.getText());
                        is.close(); //关闭的InputStream
                     }
                     eo.recycle(); //回收EmbeddedObject   //感谢rhsatrhs为接近()和再循环()小费!

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.

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

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

lotus notes search by date with Java api

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

How do I get all the attachments from a .nsf(lotus notes) file using java

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.

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.

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'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天全站免登陆