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 2015/07/29 09:39:55 UTC

svn commit: r959982 - in /websites/staging/sling/trunk/content: ./ documentation/bundles/validation.html

Author: buildbot
Date: Wed Jul 29 07:39:55 2015
New Revision: 959982

Log:
Staging update by buildbot for sling

Modified:
    websites/staging/sling/trunk/content/   (props changed)
    websites/staging/sling/trunk/content/documentation/bundles/validation.html

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Jul 29 07:39:55 2015
@@ -1 +1 @@
-1692853
+1693196

Modified: websites/staging/sling/trunk/content/documentation/bundles/validation.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/bundles/validation.html (original)
+++ websites/staging/sling/trunk/content/documentation/bundles/validation.html Wed Jul 29 07:39:55 2015
@@ -39,7 +39,18 @@
     </div>
     
     <div class="menu"> 
-      <p><strong><a href="/documentation.html">Documentation</a></strong> <br />
+      <style type="text/css">
+/* The following code is added by mdx_elementid.py
+   It was originally lifted from http://subversion.apache.org/style/site.css */
+/*
+ * Hide class="elementid-permalink", except when an enclosing heading
+ * has the :hover property.
+ */
+.headerlink, .elementid-permalink {
+  visibility: hidden;
+}
+h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
+<p><strong><a href="/documentation.html">Documentation</a></strong> <br />
 <a href="/documentation/getting-started.html">Getting Started</a> <br />
 <a href="/documentation/the-sling-engine.html">The Sling Engine</a> <br />
 <a href="/documentation/development.html">Development</a> <br />
@@ -90,14 +101,28 @@
       
       
       <h1>Sling Validation</h1>
-      <div class="note">
+      <style type="text/css">
+/* The following code is added by mdx_elementid.py
+   It was originally lifted from http://subversion.apache.org/style/site.css */
+/*
+ * Hide class="elementid-permalink", except when an enclosing heading
+ * has the :hover property.
+ */
+.headerlink, .elementid-permalink {
+  visibility: hidden;
+}
+h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
+<div class="note">
 This documentation is still work in progress!
 </div>
 
 <div class="toc">
 <ul>
 <li><a href="#basic-usage">Basic Usage</a></li>
-<li><a href="#validation-model-resources">Validation Model Resources</a></li>
+<li><a href="#validation-model-resources">Validation Model Resources</a><ul>
+<li><a href="#overwriting-properties-or-children-in-super-models">Overwriting Properties or Children in Super Models</a></li>
+</ul>
+</li>
 <li><a href="#usage-in-sling-models">Usage in Sling Models</a><ul>
 <li><a href="#since-sling-models-120">Since Sling Models 1.2.0</a></li>
 <li><a href="#before-sling-models-120">Before Sling Models 1.2.0</a></li>
@@ -108,10 +133,10 @@ This documentation is still work in prog
 </ul>
 </div>
 <p>Many Sling projects want to be able to validate both Resources and request parameters. Through the Sling Validation Bundle this is possible with the help of validation model resources which define validation rules for a certain resourceType.</p>
-<h1 id="basic-usage">Basic Usage</h1>
+<h1 id="basic-usage">Basic Usage<a class="headerlink" href="#basic-usage" title="Permanent link">&para;</a></h1>
 <p>To validate a resource one first needs to get a <code>ValidationModel</code> and then validate the resource with that model. Both functionalities are provided by the <code>ValidationService</code> OSGi service:</p>
 <div class="codehilite"><pre><span class="k">try</span> <span class="o">{</span>
-    <span class="n">ValidationModel</span> <span class="n">validationModel</span> <span class="o">=</span> <span class="n">validationService</span><span class="o">.</span><span class="na">getValidationModel</span><span class="o">(</span><span class="n">resource</span><span class="o">);</span>
+    <span class="n">ValidationModel</span> <span class="n">validationModel</span> <span class="o">=</span> <span class="n">validationService</span><span class="o">.</span><span class="na">getValidationModel</span><span class="o">(</span><span class="n">resource</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
     <span class="k">if</span> <span class="o">(</span><span class="n">validationModel</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
         <span class="n">ValidationResult</span> <span class="n">result</span> <span class="o">=</span> <span class="n">validationService</span><span class="o">.</span><span class="na">validate</span><span class="o">(</span><span class="n">resource</span><span class="o">,</span> <span class="n">validationModel</span><span class="o">);</span>
         <span class="k">if</span> <span class="o">(!</span><span class="n">result</span><span class="o">.</span><span class="na">isValid</span><span class="o">())</span> <span class="o">{</span>
@@ -135,7 +160,7 @@ This documentation is still work in prog
             <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
         <span class="o">}</span>
     <span class="o">}</span>
-    <span class="n">ValidationResult</span> <span class="n">result</span> <span class="o">=</span> <span class="n">validationService</span><span class="o">.</span><span class="na">validateResourceRecursively</span><span class="o">(</span><span class="n">resource</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="n">ignoreResourceType1Predicate</span><span class="o">);</span>
+    <span class="n">ValidationResult</span> <span class="n">result</span> <span class="o">=</span> <span class="n">validationService</span><span class="o">.</span><span class="na">validateResourceRecursively</span><span class="o">(</span><span class="n">resource</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="n">ignoreResourceType1Predicate</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
     <span class="k">if</span> <span class="o">(!</span><span class="n">result</span><span class="o">.</span><span class="na">isValid</span><span class="o">())</span> <span class="o">{</span>
         <span class="c1">// give out validation messages from result.getFailureMessages()</span>
     <span class="o">}</span>
@@ -148,17 +173,18 @@ This documentation is still work in prog
 </pre></div>
 
 
-<h1 id="validation-model-resources">Validation Model Resources</h1>
+<p>All methods to retrieve a validation model support a boolean parameter <code>considerResourceSuperTypeModels</code>. If this is set to true, the validation model is not only being looked up for exactly the given resource type but also for all its resource super types. The returned model is then a merged model of all found validation model along the resource type hierarchy.</p>
+<h1 id="validation-model-resources">Validation Model Resources<a class="headerlink" href="#validation-model-resources" title="Permanent link">&para;</a></h1>
 <p>The <code>ValidationModel</code> is constructed from resources with the resourceType <strong>sling/validation/model</strong>. Those resources are considered validation model resources if they are located</p>
 <ul>
 <li>below the Sling ResourceResolver search paths (<em>/apps</em> and <em>/libs</em>) <strong>and</strong></li>
 <li>below a node named <strong>validation</strong>.</li>
 </ul>
 <p>The resources should have the following format:</p>
-<table>
+<table class="table">
 <thead>
 <tr>
-<th>Property/Node Name</th>
+<th>Property/Resource Name</th>
 <th>Property or Resource</th>
 <th>Type</th>
 <th>Description</th>
@@ -259,10 +285,12 @@ This documentation is still work in prog
 </tr>
 </tbody>
 </table>
-<h1 id="usage-in-sling-models">Usage in <a href="/documentation/bundles/models.html">Sling Models</a></h1>
-<h2 id="since-sling-models-120">Since Sling Models 1.2.0</h2>
+<h2 id="overwriting-properties-or-children-in-super-models">Overwriting Properties or Children in Super Models<a class="headerlink" href="#overwriting-properties-or-children-in-super-models" title="Permanent link">&para;</a></h2>
+<p>Sling Validation optionally supports the inheritance of Sling Validation Models. To overwrite some property or child from one of the super type models, just define a property/child on the same level and with the same name in a model for a resource type which is more specific! That way the property/child on the super validation model is no longer effective.</p>
+<h1 id="usage-in-sling-models">Usage in <a href="/documentation/bundles/models.html">Sling Models</a><a class="headerlink" href="#usage-in-sling-models" title="Permanent link">&para;</a></h1>
+<h2 id="since-sling-models-120">Since Sling Models 1.2.0<a class="headerlink" href="#since-sling-models-120" title="Permanent link">&para;</a></h2>
 <p>See <a href="/documentation/bundles/models.html#validation">Sling Models validation</a></p>
-<h2 id="before-sling-models-120">Before Sling Models 1.2.0</h2>
+<h2 id="before-sling-models-120">Before Sling Models 1.2.0<a class="headerlink" href="#before-sling-models-120" title="Permanent link">&para;</a></h2>
 <p>one needs to call the validate method within the PostConstruct method of the according Sling Model</p>
 <div class="codehilite"><pre><span class="nd">@SlingObject</span>
 <span class="kd">protected</span> <span class="n">Resource</span> <span class="n">resource</span><span class="o">;</span>
@@ -290,17 +318,17 @@ This documentation is still work in prog
 </pre></div>
 
 
-<h1 id="writing-validators">Writing Validators</h1>
+<h1 id="writing-validators">Writing Validators<a class="headerlink" href="#writing-validators" title="Permanent link">&para;</a></h1>
 <p>The Sling validation bundle currently comes only with one validator <code>RegexValidator</code> which checks that the property value matches a given pattern. That validator supports only one parameter which is called <code>regex</code>. The value specifies the pattern against which the resource value is matched.</p>
 <p>To write a validator one needs to implement the <code>Validator</code> interface in an OSGi service.
 That interface defines the method <code>validate</code>. That is called for each property which is bound to the validator through the Validation Resources.</p>
 <p>Each validator needs to specify one type parameter which defines upon which classes the validator can act (usually <code>String</code>). Array types are also supported here. Collection types are not supported. If a property value cannot be converted to the requested type from the validator (through <code>ValueMap.get(name, type)</code>), validation will fail.</p>
-<h1 id="references">References</h1>
+<h1 id="references">References<a class="headerlink" href="#references" title="Permanent link">&para;</a></h1>
 <ol>
 <li><a href="http://www.slideshare.net/raducotescu/apache-sling-generic-validation-framework">Apache Sling Generic Validation Framework, adaptTo 2014</a></li>
 </ol>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1688564 by kwin on Wed, 1 Jul 2015 06:58:09 +0000
+        Rev. 1693196 by kwin on Wed, 29 Jul 2015 07:39:42 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project