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

时间:2013-04-01 16:40:23

标签: java plugins lotus-notes

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

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

“click事件”的监听器(如果您愿意)需要知道当前文档,以便它可以将其字段数据传递给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;
    }

}

1 个答案:

答案 0 :(得分:1)

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