Wenn Sie Java verwenden können (wie in XPages), dann
import com.ibm.xsp.extlib.util.ExtLibUtil;
import lotus.domino.MIMEEntity;
import lotus.domino.Document;
import lotus.domino.Session;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import lotus.domino.Database;
import lotus.domino.DocumentCollection;
import lotus.domino.EmbeddedObject;
import lotus.domino.Item;
import lotus.domino.MIMEHeader;
import lotus.domino.NotesException;
import lotus.domino.RichTextNavigator;
import lotus.domino.RichTextItem;
import lotus.domino.Stream;
import lotus.domino.View;
// ...
private String fileSeparator = File.separator;
private String tempPath = System.getProperty("java.io.tmpdir") + fileSeparator + "Temp" + fileSeparator;
// ...
private void saveFilesFromDoc(Document doc) throws NotesException {
if (doc.hasEmbedded()) {
RichTextItem body = null;
try {
body = (RichTextItem) doc.getFirstItem("body");
} catch (ClassCastException e) {
// save file from MIME (Rich text is converted to MIME)
MIMEEntity mime = doc.getMIMEEntity();
findMimeWithFile(mime);
return;
}
if (body != null) {
// save file from richtext
RichTextNavigator rtnav = body.createNavigator();
if (rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_FILEATTACHMENT)) {
do {
EmbeddedObject att = (EmbeddedObject) rtnav.getElement();
String fileName = att.getSource();
fileName = notConflictFileName(fileName );
String path = tempPath + fileName ;
att.extractFile(path);
} while (rtnav.findNextElement());
}
} else {
// ("BODY is NULL");
}
}
Datei aus richtext in Mime konvertiert holen
private void findMimeWithFile(MIMEEntity mime) {
try {
askMimeForFiles(mime, "");
MIMEEntity child = mime.getFirstChildEntity();
while (child != null) {
askMimeForFiles(child, "child");
// String encoding = "ISO-8859-2";
String c = child.getContentType();
MIMEEntity subChild = child.getFirstChildEntity();
askMimeForFiles(subChild, "subChild");
if ("multipart".equals(c)) {
while (subChild != null) {
askMimeForFiles(subChild, "subChild2");
// String sc = subChild.getContentType();
subChild = subChild.getNextSibling();
}
}
child = child.getNextSibling();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Herausfinden, ob MIME-Entität ein Dateianhang (oder ein Text) ist
private void askMimeForFiles(MIMEEntity mime, String prefix) throws NotesException {
if (mime != null) {
boolean thisMimeHasFile = false;
String fileName = "noname";
Vector<MIMEHeader> headers = mime.getHeaderObjects();
for (MIMEHeader header : headers) {
// (prefix + "-header: " + header.getHeaderName() + " :: " + header.getHeaderValAndParams());
if ("Content-Transfer-Encoding".equals(header.getHeaderName())) {
if ("binary".equals(header.getHeaderVal())) {
thisMimeHasFile = true;
}
}
if ("Content-Disposition".equals(header.getHeaderName())) {
String val = header.getHeaderValAndParams();
int odd = val.indexOf("filename=") + "filename=".length();
int doo = val.length();
fileName = val.substring(odd, doo);
this.fileNames.add(fileName);
}
}
if (thisMimeHasFile) {
safeFilesFromMIME(mime, fileName);
}
}
}
Wenn MIME ein Dateianhang ist, dann speichern Sie ihn
private void safeFilesFromMIME(MIMEEntity mime, String fileName) throws NotesException {
Session session = ExtLibUtil.getCurrentSession(); // or user variableResolver
Stream stream = session.createStream();
String pathname = tempPath + fileName;
stream.open(pathname, "binary");
mime.getContentAsBytes(stream);
stream.close();
}