本文介绍了Java - Lotus Notes - 从项目实例获取附件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个lotus.domino.Item实例。



item.getType()返回Item.ATTACHMENT(表示项目表示和附件)



当我的系统输出item.getValueString()它会写出FileName和Content。



这对我来说不好,就是要分别提取FileName和Content。检查了API,找不到正确的方法来提取这些。



或者有一种方法来分割item.getValueString()返回的内容以获取FileName和Content

解决方案

从文档获取 EmbeddedObject 类实例/ p>

  java.util.Vector embeddedObjects = notesDocument.getEmbeddedObjects(); 

或富文本项目:

  java.util.Vector embeddedObjects = richTextItem.getEmbeddedObjects(); 

EmbeddedObject 包含方法: getSource(),使用它来获取已加密对象的附件类型的文件名。

  if(embeddedObject.getType()== EmbeddedObject.EMBED_ATTACHMENT){
String attachmentFileName = embeddedObject.getSource();
}

要获取文件内容,请使用 extractFile() / code>方法的 EmbeddedObject 类实例。



下面是java代码,演示如何分离附件(样本取自官方Domino Designer文档):

  import lotus.domino。*; 
import java.util.Vector;
import java.util.Enumeration;
public class JavaAgent extends AgentBase {
public void NotesMain(){
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
//(你的代码到这里)
数据库db = agentContext.getCurrentDatabase();
DocumentCollection dc = db.getAllDocuments();
文档doc = dc.getFirstDocument();
boolean saveFlag = false;
while(doc!= null){
RichTextItem body =
(RichTextItem)doc.getFirstItem(Body);
System.out.println(doc.getItemValueString(Subject));
矢量v = body.getEmbeddedObjects();
枚举e = v.elements();
while(e.hasMoreElements()){
EmbeddedObject eo =(EmbeddedObject)e.nextElement();
if(eo.getType()== EmbeddedObject.EMBED_ATTACHMENT){
eo.extractFile(c:\\\extracts\\+ eo.getSource());
eo.remove();
saveFlag = true;
}
}
if(saveFlag){
doc.save(true,true);
saveFlag = false;
}
doc = dc.getNextDocument();
}
} catch(NotesException e){
System.out.println(e.id ++ e.text);
e.printStackTrace();
}
}
}


I have a lotus.domino.Item instance.

item.getType() returns Item.ATTACHMENT (meaning the item represents and attachment)

When I System.output the item.getValueString() it writes out the FileName and the Content.

That is not good for me as would like to extract the FileName and Content separately. Checked the API and could not find proper method to extract these.

Or is there a way to split the content returned by item.getValueString() to get the FileName and Content?

解决方案

Get EmbeddedObject class instance(s) from document:

java.util.Vector embeddedObjects = notesDocument.getEmbeddedObjects();

or from a rich text item:

java.util.Vector embeddedObjects = richTextItem.getEmbeddedObjects();

EmbeddedObject contains the method: getSource(), use it to get the filename of the attachment type of embdedded object.

if (embeddedObject.getType() == EmbeddedObject.EMBED_ATTACHMENT) {
    String attachmentFileName = embeddedObject.getSource();
}

To get file contents, use extractFile() method of the EmbeddedObject class instance.

Below there's java code that demonstrates how to detach attachments (sample is taken from the official Domino Designer documentation):

import lotus.domino.*;
import java.util.Vector;
import java.util.Enumeration;
public class JavaAgent extends AgentBase {
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      // (Your code goes here)
      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 = v.elements();
        while (e.hasMoreElements()) {
          EmbeddedObject eo = (EmbeddedObject)e.nextElement();
          if (eo.getType() == EmbeddedObject.EMBED_ATTACHMENT) {
            eo.extractFile("c:\\extracts\\" + eo.getSource());
            eo.remove();
            saveFlag = true;
            }
        }
        if (saveFlag) {
          doc.save(true, true);
          saveFlag = false;
          }
        doc = dc.getNextDocument();
      }
    } catch(NotesException e) {
      System.out.println(e.id + " " + e.text);
      e.printStackTrace();
    }
  }
}

这篇关于Java - Lotus Notes - 从项目实例获取附件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 01:38