You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bu...@apache.org on 2016/11/03 04:44:22 UTC
svn commit: r1000416 - in /websites/staging/sling/trunk/content: ./
documentation/bundles/models.html
Author: buildbot
Date: Thu Nov 3 04:44:22 2016
New Revision: 1000416
Log:
Staging update by buildbot for sling
Modified:
websites/staging/sling/trunk/content/ (props changed)
websites/staging/sling/trunk/content/documentation/bundles/models.html
Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Thu Nov 3 04:44:22 2016
@@ -1 +1 @@
-1767818
+1767819
Modified: websites/staging/sling/trunk/content/documentation/bundles/models.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/bundles/models.html (original)
+++ websites/staging/sling/trunk/content/documentation/bundles/models.html Thu Nov 3 04:44:22 2016
@@ -716,8 +716,27 @@ adapting to the interface.</p>
<p>The <code>ModelFactory</code> service interface has methods <code>Object getModelFromResource(Resource)</code> and <code>Object getModelFromRequest(SlingHttpServletRequest)</code> which will dynamically determine the adapter class based on the <code>Resource</code> using its type. In the case of the <code>SlingHttpServletRequest</code> method, it uses the request's <code>Resource</code> object (i.e. by calling <code>request.getResource()</code>)</p>
<p>The resource type is also used as part of the Exporter framework (see next section).</p>
<h1 id="exporter-framework-since-sling-models-130">Exporter Framework (Since Sling Models 1.3.0)<a class="headerlink" href="#exporter-framework-since-sling-models-130" title="Permanent link">¶</a></h1>
+<p>Sling Models objects can be exported to arbitrary Java objects through the Sling Models Exporter framework. Model objects can be
+programatically exported by calling the <code>ModelFactory</code> method <code>exportModel()</code>. This method takes as its arguments:</p>
+<ul>
+<li>the model object</li>
+<li>an exporter name</li>
+<li>a target class</li>
+<li>a map of options</li>
+</ul>
+<p>The exact semantics of the exporting will be determined by an implementation of the <code>ModelExporter</code> service interface. Sling Models
+currently includes a single exporter, using the Jackson framework, which is capable of serializing models as JSON or transforming them to <code>java.util.Map</code> objects.</p>
+<p>In addition, model objects can have servlets automatically registered for their resource type (if it is set) using the <code>@Exporter</code> annotation. For example, a model class with the annotation</p>
+<div class="codehilite"><pre><span class="nd">@Model</span><span class="o">(</span><span class="n">adaptable</span> <span class="o">=</span> <span class="n">Resource</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">resourceType</span> <span class="o">=</span> <span class="s">"myco/components/foo"</span><span class="o">)</span>
+<span class="nd">@Exporter</span><span class="o">(</span><span class="n">name</span> <span class="o">=</span> <span class="s">"jackson"</span><span class="o">,</span> <span class="n">extensions</span> <span class="o">=</span> <span class="s">"json"</span><span class="o">)</span>
+</pre></div>
+
+
+<p>results in the registration of a servlet with the resource type and extension specified and a selector of 'model' (overridable
+through the <code>@Exporter</code> annotation's <code>selector</code> attribute). When this servlet is invoked, the <code>Resource</code> will be adapted to the
+model, exported as a <code>java.lang.String</code> (via the named Exporter) and then returned to the client.</p>
<div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
- Rev. 1767818 by justin on Thu, 3 Nov 2016 04:43:21 +0000
+ Rev. 1767819 by justin on Thu, 3 Nov 2016 04:44:12 +0000
</div>
<div class="trademarkFooter">
Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project