이전에는 일부 응용프로그램의 컨텍스트 메뉴가 특정 메뉴 옵션의 제외로 인해 제한되었습니다. 그래서 선택된 자원 수, 실제 파일 이름, 자원 유형 등과 같은 알려진 주변 정보를 기반으로 했습니다. 일부의 경우 자원 컨텐츠에 대해 제한된 양의 정보가 알려졌고 이로 인해 사용하지 않는 메뉴 옵션이 상당히 줄었습니다. Ant 스크립트를 포함하는 XML 파일과 같은 정보는 조치가 XML 파일의 한 유형에는 적용 가능하지만 다른 유형에는 적용할 수 없는 여러 상황이 있을 때 XML 파일에서 유용하게 사용될 수 있습니다. 조치 Ant 실행...이 컨텍스트 메뉴에서는 논리적이지만 플러그인을 정의하는 데 사용되는 XML 파일에는 적용 가능한 조치가 아닙니다.
org.eclipse.core.runtime.contentTypes 확장점을 추가하면 Eclipse는 플러그인이 플랫폼 컨텐츠 유형 카탈로그에 제공할 수 있는 '컨텐츠 유형'을 제공하며, 더 나아가서는 컨텐츠 유형 설명자라는 클래스도 사용할 수 있습니다. 고유 컨텐츠 유형을 제공하는 개발자의 경우 사용자 정의할 수 있는 두 개의 내장형 컨텐츠 유형 설명자를 사용할 수 있습니다. 즉, BinarySignatureDescriber(2진 컨텐츠 유형용) 및 XMLRootElementContentDescriber(XML 기반 컨텐츠 유형의 텍스트용)가 있습니다. 또한 플러그인 제공자는 고유 컨텐츠 설명자를 작성할 수 있습니다. 자세한 내용은 플랫폼 플러그인 개발자 안내서(프로그래머 안내서 > 런타임 개요 > 컨텐츠 유형)를 참조하십시오.
이제는 제공된 최상위 레벨 태그가 있거나 주어진 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는 파일 내의 제공된 오프셋에서 지정된 2진 'signature'를 발견하는 컨텐츠 설명자입니다. 이 설명자는 "element" 또는 "dtd" 대신에 "signature", "offset" 및 "required" 매개변수를 사용하는 것을 제외하고는 XMLRootElementContentDescriber와 동일한 방식으로 사용됩니다. BinarySignatureDescriber의 Javadoc에는 이 컨텐츠 설명자의 클래스 사용법에 대한 전체 세부사항이 있습니다.