platform-ui-home/object-aware-contributions/objCont.htm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Wed Dec 10 20:02:40 2003 UTC revision 1.2, Fri Jun 11 15:12:05 2004 UTC
# Line 7  Line 7 
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 &quot;Run Ant...&quot; makes sense in its context menu. But this    some XML files contain Ant scripts. The action &quot;Run Ant...&quot; 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      -&gt; Runtime overview -&gt; 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">&lt;objectState name=&quot;xmlFirstTag&quot; value=&quot;<em>tagValue</em>&quot;/&gt;</font></p>    with a describer class of XMLRootElementContentDescriber and parameters indicating
35  <p><font size="3">&lt;objectState name=&quot;xmlDTDName&quot; value=&quot;<em>dtdValue</em>&quot;\&gt;</font></p>    the top level tag name or the dtd name as follows:</p>
36    <pre>   &lt;extension
37           point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
38           &lt;content-type
39               id=&lt;id&gt;
40               name=&lt;name&gt;
41               base-type=&quot;org.eclipse.core.runtime.xml&quot;&gt;
42               &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
43                   &lt;parameter name=&quot;element&quot; value=<em>tagValue</em> /&gt;
44               &lt;/describer&gt;
45           &lt;/content-type&gt;
46       &lt;/extension&gt;</pre>
47    or
48    <pre>   &lt;extension
49           point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
50           &lt;content-type
51               id=&lt;id&gt;
52               name=&lt;name&gt;
53               base-type=&quot;org.eclipse.core.runtime.xml&quot;&gt;
54               &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
55                   &lt;parameter name=&quot;dtd&quot; value=<em>dtdValue</em> /&gt;
56               &lt;/describer&gt;
57           &lt;/content-type&gt;
58        &lt;/extension&gt;</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>
# Line 30  Line 64 
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>   &lt;extension
68           point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
69           &lt;content-type
70               id=&quot;topElementContentType&quot;
71               name=&quot;Tests top-level element recognition&quot;
72               base-type=&quot;org.eclipse.core.runtime.xml&quot;
73               priority=&quot;high&quot;&gt;
74               &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
75                   &lt;parameter name=&quot;element&quot; value=&quot;myTag&quot; /&gt;
76               &lt;/describer&gt;
77           &lt;/content-type&gt;
78       &lt;/extension&gt;
79    
80       &lt;extension
81           point=&quot;org.eclipse.core.runtime.contentTypes&quot;&gt;
82           &lt;content-type
83               id=&quot;dtdContentType&quot;
84               name=&quot;Tests dtd element recognition&quot;
85               base-type=&quot;org.eclipse.core.runtime.xml&quot;
86               priority=&quot;high&quot;&gt;
87               &lt;describer class=&quot;org.eclipse.core.runtime.content.XMLRootElementContentDescriber&quot;&gt;
88                   &lt;parameter name=&quot;dtd&quot; value=&quot;myDTD.xml&quot; /&gt;
89               &lt;/describer&gt;
90           &lt;/content-type&gt;
91       &lt;/extension&gt;
92    </pre>
93  <pre>   &lt;extension point = &quot;org.eclipse.ui.popupMenus&quot;&gt;  <pre>   &lt;extension point = &quot;org.eclipse.ui.popupMenus&quot;&gt;
94       &lt;objectContribution       &lt;objectContribution
95              id=&quot;org.eclipse.ui.examples.objectContributions&quot;              id=&quot;org.eclipse.ui.examples.objectContributions&quot;
# Line 37  Line 97 
97                  nameFilter=&quot;*.xml&quot;&gt;                  nameFilter=&quot;*.xml&quot;&gt;
98                  &lt;visibility&gt;                  &lt;visibility&gt;
99                          &lt;or&gt;                          &lt;or&gt;
100                            &lt;objectState name=&quot;xmlFirstTag&quot; value=&quot;myTag&quot;/&gt;                     &lt;objectState
101                            &lt;objectState name=&quot;xmlDTDName&quot; value=&quot;myDTD.xml&quot;/&gt;                         name=&quot;contentTypeId&quot;
102                           value=&quot;org.eclipse.ui.examples.topElementContentType&quot;/&gt;
103                       &lt;objectState
104                           name=&quot;contentTypeId&quot;
105                           value=&quot;org.eclipse.ui.examples.dtdContentType&quot;/&gt;
106                          &lt;/or&gt;                          &lt;/or&gt;
107              &lt;/visibility&gt;              &lt;/visibility&gt;
108                  &lt;action id=&quot;org.eclipse.ui.examples.objectContributions.action1&quot;                  &lt;action id=&quot;org.eclipse.ui.examples.objectContributions.action1&quot;
# Line 78  Line 142 
142                    &lt;packages prefixes=&quot;org.eclipse.ui, org.eclipse.jface&quot;/&gt;                    &lt;packages prefixes=&quot;org.eclipse.ui, org.eclipse.jface&quot;/&gt;
143             &lt;/library&gt;             &lt;/library&gt;
144          &lt;/runtime&gt;          &lt;/runtime&gt;
145  &lt;/fragment&gt;</pre>  &lt;/fragment&gt;
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 &quot;signature&quot;, &quot;offset&quot; and &quot;required&quot;
153    First, a property called &quot;xmlLastMod&quot; will be used to store the last  instead of &quot;element&quot; or &quot;dtd&quot;. 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, &quot;xmlFirstTag&quot;  
   and &quot;xmlDTDName&quot; 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 &quot;Run Ant...&quot;  
   item</p>  
 <p>45024 - JAXP and old Xerces functionality</p>  
155  </body>  </body>
156  </html>  </html>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2