java - 如何在保存之前访问新 Notes 电子邮件的基础文档

标签 java plugins lotus-notes

我们有一个用 Java 开发的 Lotus Notes 插件。我们支持的当前 Notes 版本是 8.5.2。

此插件向 Notes UI 添加了一个按钮。当用户单击它时,我们会向用户显示一个窗口,允许用户使用 Web 服务将当前项目添加到我们基于 Web 的应用程序中。一切正常,除非用户尝试添加一个新电子邮件项目。

“点击事件”(如果您愿意)的监听器需要知道当前文档,以便它可以将其字段数据传递给 Web 服务调用。为此,我们设置了一个单独的监听器 (DocumentContextService),只要 Notes UI 中的输入焦点发生变化,它就会被调用。

DocumentContextService 尝试检索当前文档的 URI。这就是事情分崩离析的地方。我发现未发送的电子邮件消息没有 URI。此外,似乎无法获取文档并保存它,以便我可以获得一份。

理论上,这是设计使然。奇怪的是,我可以看到新文档有一个 DocumentKey,所以我知道它存在(作为某处的草稿),但我无法访问它。因此,在实际保存文档之前,似乎没有任何方法可以访问该文档的数据。

除非我错了(我很可能错了)。还有一个问题:有没有办法在保存新电子邮件之前获取其基础文档,以便我可以访问其数据(特别是其字段)?

来自文档上下文监听器的代码如下。同样,问题在于 URI 属性对于新电子邮件的计算结果始终为空字符串。

package com.ibm.lotuslabs.context.service.internal;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;

import com.ibm.lotuslabs.context.service.document.IDocumentContext;
import com.ibm.rcp.jface.launcher.IURIProvider;
import com.satuit.sys.The;

/**
 * Extracts document information about about a selection object. Represents the document within the DocumentSelection.
 */
@SuppressWarnings("deprecation")
public class DocumentContext implements IDocumentContext
{
    private IWorkbenchPart part;
    private Object obj;
    private String label;
    private URI uri;
    private ImageDescriptor icon;
    private Properties properties;
    private String id;

    /**
     * Initializes a new instance of the DocumentContext class.
     * 
     * @param part  The current view part.
     * @param obj   The currently selected object.
     */
    public DocumentContext(final IWorkbenchPart part, final Object obj)
    {
        this.part = part;
        this.obj = obj;

        // Is this object a URIProvider?
        final IURIProvider provider = (IURIProvider)ContextUtil.getAdapterObject(obj, IURIProvider.class);
        if (provider != null)
        {
            this.uri = provider.getURI();
            this.label = provider.getTitle();
            this.icon = provider.getImageDescriptor();
        }

        if (this.label == null || this.icon == null)
        {
            // Is this object a workbench adapter?
            final IWorkbenchAdapter wba = (IWorkbenchAdapter)ContextUtil.getAdapterObject(obj, IWorkbenchAdapter.class);
            if (wba != null)
            {
                if (this.label != null)
                {
                    this.label = wba.getLabel(obj);
                }

                if (this.icon != null)
                {
                    this.icon = wba.getImageDescriptor(obj);
                }

            }

            if (this.icon == null)
            {
                final Image i = part.getTitleImage();
                if (i != null)
                {
                    this.icon = ImageDescriptor.createFromImage(i);
                }
            }
        }

        // Is this object a URI?
        if (this.uri == null)
        {
            this.uri = (URI)ContextUtil.getAdapterObject(obj, URI.class);
        }

        //  Is this object a PropertySource?
        //  (A document that isn't a URI provider may provide a URI in its properties.)
        final IPropertySource prop = (IPropertySource)ContextUtil.getAdapterObject(obj, IPropertySource.class);
        if (prop != null)
        {
            this.properties = buildProperties(prop);
        }
    }

    /**
     * Gets the ID of this instance.
     * @return A string containing the ID.
     */
    public final String getId()
    {
        return this.id;
    }

    /**
     * Gets the workbench part used to initialize this instance.
     * @return
     */
    public final IWorkbenchPart getPart()
    {
        return this.part;
    }

    /* (non-Javadoc)
     * @see com.ibm.lotuslabs.context.service.document.IDocumentContext#getImageDescriptor()
     */
    public final ImageDescriptor getImageDescriptor()
    {
        return this.icon;
    }

    /* (non-Javadoc)
     * @see com.ibm.lotuslabs.context.service.document.IDocumentContext#getLabel()
     */
    public final String getLabel()
    {
        if (this.label == null && this.part != null)
        {
            return this.part.getTitle();
        }

        return this.label;
    }

    /* (non-Javadoc)
     * @see com.ibm.lotuslabs.context.service.document.IDocumentContext#getObject()
     */
    public final Object getObject()
    {
        return this.obj;
    }

    /* (non-Javadoc)
     * @see com.ibm.lotuslabs.context.service.document.IDocumentContext#getProperties()
     */
    public final Properties getProperties()
    {
        return this.properties;
    }

    /* (non-Javadoc)
     * @see com.ibm.lotuslabs.context.service.document.IDocumentContext#getURI()
     */
    public final URI getURI()
    {
        return this.uri;
    }

    private Properties buildProperties(final IPropertySource source)
    {
        if (source == null)
        {
            return null;
        }

        final IPropertyDescriptor[] descs = source.getPropertyDescriptors();

        if (The.Value(null).Is.NullOrEmpty(descs))
        {
            return null;
        }

        final Properties prop = new Properties();
        for (int i = 0; i < descs.length; i++)
        {
            final Object id = descs[i].getId();
            final String name = descs[i].getDisplayName();

            String value = source.getPropertyValue(descs[i].getId()).toString();
            if (The.Value(descs[i].getDescription()).Is.Not.Null())
            {
                value += "|" + source.getPropertyValue(descs[i].getDescription()).toString();
            }

            if (this.uri == null)
            {
                if (The.Value("URI").Is.OneOfIgnoreCase(id.toString(), name) ||
                    The.Value("URL").Is.OneOfIgnoreCase(id.toString(), name))
                {
                    try
                    {
                        this.uri = new URI(value);
                        continue;
                    }
                    catch (URISyntaxException e)
                    {

                    }
                }
            }
            prop.setProperty(name, value);
        }

        return prop;
    }

}

最佳答案

抱歉,在将文档保存到后端数据库之前,没有文档可以获取 URI,因为它不存在于内存中。它根本不存在于磁盘上。

关于java - 如何在保存之前访问新 Notes 电子邮件的基础文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15747439/

相关文章:

java - 在 CN1 上获取没有时间的当前日期

php - Laravel 4 插件系统

plugins - 在自定义插件中获取正确的依赖项名称

Lotus Notes 客户端中的 CSS 媒体查询

java - UTF-8 到代码点

java - 使用java从doc或rtf文件读取表单数据

java - 列出 .zip 目录而不解压

plugins - Sublime Text 2慢-是否禁用大文件插件?

java - NotesCLI 3.4 java异常

java - 在 Lotus Notes 9 中运行 Java 代理