コンテンツに依存するオブジェクト組み込み

以前は、一部のアプリケーションのコンテキスト・メニューでは、特定メニュー・オプション の除外による制限がありました。 これは、既知の周辺情報 (選択されたリソースの数、ファイルの物理名、リソースのタイプなど) に基づいていました。 時には、リソースの内容について制限された情報量しか知られていないために、 使用不能なメニュー・オプションが大幅に削減されることもありました。 アクションが、あるタイプの XML ファイルには適用できても、他のタイプには適用できないような (Ant スクリプトを含む XML ファイルなど) 状況が多くあるため、このような情報は XML ファイルで大変便利です。 アクション「Ant の実行...」がコンテキスト・メニューにあるのは理にかなっていますが、これはプラグインの定義に使用される XML ファイルに適用できるアクションではありません。

拡張ポイント org.eclipse.core.runtime.contentTypes の追加で、Eclipse は「コンテンツ・タイプ」を提供するようになりました。 これにより、プラグインはプラットフォーム・コンテンツ型カタログにコントリビュートできるようになり、さらに、コンテンツ型ディスクライバーと呼ばれるクラスも使用可能になりました。 独自のコンテンツ型を準備する開発者のためには、カスタマイズ可能で、組み込みの コンテンツ型ディスクライバーが 2 つ使用可能です。 BinarySignatureDescriber (バイナリー・コンテント型用) と XMLRootElementContentDescriber (テキスト、XML ベースのコンテンツ型用) です。さらに、プラグイン・プロバイダーが独自の コンテンツ・ディスクライバーを作成することもできます。 詳しくは、「Platform プラグイン・デベロッパー・ガイド」 (「プログラマーズ・ガイド」> 「ランタイムの概説」>「コンテンツ・タイプ」) を参照してください。

XMLRootElementContentDescriber

特定のトップレベル・タグを持つか、または特定の DTD を指定する XML ファイルに特有のオブジェクト組み込み を定義することが可能です。このためには、以下のように、XMLRootElementContentDescriber のディスクライバー・クラスや、トップレベル・タグ名または DTD 名を示すパラメーターで、 org.eclipse.core.runtime.contentTypes 拡張ポイントに拡張を定義します。

   <extension
       point="org.eclipse.core.runtime.contentTypes">
       <content-type
           id=<id>
           name=<name> 	
           base-type="org.eclipse.core.runtime.xml">
           <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
               <parameter name="element" value=tagValue />
           </describer>
       </content-type>
 </extension>
または
   <extension
       point="org.eclipse.core.runtime.contentTypes">
       <content-type
           id=<id>
           name=<name> 	
           base-type="org.eclipse.core.runtime.xml">
           <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
               <parameter name="dtd" value=dtdValue />
           </describer>
       </content-type>
 </extension>
ここで、tagValue は一致するトップレベル・タグの名前を示し、

dtdValue は XML ファイルで表示される DTD の名前を示します。

plugin.xml ファイルの以下のオブジェクト組み込みについて考えてみてください。

   <extension
       point="org.eclipse.core.runtime.contentTypes">
       <content-type 
           id="topElementContentType"
           name="Tests top-level element recognition" 	
           base-type="org.eclipse.core.runtime.xml"
           priority="high">
           <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
               <parameter name="element" value="myTag" />
           </describer>
       </content-type>
</extension>
<extension
       point="org.eclipse.core.runtime.contentTypes">
       <content-type 
           id="dtdContentType"
           name="Tests dtd element recognition" 	
           base-type="org.eclipse.core.runtime.xml"
           priority="high">
           <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
               <parameter name="dtd" value="myDTD.xml" />
           </describer>
       </content-type>
</extension>
   <extension point="org.eclipse.ui.popupMenus">
       <objectContribution
           id="org.eclipse.ui.examples.objectContributions"
           objectClass="org.eclipse.core.resources.IFile"
           nameFilter="*.xml">
           <visibility>
               <or>
                   <objectState
                       name="contentTypeId"
                       value="org.eclipse.ui.examples.topElementContentType"/>
                   <objectState
                       name="contentTypeId"
                       value="org.eclipse.ui.examples.dtdContentType"/>
               </or>
           </visibility>
           <action id="org.eclipse.ui.examples.objectContributions.action1"
               label="%PopupMenus.action"
               icon="icons/ctool16/openbrwsr.png"
               menubarPath="additions"
               class="org.eclipse.ui.examples.objectContributions.PopupMenuActionDelegate"
               enablesFor="1">
	   </action>
       </objectContribution>
 </extension>

myTag をトップレベル XML タグとして含むか、または myDTD.xml と呼ばれる DTD が使用されていれば、これにより、*.xml と一致する名前の IFile で action1 を可視にすることができます。このため、以下の XML ファイルは一致します。

<?xml version="1.0" encoding="UTF-8"?>
<myTag
   id="org.eclipse.ui.workbench"
   name="%pluginName"
  version="3.0.0"
  provider-name="%providerName"
  class="org.eclipse.ui.internal.WorkbenchPlugin">
</myTag>

または

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Book SYSTEM "myDTD.xml">
<fragment
   id="org.eclipse.ui.workbench"
   name="%pluginName"
	version="3.0.0"
	provider-name="%providerName"
	class="org.eclipse.ui.internal.WorkbenchPlugin">
	<runtime>
	   <library name="workbench.jar">
	      <export name="*"/>
		  <packages prefixes="org.eclipse.ui, org.eclipse.jface"/>
	   </library>
	</runtime>
</fragment>

BinarySignatureDescriber

BinarySignatureDescriber は、ファイル内の特定のオフセットで指定のバイナリー「シグニチャー」 を検出するコンテンツ・ディスクライバーです。 このディスクライバーは、「element」または「dtd」の代わりに、「signature」、「offset」および「required」 というパラメーターを取ることを除いて、XMLRootElementContentDescriber と同じように使用されます。 BinarySignatureDescriber の Javadoc はこのコンテンツ・ディスクライバーのクラス使用法の詳細を提供します。