incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r818667 [14/18] - in /websites/staging/sling/trunk/content: ./ authentication/ documentation/ documentation/bundles/ documentation/development/ documentation/getting-started/ documentation/the-sling-engine/ documentation/the-sling-engine/au...
Date Tue, 22 May 2012 09:41:27 GMT
Added: websites/staging/sling/trunk/content/documentation/the-sling-engine/wrap-or-decorate-resources.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/the-sling-engine/wrap-or-decorate-resources.html (added)
+++ websites/staging/sling/trunk/content/documentation/the-sling-engine/wrap-or-decorate-resources.html Tue May 22 09:41:22 2012
@@ -0,0 +1,120 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - Wrap or Decorate Resources</title>
+    <link rel="stylesheet" href="/css/site.css" type="text/css" media="all">
+    <link rel="icon" href="http://sling.apache.org/site/media.data/favicon.ico">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/site/index.html">
+          <img border="0" alt="Apache Sling" src="http://sling.apache.org/site/media.data/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="http://sling.apache.org/site/media.data/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong>Documentation</strong> <br />
+<a href="/getting-started.html">Getting Started</a> <br />
+<a href="/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/development.html">Development</a> <br />
+<a href="/bundles.html">Bundles</a> <br />
+<a href="/tutorials-how-tos.html">Tutorials &amp; How-Tos</a> <br />
+<a href="/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="http://sling.apache.org/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="http://sling.apache.org/apidocs/sling5/index.html">Sling 5</a> <br />
+</p>
+<p><strong>Project info</strong> <br />
+<a href="http://sling.apache.org/site/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br />
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a> <br />
+<a href="/security.html">Security</a> <br />
+</p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a> <br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a> <br />
+</p>
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/the-sling-engine.html">The Sling Engine</a>
+      </div>
+      <h1>Wrap or Decorate Resources</h1>
+      <h2 id="introduction">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
+<em> overwrite resource type/resource super type (for example based on the resource path)
+</em> add metadata</p>
+<h2></h2>
+<p>To add a resource decorator just register one or more services which implement the interface <code>ResourceDecorator</code></p>
+<div class="codehilite"><pre><span class="n">interface</span> <span class="n">ResourceDecorator</span> <span class="p">{</span>
+    <span class="n">Resource</span> <span class="n">decorate</span><span class="p">(</span><span class="n">Resource</span><span class="p">)</span>
+
+    <span class="nv">@Deprecated</span>
+    <span class="n">Resource</span> <span class="n">decorate</span><span class="p">(</span><span class="n">Resource</span><span class="p">,</span> <span class="n">HttpServletRequest</span><span class="p">)</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>The registered decorators will be called from the resource resolver for each resource returned. 
+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 <code>{decorate</code>} 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="codehilite"><pre>    <span class="n">public</span> <span class="n">Resource</span> <span class="n">decorate</span><span class="p">(</span><span class="n">Resource</span> <span class="n">resource</span><span class="p">,</span> <span class="n">HttpServletRequest</span> <span class="n">request</span><span class="p">)</span> <span class="p">{</span>
+        <span class="k">return</span> <span class="n">this</span><span class="o">.</span><span class="n">decorate</span><span class="p">(</span><span class="n">resource</span><span class="p">);</span>
+    <span class="p">}</span>
+</pre></div>
+
+
+<p>And use some other method (e.g. a <code>{ThreadLocal</code>}) to obtain the current request if necessary.</p>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1341376 by fmeschbe on Tue, 22 May 2012 09:41:06 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>

Added: websites/staging/sling/trunk/content/documentation/tutorials-how-tos.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/tutorials-how-tos.html (added)
+++ websites/staging/sling/trunk/content/documentation/tutorials-how-tos.html Tue May 22 09:41:22 2012
@@ -0,0 +1,103 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - Tutorials &amp; How-Tos</title>
+    <link rel="stylesheet" href="/css/site.css" type="text/css" media="all">
+    <link rel="icon" href="http://sling.apache.org/site/media.data/favicon.ico">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/site/index.html">
+          <img border="0" alt="Apache Sling" src="http://sling.apache.org/site/media.data/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="http://sling.apache.org/site/media.data/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong>Documentation</strong> <br />
+<a href="/getting-started.html">Getting Started</a> <br />
+<a href="/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/development.html">Development</a> <br />
+<a href="/bundles.html">Bundles</a> <br />
+<a href="/tutorials-how-tos.html">Tutorials &amp; How-Tos</a> <br />
+<a href="/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="http://sling.apache.org/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="http://sling.apache.org/apidocs/sling5/index.html">Sling 5</a> <br />
+</p>
+<p><strong>Project info</strong> <br />
+<a href="http://sling.apache.org/site/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br />
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a> <br />
+<a href="/security.html">Security</a> <br />
+</p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a> <br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a> <br />
+</p>
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>
+      </div>
+      <h1>Tutorials &amp; How-Tos</h1>
+      <ul>
+<li><a href="/documentation/tutorials-how-tos/46-line-blog.html">46 Line Blog</a></li>
+<li><a href="/documentation/tutorials-how-tos/getting-resources-and-properties-in-sling.html">Getting Resources and Properties in Sling</a></li>
+<li><a href="/documentation/tutorials-how-tos/how-to-manage-events-in-sling.html">How to Manage Events in Sling</a></li>
+<li><a href="/documentation/tutorials-how-tos/installing-and-upgrading-bundles.html">Installing and Upgrading Bundles</a></li>
+<li><a href="/documentation/tutorials-how-tos/jackrabbit-persistence.html">Jackrabbit Persistence</a></li>
+<li><a href="/documentation/tutorials-how-tos/testing-sling-based-applications.html">Testing Sling-based applications</a></li>
+</ul>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1341376 by fmeschbe on Tue, 22 May 2012 09:41:06 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>

Added: websites/staging/sling/trunk/content/documentation/tutorials-how-tos/46-line-blog.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/tutorials-how-tos/46-line-blog.html (added)
+++ websites/staging/sling/trunk/content/documentation/tutorials-how-tos/46-line-blog.html Tue May 22 09:41:22 2012
@@ -0,0 +1,220 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - 46 Line Blog</title>
+    <link rel="stylesheet" href="/css/site.css" type="text/css" media="all">
+    <link rel="icon" href="http://sling.apache.org/site/media.data/favicon.ico">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/site/index.html">
+          <img border="0" alt="Apache Sling" src="http://sling.apache.org/site/media.data/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="http://sling.apache.org/site/media.data/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong>Documentation</strong> <br />
+<a href="/getting-started.html">Getting Started</a> <br />
+<a href="/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/development.html">Development</a> <br />
+<a href="/bundles.html">Bundles</a> <br />
+<a href="/tutorials-how-tos.html">Tutorials &amp; How-Tos</a> <br />
+<a href="/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="http://sling.apache.org/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="http://sling.apache.org/apidocs/sling5/index.html">Sling 5</a> <br />
+</p>
+<p><strong>Project info</strong> <br />
+<a href="http://sling.apache.org/site/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br />
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a> <br />
+<a href="/security.html">Security</a> <br />
+</p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a> <br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a> <br />
+</p>
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a>
+      </div>
+      <h1>46 Line Blog</h1>
+      <p>This tutorial is based on the first <em>Sling Gems</em> on dev.day.com: The <a href="">Sling gems: a blog in 46 lines of code</a>. It has slightly been adapted to fit here.</p>
+<p>In this tutorial, the SlingPostServlet and the sling.js library are brought together using 46 (no kidding: <em>fourty-six</em>) lines of code to create a simple blog (or let's say <em>bloggish</em>) application.</p>
+<p>I used this example in my <a href="">http://us.apachecon.com/c/acus2009/sessions/284</a> presentation at ApacheCon US 09 in Oakland (slides will be available soon), and I think it's a good testimony to the power and simplicity of Sling.</p>
+<h2 id="audience">Audience</h2>
+<p>Although this is a simple sample, it requires some custom settings to work. If you're just starting with Sling, <a href="">SLINGxSITE:Discover Sling in 15 minutes</a> might be a better choice.</p>
+<h2 id="step-0-start-configure-and-login-to-sling">Step 0: Start, configure and login to Sling</h2>
+<p>See <a href="">SLINGxSITE:Getting and Building Sling</a> for how to start Sling. Start it on port 8888 for the below links to work.</p>
+<p>For this sample we need the optional <em>org.apache.sling.samples.path-based.rtp</em> bundle, if it's not present in the <a href="">OSGi console</a>, install and start it. That bundle is not released yet so you might need to build it yourself, from its [source|http://svn.apache.org/repos/asf/sling/trunk/samples/path-based-rtp]. The bundle must then appear in the [OSGI console's list of bundles|http://localhost:8888/system/console/bundles], with name = <em>org.apache.sling.samples.path-based.rtp</em> and status = <em>Active</em>.</p>
+<p>Then, login using http://localhost:8888/?sling:authRequestLogin=1 which should prompt you for a username and password, use <em>admin</em> and <em>admin</em>. Once that's done, http://localhost:8888/index.html should say <em>You are currently logged in as user </em>admin<em> to workspace </em>default**.</p>
+<h2 id="step-1-creating-content">Step 1: Creating content</h2>
+<p>The easiest way to create content in Sling is to use an HTTP POST request, let's use a simple HTML form:</p>
+<p>{code:html}
+<html>
+  <body>
+    <h1>Sling microblog</h1></p>
+<div class="codehilite"><pre><span class="nt">&lt;div&gt;</span>
+  <span class="nt">&lt;form</span> <span class="na">method=</span><span class="s">&quot;POST&quot;</span><span class="nt">&gt;</span>
+    Title:<span class="nt">&lt;br/&gt;</span>
+    <span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;text&quot;</span> <span class="na">name=</span><span class="s">&quot;title&quot;</span> <span class="na">style=</span><span class="s">&quot;width:100%&quot;</span><span class="nt">/&gt;</span>
+
+    <span class="nt">&lt;br/&gt;</span>Text:<span class="nt">&lt;br/&gt;</span>
+    <span class="nt">&lt;textarea</span> <span class="na">style=</span><span class="s">&quot;width:100%&quot;</span> <span class="na">name=</span><span class="s">&quot;text&quot;</span><span class="nt">&gt;&lt;/textarea&gt;</span>
+
+    <span class="nt">&lt;br/&gt;</span>
+    <span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span> <span class="na">value=</span><span class="s">&quot;save&quot;</span><span class="nt">/&gt;</span>
+    <span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;hidden&quot;</span> <span class="na">name=</span><span class="s">&quot;:redirect&quot;</span> <span class="na">value=</span><span class="s">&quot;*.html&quot;</span><span class="nt">/&gt;</span>
+  <span class="nt">&lt;/form&gt;</span>
+<span class="nt">&lt;/div&gt;</span>
+
+<span class="c">&lt;!-- code of step 2 comes here --&gt;</span>
+</pre></div>
+
+
+<p></body>
+</html></p>
+<div class="codehilite"><pre><span class="n">That</span><span class="s">&#39;s two input fields, a submit button and a hidden field that tells Sling what to do after the POST (in this case: redirect to the html view of the node that was just created).</span>
+
+<span class="s">To test the form, start Sling and save the above script as  {footnote}ESP is Sling&#39;</span><span class="n">s</span> <span class="n">server</span><span class="o">-</span><span class="n">side</span> <span class="n">javascript</span> <span class="n">language</span><span class="p">{</span><span class="n">footnote</span><span class="p">}</span> <span class="n">in</span> <span class="n">the</span> <span class="n">Sling</span> <span class="n">repository</span> <span class="o">-</span> <span class="n">a</span> <span class="n">WebDAV</span> <span class="n">mount</span> <span class="n">is</span> <span class="n">the</span> <span class="n">easiest</span> <span class="n">way</span> <span class="n">to</span> <span class="k">do</span> <span class="n">that</span><span class="o">.</span> <span class="n">Browsing</span> <span class="n">to</span>  <span class="p">{</span><span class="n">footnote</span><span class="p">}</span> <span class="n">This</span> <span class="n">assum
 es</span> <span class="n">your</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">Sling</span> <span class="n">is</span> <span class="n">running</span> <span class="n">on</span> <span class="n">port</span> <span class="mi">8888</span><span class="o">.</span> <span class="n">If</span> <span class="n">that</span><span class="s">&#39;s not the case, adjust the example URLs accordingly. {footnote} should display the above form.</span>
+
+<span class="s">Input some data (using &quot;foo&quot; for the title, for the sake of our examples below), save the form, and Sling</span>
+<span class="s">should display the form again, using the URL of the node that was just created.</span>
+
+<span class="s">{note:title=AccessDeniedException?}</span>
+<span class="s">If you get an error saying _javax.jcr.AccessDeniedException: ...not allowed to add or modify item_ it means that you are not logged in as user _admin_. See instructions above for logging in.</span>
+<span class="s">{note}</span>
+
+<span class="s">At this point you&#39;</span><span class="n">re</span> <span class="n">probably</span> <span class="n">looking</span> <span class="n">at</span> <span class="n">an</span> <span class="n">empty</span> <span class="n">form</span> <span class="n">with</span> <span class="n">an</span> <span class="n">URL</span> <span class="n">ending</span> <span class="n">in</span> <span class="n">_foo_</span><span class="p">,</span> <span class="k">if</span> <span class="n">you</span> <span class="n">used</span> <span class="n">that</span> <span class="k">for</span> <span class="n">the</span> <span class="n">title</span><span class="o">.</span> <span class="n">Or</span> <span class="n">_foo_0_</span> <span class="ow">or</span> <span class="n">_foo_1_</span> <span class="k">if</span> <span class="n">other</span> <span class="n">_foo_s</span> <span class="n">already</span> <span class="n">existed</span><span class="o">.</span> <span class="n">Don</span><span class="s">&#39;t worry
  about not seeing your content, we&#39;</span><span class="n">ll</span> <span class="n">fix</span> <span class="n">that</span> <span class="n">right</span> <span class="n">away</span><span class="o">.</span>
+
+<span class="n">h2</span><span class="o">.</span> <span class="n">Step</span> <span class="mi">2</span><span class="p">:</span> <span class="n">Where</span><span class="s">&#39;s my content?</span>
+
+<span class="s">To verify that our content has been created, we can have a look at the JSON data at , which should display our new node&#39;</span><span class="n">s</span> <span class="nb">values</span><span class="p">:</span>
+
+<span class="p">{</span><span class="n">code:javascript</span><span class="p">}</span>
+<span class="p">{</span>
+  <span class="s">&quot;jcr:primaryType&quot;</span><span class="p">:</span> <span class="s">&quot;nt:unstructured&quot;</span><span class="p">,</span>
+  <span class="s">&quot;text&quot;</span><span class="p">:</span> <span class="s">&quot;This is the foo text&quot;</span><span class="p">,</span>
+  <span class="s">&quot;title&quot;</span><span class="p">:</span> <span class="s">&quot;foo&quot;</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>That's reassuring, but what we really want is for these values to be displayed on the editing form for our post.</p>
+<p>Thanks to the <em>sling.js</em> client library, we just need to add a <code>Sling.wizard()</code> call to our form to display those values. Let's first add a <code>&lt;head&gt;</code> element to our form to load the <em>sling.js</em> library, before the existing <code>&lt;body&gt;</code> of course:</p>
+<p>{code:html}
+<head>
+  <script src="/system/sling.js"></script>
+</head></p>
+<div class="codehilite"><pre>And add the  after the form, where we had the _code of step 2 comes here_ comment:
+
+{code:html}
+<span class="c">&lt;!-- code of step 2 comes here --&gt;</span>
+<span class="nt">&lt;script&gt;</span>Sling.wizard();<span class="nt">&lt;/script&gt;</span>
+</pre></div>
+
+
+<p>Reloading the form at <code>http://localhost:8888/content/blog/*.html</code> and creating a new post should now redirect to an editable version of the post, with the form fields correctly initialized.</p>
+<p>We can now create and edit posts; let's add some navigation, using more of the <em>sling.js</em> functionality. </p>
+<h2 id="step-3-navigation">Step 3: Navigation</h2>
+<p>The <em>sling.js</em> library provides utilities to access and manipulate content. For our blog, we'll use the <code>getContent(path)</code> method to list the siblings of the current node.</p>
+<p>Add the following code to your script, after the <code>Sling.wizard()</code> call that was added in step 2:</p>
+<p>{code:html}
+<h3>Navigation</h3>
+<ul>
+    <li><em><a href="/content/blog/*.html"><a href="">Create new post</a></a></em></li>
+    <script>
+      var posts = Sling.getContent("/content/blog", 2);
+      for(var i in posts) {
+        document.write("<li>"
+          + "<a href='/content/blog/" + i + ".html'>"  <br />
+          + posts<a href="">i</a>.title
+          + "</a></li>");
+      }
+    </script>
+</ul></p>
+<div class="codehilite"><pre><span class="n">The</span> <span class="n">first</span> <span class="nb">link</span> <span class="n">to</span>  <span class="n">brings</span> <span class="n">us</span> <span class="n">back</span> <span class="n">to</span> <span class="k">our</span> <span class="n">content</span> <span class="n">creating</span> <span class="n">form</span><span class="p">,</span> <span class="n">which</span> <span class="n">is</span> <span class="n">nothing</span> <span class="k">else</span> <span class="n">than</span> <span class="n">the</span> <span class="n">editing</span> <span class="n">form</span> <span class="n">reading</span> <span class="n">empty</span> <span class="nb">values</span> <span class="ow">and</span> <span class="n">posting</span> <span class="n">to</span> <span class="n">the</span> <span class="s">&quot;magic star&quot;</span> <span class="n">URL</span><span class="o">.</span>
+
+<span class="n">The</span> <span class="n">rest</span> <span class="n">of</span> <span class="n">the</span> <span class="n">javascript</span> <span class="n">runs</span> <span class="n">client</span><span class="o">-</span><span class="n">side</span><span class="p">,</span> <span class="n">as</span> <span class="n">it</span> <span class="n">is</span> <span class="ow">not</span> <span class="n">embedded</span> <span class="n">in</span>  <span class="n">code</span> <span class="n">markers</span><span class="p">,</span> <span class="n">calls</span> <span class="n">the</span>  <span class="n">method</span> <span class="n">to</span> <span class="n">get</span> <span class="n">two</span> <span class="n">levels</span> <span class="n">of</span> <span class="n">node</span> <span class="n">data</span> <span class="n">below</span> <span class="p">,</span> <span class="ow">and</span> <span class="n">displays</span> <span class="n">links</span> <span class="n">to</span> <span class="n">no
 des</span> <span class="n">that</span> <span class="n">it</span> <span class="n">finds</span><span class="o">.</span>
+
+<span class="n">That</span><span class="s">&#39;s a basic navigation, of course, in a real blog we&#39;</span><span class="n">d</span> <span class="n">need</span> <span class="n">some</span> <span class="n">paging</span> <span class="ow">and</span> <span class="n">contextualization</span> <span class="n">to</span> <span class="n">cope</span> <span class="n">with</span> <span class="n">large</span> <span class="n">numbers</span> <span class="n">of</span> <span class="n">posts</span><span class="o">.</span>
+
+<span class="n">Nevertheless</span><span class="p">,</span> <span class="n">with</span> <span class="n">this</span> <span class="n">addition</span> <span class="k">our</span> <span class="n">ESP</span> <span class="n">script</span> <span class="n">allows</span> <span class="n">us</span> <span class="n">to</span> <span class="n">create</span><span class="p">,</span> <span class="n">edit</span> <span class="ow">and</span> <span class="n">navigate</span> <span class="n">blog</span> <span class="n">posts</span> <span class="o">-</span> <span class="ow">not</span> <span class="n">bad</span> <span class="k">for</span> <span class="mi">46</span> <span class="n">lines</span> <span class="n">of</span> <span class="n">code</span><span class="p">,</span> <span class="n">including</span> <span class="n">comments</span><span class="p">,</span> <span class="n">whitespace</span> <span class="ow">and</span> <span class="n">output</span> <span class="n">formatting</span><span class="o">.</sp
 an>
+
+<span class="n">h2</span><span class="o">.</span> <span class="n">Step</span> <span class="mi">4</span><span class="p">:</span> <span class="n">Data</span> <span class="n">first</span><span class="p">,</span> <span class="n">structure</span> <span class="n">later</span>
+
+<span class="n">You</span> <span class="n">might</span> <span class="n">have</span> <span class="n">heard</span> <span class="n">this</span> <span class="n">mantra</span><span class="p">,</span> <span class="n">which</span> <span class="n">we</span> <span class="n">apply</span> <span class="n">in</span> <span class="n">many</span> <span class="n">areas</span> <span class="n">of</span> <span class="n">Sling</span><span class="o">.</span>
+
+<span class="n">In</span> <span class="n">this</span> <span class="k">case</span><span class="p">,</span> <span class="n">adding</span> <span class="n">a</span> <span class="k">new</span> <span class="n">field</span> <span class="n">to</span> <span class="k">our</span> <span class="n">blog</span> <span class="n">posts</span> <span class="n">could</span> <span class="ow">not</span> <span class="n">be</span> <span class="n">easier:</span> <span class="n">just</span> <span class="n">add</span> <span class="n">an</span> <span class="n">input</span> <span class="n">field</span> <span class="n">to</span> <span class="n">the</span> <span class="n">form</span><span class="p">,</span> <span class="ow">and</span> <span class="n">Sling</span> <span class="n">will</span> <span class="k">do</span> <span class="n">the</span> <span class="n">rest</span><span class="o">.</span>
+
+<span class="n">Adding</span> <span class="n">this</span> <span class="n">inside</span> <span class="k">our</span> <span class="n">script</span><span class="err">&#39;</span><span class="n">s</span>  <span class="n">element</span><span class="p">,</span> <span class="k">for</span> <span class="n">example:</span>
+
+<span class="p">{</span><span class="n">code:html</span><span class="p">}</span>
+<span class="sr">&lt;br/&gt;</span><span class="n">Author:</span><span class="sr">&lt;br/&gt;</span>
+<span class="o">&lt;</span><span class="n">input</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;author&quot;</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;author&quot;</span> <span class="n">style</span><span class="o">=</span><span class="s">&quot;width:100%&quot;</span><span class="o">/&gt;</span>
+</pre></div>
+
+
+<p>Allows us to add an author name to our blog posts. No need to define anything at the repository level, as Sling is using it in unstructured mode in this case, and no need to migrate existing data, the author field of existing posts will simply be empty.</p>
+<h2 id="i-want-my-esp">I want my ESP!</h2>
+<p>Now wait...we said we were going to create an ESP script, but our "application" is just static HTML and some client javascript at this point.</p>
+<p>That's correct - as we are using only Sling client-facing features at this point (HTTP POST and <code>sling.js</code>), we do not necessarily need to use ESP code.</p>
+<p>To keep things simple, we'll refrain from adding ESP-based features at this point, but you can of course use any ESP code in the <em>blog.esp</em> "script".</p>
+<h2 id="thats-the-power-of-sling">That's the power of Sling</h2>
+<p>The 46-line blog is a good example of the power of Sling. It leverages the <a href="">SlingPostServlet</a>, which handles POST requests in a form-friendly way, and the <code>[sling.js|http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/resources/system/sling.js]</code> client library, which provides high-level functionality on the client side.</p>
+<hr />
+<p>///Footnotes Go Here///</p>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1341347 by fmeschbe on Tue, 22 May 2012 08:25:18 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>

Added: websites/staging/sling/trunk/content/documentation/tutorials-how-tos/getting-resources-and-properties-in-sling.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/tutorials-how-tos/getting-resources-and-properties-in-sling.html (added)
+++ websites/staging/sling/trunk/content/documentation/tutorials-how-tos/getting-resources-and-properties-in-sling.html Tue May 22 09:41:22 2012
@@ -0,0 +1,170 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - Getting Resources and Properties in Sling</title>
+    <link rel="stylesheet" href="/css/site.css" type="text/css" media="all">
+    <link rel="icon" href="http://sling.apache.org/site/media.data/favicon.ico">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/site/index.html">
+          <img border="0" alt="Apache Sling" src="http://sling.apache.org/site/media.data/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="http://sling.apache.org/site/media.data/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong>Documentation</strong> <br />
+<a href="/getting-started.html">Getting Started</a> <br />
+<a href="/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/development.html">Development</a> <br />
+<a href="/bundles.html">Bundles</a> <br />
+<a href="/tutorials-how-tos.html">Tutorials &amp; How-Tos</a> <br />
+<a href="/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="http://sling.apache.org/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="http://sling.apache.org/apidocs/sling5/index.html">Sling 5</a> <br />
+</p>
+<p><strong>Project info</strong> <br />
+<a href="http://sling.apache.org/site/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br />
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a> <br />
+<a href="/security.html">Security</a> <br />
+</p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a> <br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a> <br />
+</p>
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a>
+      </div>
+      <h1>Getting Resources and Properties in Sling</h1>
+      <h1 id="getting-resources-and-properties-in-sling">Getting Resources and Properties in Sling</h1>
+<p>The Resource is one of the central parts of Sling. Extending from JCR's Everything is Content, Sling assumes Everthing is a Resource. Thus Sling is maintaining a virtual tree of resources, which is a merger of the actual contents in the JCR Repository and resources provided by so called resource providers. By doing this Sling fits very well in the paradigm of the REST architecture.</p>
+<p>In this article we will explore a few ways to programmatically map a resource path (String) to a resource object (Resource) and its properties in Sling, from within an OSGI service, a servlet and a JSP.</p>
+<p>The whole game consists in first getting a <code>ResourceResolver</code> and then getting the <code>Resource</code> itself.</p>
+<h2 id="within-an-osgi-servicecompoment">Within an OSGI Service/Compoment</h2>
+<p>You can access a resource through the <code>ResourceResolverFactory</code> service:</p>
+<div class="codehilite"><pre><span class="sr">/** @scr.reference */</span>
+<span class="n">private</span> <span class="n">ResourceResolverFactory</span> <span class="n">resolverFactory</span><span class="p">;</span>
+
+<span class="n">public</span> <span class="n">void</span> <span class="n">myMethod</span><span class="p">()</span> <span class="p">{</span>
+    <span class="n">try</span> <span class="p">{</span>
+    <span class="n">String</span> <span class="n">resourcePath</span> <span class="o">=</span> <span class="s">&quot;path/to/resource&quot;</span><span class="p">;</span>
+        <span class="n">ResourceResolver</span> <span class="n">resourceResolver</span> <span class="o">=</span> <span class="n">resolverFactory</span><span class="o">.</span><span class="n">getAdministrativeResourceResolver</span><span class="p">(</span><span class="n">null</span><span class="p">);</span>
+    <span class="n">Resource</span> <span class="n">res</span> <span class="o">=</span> <span class="n">resourceResolver</span><span class="o">.</span><span class="n">getResource</span><span class="p">(</span><span class="n">resourcePath</span><span class="p">);</span>
+    <span class="sr">//</span> <span class="k">do</span> <span class="n">something</span> <span class="n">with</span> <span class="n">the</span> <span class="n">resource</span>
+    <span class="sr">//</span> <span class="n">when</span> <span class="n">done</span><span class="p">,</span> <span class="nb">close</span> <span class="n">the</span> <span class="n">ResourceResolver</span>
+    <span class="n">resourceResolver</span><span class="o">.</span><span class="nb">close</span><span class="p">();</span>
+    <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">LoginException</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+        <span class="sr">//</span> <span class="nb">log</span> <span class="n">the</span> <span class="n">error</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<h2 id="within-a-servlet">Within a Servlet</h2>
+<p>You can access the resource defined by the request URL through the <code>SlingHttpServletRequest</code>:</p>
+<div class="codehilite"><pre><span class="n">Resource</span> <span class="n">res</span> <span class="o">=</span> <span class="n">req</span><span class="o">.</span><span class="n">getResource</span><span class="p">();</span>
+<span class="sr">//</span> <span class="n">req</span> <span class="n">is</span> <span class="n">the</span> <span class="n">SlingHttpServletRequest</span>
+</pre></div>
+
+
+<p>You can access any resource by first accessing the <code>ResourceResolver</code>:</p>
+<div class="codehilite"><pre><span class="n">String</span> <span class="n">resourcePath</span> <span class="o">=</span> <span class="s">&quot;path/to/resource&quot;</span><span class="p">;</span>
+<span class="n">ResourceResolver</span> <span class="n">resourceResolver</span> <span class="o">=</span> <span class="n">req</span><span class="o">.</span><span class="n">getResourceResolver</span><span class="p">();</span>
+<span class="sr">//</span> <span class="n">req</span> <span class="n">is</span> <span class="n">the</span> <span class="n">SlingHttpServletRequest</span>
+<span class="n">Resource</span> <span class="n">res</span> <span class="o">=</span> <span class="n">resourceResolver</span><span class="o">.</span><span class="n">getResource</span><span class="p">(</span><span class="n">resourcePath</span><span class="p">);</span>
+</pre></div>
+
+
+<h2 id="within-a-jsp-file">Within a JSP file</h2>
+<p>When you use the <code>&lt;sling:defineObjects&gt;</code> tag in a JSP file, you have access to a few handy objects, one of them is <code>resource</code>, the resource that is resolved from the URL. Another one is <code>resourceResolver</code>, the <code>ResourceResolver</code> defined through the <code>SlingHttpServletRequest</code>. </p>
+<p>To access a resource:</p>
+<div class="codehilite"><pre><span class="x">&lt;sling:defineObjects&gt;</span>
+<span class="cp">&lt;%</span>
+<span class="nb">String</span> <span class="n">resourcePath</span> <span class="o">=</span> <span class="s2">&quot;path/to/resource&quot;</span><span class="p">;</span>
+<span class="no">Resource</span> <span class="n">res</span> <span class="o">=</span> <span class="n">resourceResolver</span><span class="o">.</span><span class="n">getResource</span><span class="p">(</span><span class="n">resourcePath</span><span class="p">);</span>
+<span class="cp">%&gt;</span><span class="x"></span>
+</pre></div>
+
+
+<p>If needed you can adapt a Sling Resource to a JCR Node:</p>
+<div class="codehilite"><pre><span class="n">Node</span> <span class="n">node</span> <span class="o">=</span> <span class="n">resource</span><span class="o">.</span><span class="n">adaptTo</span><span class="p">(</span><span class="n">Node</span><span class="o">.</span><span class="n">class</span><span class="p">);</span>
+</pre></div>
+
+
+<p>Note: <code>resource.adaptTo(Node.class)</code> may return null if the resource is not backed by a JCR node. This is particularly the case for <code>NonExistingResource</code> resources or resource provided by a non-JCR resource provider.</p>
+<h2 id="accessing-a-property">Accessing a Property</h2>
+<p>The <code>ValueMap</code> is an easy way to access properties of a resource. With most resources you can use <code>Adaptable.adaptTo(Class)</code> to adapt the resource to a value map:</p>
+<div class="codehilite"><pre><span class="n">ValueMap</span> <span class="n">properties</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">adaptTo</span><span class="p">(</span><span class="n">ValueMap</span><span class="o">.</span><span class="n">class</span><span class="p">);</span>
+<span class="sr">//</span> <span class="n">res</span> <span class="n">is</span> <span class="n">the</span> <span class="n">Resource</span>
+</pre></div>
+
+
+<p>You can also access the properties through the <code>ResourceUtil</code> utility class:</p>
+<div class="codehilite"><pre><span class="n">ValueMap</span> <span class="n">properties</span> <span class="o">=</span> <span class="n">ResourceUtil</span><span class="o">.</span><span class="n">getValueMap</span><span class="p">(</span><span class="n">res</span><span class="p">);</span>
+<span class="sr">//</span> <span class="n">res</span> <span class="n">is</span> <span class="n">the</span> <span class="n">Resource</span>
+</pre></div>
+
+
+<p>Then, to access a specific String property called <code>propName</code>:</p>
+<div class="codehilite"><pre><span class="n">String</span> <span class="n">rule</span> <span class="o">=</span> <span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">propName</span><span class="p">,</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">null</span><span class="p">);</span>
+</pre></div>
+
+
+<p>For more details about resources and how to access them in Sling, you can refer to the <a href="">Sling documentation about Resources</a>.</p>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1341347 by fmeschbe on Tue, 22 May 2012 08:25:18 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>

Added: websites/staging/sling/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.html (added)
+++ websites/staging/sling/trunk/content/documentation/tutorials-how-tos/how-to-manage-events-in-sling.html Tue May 22 09:41:22 2012
@@ -0,0 +1,275 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - How to Manage Events in Sling</title>
+    <link rel="stylesheet" href="/css/site.css" type="text/css" media="all">
+    <link rel="icon" href="http://sling.apache.org/site/media.data/favicon.ico">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/site/index.html">
+          <img border="0" alt="Apache Sling" src="http://sling.apache.org/site/media.data/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="http://sling.apache.org/site/media.data/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong>Documentation</strong> <br />
+<a href="/getting-started.html">Getting Started</a> <br />
+<a href="/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/development.html">Development</a> <br />
+<a href="/bundles.html">Bundles</a> <br />
+<a href="/tutorials-how-tos.html">Tutorials &amp; How-Tos</a> <br />
+<a href="/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="http://sling.apache.org/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="http://sling.apache.org/apidocs/sling5/index.html">Sling 5</a> <br />
+</p>
+<p><strong>Project info</strong> <br />
+<a href="http://sling.apache.org/site/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br />
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a> <br />
+<a href="/security.html">Security</a> <br />
+</p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a> <br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a> <br />
+</p>
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a>
+      </div>
+      <h1>How to Manage Events in Sling</h1>
+      <h1 id="how-to-manage-events-in-sling">How to Manage Events in Sling</h1>
+<p>Apache Sling provides some mechanisms and support for managing events.</p>
+<p>The event mechanism is leveraging the OSGi Event Admin Specification (OSGi Compendium 113). The OSGi API is very simple and lightweight. Sending an event is just generating the event object and calling the event admin. Receiving the event is implementing a single interface and declaring through properties which topics one is interested in. 
+Sling makes a distinction between events and job events. Unlike events, job events are garanteed to be processed. In other words: someone has to do something with the job event (do the job). </p>
+<p>For more details please refer to the following resources:
+<em> <a href="">Eventing, Jobs and Scheduling section</a> to get detailed information on the eventing mechanisms in Sling.
+</em> package <a href="">org.osgi.service.event</a> of the OSGI API.
+* package <a href="">org.apache.sling.event</a> of the Sling API.</p>
+<p>This page drives you through the implementation of two services that rely on the Sling eventing mechanisms. The services implement the following use case: whenever a file is uploaded to a temporary location in your web application, the file is moved to a specific location according to its MIME type.</p>
+<h2 id="introduction">Introduction</h2>
+<p>You will now implement the logic to listen to files posted to <em>/tmp/dropbox</em> and to move them to the appropriate locations depending on the MIME type:
+<em> images (.png) are moved to </em>/dropbox/images/<em>
+</em> music (.mp3) are moved to <em>/dropbox/music/</em>
+<em> movies (.avi) are moved to </em>/dropbox/movies/<em>
+</em> otherwise the files are moved to <em>/dropbox/other/</em></p>
+<p>To do that, you will implement two services. The first one, called <em>DropBoxService</em>:
+<em> Listens to OSGI events.
+</em> Sends a job event if a resource has been added to <em>/tmp/dropbox</em>.</p>
+<p>The second one, called <em>DropBoxEventHandler</em>:
+<em> Listens to the former job event.
+</em> Moves the file according to its extension.</p>
+<h2 id="listening-to-osgi-events">Listening to OSGI Events</h2>
+<p>To listen to the specific OSGI event <em>"resource added"</em>:
+<em> The property </em>event.topics<em> needs to be set to </em>org.apache.sling.api.SlingConstants.TOPIC<em>RESOURCE</em>ADDED* in the class annotations.</p>
+<div class="codehilite"><pre> <span class="o">*</span> <span class="nv">@scr</span><span class="o">.</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;event.topics&quot;</span> <span class="n">valueRef</span><span class="o">=</span><span class="s">&quot;org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED&quot;</span>
+</pre></div>
+
+
+<p>You can refer to the <a href="">org.apache.sling.api.SlingConstants</a> class in the Javadocs to know about other events available in Sling.</p>
+<h2 id="sending-job-events">Sending Job Events</h2>
+<p>To send a job event the service needs to implement:
+<em> the </em>org.osgi.service.event.EventHandler<em> interface.
+</em> the <em>org.apache.sling.event.JobProcessor</em> interface.</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">class</span> <span class="n">DropBoxService</span> <span class="n">implements</span> <span class="n">JobProcessor</span><span class="p">,</span> <span class="n">EventHandler</span> <span class="p">{</span>
+</pre></div>
+
+
+<p>To send the job event the Event Admin service needs to be referenced:</p>
+<div class="codehilite"><pre>    <span class="o">/**</span> 
+     <span class="o">*</span> <span class="n">The</span> <span class="n">OSGI</span> <span class="n">event</span> <span class="n">admin</span> <span class="n">used</span> <span class="k">for</span> <span class="n">sending</span> <span class="n">events</span> 
+     <span class="o">*</span> <span class="nv">@scr</span><span class="o">.</span><span class="n">reference</span>
+     <span class="o">*/</span>
+    <span class="n">private</span> <span class="n">EventAdmin</span> <span class="n">eventAdmin</span><span class="p">;</span>
+</pre></div>
+
+
+<p>The job topic for dropbox job events needs to be defined:</p>
+<div class="codehilite"><pre>    <span class="sr">/** The job topic for dropbox job events. */</span>
+    <span class="n">public</span> <span class="n">static</span> <span class="n">final</span> <span class="n">String</span> <span class="n">JOB_TOPIC</span> <span class="o">=</span> <span class="s">&quot;com/sling/eventing/dropbox/job&quot;</span><span class="p">;</span>
+</pre></div>
+
+
+<p>The <em>org.osgi.service.event.EventHandler#handleEvent(Event event)</em> method needs to be implemented:</p>
+<div class="codehilite"><pre>    <span class="n">public</span> <span class="n">void</span> <span class="n">handleEvent</span><span class="p">(</span><span class="n">Event</span> <span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">EventUtil</span><span class="o">.</span><span class="n">isLocal</span><span class="p">(</span><span class="n">event</span><span class="p">))</span> <span class="p">{</span>
+            <span class="n">EventUtil</span><span class="o">.</span><span class="n">processJob</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="n">this</span><span class="p">);</span>
+        <span class="p">}</span>
+    <span class="p">}</span>
+</pre></div>
+
+
+<p>The <em>org.apache.sling.event.JobProcessor#process(Event event)</em> method needs to be implemented.</p>
+<p>Its logic is as follows:
+<em> The OSGI event is analyzed.
+</em> If the event is a file that has been added to <em>/tmp/dropbox</em>:
+<strong> An event is created with 2 properties:
+<strong><em> A property to set the event as a job event.
+</em></strong> A property for the file path.
+</strong> The job event is sent to all the listeners that subscribe to the topic of the event.</p>
+<div class="codehilite"><pre>    <span class="n">public</span> <span class="n">boolean</span> <span class="n">process</span><span class="p">(</span><span class="n">Event</span> <span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+        <span class="n">String</span> <span class="n">propPath</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">event</span><span class="o">.</span><span class="n">getProperty</span><span class="p">(</span><span class="n">SlingConstants</span><span class="o">.</span><span class="n">PROPERTY_PATH</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">propResType</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">event</span><span class="o">.</span><span class="n">getProperty</span><span class="p">(</span><span class="n">SlingConstants</span><span class="o">.</span><span class="n">PROPERTY_RESOURCE_TYPE</span><span class="p">);</span>
+        <span class="sr">//</span> <span class="n">an</span> <span class="n">event</span> <span class="n">is</span> <span class="n">sent</span> <span class="k">if</span> <span class="n">a</span> <span class="n">file</span> <span class="n">is</span> <span class="n">added</span> <span class="n">to</span> <span class="sr">/tmp/</span><span class="n">dropbox</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">propPath</span><span class="o">.</span><span class="n">startsWith</span><span class="p">(</span><span class="s">&quot;/tmp/dropbox&quot;</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="n">propResType</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="s">&quot;nt:file&quot;</span><span class="p">))</span> <span class="p">{</span>
+            <span class="n">final</span> <span class="n">Dictionary</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">props</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Hashtable</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span><span class="p">();</span>
+            <span class="n">props</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">EventUtil</span><span class="o">.</span><span class="n">PROPERTY_JOB_TOPIC</span><span class="p">,</span> <span class="n">JOB_TOPIC</span><span class="p">);</span>
+            <span class="n">props</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="s">&quot;resourcePath&quot;</span><span class="p">,</span> <span class="n">propPath</span><span class="p">);</span>
+            <span class="n">Event</span> <span class="n">dropboxJobEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Event</span><span class="p">(</span><span class="n">EventUtil</span><span class="o">.</span><span class="n">TOPIC_JOB</span><span class="p">,</span> <span class="n">props</span><span class="p">);</span>
+            <span class="n">eventAdmin</span><span class="o">.</span><span class="n">sendEvent</span><span class="p">(</span><span class="n">dropboxJobEvent</span><span class="p">);</span>
+            <span class="nb">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;the dropbox job has been sent: {}&quot;</span><span class="p">,</span> <span class="n">propPath</span><span class="p">);</span>
+        <span class="p">}</span>
+        <span class="k">return</span> <span class="n">true</span><span class="p">;</span>
+    <span class="p">}</span>
+</pre></div>
+
+
+<p>The complete code for the <em>DropBoxService</em> service is available <a href="">here</a>.</p>
+<h2 id="listening-to-job-events">Listening to Job Events</h2>
+<p>Now that you have implemented a service that sends a job event when a file is uploaded to <em>/tmp/dropbox</em>, you will implement the service <em>DropBoxEventHandler</em> that listens to those job events and moves the files to a location according to their MIME types.</p>
+<p>To listen to the job events that have been defined before:
+<em> The property </em>event.topics<em> needs to be set to </em>mypackage.DropBoxService.JOB_TOPIC* in the class annotations.</p>
+<div class="codehilite"><pre> <span class="o">*</span> <span class="nv">@scr</span><span class="o">.</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;event.topics&quot;</span> <span class="n">valueRef</span><span class="o">=</span><span class="s">&quot;mypackage.DropBoxService.JOB_TOPIC&quot;</span>
+</pre></div>
+
+
+<h2 id="handling-job-events">Handling Job Events</h2>
+<p>To move the files the service needs to implement:
+<em> the </em>org.osgi.service.event.EventHandler<em> interface.
+</em> the <em>org.apache.sling.event.JobProcessor</em> interface.</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">class</span> <span class="n">DropBoxEventHandler</span> <span class="n">implements</span> <span class="n">JobProcessor</span><span class="p">,</span> <span class="n">EventHandler</span> <span class="p">{</span>
+</pre></div>
+
+
+<p>Some class fields need to be defined for:
+<em> The default log.
+</em> The references to the SlingRepository and the JcrResourceResolverFactory services, which are used in the implementation.
+* The destination paths of the files.</p>
+<p>{code}
+   /*<em> Default log. </em>/
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());</p>
+<div class="codehilite"><pre><span class="sr">/** @scr.reference */</span>
+<span class="n">private</span> <span class="n">SlingRepository</span> <span class="n">repository</span><span class="p">;</span>
+
+<span class="o">/**</span>
+ <span class="o">*</span> <span class="nv">@scr</span><span class="o">.</span><span class="n">reference</span>
+ <span class="o">*/</span>
+<span class="n">private</span> <span class="n">JcrResourceResolverFactory</span> <span class="n">resolverFactory</span><span class="p">;</span>
+
+<span class="n">private</span> <span class="n">final</span> <span class="n">static</span> <span class="n">String</span> <span class="n">IMAGES_PATH</span> <span class="o">=</span> <span class="s">&quot;/dropbox/images/&quot;</span><span class="p">;</span>
+<span class="n">private</span> <span class="n">final</span> <span class="n">static</span> <span class="n">String</span> <span class="n">MUSIC_PATH</span> <span class="o">=</span> <span class="s">&quot;/dropbox/music/&quot;</span><span class="p">;</span>
+<span class="n">private</span> <span class="n">final</span> <span class="n">static</span> <span class="n">String</span> <span class="n">MOVIES_PATH</span> <span class="o">=</span> <span class="s">&quot;/dropbox/movies/&quot;</span><span class="p">;</span>
+<span class="n">private</span> <span class="n">final</span> <span class="n">static</span> <span class="n">String</span> <span class="n">OTHER_PATH</span> <span class="o">=</span> <span class="s">&quot;/dropbox/other/&quot;</span><span class="p">;</span>
+
+<span class="n">The</span> <span class="o">*</span><span class="n">org</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">service</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">EventHandler</span><span class="c1">#handleEvent(Event event)* method needs to be implemented:</span>
+
+<span class="n">public</span> <span class="n">void</span> <span class="n">handleEvent</span><span class="p">(</span><span class="n">Event</span> <span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">EventUtil</span><span class="o">.</span><span class="n">isLocal</span><span class="p">(</span><span class="n">event</span><span class="p">))</span> <span class="p">{</span>
+        <span class="n">EventUtil</span><span class="o">.</span><span class="n">processJob</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="n">this</span><span class="p">);</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="n">The</span> <span class="o">*</span><span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">sling</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">JobProcessor</span><span class="c1">#process(Event event)* method needs to be implemented.</span>
+
+<span class="n">Its</span> <span class="n">logic</span> <span class="n">is</span> <span class="n">as</span> <span class="n">follows:</span>
+<span class="o">*</span> <span class="n">The</span> <span class="n">resource</span> <span class="n">path</span> <span class="n">is</span> <span class="n">extracted</span> <span class="n">from</span> <span class="n">the</span> <span class="n">job</span> <span class="n">event</span> <span class="n">property</span><span class="o">.</span>
+<span class="o">*</span> <span class="n">The</span> <span class="n">resource</span> <span class="n">is</span> <span class="n">obtained</span> <span class="n">from</span> <span class="n">the</span> <span class="n">resource</span> <span class="n">path</span><span class="o">.</span>
+<span class="o">*</span> <span class="n">If</span> <span class="n">the</span> <span class="n">resource</span> <span class="n">is</span> <span class="n">a</span> <span class="n">file</span><span class="p">,</span> <span class="n">the</span> <span class="n">destination</span> <span class="n">path</span> <span class="n">is</span> <span class="nb">defined</span> <span class="n">based</span> <span class="n">on</span> <span class="n">the</span> <span class="n">file</span> <span class="n">MIME</span> <span class="n">type</span><span class="o">.</span>
+<span class="o">*</span> <span class="n">The</span> <span class="n">file</span> <span class="n">is</span> <span class="n">moved</span> <span class="n">to</span> <span class="n">the</span> <span class="k">new</span> <span class="n">location</span><span class="o">.</span>
+
+<span class="n">public</span> <span class="n">boolean</span> <span class="n">process</span><span class="p">(</span><span class="n">Event</span> <span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">Session</span> <span class="n">adminSession</span> <span class="o">=</span> <span class="n">null</span><span class="p">;</span>
+    <span class="n">try</span> <span class="p">{</span>
+        <span class="n">String</span> <span class="n">resourcePath</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">event</span><span class="o">.</span><span class="n">getProperty</span><span class="p">(</span><span class="s">&quot;resourcePath&quot;</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">resourceName</span> <span class="o">=</span> <span class="n">resourcePath</span><span class="o">.</span><span class="n">substring</span><span class="p">(</span><span class="n">resourcePath</span><span class="o">.</span><span class="n">lastIndexOf</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
+        <span class="n">adminSession</span> <span class="o">=</span> <span class="n">repository</span><span class="o">.</span><span class="n">loginAdministrative</span><span class="p">(</span><span class="n">null</span><span class="p">);</span>
+        <span class="n">ResourceResolver</span> <span class="n">resourceResolver</span> <span class="o">=</span> <span class="n">resolverFactory</span><span class="o">.</span><span class="n">getResourceResolver</span><span class="p">(</span><span class="n">adminSession</span><span class="p">);</span>
+        <span class="n">Resource</span> <span class="n">res</span> <span class="o">=</span> <span class="n">resourceResolver</span><span class="o">.</span><span class="n">getResource</span><span class="p">(</span><span class="n">resourcePath</span><span class="p">);</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">ResourceUtil</span><span class="o">.</span><span class="n">isA</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="s">&quot;nt:file&quot;</span><span class="p">))</span> <span class="p">{</span>
+            <span class="n">String</span> <span class="n">mimeType</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">getResourceMetadata</span><span class="p">()</span><span class="o">.</span><span class="n">getContentType</span><span class="p">();</span>
+            <span class="n">String</span> <span class="n">destDir</span><span class="p">;</span>
+            <span class="k">if</span> <span class="p">(</span><span class="n">mimeType</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="s">&quot;image/png&quot;</span><span class="p">))</span> <span class="p">{</span>
+                <span class="n">destDir</span> <span class="o">=</span> <span class="n">IMAGES_PATH</span><span class="p">;</span>
+            <span class="p">}</span>
+            <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">mimeType</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="s">&quot;audio/mpeg&quot;</span><span class="p">))</span> <span class="p">{</span>
+                <span class="n">destDir</span> <span class="o">=</span> <span class="n">MUSIC_PATH</span><span class="p">;</span>
+            <span class="p">}</span>
+            <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">mimeType</span><span class="o">.</span><span class="n">equals</span><span class="p">(</span><span class="s">&quot;video/x-msvideo&quot;</span><span class="p">))</span> <span class="p">{</span>
+                <span class="n">destDir</span> <span class="o">=</span> <span class="n">MOVIES_PATH</span><span class="p">;</span>
+            <span class="p">}</span>
+            <span class="k">else</span> <span class="p">{</span>
+                <span class="n">destDir</span> <span class="o">=</span> <span class="n">OTHER_PATH</span><span class="p">;</span>
+            <span class="p">}</span>
+            <span class="n">adminSession</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">resourcePath</span><span class="p">,</span> <span class="n">destDir</span> <span class="o">+</span> <span class="n">resourceName</span><span class="p">);</span>
+            <span class="n">adminSession</span><span class="o">.</span><span class="n">save</span><span class="p">();</span>
+            <span class="nb">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;The file {} has been moved to {}&quot;</span><span class="p">,</span> <span class="n">resourceName</span><span class="p">,</span> <span class="n">destDir</span><span class="p">);</span>
+        <span class="p">}</span>
+        <span class="k">return</span> <span class="n">true</span><span class="p">;</span>
+    <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">RepositoryException</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nb">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">&quot;RepositoryException: &quot;</span> <span class="o">+</span> <span class="n">e</span><span class="p">);</span>
+        <span class="k">return</span> <span class="n">false</span><span class="p">;</span>
+    <span class="p">}</span> <span class="n">finally</span> <span class="p">{</span>
+        <span class="k">if</span> <span class="p">(</span><span class="n">adminSession</span> <span class="o">!=</span> <span class="n">null</span> <span class="o">&amp;&amp;</span> <span class="n">adminSession</span><span class="o">.</span><span class="n">isLive</span><span class="p">())</span> <span class="p">{</span>
+            <span class="n">adminSession</span><span class="o">.</span><span class="n">logout</span><span class="p">();</span>
+            <span class="n">adminSession</span> <span class="o">=</span> <span class="n">null</span><span class="p">;</span>
+        <span class="p">}</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="n">The</span> <span class="n">complete</span> <span class="n">code</span> <span class="k">for</span> <span class="n">the</span> <span class="o">*</span><span class="n">DropBoxEventHandler</span><span class="o">*</span> <span class="n">service</span> <span class="n">is</span> <span class="n">available</span> <span class="p">[</span><span class="n">here</span><span class="o">|^</span><span class="n">DropBoxEventHandler</span><span class="o">.</span><span class="n">java</span><span class="p">]</span><span class="o">.</span>
+</pre></div>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1341347 by fmeschbe on Tue, 22 May 2012 08:25:18 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>

Added: websites/staging/sling/trunk/content/documentation/tutorials-how-tos/installing-and-upgrading-bundles.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/tutorials-how-tos/installing-and-upgrading-bundles.html (added)
+++ websites/staging/sling/trunk/content/documentation/tutorials-how-tos/installing-and-upgrading-bundles.html Tue May 22 09:41:22 2012
@@ -0,0 +1,133 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE- 2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+  <head>
+    <title>Apache Sling - Installing and Upgrading Bundles</title>
+    <link rel="stylesheet" href="/css/site.css" type="text/css" media="all">
+    <link rel="icon" href="http://sling.apache.org/site/media.data/favicon.ico">
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+  </head>
+  <body>
+    <div class="title">
+      <div class="logo">
+        <a href="http://sling.apache.org/site/index.html">
+          <img border="0" alt="Apache Sling" src="http://sling.apache.org/site/media.data/logo.png">
+        </a>
+      </div>
+      <div class="header">
+        <a href="http://www.apache.org/">
+          <img border="0" alt="Apache" src="http://sling.apache.org/site/media.data/apache.png">
+        </a>
+      </div>
+    </div>
+    
+    <div class="menu"> 
+      <p><strong>Documentation</strong> <br />
+<a href="/getting-started.html">Getting Started</a> <br />
+<a href="/the-sling-engine.html">The Sling Engine</a> <br />
+<a href="/development.html">Development</a> <br />
+<a href="/bundles.html">Bundles</a> <br />
+<a href="/tutorials-how-tos.html">Tutorials &amp; How-Tos</a> <br />
+<a href="/configuration.html">Configuration</a> <br />
+<a href="http://s.apache.org/sling.wiki">Wiki</a> <br />
+<a href="http://s.apache.org/sling.faq">FAQ</a> <br />
+<a href="/sitemap.html">Site Map</a></p>
+<p><strong>API Docs</strong>  <br />
+<a href="http://sling.apache.org/apidocs/sling6/index.html">Sling 6</a> <br />
+<a href="http://sling.apache.org/apidocs/sling5/index.html">Sling 5</a> <br />
+</p>
+<p><strong>Project info</strong> <br />
+<a href="http://sling.apache.org/site/downloads.cgi">Downloads</a> <br />
+<a href="http://www.apache.org/licenses/">License</a> <br />
+<a href="/contributing.html">Contributing</a> <br />
+<a href="/news.html">News</a> <br />
+<a href="/links.html">Links</a> <br />
+<a href="/project-information.html">Project Information</a> <br />
+<a href="https://issues.apache.org/jira/browse/SLING">Issue Tracker</a> <br />
+<a href="http://svn.apache.org/viewvc/sling/trunk">Browse Source Repository</a> <br />
+<a href="/security.html">Security</a> <br />
+</p>
+<p><strong>Sponsorship</strong> <br />
+<a href="http://www.apache.org/foundation/thanks.html">Thanks</a> <br />
+<a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a> <br />
+<a href="http://www.apache.org/foundation/buy_stuff.html">Buy Stuff</a> <br />
+</p>
+<iframe 
+    src="http://www.apache.org/ads/button.html"
+    style="border-width:0; float: left" frameborder="0" 
+    scrolling="no"
+    width="135" 
+    height="135">
+</iframe>
+    </div>
+    
+    <div class="main">
+      <div class="breadcrump" style="font-size: 80%;">
+        <a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>&nbsp;&raquo&nbsp;<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a>
+      </div>
+      <h1>Installing and Upgrading Bundles</h1>
+      <h1 id="installing-and-upgrading-bundles">Installing and Upgrading Bundles</h1>
+<p>{note}
+We recommend to use the Apache Felix Web Console. The documentation below describes the old Sling Management Console, which isn't in use any more. Please refer to the documentation of the <a href="">Apache Felix Web Console</a>.
+{note}</p>
+<p>OSGi bundles installed in the OSGi framework, which is provided by Sling, may be upgraded or removed and new bundles may be installed by using the Sling Management Console. This page is about using the Sling Management Console for those tasks.</p>
+<p>Basically, you have two choices to install and upgrade bundles: Upload the bundle files or install them from a Bundle Repository.</p>
+<h2 id="sling-management-console">Sling Management Console</h2>
+<p>The Sling Management Console is installed by default when Sling is running and may be reached at on the page <code>/system/console</code> in the Sling Context by default. For example if you installed the Sling Web Application in the <code>/sample</code> context of the Servlet Container running at <code>http``://somehost:4402</code>, you would access the Sling Management Console at <code>http``://somehost:4402/sample/system/console</code>.</p>
+<p>You will be prompted for a user name and password to access the Sling Management Console. This password is preset to be <em>admin</em> for the user name and <em>admin</em> for the password.</p>
+<p>NB: Both the username and password and the location of the Sling Management Console inside the Web Application Context is configurable in the <em>Sling Management Console</em> configuration on the <em>Configuration</em> page.</p>
+<h2 id="installing-and-upgrading-bundles-by-upload">Installing and upgrading bundles by Upload</h2>
+<p>To install a new bundle or upgrade an already installed bundle, go to the <em>Bundles</em> page in the Sling Management Console. At the top and the bottom of the page you have a form to specify and upload a bundle as a file :</p>
+<ul>
+<li>Select the bundle file to upload</li>
+<li>Click the <em>Start</em> checkbox, if you want to start the bundle after installation. If the bundle is upgraded, this checkbox is ignored.</li>
+<li>Specify the start level of the bundle in the <em>Start Level</em> field. This must be a number higher than 0 and is ignored for bundles, which are already installed. Most of the time, you will use the default value.</li>
+<li>Click the <em>Install or Update</em> button</li>
+</ul>
+<p>After clicking the button, the bundle file will be uploaded. If a bundle with the same bundle symbolic name is already installed, the respective bundle will be updated with the new bundle file. Otherwise the bundle file will be installed as a new bundle and its start level is set as defined. Additionally the bundle will optionally be started.</p>
+<p>After having updated a bundle, you should also refresh the packages by clicking on the <em>Refresh Packages</em> button. The reson for this is, that the old version of the bundle is still used by other bundles even after upgrading to a new version. Only when the packages are refreshed any users of the bundle will be relinked to use the new bundle version. As this might be a somewhat lengthy operation, which also stops and restarts using bundles, this operation has to be executed explicitly.</p>
+<p>Also, if you plan to upgrade multiple bundles, you may wish to upgrade all bundles before repackaging the using bundles.</p>
+<h2 id="installing-and-upgrading-bundles-from-the-bundle-repository">Installing and upgrading bundles from the Bundle Repository</h2>
+<p>The OSGi Bundle Repository is a repository of bundles, from which Sling may download and install or upgrade bundles very easily. Unlike the installation of bundles by file upload, the OSGi Bundle Repository has the functionality to resolve and dependencies of bundles to be installed.</p>
+<p>Say you wish to install bundle <em>X</em> which depends on packages provided by bundle <em>Y</em>. When uploading bundle <em>X</em> as a file it will not resolve, that is Sling (the OSGi framework actually) is not able to ensure proper operation of bundle <em>X</em> and thus prevents the bundle from being started and used. You will have to manually upload bundle <em>Y</em> yourself. When using the OSGi Bundle Repository, you just select bundle <em>X</em> for installation and the bundle repository will find out, that bundle <em>Y</em> is also required and will automatically download and install it along with bundle <em>X</em>.</p>
+<h3 id="the-bundle-repository-page">The Bundle Repository page</h3>
+<p>Installation or update of bundles may be done on the <em>Bundle Repository</em> page of the Sling Management Console. In the upper part of the page, you will see a list (usually just a single entry) of OSGi Bundle Repositories known to Sling. In the lower part of the list you see the bundles available from these repositories. To install or update bundles, just check the respective button and click on the <em>Deploy Selected</em> or <em>Deploy and Start Selected</em> button at the bottom of the page depending on whether you want to start the bundle(s) after installation or not.</p>
+<p>See below for more information on OSGi Bundle Repository management.</p>
+<h3 id="the-bundles-page">The Bundles page</h3>
+<p>You may also want to upgrade already installed bundles from the <em>Bundles</em> page of the Sling Management Console. For each bundle listed in this page, there is an <em>Upgrade</em> button. If there is an upgrade to the installed bundle available in the OSGi Bundle Repository, the button is enabled and clicking on the button will upgrade the respective bundle. If no upgrade is available from the OSGi Bundle Repository, this button is disabled.</p>
+<h3 id="managing-osgi-bundle-repositories">Managing OSGi Bundle Repositories</h3>
+<p>Currently management of known OSGi Bundle Repositories is very simple. If a configured bundle repository is not available on startup, it will be marked as being inactive. If you know the repository is now available, you may click on the <em>Refresh</em> button, to activate it. Similarly, the contents of the repository may be modified by for example adding new bundles or updating bundles in the repository, these changes will be made known to Sling by clicking the <em>Refresh</em> button.</p>
+<p>There exists no GUI functionality yet to add a new repository to the list of known repositories. Instead you may submit a request with parameters <code>action</code> whose value must be <code>refreshOBR</code> and <code>repository</code> whose value must be the URL to the repository descriptor file generally called <code>repository.xml</code>.</p>
+<p>For example, if you run Sling on <code>http``://localhost:7402/sample</code> with default location of the Sling Management Console, the following request would add a repository at <code>/tmp/repo/repository.xml</code> in the filesystem:</p>
+<div class="codehilite"><pre><span class="n">http:</span><span class="sr">//</span><span class="n">localhost:7402</span><span class="sr">/sample/s</span><span class="n">ystem</span><span class="sr">/console/</span><span class="n">bundlerepo</span><span class="p">?</span><span class="n">action</span><span class="o">=</span><span class="n">refreshOBR</span><span class="o">&amp;</span><span class="n">repository</span><span class="o">=</span><span class="n">file:</span><span class="sr">///tmp/</span><span class="n">repo</span><span class="o">/</span><span class="n">repository</span><span class="o">.</span><span class="n">xml</span>
+</pre></div>
+
+
+<p>Note: Only use <code>file:</code> URLs if you know Sling has access to the named file !</p>
+      <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
+        Rev. 1341347 by fmeschbe on Tue, 22 May 2012 08:25:18 +0000
+      </div>
+      <div class="trademarkFooter"> 
+        Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project
+        logo are trademarks of The Apache Software Foundation. All other marks mentioned
+        may be trademarks or registered trademarks of their respective owners.
+      </div>
+    </div>
+  </body>
+</html>



Mime
View raw message