incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling > Resource Resolution Plugins
Date Mon, 30 Nov 2009 12:08:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=SLING&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/display/SLING/Resource+Resolution+Plugins">Resource
Resolution Plugins</a></h2>
    <h4>Page  <b>added</b> by             <a href="http://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h1><a name="ResourceResolutionPlugins-ResourceResolutionPlugins"></a>Resource
Resolution Plugins</h1>



<p>Status: DRAFT<br/>
Created: 30. November 2009<br/>
Author: fmeschbe<br/>
JIRA: &#8211;<br/>
References: <a href="http://sling.apache.org/site/mappings-for-resource-resolution.html"
rel="nofollow">Mappings for Resource Resolution</a>, <a href="https://issues.apache.org/jira/browse/SLING-1198"
rel="nofollow">SLING-1198</a><br/>
Update: &#8211;</p>

<div>
<ul>
    <li><a href='#ResourceResolutionPlugins-Introduction'>Introduction</a></li>
    <li><a href='#ResourceResolutionPlugins-Concept'>Concept</a></li>
    <li><a href='#ResourceResolutionPlugins-Interfaces'>Interfaces</a></li>
</ul></div>

<h2><a name="ResourceResolutionPlugins-Introduction"></a>Introduction</h2>

<p>The current support for flexible resource resolution as described in <a href="http://sling.apache.org/site/mappings-for-resource-resolution.html"
rel="nofollow">Mappings for Resource Resolution</a> only supports simple regular
expressions for mapping Request URLs into resource paths.</p>

<p>These mappings do not take into consideration any request headers &#8211; e.g.
the <tt>Accept-Language</tt> header &#8211; or any request parameters. There
might be use cases which require more flexibility. For example <a href="https://issues.apache.org/jira/browse/SLING-1198"
rel="nofollow">SLING-1198</a> proposes an enhancement for the matching algorithm.</p>

<p>This page provides a proposal to enhance the resource resolution by defining plugin
interfaces.</p>


<h2><a name="ResourceResolutionPlugins-Concept"></a>Concept</h2>

<p>Currently each entry below <tt>/etc/map</tt> may contain the following
configuration:</p>

<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> Property </td>
<td class='confluenceTd'> Description </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sling:match</tt> </td>
<td class='confluenceTd'> This property when set on a node in the /etc/map tree (see
below) defines a partial regular expression which is used instead of the node's name to match
the incoming request. This property is only needed if the regular expression includes characters
which are not valid JCR name characters. The list of invalid characters for JCR names is:
/, :, <a href="/confluence/pages/createpage.action?spaceKey=SLING&amp;title=%2C&amp;linkCreation=true&amp;fromPageId=8552613"
class="createlink">,</a>, *, ', ", &#124; and any whitespace except blank space.
In addition a name without a name space may not be . or .. and a blank space is only allowed
inside the name. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sling:redirect</tt> </td>
<td class='confluenceTd'> This property when set on a node in the /etc/map tree (see
below) causes a redirect response to be sent to the client, which causes the client to send
in a new request with the modified location. The value of this property is applied to the
actual request and sent back as the value of Location response header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sling:status</tt> </td>
<td class='confluenceTd'> This property defines the HTTP status code sent to the client
with the sling:redirect response. If this property is not set, it defaults to 302 (Found).
Other status codes supported are 300 (Multiple Choices), 301 (Moved Permanently), 303 (See
Other), and 307 (Temporary Redirect). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sling:internalRedirect</tt> </td>
<td class='confluenceTd'> This property when set on a node in the /etc/map tree (see
below) causes the current path to be modified internally to continue with resource resoltion.
</td>
</tr>
</tbody></table>

<p>This allows for the current regular expression based mapping.</p>

<p>I propose to define a new property which allows for the specification of a plugin:</p>

<p><tt>sling:plugin</tt> &#8211; This (single-value)  property defines
the service reference filter to use to find a resource resolution plugin. If this is a simple
string it is used to find a resource resolution plugin whose <tt>sling.plugin</tt>
service property is set to this string.</p>

<p>The resource resolution plugin is actually a factory for the actual plugin instances
used during the resolution procies. The resource resolution plugin addressed by the <tt>sling:plugin</tt>
property must be registered as an OSGi service with the service name <tt>ResourceResolutionPlugin</tt>.</p>

<p>If the <tt>sling:plugin</tt> property is not set, the default resource
resolution plugin, which is the current regular expression based mapping.</p>

<p>Upon reading the configuration from <tt>/etc/map</tt> (and other sources
like the current <tt>sling:vanityPath</tt> properties and the existing configurtion)
a list of resource resolution plugins is built.</p>

<p>When resolving a request URL to a resource, the list is walked and each plugin is
in turn asked, whether it matches the request and can provide a resource mapping. Likewise
when mapping resource paths to request URLs the list is walked and the plugin is asked whether
it matches the path and can provide a mapped URL.</p>



<h2><a name="ResourceResolutionPlugins-Interfaces"></a>Interfaces</h2>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>ResourceResolutionPlugin.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">interface</span>
ResourceResolutionPlugin {

   <span class="code-keyword">static</span> <span class="code-keyword">final</span>
<span class="code-object">String</span> SERVICE = <span class="code-quote">"ResourceResolutionPlugin"</span>;

   /**
    * Return a <span class="code-keyword">new</span> resource resolution plugin
instance configured
    * from the given configuration. This ValueMap is created from the
    * resource below /etc/map which instructs <span class="code-keyword">this</span>
plugin to be used.
    */
   ResourceResolutionInstance newInstance(ValueMap configuration);

}
</pre>
</div></div>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>ResourceResolutionInstance.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">interface</span>
ResourceResolutionInstance {

   /**
    * Return redirect information with respect to the
    * request and the path or <span class="code-keyword">null</span> <span
class="code-keyword">if</span> <span class="code-keyword">this</span>
instance
    * cannot handle the path.
    */
   RedirectInfo resolve(ResourceResolver resolver, HttpServletRequest request, <span class="code-object">String</span>
path);

   /**
    * Return an URL string or <span class="code-keyword">null</span> <span
class="code-keyword">if</span> <span class="code-keyword">this</span>
instance cannot
    * map the path.
    */
   <span class="code-object">String</span> map(ResourceResolver resolver, HttpServletRequest
request, <span class="code-object">String</span> path);

}
</pre>
</div></div>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>RedirectInfo.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// <span class="code-keyword">this</span> may
also be a class ...
</span><span class="code-keyword">public</span> <span class="code-keyword">interface</span>
RedirectInfo {

    /**
     * Returns the resource to which the path resolved. This must
     * only <span class="code-keyword">return</span> a non-<span class="code-keyword">null</span>
value <span class="code-keyword">if</span> getRedirect() returns <span class="code-keyword">null</span>.
     */
    Resource getResource();

    /**
     * Returns the redirect target to which the path resolved. This
     * must only <span class="code-keyword">return</span> a non-<span class="code-keyword">null</span>
value <span class="code-keyword">if</span> getResource() returns
     * <span class="code-keyword">null</span>.
     */
    <span class="code-object">String</span> getRedirect();

    /**
     * The HTTP status code to use <span class="code-keyword">for</span> the redirect
to the target
     * given by getRedirect(). This should only be considered valid
     * <span class="code-keyword">if</span> getRedirect() returns a non-<span
class="code-keyword">null</span> value.
    <span class="code-object">int</span> getStatus();
}
</pre>
</div></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="http://cwiki.apache.org/confluence/display/SLING/Resource+Resolution+Plugins">View
Online</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/SLING/Resource+Resolution+Plugins?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message