Author: buildbot Date: Thu Oct 13 13:33:00 2016 New Revision: 999314 Log: Staging update by buildbot for sling
Added: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/ websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/config-resource-lookup.png (with props) websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-and-config-reference.png (with props) websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-default-implementation.html websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-example.png (with props) websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-spi.html websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/illustration-sources.pptx (with props) websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/resource-inheritance.png (with props) Modified: websites/staging/sling/trunk/content/ (props changed) websites/staging/sling/trunk/content/documentation/bundles.html Propchange: websites/staging/sling/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Thu Oct 13 13:33:00 2016 @@ -1 +1 @@ -1764627 +1764671 Modified: websites/staging/sling/trunk/content/documentation/bundles.html ============================================================================== --- websites/staging/sling/trunk/content/documentation/bundles.html (original) +++ websites/staging/sling/trunk/content/documentation/bundles.html Thu Oct 13 13:33:00 2016 @@ -161,6 +161,7 @@ h2:hover > .headerlink, h3:hover > .head <li><a href="/documentation/bundles/sling-pipes.html">Sling Pipes</a></li> <li><a href="/documentation/bundles/metrics.html">Sling Metrics</a></li> <li><a href="/documentation/bundles/servlet-helpers.html">Servlet Helpers</a></li> +<li><a href="/documentation/bundles/context-aware-configuration/context-aware-configuration.html">Context-Aware Configuration</a></li> </ul> <h2 id="content-presentation">Content Presentation<a class="headerlink" href="#content-presentation" title="Permanent link">¶</a></h2> <ul> @@ -184,7 +185,7 @@ h2:hover > .headerlink, h3:hover > .head <li><a href="/documentation/bundles/log-tracers.html">Log Tracer</a></li> </ul> <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;"> - Rev. 1764627 by sseifert on Thu, 13 Oct 2016 08:51:00 +0000 + Rev. 1764671 by sseifert on Thu, 13 Oct 2016 13:32:39 +0000 </div> <div class="trademarkFooter"> Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project Added: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/config-resource-lookup.png ============================================================================== Binary file - no diff available. Propchange: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/config-resource-lookup.png ------------------------------------------------------------------------------ svn:mime-type = image/png Added: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-and-config-reference.png ============================================================================== Binary file - no diff available. Propchange: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-and-config-reference.png ------------------------------------------------------------------------------ svn:mime-type = image/png Added: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-default-implementation.html ============================================================================== --- websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-default-implementation.html (added) +++ websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-default-implementation.html Thu Oct 13 13:33:00 2016 @@ -0,0 +1,201 @@ +<!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> + <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> + <title>Apache Sling - Apache Sling Context-Aware Configuration - Default Implementation</title> + <link rel="icon" href="/res/favicon.ico"> + <link rel="stylesheet" href="/res/site.css" type="text/css" media="all"> + <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all"> + </head> + <body> + <div class="title"> + <div class="logo"> + <a href="//sling.apache.org/"> + <img border="0" alt="Apache Sling" src="/res/logo.png"> + </a> + </div> + <div class="header"> + <a href="//www.apache.org/"> + <img border="0" alt="Apache" src="/res/apache.png"> + </a> + </div> + </div> + + <div class="menu"> + <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 /> +<a href="/documentation/bundles.html">Bundles</a> <br /> +<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a> <br /> +<a href="/documentation/configuration.html">Configuration</a> </p> +<p><a href="http://s.apache.org/sling.wiki">Wiki</a> <br /> +<a href="http://s.apache.org/sling.faq">FAQ</a> </p> +<p><strong>API Docs</strong> <br /> +<a href="/apidocs/sling8/index.html">Sling 8</a> <br /> +<a href="/apidocs/sling7/index.html">Sling 7</a> <br /> +<a href="/apidocs/sling6/index.html">Sling 6</a> <br /> +<a href="/apidocs/sling5/index.html">Sling 5</a> <br /> +<a href="/javadoc-io.html">Archive at javadoc.io</a> </p> +<p><strong>Project info</strong> <br /> +<a href="/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://ci.apache.org/builders/sling-trunk">Build Server</a> <br /> +<a href="/project-information/security.html">Security</a> </p> +<p><strong>Source</strong> <br /> +<a href="http://svn.apache.org/viewvc/sling/trunk">Subversion</a> <br /> +<a href="git://git.apache.org/sling.git">Git</a> <br /> +<a href="https://github.com/apache/sling">Github Mirror</a> </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> </p> +<p><strong><a href="/sitemap.html">Site Map</a></strong></p> +<!-- no valid ads for now, we'll reactivate this when needed +<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> » <a href="/documentation.html">Documentation</a> » <a href="/documentation/bundles.html">Bundles</a> + </div> + + + + <h1>Apache Sling Context-Aware Configuration - Default Implementation</h1> + <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="toc"> +<ul> +<li><a href="#about">About</a></li> +<li><a href="#repository-paths">Repository paths</a></li> +<li><a href="#context-paths">Context paths</a></li> +<li><a href="#configuration-resource-resolving">Configuration resource resolving</a></li> +<li><a href="#configuration-persistence">Configuration persistence</a></li> +<li><a href="#resource-inheritance">Resource inheritance</a></li> +<li><a href="#property-inheritance">Property inheritance</a></li> +</ul> +</div> +<h1 id="about">About<a class="headerlink" href="#about" title="Permanent link">¶</a></h1> +<p>By default the 'default implementation' us used by the Context-Aware Configuration concerning lookup and persistence of configuration data, resource and property inheritance and context path detection. Using the <a href="">SPI</a> it is possible to overlay, extend or replace this functionality.</p> +<p>This page documents the details of the default implementation.</p> +<h1 id="repository-paths">Repository paths<a class="headerlink" href="#repository-paths" title="Permanent link">¶</a></h1> +<p>By default all configuration data is stored in <code>/conf</code>. Fallback paths are <code>/conf/global</code>, <code>/apps/conf</code>and <code>/libs/conf</code>.</p> +<p>The paths are configurable in the service configuration.</p> +<h1 id="context-paths">Context paths<a class="headerlink" href="#context-paths" title="Permanent link">¶</a></h1> +<p>The content resource hierarchy is defined by setting <code>sling:config-ref</code> properties. Each resource that has a <code>sling:config-ref</code> property set defines the root resource of a context, the whole subtree is the context. Within the subtree further nested contexts can be defined.</p> +<h1 id="configuration-resource-resolving">Configuration resource resolving<a class="headerlink" href="#configuration-resource-resolving" title="Permanent link">¶</a></h1> +<p>This illustration shows an example for configuration resource lookup:</p> +<p><img alt="Configuration resource lookup" src="config-resource-lookup.png" /></p> +<p>If you get the context-aware configuration via the API for any resource below <code>/content/tenant1/region1/site1</code> it is looked up in this path in this order:</p> +<ol> +<li><code>/conf/brand1/tenant1/region1/site1</code> - because referenced by <code>/content/tenant1/region1/site1</code></li> +<li><code>/conf/brand1/tenant1/region1</code> - because referenced by <code>/content/tenant1/region1</code> (parent context)</li> +<li><code>/conf/brand1/tenant1</code> - because referenced by <code>/content/tenant1</code> (parent context)</li> +<li><code>/conf/brand1</code> - because it is a parent of by <code>/conf/brand1/tenant1</code></li> +<li><code>/conf/global</code> - because it is configured as fallback path</li> +<li><code>/apps/conf</code> - because it is configured as fallback path</li> +<li><code>/libs/conf</code> - because it is configured as fallback path</li> +</ol> +<p>So the basic rules are: +<em> Go up in the content resource tree until a resource with <code>sling:config-ref</code> is found. This is the 'inner-most' context. Check if a configuration resource exists at the path the property points to. +</em> Check for parent resources of the references configuration resource (below <code>/conf</code>) +<em> Go further up in the content resource tree for parent contexts, and check their configuration resources as well (they may reference completely different location below <code>/conf</code>) +</em> Check the fallback paths</p> +<h1 id="configuration-persistence">Configuration persistence<a class="headerlink" href="#configuration-persistence" title="Permanent link">¶</a></h1> +<p>Example for the resource structure for a configuration resource at <code>/conf/mysite</code>:</p> +<div class="codehilite"><pre><span class="o">/</span><span class="n">conf</span> + <span class="o">/</span><span class="n">mysite</span> + <span class="o">/</span><span class="n">sling</span><span class="p">:</span><span class="n">configs</span> + <span class="o">/</span><span class="n">x</span><span class="p">.</span><span class="n">y</span><span class="p">.</span><span class="n">z</span><span class="p">.</span><span class="n">MyConfig</span> + <span class="p">@</span><span class="n">prop1</span> <span class="p">=</span> <span class="s">'value1'</span> + <span class="p">@</span><span class="n">prop2</span> <span class="p">=</span> 123 + <span class="p">@</span><span class="n">prop3</span><span class="p">=</span> <span class="n">true</span> +</pre></div> + + +<p>Explanation:</p> +<ul> +<li><code>sling:configs</code> is the bucket named which is used by the ConfigurationResolver by default for context-aware configurations. May be another name if you use the ConfigurationResourceResolver directly.</li> +<li><code>x.y.z.MyConfig</code> is the configuration name, in this case derived from an annotation class. May be any other custom name as well.</li> +<li><code>prop1..3</code>are example for configuration properties</li> +<li>It is possible to use deeper hierarchies below <code>sling:configs</code> as well.</li> +<li>Nested configurations are supported as well. This can be mapped to annotation classes referencing other annotation classes.</li> +</ul> +<h1 id="resource-inheritance">Resource inheritance<a class="headerlink" href="#resource-inheritance" title="Permanent link">¶</a></h1> +<p>We distinguish between:</p> +<ul> +<li>Singleton resources: Configuration resources looked up by the <code>get</code>/<code>as</code> method variants</li> +<li>Collection resources: Configuration resources lists looked up by the <code>getCollection</code>/<code>asCollection</code> method variants</li> +</ul> +<p>For singleton resources, there is not resource inheritance. The first resource that is found in the configuration resource resolving lookup order is returned.</p> +<p>For collection resources there is no resource inheritance enabled by default. The children of the first resource that is found in the configuration resource resolving lookup order are returned.</p> +<p>By defining a property <code>sling:config-collection-inherit</code> on the configuration resource, the children of the next resource that is found in the configuration resource resolving lookup order are combined with the children of the current configuration resource, returned a merged list. If both configuration resources contain child resources with the same name, duplicates are eliminated and only the children of the first resource are included.</p> +<p>By setting the property <code>sling:config-collection-inherit</code> on multiple configuration resources that are part of the lookup order it is possible to form deeper inheritance chains following the same rules.</p> +<p>Example for resource inheritance:</p> +<p><img alt="Resource inheritance" src="resource-inheritance.png" /></p> +<p>The result of this example is: <strong>C, A, B</strong>. It would by just <strong>C</strong> if the <code>sling:config-collection-inherit</code> is not set.</p> +<h1 id="property-inheritance">Property inheritance<a class="headerlink" href="#property-inheritance" title="Permanent link">¶</a></h1> +<p>By default, no property inheritance takes place. That means only the properties that are stored in the configuration resource are mapped to the annotation class or returned as value map, regardless wither singleton or collection resources are returned, or if resource collection inheritance is enabled or not.</p> +<p>By defining a property <code>sling:config-property-inherit</code> on the configuration resource, property merging is enabled between the current configuration resource and the next resource with the same name (singleton or resource collection item) in the configuration resource lookup order. That means that all properties that are not defined on the current configuration resource are inherited from the next resources and a merged value map is used for the configuration mapping.</p> +<p>By setting the property <code>sling:config-property-inherit</code> on multiple configuration resources that are part of the lookup order it is possible to form deeper inheritance chains following the same rules.</p> + <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;"> + Rev. 1764671 by sseifert on Thu, 13 Oct 2016 13:32:39 +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/bundles/context-aware-configuration/context-aware-config-example.png ============================================================================== Binary file - no diff available. Propchange: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-example.png ------------------------------------------------------------------------------ svn:mime-type = image/png Added: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-spi.html ============================================================================== --- websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-spi.html (added) +++ websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-config-spi.html Thu Oct 13 13:33:00 2016 @@ -0,0 +1,158 @@ +<!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> + <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> + <title>Apache Sling - Apache Sling Context-Aware Configuration - SPI</title> + <link rel="icon" href="/res/favicon.ico"> + <link rel="stylesheet" href="/res/site.css" type="text/css" media="all"> + <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all"> + </head> + <body> + <div class="title"> + <div class="logo"> + <a href="//sling.apache.org/"> + <img border="0" alt="Apache Sling" src="/res/logo.png"> + </a> + </div> + <div class="header"> + <a href="//www.apache.org/"> + <img border="0" alt="Apache" src="/res/apache.png"> + </a> + </div> + </div> + + <div class="menu"> + <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 /> +<a href="/documentation/bundles.html">Bundles</a> <br /> +<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a> <br /> +<a href="/documentation/configuration.html">Configuration</a> </p> +<p><a href="http://s.apache.org/sling.wiki">Wiki</a> <br /> +<a href="http://s.apache.org/sling.faq">FAQ</a> </p> +<p><strong>API Docs</strong> <br /> +<a href="/apidocs/sling8/index.html">Sling 8</a> <br /> +<a href="/apidocs/sling7/index.html">Sling 7</a> <br /> +<a href="/apidocs/sling6/index.html">Sling 6</a> <br /> +<a href="/apidocs/sling5/index.html">Sling 5</a> <br /> +<a href="/javadoc-io.html">Archive at javadoc.io</a> </p> +<p><strong>Project info</strong> <br /> +<a href="/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://ci.apache.org/builders/sling-trunk">Build Server</a> <br /> +<a href="/project-information/security.html">Security</a> </p> +<p><strong>Source</strong> <br /> +<a href="http://svn.apache.org/viewvc/sling/trunk">Subversion</a> <br /> +<a href="git://git.apache.org/sling.git">Git</a> <br /> +<a href="https://github.com/apache/sling">Github Mirror</a> </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> </p> +<p><strong><a href="/sitemap.html">Site Map</a></strong></p> +<!-- no valid ads for now, we'll reactivate this when needed +<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> » <a href="/documentation.html">Documentation</a> » <a href="/documentation/bundles.html">Bundles</a> + </div> + + + + <h1>Apache Sling Context-Aware Configuration - SPI</h1> + <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="toc"> +<ul> +<li><a href="#about">About</a></li> +<li><a href="#general-principles">General principles</a></li> +<li><a href="#context-path-strategy">Context Path Strategy</a></li> +<li><a href="#configuration-resource-resolver-strategy">Configuration Resource Resolver Strategy</a></li> +<li><a href="#configuration-persistence-strategy">Configuration Persistence Strategy</a></li> +<li><a href="#configuration-metadata-provider">Configuration Metadata Provider</a></li> +</ul> +</div> +<h1 id="about">About<a class="headerlink" href="#about" title="Permanent link">¶</a></h1> +<p>The Context-Aware Configuration implementation provides a set of Service Provider Interfaces (SPI) that allows you to overlay, enhance or replace the default implementation and adapt it to your needs.</p> +<p>Please use the SPI with care, and first check if the <a href="">Default Implementation</a> does not already fulfill your needs.</p> +<h1 id="general-principles">General principles<a class="headerlink" href="#general-principles" title="Permanent link">¶</a></h1> +<p>All SPIs share a common principle:</p> +<ul> +<li>Support multiple strategies at the same time</li> +<li>No need to switch off or âcopyâ the initial strategy</li> +<li>Apply additional strategies only for those places where needed (âminimally invasiveâ)</li> +</ul> +<p>All existing implementations are iterated in order of their service ranking.</p> +<h1 id="context-path-strategy">Context Path Strategy<a class="headerlink" href="#context-path-strategy" title="Permanent link">¶</a></h1> +<p>By providing an implementation of <code>org.apache.sling.contextaware.config.resource.spi.ContextPathStrategy</code> you can provide additional ways how context paths are detected in your content resource hierarchy.</p> +<p>E.g. you could implement detecting context paths by project-specific conventions.</p> +<h1 id="configuration-resource-resolver-strategy">Configuration Resource Resolver Strategy<a class="headerlink" href="#configuration-resource-resolver-strategy" title="Permanent link">¶</a></h1> +<p>By providing an implementation of <code>org.apache.sling.contextaware.config.resource.spi.ConfigurationResourceResolvingStrategy</code> you can define where configuration data is looked up, and how resource and property inheritance is handled.</p> +<h1 id="configuration-persistence-strategy">Configuration Persistence Strategy<a class="headerlink" href="#configuration-persistence-strategy" title="Permanent link">¶</a></h1> +<p>By providing an implementation of <code>org.apache.sling.contextaware.config.spi.ConfigurationPersistenceStrategy</code> you can define the peristence structure of the configuration within the configuration resources.</p> +<p>E.g. you could use a specific JCR node type or slightly different content structure to store the configuration data.</p> +<h1 id="configuration-metadata-provider">Configuration Metadata Provider<a class="headerlink" href="#configuration-metadata-provider" title="Permanent link">¶</a></h1> +<p>By providing an implementation of <code>org.apache.sling.contextaware.config.spi.ConfigurationMetadataProvider</code> you can provide information about configuration metadata from other sources than annotation classes.</p> + <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;"> + Rev. 1764671 by sseifert on Thu, 13 Oct 2016 13:32:39 +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/bundles/context-aware-configuration/context-aware-configuration.html ============================================================================== --- websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html (added) +++ websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html Thu Oct 13 13:33:00 2016 @@ -0,0 +1,300 @@ +<!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> + <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> + <title>Apache Sling - Apache Sling Context-Aware Configuration</title> + <link rel="icon" href="/res/favicon.ico"> + <link rel="stylesheet" href="/res/site.css" type="text/css" media="all"> + <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all"> + </head> + <body> + <div class="title"> + <div class="logo"> + <a href="//sling.apache.org/"> + <img border="0" alt="Apache Sling" src="/res/logo.png"> + </a> + </div> + <div class="header"> + <a href="//www.apache.org/"> + <img border="0" alt="Apache" src="/res/apache.png"> + </a> + </div> + </div> + + <div class="menu"> + <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 /> +<a href="/documentation/bundles.html">Bundles</a> <br /> +<a href="/documentation/tutorials-how-tos.html">Tutorials & How-Tos</a> <br /> +<a href="/documentation/configuration.html">Configuration</a> </p> +<p><a href="http://s.apache.org/sling.wiki">Wiki</a> <br /> +<a href="http://s.apache.org/sling.faq">FAQ</a> </p> +<p><strong>API Docs</strong> <br /> +<a href="/apidocs/sling8/index.html">Sling 8</a> <br /> +<a href="/apidocs/sling7/index.html">Sling 7</a> <br /> +<a href="/apidocs/sling6/index.html">Sling 6</a> <br /> +<a href="/apidocs/sling5/index.html">Sling 5</a> <br /> +<a href="/javadoc-io.html">Archive at javadoc.io</a> </p> +<p><strong>Project info</strong> <br /> +<a href="/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://ci.apache.org/builders/sling-trunk">Build Server</a> <br /> +<a href="/project-information/security.html">Security</a> </p> +<p><strong>Source</strong> <br /> +<a href="http://svn.apache.org/viewvc/sling/trunk">Subversion</a> <br /> +<a href="git://git.apache.org/sling.git">Git</a> <br /> +<a href="https://github.com/apache/sling">Github Mirror</a> </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> </p> +<p><strong><a href="/sitemap.html">Site Map</a></strong></p> +<!-- no valid ads for now, we'll reactivate this when needed +<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> » <a href="/documentation.html">Documentation</a> » <a href="/documentation/bundles.html">Bundles</a> + </div> + + + + <h1>Apache Sling Context-Aware Configuration</h1> + <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="toc"> +<ul> +<li><a href="#about">About</a></li> +<li><a href="#java-api">Java API</a><ul> +<li><a href="#context-aware-resources">Context-Aware Resources</a></li> +<li><a href="#context-aware-configurations">Context-Aware Configurations</a></li> +</ul> +</li> +<li><a href="#contexts-and-configuration-references">Contexts and configuration references</a></li> +<li><a href="#describe-configurations-via-annotation-classes">Describe configurations via annotation classes</a></li> +<li><a href="#context-aware-configuration-bnd-plugin">Context-Aware Configuration BND plugin</a></li> +<li><a href="#customizing-the-configuration-lookup">Customizing the configuration lookup</a></li> +<li><a href="#references">References</a></li> +</ul> +</div> +<h1 id="about">About<a class="headerlink" href="#about" title="Permanent link">¶</a></h1> +<p>These bundles provide a service API that can be used to get context-aware configurations. Context-aware configurations are configurations that are related to a content resource or a resource tree, e.g. a web site or a tenant site.</p> +<p>Here is an example how your content structure may look like:</p> +<p><img alt="Configuration example" src="context-aware-config-example.png" /></p> +<p>The application needs different configuration for different sites, regions and tenants = different contexts. Some parameters may be shared, so inheritance for nested contexts and from global fallback values is supported as well. You have full control which content subtrees are the contexts in your application, the structure above is only an example.</p> +<p>Using the Context-Aware Configuration Java API you can get the matching configuration for each content resource without caring where it is stored or how the inheritance works.</p> +<h1 id="java-api">Java API<a class="headerlink" href="#java-api" title="Permanent link">¶</a></h1> +<p>To get and use configurations, the Java API must be used. Any using code must not make any assumptions on how the context-aware configurations are searched or stored!</p> +<p>The Java API consists of two parts:</p> +<ul> +<li>Context-Aware Resources: 'Low-level' API for accessing configuration resources (which can be anything, e.g. workflow definitions)</li> +<li>Context-Aware Configurations: 'High-level' API for accessing configuration data (key/value pairs)</li> +</ul> +<p>In most cases you will use only the 'High-level' API for getting context-aware configurations.</p> +<h2 id="context-aware-resources">Context-Aware Resources<a class="headerlink" href="#context-aware-resources" title="Permanent link">¶</a></h2> +<p>The base concept are context-aware resources: for a given content resource, a named configuration resource can be get. +The service for getting the configuration resources is called the ConfigurationResourceResolver. This service has two methods:</p> +<ul> +<li>getting a named configuration resource</li> +<li>getting all child resources of a named configuration resource.</li> +</ul> +<p>For example to get a configuration resource for a content resource at /content/mysite/page1, you would get a reference to the OSGi service +<code>org.apache.sling.contextaware.config.resource.ConfigurationResourceResolver</code> and write:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1 +2 +3</pre></div></td><td class="code"><div class="codehilite"><pre><span class="n">Resource</span> <span class="n">contentResource</span> <span class="o">=</span> <span class="n">resourceResolver</span><span class="o">.</span><span class="na">getResource</span><span class="o">(</span><span class="s">"/content/mysite/page1"</span><span class="o">);</span> + +<span class="n">Resource</span> <span class="n">configResource</span> <span class="o">=</span> <span class="n">configurationResourceResolver</span><span class="o">.</span><span class="na">getResource</span><span class="o">(</span><span class="n">contentResource</span><span class="o">,</span> <span class="s">"my-bucket"</span><span class="o">,</span> <span class="s">"my-config"</span><span class="o">);</span> +</pre></div> +</td></tr></table> + +<p>Or if you have several configuration resources of the same type and you need all of them:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="codehilite"><pre><span class="n">Collection</span><span class="o"><</span><span class="n">Resource</span><span class="o">></span> <span class="n">configResources</span> <span class="o">=</span> <span class="n">configurationResourceResolver</span><span class="o">.</span><span class="na">getResourceCollection</span><span class="o">(</span><span class="n">contentResource</span><span class="o">,</span> <span class="s">"my-bucket"</span><span class="o">,</span> <span class="s">"my-config"</span><span class="o">);</span> +</pre></div> +</td></tr></table> + +<p>The ConfigurationResourceResolver has a concept of "buckets" (2nd parameter in the method signatures) that allows to separate different types of configuration resources into different resource hierarchies, so you have a separate "namespaces" for the named configuration resources. For example one bucket for workflow definitions, one bucket for template definitions, one for key/value-pairs.</p> +<p>The configuration name (3rd parameter) defines which configuration you are interested in. The name can be a relative path as well (e.g. <code>"sub1/my-config"</code>).</p> +<h2 id="context-aware-configurations">Context-Aware Configurations<a class="headerlink" href="#context-aware-configurations" title="Permanent link">¶</a></h2> +<p>While context-aware resources give you pure resources and your application code can decide what to do with it, +the most common use case is some configuration. A configuration is usually described by an annotation class +(like Declarative Services does for component configurations). These are typed configuration objects +and the context-aware configuration support automatically converts resources into the wanted configuration type.</p> +<p>Context-aware configurations are built on top of context-aware resources. The same concept is used: configurations are +named and the service to get them is the ConfigurationResolver. You can get a reference to the OSGi service +<code>org.apache.sling.contextaware.config.ConfigurationResolver</code> - it has a single method to get a ConfigurationBuilder. +Alternatively you can directly adapt your content resource directly to the ConfigurationBuilder interface and get the configuration:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1 +2 +3</pre></div></td><td class="code"><div class="codehilite"><pre><span class="n">Resource</span> <span class="n">contentResource</span> <span class="o">=</span> <span class="n">resourceResolver</span><span class="o">.</span><span class="na">getResource</span><span class="o">(</span><span class="s">"/content/mysite/page1"</span><span class="o">);</span> + +<span class="n">MyConfig</span> <span class="n">config</span> <span class="o">=</span> <span class="n">contentResource</span><span class="o">.</span><span class="na">adaptTo</span><span class="o">(</span><span class="n">ConfigurationBuilder</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">as</span><span class="o">(</span><span class="n">MyConfig</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +</pre></div> +</td></tr></table> + +<p>Or if you want to get a list of configurations:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="codehilite"><pre><span class="n">Collection</span><span class="o"><</span><span class="n">MyConfig</span><span class="o">></span> <span class="n">configs</span> <span class="o">=</span> <span class="n">contentResource</span><span class="o">.</span><span class="na">adaptTo</span><span class="o">(</span><span class="n">ConfigurationBuilder</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">asCollection</span><span class="o">(</span><span class="n">MyConfig</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +</pre></div> +</td></tr></table> + +<p>The ConfigurationBuilder also supports getting the configurations as ValueMap or by adapting the configuration resources e.g. to a Sling Model. In this case you have to specify a configuration name which is otherwise derived automatically from the annotation class.</p> +<p>Internally the ConfigurationResolver used the ConfigurationResourceResolver to get the configuration resources. It uses always the bucket name <code>sling:configs</code>.</p> +<h1 id="contexts-and-configuration-references">Contexts and configuration references<a class="headerlink" href="#contexts-and-configuration-references" title="Permanent link">¶</a></h1> +<p>When you use the <a href="">Default Implementation</a> contexts in the content resource hierarchy is defined by setting <code>sling:config-ref</code> properties. Each resource that has a <code>sling:config-ref</code> property set defines the root resource of a context, the whole subtree is the context. Within the subtree further nested contexts can be defined. The property contains a resource path pointing to a resource below <code>/conf</code>. This is the configuration reference.</p> +<p>Example:</p> +<p><img alt="Context and config reference" src="context-and-config-reference.png" /></p> +<p>If you define nested contexts or use a deeper hierarchy of resourced in <code>/conf</code> the inheritance rules are applied. Additionally it is possible to define default values as fallback if no configuration resource exists yet in <code>/conf</code>. See <a href="">Default Implementation</a> for details.</p> +<h1 id="describe-configurations-via-annotation-classes">Describe configurations via annotation classes<a class="headerlink" href="#describe-configurations-via-annotation-classes" title="Permanent link">¶</a></h1> +<p>You need an annotation class for each configuration you want to read via the ConfigurationBuilder. The annotation classes may be provided by +the applications/libraries you use, or you can define your own annotation classes for your application.</p> +<p>The annotation class may look like this:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13</pre></div></td><td class="code"><div class="codehilite"><pre><span class="nd">@Configuration</span><span class="o">(</span><span class="n">label</span><span class="o">=</span><span class="s">"My Configuration"</span><span class="o">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"Describe me"</span><span class="o">)</span> +<span class="kd">public</span> <span class="nd">@interface</span> <span class="n">MyConfig</span> <span class="o">{</span> + + <span class="nd">@Property</span><span class="o">(</span><span class="n">label</span><span class="o">=</span><span class="s">"Parameter #1"</span><span class="o">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"Describe me"</span><span class="o">)</span> + <span class="n">String</span> <span class="nf">param1</span><span class="o">();</span> + + <span class="nd">@Property</span><span class="o">(</span><span class="n">label</span><span class="o">=</span><span class="s">"Parameter with Default value"</span><span class="o">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"Describe me"</span><span class="o">)</span> + <span class="n">String</span> <span class="nf">paramWithDefault</span><span class="o">()</span> <span class="k">default</span> <span class="s">"defValue"</span><span class="o">;</span> + + <span class="nd">@Property</span><span class="o">(</span><span class="n">label</span><span class="o">=</span><span class="s">"Integer parameter"</span><span class="o">,</span> <span class="n">description</span><span class="o">=</span><span class="s">"Describe me"</span><span class="o">)</span> + <span class="kt">int</span> <span class="nf">intParam</span><span class="o">();</span> + +<span class="o">}</span> +</pre></div> +</td></tr></table> + +<p>The <code>@Configuration</code> annotation is mandatory. All properties on the <code>@Configuration</code> annotation and the <code>@Property</code> annotations are optional - they provide additional metadata for tooling e.g. configuration editors. </p> +<p>By default the annotation class name is used as configuration name, which is also the recommended option. If you want to use an arbitrary configuration name you can specify it via a <code>name</code> property on the <code>@Configuration</code> annotation.</p> +<p>You may specify custom properties (via <code>property</code> string array) for the configuration class or each properties. They are not used by the Sling Context-Aware configuration implementation, but may be used by additional tooling to manage the configurations.</p> +<p>If you provide your own configuration annotation classes in your bundle, you have to export them and list all class names in a bundle header named <code>Sling-ContextAware-Configuration-Classes</code> - example:</p> +<div class="codehilite"><pre><span class="n">Sling</span><span class="o">-</span><span class="n">ContextAware</span><span class="o">-</span><span class="n">Configuration</span><span class="o">-</span><span class="n">Classes</span><span class="p">:</span> <span class="n">x</span><span class="p">.</span><span class="n">y</span><span class="p">.</span><span class="n">z</span><span class="p">.</span><span class="n">MyConfig</span><span class="p">,</span> <span class="n">x</span><span class="p">.</span><span class="n">y</span><span class="p">.</span><span class="n">z</span><span class="p">.</span><span class="n">MyConfig2</span> +</pre></div> + + +<p>To automate this you can use the Context-Aware Configuration BND plugin (see next chapter). </p> +<h1 id="context-aware-configuration-bnd-plugin">Context-Aware Configuration BND plugin<a class="headerlink" href="#context-aware-configuration-bnd-plugin" title="Permanent link">¶</a></h1> +<p>A <a href="http://bnd.bndtools.org/">BND</a> plugin is provided that scans the classpath of a bundle Maven project at build time and automatically generates a <code>Sling-ContextAware-Configuration-Classes</code> bundle header for all annotation classes annotated with <code>@Configuration</code>. It can be used by both <a href="http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html">maven-bundle-plugin</a> and <a href="https://github.com/bndtools/bnd/tree/master/maven">bnd-maven-plugin</a>, as both use the BND library internally.</p> +<p>Example configuration:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 +18</pre></div></td><td class="code"><div class="codehilite"><pre><span class="nt"><plugin></span> + <span class="nt"><groupId></span>org.apache.felix<span class="nt"></groupId></span> + <span class="nt"><artifactId></span>maven-bundle-plugin<span class="nt"></artifactId></span> + <span class="nt"><extensions></span>true<span class="nt"></extensions></span> + <span class="nt"><configuration></span> + <span class="nt"><instructions></span> + <span class="c"><!-- Generate bundle header containing all configuration annotation classes --></span> + <span class="nt"><_plugin></span>org.apache.sling.contextaware.config.bndplugin.ConfigurationClassScannerPlugin<span class="nt"></_plugin></span> + <span class="nt"></instructions></span> + <span class="nt"></configuration></span> + <span class="nt"><dependencies></span> + <span class="nt"><dependency></span> + <span class="nt"><groupId></span>org.apache.sling<span class="nt"></groupId></span> + <span class="nt"><artifactId></span>org.apache.sling.contextaware.config.bnd-plugin<span class="nt"></artifactId></span> + <span class="nt"><version></span>1.0.0<span class="nt"></version></span> + <span class="nt"></dependency></span> + <span class="nt"></dependencies></span> +<span class="nt"></plugin></span> +</pre></div> +</td></tr></table> + +<h1 id="customizing-the-configuration-lookup">Customizing the configuration lookup<a class="headerlink" href="#customizing-the-configuration-lookup" title="Permanent link">¶</a></h1> +<p>The Context-Aware Configuration implementation provides a set of Service Provider Interfaces (SPI) that allows you to overlay, enhance or replace the default implementation and adapt it to your needs.</p> +<p>See <a href="">SPI</a> for details.</p> +<h1 id="references">References<a class="headerlink" href="#references" title="Permanent link">¶</a></h1> +<ul> +<li><a href="">Context-Aware Configuration - Default Implementation</a></li> +<li><a href="">Context-Aware Configuration - SPI</a></li> +<li><a href="https://adapt.to/2016/en/schedule/sling-context-aware-configuration.html">Sling Context-Aware Configuration - Talk from adaptTo() 2016</a></li> +</ul> + <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;"> + Rev. 1764671 by sseifert on Thu, 13 Oct 2016 13:32:39 +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/bundles/context-aware-configuration/illustration-sources.pptx ============================================================================== Binary file - no diff available. Propchange: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/illustration-sources.pptx ------------------------------------------------------------------------------ svn:mime-type = application/vnd.ms-powerpoint Added: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/resource-inheritance.png ============================================================================== Binary file - no diff available. Propchange: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/resource-inheritance.png ------------------------------------------------------------------------------ svn:mime-type = image/png