DevFaqEditorWhatIsMimeLookup

(Difference between revisions)
m (Minor grammatical changes)
m (Minor grammatical changes)
 
Line 7: Line 7:
Most of the editor functionality in NetBeans is organized by mime types of
Most of the editor functionality in NetBeans is organized by mime types of
documents that are edited. There are special modules that provide support for
documents that are edited. There are special modules that provide support for
-
editing java, xml, jsp, c++ and many other file types. All these modules need
+
editing Java, XML, JSP, C++ and many other file types. All of these modules need
to provide more or less the same features such as syntax coloring, code
to provide more or less the same features such as syntax coloring, code
completion, code folding, popup menu, etc. However, the implementation of
completion, code folding, popup menu, etc. However, the implementation of
these features is different for particular file types.
these features is different for particular file types.
-
The editor insfrastructure provides many SPI interfaces that can be
+
The editor insfrastructure provides many SPI interfaces that can be implemented by modules providing specific implementations of editor features, and the <tt>MimeLookup</tt> is the way that these implementations can be plugged in to the system.
-
implemented by modules providing specific implementation of editor
+
-
features and the <tt>MimeLookup</tt> is the way that these implementations can be plugged in
+
-
to the system.
+
-
As its name suggests <tt>MimeLookup</tt> is a mime-type specific <tt>Lookup</tt>. This means that
+
As its name suggests, <tt>MimeLookup</tt> is a mime-type specific <tt>Lookup</tt>. This means that modules can register instances in the Lookup dedicated to the mime type of
-
modules can register instances in the Lookup dedicated to the mime type of
+
files that they support. For example, there are different Lookups for
-
files that they support. For example there are different Lookups for
+
<tt>text/x-java</tt> and <tt>text/xml</tt> mime types, and both contain FoldManager
-
<tt>text/x-java</tt> and <tt>text/xml</tt> mime types and both contain FoldManager
+
implementations specific for Java and XML languages respectively.
-
implementations specific for java and XML languages respectively.
+
The <tt>MimeLookup</tt> implementation is split in two parts. The first part is pretty
The <tt>MimeLookup</tt> implementation is split in two parts. The first part is pretty
-
much independent on most of the other NetBeans libraries and provides a simple
+
much independent of most of the other NetBeans libraries and provides a simple
API and SPI for accessing contents of <tt>MimeLookup</tt>. The second part is a
API and SPI for accessing contents of <tt>MimeLookup</tt>. The second part is a
NetBeans specific implementation of the <tt>MimeLookup</tt>'s registry based on the
NetBeans specific implementation of the <tt>MimeLookup</tt>'s registry based on the
-
modules XML layers. This registry is in fact a hierarchical structure of
+
modules' XML layers. This registry is in fact a hierarchical structure of folders under the <tt>Editors/</tt> folder on the system filesystem.
-
folders under the <tt>Editors/</tt> folder on the system filesystem.
+
--------
--------
Line 35: Line 30:
<pre>
<pre>
-
# How to get Lookup for java files?
+
# How to get the Lookup for Java files?
MimePath mimePath = MimePath.parse("text/x-java");
MimePath mimePath = MimePath.parse("text/x-java");
Lookup lookup = MimeLookup.getLookup(mimePath);
Lookup lookup = MimeLookup.getLookup(mimePath);
-
# How to register instances (e.g. EditorKit) in the Lookup for java files?
+
# How to register instances (e.g. EditorKit) in the Lookup for Java files?
<folder name="Editors>
<folder name="Editors>
   <folder name="text">
   <folder name="text">

Current revision as of 10:33, 30 September 2010

What is MimeLookup?

The MimeLookup is a mechanism for extending editor functionality provided by NetBeans modules.

Most of the editor functionality in NetBeans is organized by mime types of documents that are edited. There are special modules that provide support for editing Java, XML, JSP, C++ and many other file types. All of these modules need to provide more or less the same features such as syntax coloring, code completion, code folding, popup menu, etc. However, the implementation of these features is different for particular file types.

The editor insfrastructure provides many SPI interfaces that can be implemented by modules providing specific implementations of editor features, and the MimeLookup is the way that these implementations can be plugged in to the system.

As its name suggests, MimeLookup is a mime-type specific Lookup. This means that modules can register instances in the Lookup dedicated to the mime type of files that they support. For example, there are different Lookups for text/x-java and text/xml mime types, and both contain FoldManager implementations specific for Java and XML languages respectively.

The MimeLookup implementation is split in two parts. The first part is pretty much independent of most of the other NetBeans libraries and provides a simple API and SPI for accessing contents of MimeLookup. The second part is a NetBeans specific implementation of the MimeLookup's registry based on the modules' XML layers. This registry is in fact a hierarchical structure of folders under the Editors/ folder on the system filesystem.


Examples

# How to get the Lookup for Java files?
MimePath mimePath = MimePath.parse("text/x-java");
Lookup lookup = MimeLookup.getLookup(mimePath);

# How to register instances (e.g. EditorKit) in the Lookup for Java files?
<folder name="Editors>
  <folder name="text">
    <folder name="x-java">
      <file name="org-netbeans-modules-java-JavaEditorKitImpl.instance"/>
    </folder>
  </folder>
</folder>

Applies to: NetBeans 5.x, 6.x

Platforms: All

See also: What is Lookup?, MimeLookup API

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo