| 7 |
|
|
| 8 |
<body> |
<body> |
| 9 |
<h1>Content Sensitive Object Contributions</h1> |
<h1>Content Sensitive Object Contributions</h1> |
| 10 |
<p><em>Last modified December 10, 2003</em></p> |
<p><em>Last modified June 10, 2004</em></p> |
| 11 |
<p>Context menus for some applications have previously only been able to exclude |
<p>Context menus for some applications have previously only been able to exclude |
| 12 |
some menu options based on peripheral information known about the resources |
some menu options based on peripheral information known about the resources |
| 13 |
selected (the number of resources selected, the physical name of the file, the |
selected (the number of resources selected, the physical name of the file, the |
| 14 |
type of the resource, etc.). There are some cases where a restricted amount |
type of the resource, etc.). There are some cases where a restricted amount |
| 15 |
of information, known about the contents of the resource would significantly |
of information known about the contents of the resource would significantly |
| 16 |
reduce unusable options from the menus. The first area targeted is that of XML |
reduce unusable options from the menus. Consider XML files as a good example |
| 17 |
files. There are numerous situations where an action is applicable for one type |
of where such information would be useful. There are numerous situations where |
| 18 |
of XML file but not another. For example, some XML files contain Ant scripts. |
an action is applicable for one type of XML file but not another. For example, |
| 19 |
The action "Run Ant..." makes sense in its context menu. But this |
some XML files contain Ant scripts. The action "Run Ant..." makes |
| 20 |
action is not applicable to an XML file used to define a plug-in.</p> |
sense in its context menu. But this action is not applicable to an XML file |
| 21 |
|
used to define a plug-in.</p> |
| 22 |
|
<p>The notion of a content type has been added to Eclipse. A new extension point, |
| 23 |
|
org.eclipse.core.runtime.contentTypes allows plug-ins to contribute to the Platform |
| 24 |
|
content type catalog. Further, classes called Content Type Describers have been |
| 25 |
|
added.</p> |
| 26 |
|
<p>Initially, two content describers will be supported: BinarySignatureDescriber |
| 27 |
|
and XMLRootElementContentDescriber. Eclipse developers may create their own |
| 28 |
|
content describers. The Platform Plug-in Developer Guide (Programmer's Guide |
| 29 |
|
-> Runtime overview -> Content types) describes this in more detail.</p> |
| 30 |
|
<h3>XMLRootElementContentDescriber</h3> |
| 31 |
<p>It will now be possible to define object contributions which are specific to |
<p>It will now be possible to define object contributions which are specific to |
| 32 |
an XML file with a given top level tag or which specify a given DTD. The objectState |
an XML file with a given top level tag or which specify a given DTD. To do this, |
| 33 |
key of an ActionExpression will be used to specify these values as follows:</p> |
define an extension to the org.eclipse.core.runtime.contentTypes extension point |
| 34 |
<p><font size="3"><objectState name="xmlFirstTag" value="<em>tagValue</em>"/></font></p> |
with a describer class of XMLRootElementContentDescriber and parameters indicating |
| 35 |
<p><font size="3"><objectState name="xmlDTDName" value="<em>dtdValue</em>"\></font></p> |
the top level tag name or the dtd name as follows:</p> |
| 36 |
|
<pre> <extension |
| 37 |
|
point="org.eclipse.core.runtime.contentTypes"> |
| 38 |
|
<content-type |
| 39 |
|
id=<id> |
| 40 |
|
name=<name> |
| 41 |
|
base-type="org.eclipse.core.runtime.xml"> |
| 42 |
|
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| 43 |
|
<parameter name="element" value=<em>tagValue</em> /> |
| 44 |
|
</describer> |
| 45 |
|
</content-type> |
| 46 |
|
</extension></pre> |
| 47 |
|
or |
| 48 |
|
<pre> <extension |
| 49 |
|
point="org.eclipse.core.runtime.contentTypes"> |
| 50 |
|
<content-type |
| 51 |
|
id=<id> |
| 52 |
|
name=<name> |
| 53 |
|
base-type="org.eclipse.core.runtime.xml"> |
| 54 |
|
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| 55 |
|
<parameter name="dtd" value=<em>dtdValue</em> /> |
| 56 |
|
</describer> |
| 57 |
|
</content-type> |
| 58 |
|
</extension></pre> |
| 59 |
|
|
| 60 |
<blockquote> |
<blockquote> |
| 61 |
<p><font size="3">where <em>tagValue</em> represents the name of the top level |
<p><font size="3">where <em>tagValue</em> represents the name of the top level |
| 62 |
tag to match and</font></p> |
tag to match and</font></p> |
| 64 |
the XML file.</font></p> |
the XML file.</font></p> |
| 65 |
</blockquote> |
</blockquote> |
| 66 |
<p><font size="3">Consider the following object contribution in a plugin.xml file:</font></p> |
<p><font size="3">Consider the following object contribution in a plugin.xml file:</font></p> |
| 67 |
|
<pre> <extension |
| 68 |
|
point="org.eclipse.core.runtime.contentTypes"> |
| 69 |
|
<content-type |
| 70 |
|
id="topElementContentType" |
| 71 |
|
name="Tests top-level element recognition" |
| 72 |
|
base-type="org.eclipse.core.runtime.xml" |
| 73 |
|
priority="high"> |
| 74 |
|
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| 75 |
|
<parameter name="element" value="myTag" /> |
| 76 |
|
</describer> |
| 77 |
|
</content-type> |
| 78 |
|
</extension> |
| 79 |
|
|
| 80 |
|
<extension |
| 81 |
|
point="org.eclipse.core.runtime.contentTypes"> |
| 82 |
|
<content-type |
| 83 |
|
id="dtdContentType" |
| 84 |
|
name="Tests dtd element recognition" |
| 85 |
|
base-type="org.eclipse.core.runtime.xml" |
| 86 |
|
priority="high"> |
| 87 |
|
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> |
| 88 |
|
<parameter name="dtd" value="myDTD.xml" /> |
| 89 |
|
</describer> |
| 90 |
|
</content-type> |
| 91 |
|
</extension> |
| 92 |
|
</pre> |
| 93 |
<pre> <extension point = "org.eclipse.ui.popupMenus"> |
<pre> <extension point = "org.eclipse.ui.popupMenus"> |
| 94 |
<objectContribution |
<objectContribution |
| 95 |
id="org.eclipse.ui.examples.objectContributions" |
id="org.eclipse.ui.examples.objectContributions" |
| 97 |
nameFilter="*.xml"> |
nameFilter="*.xml"> |
| 98 |
<visibility> |
<visibility> |
| 99 |
<or> |
<or> |
| 100 |
<objectState name="xmlFirstTag" value="myTag"/> |
<objectState |
| 101 |
<objectState name="xmlDTDName" value="myDTD.xml"/> |
name="contentTypeId" |
| 102 |
|
value="org.eclipse.ui.examples.topElementContentType"/> |
| 103 |
|
<objectState |
| 104 |
|
name="contentTypeId" |
| 105 |
|
value="org.eclipse.ui.examples.dtdContentType"/> |
| 106 |
</or> |
</or> |
| 107 |
</visibility> |
</visibility> |
| 108 |
<action id="org.eclipse.ui.examples.objectContributions.action1" |
<action id="org.eclipse.ui.examples.objectContributions.action1" |
| 142 |
<packages prefixes="org.eclipse.ui, org.eclipse.jface"/> |
<packages prefixes="org.eclipse.ui, org.eclipse.jface"/> |
| 143 |
</library> |
</library> |
| 144 |
</runtime> |
</runtime> |
| 145 |
</fragment></pre> |
</fragment> |
| 146 |
|
</pre> |
| 147 |
</blockquote> |
</blockquote> |
| 148 |
|
<h3>BinarySignatureDescriber</h3> |
| 149 |
<p>A new parser, called PropertyParser, will be used to collect this information. |
The BinarySignatureDescriber is a content describer to detect a specified binary |
| 150 |
This parser will be a SAX based parser as we don't necessarily need to parse |
'signature' at a given offset within a file. This describer is used in the same |
| 151 |
the entire file.</p> |
fashion as the XMLRootElementContentDescriber with the exception that it takes |
| 152 |
<p>New persistent properties will be stored for any file that requires this information. |
parameters "signature", "offset" and "required" |
| 153 |
First, a property called "xmlLastMod" will be used to store the last |
instead of "element" or "dtd". The Javadoc for BinarySignatureDescriber |
| 154 |
modified time of the file (as know by IResource). This will ensure that we don't |
gives complete details on this content describer's class usage. |
|
re-parse this file if it isn't necessary. Two other properties, "xmlFirstTag" |
|
|
and "xmlDTDName" will be used to store the name of the root level |
|
|
tag and a DTD file (if specified) respectively. Note that if the parser is called |
|
|
for either one of these, both will be stored (if they exist). The structure |
|
|
of XML dictates that the DTD specification, if it exists, must occur before |
|
|
the root level tag. As a result, once PropertyParser has parsed to the root |
|
|
level tag, it's work is done. At this point, all other parsing is stopped.</p> |
|
|
<p>Any exceptions thrown by the parser are output to the .log file. PropertyParser |
|
|
will explicitly test for an empty file as many SAX parsers will throw an exception |
|
|
if they encounter an XML file without a root level tag.</p> |
|
|
<p>It should be noted that if a DTD is specified in a file, Crimson, a commonly |
|
|
used SAX parser in Eclipse, requires that the DTD file exists and is readable. |
|
|
If this is not the case, a SAXException will be thrown. The PropertyParser does |
|
|
not require the DTD to be present, but the underlying parser often does.</p> |
|
|
<p>Related Bug Reports</p> |
|
|
<p>33018 - [Contributions] plugin.xml context menu should not have "Run Ant..." |
|
|
item</p> |
|
|
<p>45024 - JAXP and old Xerces functionality</p> |
|
| 155 |
</body> |
</body> |
| 156 |
</html> |
</html> |