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 Website > Wrap or Decorate Resources
Date Thu, 16 Feb 2012 23:24:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Wrap+or+Decorate+Resources">Wrap
or Decorate Resources</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~justinedelson">Justin
Edelson</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >interface ResourceDecorator { <br>
   Resource decorate(Resource) <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>    @Deprecated <br></td></tr>
            <tr><td class="diff-unchanged" >    Resource decorate(Resource, HttpServletRequest)
<br>}  <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The registered decorators will be
called from the resource resolver for each resource returned.  <br>If the service decorates
the resource it should return the new resource. If the service does not want to decorate the
resource, it should return the original resource or null.  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>The two-argument {{{decorate}}} method will not be invoked, starting with version
2.1.0 of the JCR Resource bundle. Implementors of this interface targeting both newer and
older versions of this bundle are advised to implement this method with: <br> <br>{code}
<br>    public Resource decorate(Resource resource, HttpServletRequest request) { <br>
       return this.decorate(resource); <br>    } <br>{code} <br> <br>And
use some other method (e.g. a {{{ThreadLocal}}}) to obtain the current request if necessary.
<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="WraporDecorateResources-Servicetowrapresources"></a>Service
to wrap resources</h1>

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

<p>The Sling API provides an easy way to wrap or decorate a resource before returning.
Use cases for this could for example be</p>
<ul>
	<li>overwrite resource type/resource super type (for example based on the resource
path)</li>
	<li>add metadata</li>
</ul>


<h2><a name="WraporDecorateResources-"></a></h2>

<p>To add a resource decorator just register one or more services which implement the
interface <tt>ResourceDecorator</tt></p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">interface</span> ResourceDecorator {
    Resource decorate(Resource)

    @Deprecated
    Resource decorate(Resource, HttpServletRequest)
} 
</pre>
</div></div>

<p>The registered decorators will be called from the resource resolver for each resource
returned. <br/>
If the service decorates the resource it should return the new resource. If the service does
not want to decorate the resource, it should return the original resource or null. </p>

<p>The two-argument {{</p>
<div class="error"><span class="error">Unknown macro: {decorate}</span>
</div>
<p>}} method will not be invoked, starting with version 2.1.0 of the JCR Resource bundle.
Implementors of this interface targeting both newer and older versions of this bundle are
advised to implement this method with:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> Resource decorate(Resource resource,
HttpServletRequest request) {
        <span class="code-keyword">return</span> <span class="code-keyword">this</span>.decorate(resource);
    }
</pre>
</div></div>

<p>And use some other method (e.g. a {{</p>
<div class="error"><span class="error">Unknown macro: {ThreadLocal}</span>
</div>
<p>}}) to obtain the current request if necessary.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Wrap+or+Decorate+Resources">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=23335935&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Wrap+or+Decorate+Resources?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message