platform-core-home/documents/content_types.html

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

revision 1.8, Wed Feb 16 16:23:03 2005 UTC revision 1.9, Thu Feb 17 22:24:28 2005 UTC
# Line 7  Line 7 
7  <body text="#000000" bgcolor="#ffffff">  <body text="#000000" bgcolor="#ffffff">
8  <h1>A central content type catalog for Eclipse</h1>  <h1>A central content type catalog for Eclipse</h1>
9  <p><font size="-1">Last modified: Feb 16, 2005</font></p>  <p><font size="-1">Last modified: Feb 16, 2005</font></p>
10    <p><font size="-1"><strong>Note: this document has been updated/extended to depict
11      the solution actually implemented in the 3.0 release and changes made during
12      the 3.1 cycle. The <a href="http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-core-home/documents/content_types.html?rev=1.4">
13      original proposal written the 3.0 development cycle</a>, as well as <a href="http://dev.eclipse.org/viewcvs/index.cgi/platform-core-home/documents/content_types.html">
14      all versions of this document</a> are also available</strong> (<img src="../images/changed.gif" width="12" height="12">
15      marks interesting changes since the original proposal).</font></p>
16  <p><cite><strong>Plan item description:</strong> Content-type-based editor lookup.  <p><cite><strong>Plan item description:</strong> Content-type-based editor lookup.
17    The choice of editor is currently based on file name pattern. This is not very    The choice of editor is currently based on file name pattern. This is not very
18    flexible, and breaks down when fundamentally different types of content are    flexible, and breaks down when fundamentally different types of content are
# Line 113  Line 119 
119    such as what charset was used to encode the contents (for text files), and any    such as what charset was used to encode the contents (for text files), and any
120    content type specific information that may be required.</p>    content type specific information that may be required.</p>
121  <p>The main method in <code>IContentDescriber</code> is:</p>  <p>The main method in <code>IContentDescriber</code> is:</p>
122  <p><code>int describe(InputStream contents, IContentDescription description, int  <p><code>int describe(InputStream contents, IContentDescription description, QualifiedName[]
123    optionsMask) throws IOException;</code></p>    options) throws IOException;</code></p>
124  <p>The first thing implementations for this method must do is to check if the  <p>The first thing implementations for this method must do is to check if the
125    contents represent a valid sample for their corresponding content type file    contents represent a valid sample for their corresponding content type file
126    format. If not (or if cannot be determined), this method should exit immediately,    format. If not (or if cannot be determined), this method should exit immediately,
# Line 138  Line 144 
144    about an arbitrary stream of bytes. These information are filled partially by    about an arbitrary stream of bytes. These information are filled partially by
145    the platform and partially by the content describer elected (if any).</p>    the platform and partially by the content describer elected (if any).</p>
146  <h3>Conflict resolution</h3>  <h3>Conflict resolution</h3>
147  <p>Content types are managed by the platform but plug-ins  <p>Content types are managed by the platform but plug-ins are in charge of contributing
148    are in charge of contributing content types. While this provides good flexibility,    content types. While this provides good flexibility, it also opens oportunities
149    it also opens oportunities for conflicts. There are a few scenarios where conflicts    for conflicts. There are a few scenarios where conflicts may arise:</p>
   may arise:</p>  
150  <ol>  <ol>
151    <li><em>two content types provided by independently developed plug-ins intended    <li><em>two content types provided by independently developed plug-ins intended
152      for the same file selection specification</em> - this may happen for popular      for the same file selection specification</em> - this may happen for popular
153      file types that are not provided by the platform. In this case, one of the      file types that are not provided by the platform. In this case, one of the
154      content types will be automatically made into an alias for the other. The      content types will be ellected arbitrarily. User intervention is required
155      intended effect is that content types/code depending on the content type transformed      (by disabling one of the content types, for instance) if automatic determination
156      into an alias should still work, acting on the alias target instead. Content      does not choose the preferred content type If multiple content types can be
157      type priorities help deciding which content type should be preserved, and      returned by the API, both will appear in the list.<img src="../images/changed.gif" width="12" height="12"> (see
158      which ones made into aliases. If a plug-in provider feels it should be the      bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=83004">83004</a>) <font size="-1">
159      official provider of a content type, a high priority should be assigned to      </font></li>
     it. Usually, &quot;normal&quot; priorities (the default value) should be used,  
     meaning that if a similar high priority content type is available, it should  
     be picked instead. </li>  
160    <li><em>two related (but different) content types that share a same file name/extension    <li><em>two related (but different) content types that share a same file name/extension
161      specification</em> - think of general XML documents and Ant build scripts      specification</em> - think of general XML documents and Ant build scripts
162      (a sub-type of XML document, inheriting its file selection specifications).      (a sub-type of XML document, inheriting its file selection specifications).
# Line 167  Line 169 
169      more specific type will appear before the general one. For APIs that do content-based      more specific type will appear before the general one. For APIs that do content-based
170      analysis, if both content type describers deem the contents as valid, the      analysis, if both content type describers deem the contents as valid, the
171      more specific content type will also appear first. For two sibling content      more specific content type will also appear first. For two sibling content
172      types that deem a same set of bytes as valid, no ordering between them will      types that deem a same set of bytes as valid, an arbitrary order will be chosen.</li>
     be enforced (aliasing is not done since those types do not explicitly specify  
     file specs - they inherit them instead).</li>  
173    <li><em>two completely unrelated content types that share a same file name/extension    <li><em>two completely unrelated content types that share a same file name/extension
174      specification</em> - this is the more unlikely scenario (imagine an image      specification</em> - this is the more unlikely scenario (imagine an image
175      file format and a word-processor file format sharing the same file extension).      file format and a word-processor file format sharing the same file extension).
176      In this case, aliasing is not desirable (since the content types are fundamentally      In this case, one of the content types will be ellected arbitrarily. User
177      different). User intervention is required (by disabling one of the content      intervention is required (by disabling one of the content types, for instance)
178      types, for instance, and manually associating any editors, etc to the other      if automatic determination does not choose the preferred content type.<img src="../images/changed.gif" width="12" height="12"> (see
179      content type) to avoid incorrect aliasing.</li>      bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=83004">83004</a>) <font size="-1"></li>
180  </ol>  </ol>
181  <h3>Frequently Asked Questions</h3>  <h3>Frequently Asked Questions</h3>
182  <ol>  <ol>
# Line 204  Line 204 
204      </li>      </li>
205    <li> What happens if the base type for a new content type is not present in    <li> What happens if the base type for a new content type is not present in
206      the platform (the plug-in that provides it is not available)?      the platform (the plug-in that provides it is not available)?
207      <p>The content type (and consequently any descendants) will be deemed      <p>The content type (and consequently any descendants) will be deemed invalid
208        invalid and ignored.</p>        and ignored.</p>
209    </li>    </li>
210    <li><a name="FAQ-MIME"></a>Do Eclipse's content types have anything to do with    <li><a name="FAQ-MIME"></a>Do Eclipse's content types have anything to do with
211      IANA's MIME Media Types?      IANA's MIME Media Types?
212      <p>Not so far.</p>      <p>Not so far. The main reason is that not every file format with a content
213          type in Eclipse will have a MIME type, so we could not use it as the main
214          association mechanism between content types and applications. We considered
215          keeping MIME-types as an optional property for each content type, and provide
216          a method findContentTypesByMIMEType (or something like that), but decided
217          removing it since there was no sound use case for that (and the idea in
218          the initial proposal was to keep only the essential stuff to avoid distractions).<font size="-1"><strong><img src="../images/changed.gif" width="12" height="12"></strong></font></p>
219    </li>    </li>
220    <li>How can users customize the way content types are chosen?    <li>How can users customize the way content types are chosen?
221      <p>By:      <p>By:
# Line 228  Line 234 
234    </li>    </li>
235    <li>Can two completely unrelated content types be associated with the same file    <li>Can two completely unrelated content types be associated with the same file
236      spec?      spec?
237      <p>What happens is that only one of the content types (arbitrarily selected)      <p>One of the content types (arbitrarily selected) will be chosen as the preferred
238        will be enabled. If only one of them is declared as high priority, it will        one (the other will also be associated). Priorities are also taken into
239        be picked. Otherwise, one will be arbitrarily chosen by the platform. In        account.</p>
       either case, the others will be made into aliases for the elected content  
       type.</p>  
240    </li>    </li>
241    <!--li>How are conflicts (two different content types associated to the same file)    <!--li>How are conflicts (two different content types associated to the same file)
242      prevented?      prevented?
# Line 257  Line 261 
261        This ensures that actions applicable to general XML documents will be applicable        This ensures that actions applicable to general XML documents will be applicable
262        to a plugin manifest.</p>        to a plugin manifest.</p>
263    </li>    </li>
264    <li>What are content type aliases?    <li>What are aliases for? <font size="-1"><strong><img src="../images/changed.gif" width="12" height="12"></strong></font>
265      <p>When a content type is marked as an alias for another content type (due      (see bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=83004">83004</a>)
       to a file spec conflict), all of its properties are ignored, and any associations  
       with it will actually be made on the target type.</p></li>  
   <li>What are aliases for?  
266      <p>It is a mechanism to prevent conflicts. When multiple plugins contribute      <p>It is a mechanism to prevent conflicts. When multiple plugins contribute
267        content types associated with the same file specs, we have a conflict. Conflicts        content types associated with the same file specs, we have a conflict. Conflicts
268        are bad because introduce ambiguity (which one is the right content type?).        are bad because introduce ambiguity (what is the right content type?). Most
269        Most of times when such conflicts arise, it is a case of independently developed        of times when such conflicts arise, it is a case of independently developed
270        plugins trying to contribute the same content type (semantically speaking).        plugins trying to contribute the same content type (semantically speaking).
271        Aliasing between conflicting content types will be automatically created        Imagine a plug-in com.examples.foo that wants to be associated to the Java
272        when necessary.</p>        Source content typ (org.eclipse.jdt.core.javaSource)e, provided by org.eclipse.jdt.core,
273          but that does not require org.eclipse.jdt.core to be present to work. Such
274          plug-in can contribute its own Java Source content type (com.examples.foo.java),
275          and mark it as an alias for the content type provided by JDT/Core. If JDT/Core
276          is present, the com.examples.foo.java will be omitted from the content type
277          registry, and all references to it will be automatically interpreted as
278          references to org.eclipse.jdt.core.javaSource instead.<font size="-1"></font></p>
279    </li>    </li>
280    <li>How do I prevent my specialized content-type to be disabled even if its    <li>How do I prevent my specialized content-type to be disabled even if its
281      parent is not available?      parent is not available? <font size="-1"><strong><img src="../images/changed.gif" width="12" height="12"></strong></font>
282        (see bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=83004">83004</a>)
283      <p> Sometimes a plugin A does not depend on plugin B, but declares a content      <p> Sometimes a plugin A does not depend on plugin B, but declares a content
284        type which is intended to be a specialization of another content type declared        type which is intended to be a specialization of another content type declared
285        by B. To prevent the content type declared by A to be disabled: </p>        by B. To prevent the content type declared by A to be disabled: </p>
286      <ol>      <ol>
287        <li>declare a low priority content type associated with the same file specs        <li>declare an alias content type having the intended parent as its target
288          the intended parent is usually associated with (a placeholder);</li>          (a placeholder);</li>
289        <li>make your specialized content type have this placeholder as its base        <li>make your specialized content type have this placeholder as its base
290          type;</li>          type;</li>
291      </ol>      </ol>
292      <p>If the originally intended base type is available, your base type will      <p>If the originally intended base type is available, your base type will
293        be marked as just an alias, and your specialized content type will be properly        be marked as just an alias, and your specialized content type will be properly
294        attached to the official content type. Otherwise, the placeholder will be        attached to the intended content type. Otherwise, the placeholder will be
295        elected, and although things might not be as great as intended (actions        enabled, and although things might not be as great as intended (actions
296        associated to the original content type will not be available), your content        associated to the original content type will not be available), your content
297        type will still be enabled.</p>        type will still be enabled.<font size="-1"></font></p>
298    </li>    </li>
299    <li>When should a file-association be contributed instead of declaring a new    <li>When should a file-association be contributed instead of declaring a new
300      (derived) content type?      (derived) content type?
# Line 312  Line 320 
320  <p> <em>Note: comments are encouraged. Any questions/concerns not addressed here  <p> <em>Note: comments are encouraged. Any questions/concerns not addressed here
321    should be discussed in the platform-core-dev list, or bug <a    should be discussed in the platform-core-dev list, or bug <a
322   href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=37668">37668</a>. </em></p>   href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=37668">37668</a>. </em></p>
323  <h2>Addendum: issues to be addressed in the 3.1 cycle</h2>  <h2>Addendum: issues to be addressed in the 3.1 cycle<font size="-1"><strong><img src="../images/changed.gif" width="12" height="12"></strong></font></h2>
324  <p>The solution described above was implemented and relatively succesful. Some  <p>The solution described above was implemented and relatively succesful. Some
325    components took advantage of the new content type infrastructure, but still    components took advantage of the new content type infrastructure, but still
326    in many cases file-association is being done in an ad-hoc manner. Also, no UI    in many cases file-association is being done in an ad-hoc manner. Also, no UI
# Line 333  Line 341 
341  </ul>  </ul>
342  <h3>Support more use cases</h3>  <h3>Support more use cases</h3>
343  <p>Ensure the content type support works for the SDK plug-ins and for products  <p>Ensure the content type support works for the SDK plug-ins and for products
344    built on top of Eclipse.</p>    built on top of Eclipse (see bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=78654">78654</a>).</p>
 <p>TBD</p>  
345  <p><strong>Platform/UI - file/editor association</strong></p>  <p><strong>Platform/UI - file/editor association</strong></p>
346  <p>Content type-editor association is definitely the most important use case for  <p>Content type-editor association is definitely the most important use case for
347    the content type support. The basic idea is that for a given file or stream    the content type support. The basic idea is that for a given file or stream
# Line 353  Line 360 
360  <p>Content types add a level of indirection between files and editors. At a first  <p>Content types add a level of indirection between files and editors. At a first
361    glance, there is no reason why changing the default editor would affect what    glance, there is no reason why changing the default editor would affect what
362    content type is assigned to a file, so users should be able to pick up any editors    content type is assigned to a file, so users should be able to pick up any editors
363    without affecting what content type detection.</p>    without affecting content type detection.</p>
364  <p><strong>Platform/Team - binary vs ascii files</strong></p>  <p><strong>Platform/Team - binary vs ascii files</strong></p>
365  <p>The Team plug-in keeps a catalog of file extensions and their expected content  <p>The Team plug-in keeps a catalog of file extensions and their expected content
366    type (either binary or ASCII). If content types were broadly adopted throughout the rest    type (either binary or ASCII). If content types were broadly adopted throughout
367    of Eclipse (so that most files dealt with by users have a content type), couldn't the Team    the rest of Eclipse (so that most files dealt with by users have a content type),
368    plug-in use content type based encoding determination to figure out a good default for this    couldn't the Team plug-in use content type based encoding determination to figure
369    setting?</p>    out a good default for this setting? (see bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=85490">85490</a>)</p>
370  <h3>Give users more power</h3>  <h3>Give users more power</h3>
371  <p>Ensure users have means to customize how the content type detection works for  <p>Ensure users have means to customize how the content type detection works for
372    them. Provide UI for content types. May provide some way of showing related    them. Provide UI for content types. May provide some way of showing related
# Line 373  Line 380 
380  <p>Ensure content type detection works (or can be made to work) appropriately  <p>Ensure content type detection works (or can be made to work) appropriately
381    when incompatible products are deployed together.</p>    when incompatible products are deployed together.</p>
382  <ol>  <ol>
383    <li><strong>nature-specific content types</strong> - to reduce chances for collisions,    <li><strong>project-specific content type resolution</strong> - to reduce chances
384      there should be a way of constraining which content types are available on      for collisions, there should be a way of constraining which content types
385      a project basis. One possible solution would be to have content type-nature      are available on a project basis. One possible solution would be to have content
386      associations. Natures could declare somre preferred content types, and those      type-nature associations. Natures could declare some preferred content types,
387      preferred content types would always win.</li>      and those preferred content types would always win (see bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=69640">69640</a>)</li>
388    <li><strong>user-defined content type determination - </strong>two plug-ins    <li><strong>user-defined content type determination - </strong>two plug-ins
389      provide completely unrelated content types A and B for files with extension      provide completely unrelated content types A and B for files with extension
390      &quot;.foo&quot;. The current implementation will choose one of them (by priority,      &quot;.foo&quot;. The current implementation will choose one of them (by priority,
391      depth, or arbitrarily if they have the same priority and depth) and mark the      depth, or arbitrarily if they have the same priority and depth). If A is automatically
392      other one as an alias, so if they have sub-content types, the two trees will      chosen, the user might want to choose B instead as the default content type.
393      be combined under the chosen one. If A is automatically chosen, the user might      Instead of doing that on a file basis, it seems better to do it on a coarser
394      want to choose B instead as the default content type. </li>      granularity, such as at the project level or at the workspace level (see bug
395    <li><strong>fine-grained user-defined content type determination</strong> -      <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=85765">85765</a>).
396      if for some reason we have problems detecting the right content type for a    </li>
     file, the user should be able to fix that by saying: I want <em><strong>this</strong></em>  
     content type for this file. This is similar to allowing users to specify encoding  
     on a file basis. A possible implementation could be to use persistent properties  
     for that. Another would be to use project preferences (because they are shared).</li>  
397    <li><strong>product defined policies for overriding content types</strong> -    <li><strong>product defined policies for overriding content types</strong> -
398      a product may want to override some of the existing content type definitions.      a product may want to override some of the existing content type definitions.
399      Products should be able to do that in a way that would circumvent the regular      Products should be able to do that in a way that would circumvent the regular
400      conflict resolution.</li>      conflict resolution.</li>
401  </ol>  </ol>
402  <p>See also corresponding PR <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=78654">78654</a>  <p>See also corresponding PR <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=78654">78654</a>
403    - content type should be used universally</p>.    - content type should be used universally</p>
404  </body></html>  </body></html>

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9