2

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;
    }

}
4

1 に答える 1