incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject svn commit: r911600 - in /websites/staging/sling/trunk/content: ./ documentation/bundles/mime-type-support-commons-mime.html
Date Fri, 06 Jun 2014 15:51:43 GMT
Author: buildbot
Date: Fri Jun  6 15:51:43 2014
New Revision: 911600

Staging update by buildbot for sling

    websites/staging/sling/trunk/content/   (props changed)

Propchange: websites/staging/sling/trunk/content/
--- cms:source-revision (original)
+++ cms:source-revision Fri Jun  6 15:51:43 2014
@@ -1 +1 @@

Modified: websites/staging/sling/trunk/content/documentation/bundles/mime-type-support-commons-mime.html
--- websites/staging/sling/trunk/content/documentation/bundles/mime-type-support-commons-mime.html
+++ websites/staging/sling/trunk/content/documentation/bundles/mime-type-support-commons-mime.html
Fri Jun  6 15:51:43 2014
@@ -89,9 +89,64 @@
       <h1>MIME Type Support (commons.mime)</h1>
+      <p>Support for MIME type mappings is generally a problematic issue. On the one
hand applications have to take care to stay up to date with their mappings on the other hands
in web applications it is tedious to maintain the mappings. Apache Sling takes a very user
and deployment friendly approadch to this problem which is described in detail on this page.</p>
+<h2 id="servlet-api-support">Servlet API Support</h2>
+<p>The Servlet API specification provides a limited support for MIME type mappings
+<li>Mappings may be defined in the <code>mime-mapping</code> elements of
the the web application descriptor <code>web.xml</code>. Managing these mappings
is presumably tedious. So servlet containers may provide reasonable defaults (or not).</li>
+<li>The <code>ServletContext.getMimeType(String)</code> returns a MIME
type for a given file name based on the extension of the filename. The mapping returned is
based on the servlet container configuration as well as the web application descriptor's <code>mime-mapping</code>
+<h2 id="enter-sling-the-mimetypeservice">Enter Sling: The MimeTypeService</h2>
+<p>Already at the start of the Sling project we realized, that just basing the MIME
type mapping decisions on the servlet container will not yield acceptable results. For this
reason the Apache Sling projects provides a spezialized and configurable service supporting
such mappings: The <a href="/apidocs/sling6/org/apache/sling/commons/mime/MimeTypeService.html"><code>MimeTypeService</code></a>.</p>
+<p>This service provides access to registered MIME types and their mappings with two
+<li><code>getExtension(String)</code> -- given a MIME type this methods
returns a primary extension. For example for the type <code>text/plain</code>
this method will return <code>txt</code></li>
+<li><code>getMimeType(String)</code> -- given a file name or just the extension)
returns the mapped MIME type. For example for the filename <code>sample.html</code>
(or just the extension <code>html</code>) this method will return <code>text/html</code></li>
+<p>Two more method allow to programmatically add MIME type mappings:</p>
+<li><code>registerMimeType(InputStream)</code> registers additional mappings
from the given input stream which is expected to be formated in traditional <code>mime.types</code>
file format (see below).</li>
+<li><code>registerMimeType(String, String...)</code> registers a single
mapping for the give MIME type and the respective extensions.</li>
+<h2 id="and-more">And More...</h2>
+<p>Besides the <code>MimeTypeService</code> provided by Apache Sling, there
is actually more:</p>
+<li>The <a href="/apidocs/sling6/org/apache/sling/api/SlingHttpServletRequest.html"><code>SlingHttpServletRequest</code></a>
provides the <code>getResponseContentType()</code> method, which returns the preferred
<em>Content-Type</em> for the response based on the requests extension. This method
is implemented by Apache Sling using the <code>MimeTypeService</code>. So servlets
and scripts may just call this method to set the content type of the response to the desired
+<li>Each Servlet (and JSP scripts) is initialized by Apache Sling with a <code>ServletContext</code>
instance whose implementation of the <code>getMimeType(String)</code> effectively
calls the <code>MimeTypeService.getMimeType(String)</code> method.</li>
+<li>The Scripting support infrastructure of Sling sets the response content type on
behalf of the script to the default value as returned by the <code>SlingHttpServletRequest.getResponseContentType()</code>
method. At the same time the response character set is also set to <code>UTF-8</code>
for <em>text</em> content types.</li>
+<h2 id="configuring-mime-type-mappings">Configuring MIME Type Mappings</h2>
+<p>The implementation of the <code>MimeTypeService</code> in the Apache
Sling MIME type mapping support (<code></code>) bundle
supports a numnber of ways to configure and extend the set of MIME type mappings:</p>
+<li>Default configuration. The default configuration is based on the <a href=""><code>mime.types</code></a>
file maintained by Roy Fielding for the Apache httpd project and some extensions by Apache
+<li>Bundle provided mappings. Bundles registered in the OSGi framework may contain
MIME type mappings files <code>META-INF/mime.types</code> which are loaded automatically
by the Apache Sling MIME type mapping support bundle.</li>
+<li>Configuration. Mappings may be supplied by configuration of the <code>MimeTypeService</code>
implementation as the multi-value string property <code>mime.types</code>. Each
value of the property corresponds to a line in a MIME type configuration file (see below for
the format).</li>
+<li>Registered Mappings. Mappings may be registered with the <code>MimeTypeService.registerMapping</code>
+<li><a href="/apidocs/sling6/org/apache/sling/commons/mime/MimeTypeProvider.html"><code>MimeTypeProvider</code></a>.
Additional mappings may be provided by service implementing the <code>MimeTypeProvider</code>
interface. The <code>MimeTypeService</code> implementation will call these services
in turn until a service returns a mapping provided there is no static configuration to responde
to the mapping request.</li>
+<p>Please note, that existing mappings cannot be overwritten later. Thus mappings have
an inherent priority:</p>
+<li>Mappings provided by the Apache httpd project's <code>mime.types</code>
+<li>Extensions by the Apache Sling MIME type mapping support bundle</li>
+<li>Bundles providing a <code>META-INF/mime.types</code> file in the order
of their bundle-id (or startup order if started after the MIME type mapping support bundle)</li>
+<li>OSGi Configuration. Note that bundles started <em>after</em> the MIME
type mapping support bundle may not overwrite mappings provided by the OSGi configuration.
This may sounds like a problem, but in reality this should genrally not matter</li>
+<li>Mappings registered calling the <code>MimeTypeService.registerMimeType</code>
+<li>Mappings provided by <code>MimeTypeProvider</code> services</li>
+<h2 id="mime-type-mapping-file-format">MIME Type Mapping File Format</h2>
+<p>The file format for MIME type mapping files is rather simple:</p>
+<li>The files are assumed to be encoded with the <em>ISO-8859-1</em> (aka
Latin 1) character encoding</li>
+<li>The files consist of lines defining mappings where each line is terminated with
either or both of a carriage return (CR, 0x0c) and line feed character (LF, 0x0a). There is
no line continuation support *-la shell scripts or Java properties files.</li>
+<li>Empty lines and lines starting with a hash sign (<code>#</code>) are
+<li>Data lines consist of space (any whitespace matching the <code>\s</code>
regular expression) separated values. The first value is the MIME type name and the remaining
values defining mappings to file name extensions. The first listed file name extension is
considered the <em>default mapping</em> and is returned by the <code>MimeTypeService.getExtension(String)</code>
method. Entry lines consisting of just a mime type but no extensions are also (currently)
+<p>THe data line format described here also applies to configuration provided by the
values of the <code>mime.types</code> property of the MIME type service configuration.
The file format description applies to all <code>META-INF/mime.types</code> files
provided by the bundles as well as input streams supplied to the <code>MimeTypeService.registerMimeType(InputStream)</code>
+<h2 id="web-console-plugin">Web Console Plugin</h2>
+<p>The Apache Sling MIME type mapping support bundle implements a plugin for the Apache
Felix Web Console which may be consulted to investigate the current contents of the MIME type
mapping tables.</p>
+<p><img alt="Mime Types Web Console Plugin" src="/documentation/bundles/mimetypes.png"
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1600905 by dklco on Fri, 6 Jun 2014 15:04:44 +0000
+        Rev. 1600939 by dklco on Fri, 6 Jun 2014 15:51:36 +0000
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project

View raw message