如何提取Lotus Notes数据库图标?

时间:2012-03-23 04:38:40

标签: java lotus-notes

我尝试使用DXL Exporter提取Lotus Notes数据库图标但不成功。结果文件已损坏,无法由图像查看器打开。

如何使用java提取Lotus Notes数据库图标?

private String extractDatabaseIcon() {
    String tag = "";
    String idfile = "";
    String password = "";
    String dbfile = "";
    NotesThread.sinitThread();
    Session s = NotesFactory.createSessionWithFullAccess();
    s.createRegistration().switchToID(idfile, password);
    Database d = s.getDatabase("", dbfile);

    NoteCollection nc = d.createNoteCollection(false);
    nc.setSelectIcon(true);
    nc.buildCollection();
    String noteId = nc.getFirstNoteID();
    int counter = 0;
    while (noteId != null) {
        counter++;
        try {
            Document doc = d.getDocumentByID(noteId);
            DxlExporter dxl = s.createDxlExporter();
            String xml = dxl.exportDxl(doc);
            xml = xml.substring(xml.indexOf("<note "));
            org.jsoup.nodes.Document jdoc = Jsoup.parse(xml);
            Element ele = jdoc.select("rawitemdata").first();
            String raw = ele.text().trim();
            String temp = System.getProperty("java.io.tmpdir") + UUID.randomUUID().toString() + "\\";
            File file = new File(temp);
            file.mkdir();
            String filename = temp + UUID.randomUUID().toString().replaceAll("-", "") + ".gif";
            byte[] buffer = decode(raw.getBytes());
            FileOutputStream fos = new FileOutputStream(filename);
            fos.write(buffer);
            fos.close();
            tag = filename;
        } catch (Exception e) {
            logger.error("", e);
        }

        if (counter >= nc.getCount()) {
            noteId = null;
        } else {
            noteId = nc.getNextNoteID(noteId);
        }
   }
   return tag;
}

private byte[] decode(byte[] b) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    InputStream b64is = MimeUtility.decode(bais, "base64");
    byte[] tmp = new byte[b.length];
    int n = b64is.read(tmp);
    byte[] res = new byte[n];
    System.arraycopy(tmp, 0, res, 0, n);
    return res;
}  

2 个答案:

答案 0 :(得分:3)

它甚至不是位图,它是一个图标。您可以在此处找到的格式: http://www.daubnet.com/formats/ICO.html

很久以前,我在LotusScript中设法做到了这一点。我的代码基于此页面的早期版本: http://www2.tcl.tk/11202

对于图标本身,您只需打开一个文档:

NotesDocument doc = db.getDocumentByID("FFFF8010")
exporter = session.createDXLExporter
exporter.setConvertNotesBitmapsToGIF(false)
outputXML = exporter.export(doc)

然后解析XML以从IconBitmap项找到rawitemdata,就像在原始代码中一样。

答案 1 :(得分:1)

我不确定格式是什么。据我所知'这是一个16色位图,但不是标准的BMP文件格式。它绝对不是GIF格式,但你可以告诉DXLExporter转换它。默认设置是将其保留为原生状态,因此您需要在导出之前将其添加到代码中:

dxl.setConvertNotesBitmapsToGIF(true);