<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Development Archives - Sourced Code</title>
	<atom:link href="https://sourcedcode.com/blog/category/aem/development/feed" rel="self" type="application/rss+xml" />
	<link>https://sourcedcode.com</link>
	<description>AEM Blog Made Just for You.</description>
	<lastBuildDate>Mon, 23 Jun 2025 20:33:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.8</generator>

<image>
	<url>https://sourcedcode.com/wp-content/uploads/2019/09/cropped-favicon-32x32.png</url>
	<title>Development Archives - Sourced Code</title>
	<link>https://sourcedcode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Understanding `data-sly-attribute` in AEM Sightly (HTL)</title>
		<link>https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl</link>
					<comments>https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 27 Jun 2024 05:30:13 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=7113</guid>

					<description><![CDATA[<p>The data-sly-attribute directive in HTL (HTML Template Language) allows developers to dynamically set one or more attributes on an HTML element. This powerful feature provides flexibility in managing HTML attributes based on the logic defined in your Sling models or Use classes. Quick Links 1. Element and Attribute Visibility 2. Attribute Value Options 3. Attribute [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl">Understanding `data-sly-attribute` in AEM Sightly (HTL)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The <span class="code-highlight-primary">data-sly-attribute</span> directive in HTL (HTML Template Language) allows developers to dynamically set one or more attributes on an HTML element. This powerful feature provides flexibility in managing HTML attributes based on the logic defined in your Sling models or Use classes.</p>
<div class="mention-block">
  <strong>Quick Links</strong></p>
<ul>
<li><a href="#element_and_attribute_visibility">1. Element and Attribute Visibility</a></li>
<li><a href="#attribute_value_options">2. Attribute Value Options</a></li>
<li><a href="#attribute_identifier">3. Attribute Identifier</a></li>
<li><a href="#using_data_sly_attribute">4. Using `data-sly-attribute`</a></li>
<li><a href="#injecting_multiple_attributes">5. Injecting Multiple Attributes</a></li>
<li><a href="#more_examples">6. More Examples</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
</div>
<hr class="spacer-larger" />
<h2 id="element_and_attribute_visibility">1. Element and Attribute Visibility</h2>
<p>When using the <span class="code-highlight-primary">data-sly-attribute</span> directive, it&#8217;s important to understand how it affects the visibility of elements and their attributes:</p>
<p><strong>Element Visibility</strong>: The HTML element to which the <span class="code-highlight-primary">data-sly-attribute</span> directive is applied will always be rendered in the DOM. This means that the element itself will always be visible, regardless of the attributes set or not set by the directive.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>p data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicClass}&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicClass <span style="color: #339933;">=</span> <span style="color: #0000ff;">'highlight'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;highlight&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>Even if <span class="code-highlight-primary">dynamicClass</span> is empty or undefined, the paragraph will still appear in the DOM.</p>
<p><strong>Element Content</strong>: The content inside the HTML element will also always be displayed. The <span class="code-highlight-primary">data-sly-attribute</span> directive only affects the attributes of the element, not its content. This ensures that the inner content remains intact and visible to the users.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>span data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">id</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicId}&quot;</span><span style="color: #339933;">&gt;</span>Content remains visible.<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicId <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>span<span style="color: #339933;">&gt;</span>Content remains visible.<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>Even if <span class="code-highlight-primary">dynamicId</span> is empty or undefined, the text &#8220;Content remains visible&#8221; will still be displayed within the span element.</p>
<hr class="spacer-larger" />
<h2 id="attribute_value_options">2. Attribute Value Options</h2>
<p>The attribute value in <span class="code-highlight-primary">data-sly-attribute</span> is optional and can be of different types:</p>
<p><strong>String</strong>: Used to set the content of the attribute.</p>
<p>Example:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>a data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">href</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicHref}&quot;</span><span style="color: #339933;">&gt;</span>Click here<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicHref <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://www.example.com'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.example.com&quot;</span><span style="color: #339933;">&gt;</span>Click here<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Boolean</strong>: Used for setting boolean attributes.</p>
<p>Example:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">checked</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${isChecked}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming isChecked <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> checked <span style="color: #339933;">/&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Object</strong>: Used for setting multiple attributes simultaneously.</p>
<p>Example:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${attributeMap}&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming attributeMap <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicDiv'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicClass'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicDiv&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicClass&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>If the attribute value is omitted, the attribute will be removed.</p>
<hr class="spacer-larger" />
<h2 id="attribute_identifier">3. Attribute Identifier</h2>
<p>The attribute identifier, which is the name of the attribute, is also optional. It must be omitted only if the attribute value is an Object.</p>
<p><strong>Detailed Explanation:</strong></p>
<p>When using the <span class="code-highlight-primary">data-sly-attribute</span> directive, you can specify the name of the attribute you want to set. This is called the attribute identifier. However, when you are using an Object to set multiple attributes at once, you do not need to specify individual attribute names.</p>
<p><strong>Code Examples:</strong></p>
<p><strong>Specifying Attribute Identifier:</strong></p>
<p>When setting a single attribute, you provide the attribute name directly.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>p data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicClass}&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicClass <span style="color: #339933;">=</span> <span style="color: #0000ff;">'highlight'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;highlight&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> is a paragraph.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Omitting Attribute Identifier (Using an Object):</strong></p>
<p>When setting multiple attributes simultaneously, you use an Object and omit the attribute name.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${attributeMap}&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming attributeMap <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicDiv'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicClass'</span>, <span style="color: #0000ff;">'aria-label'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'click'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicDiv&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicClass&quot;</span> aria<span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;click&quot;</span><span style="color: #339933;">&gt;</span>Dynamic Attributes<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>In this case, the keys of the Object (<span class="code-highlight-primary">id</span> and <span class="code-highlight-primary">class</span>) are used as attribute names, and their corresponding values (<span class="code-highlight-primary">dynamicDiv</span> and <span class="code-highlight-primary">dynamicClass</span>) are assigned to those attributes.</p>
<hr class="spacer-larger" />
<h2 id="using_data_sly_attribute">4. Using `data-sly-attribute`</h2>
<p>You can define attributes either directly through an expression or by using a <span class="code-highlight-primary">data-sly-attribute.*</span> attribute. This approach allows designers to annotate HTML without modifying the mock content.</p>
<hr class="spacer-medium" />
<h3 id="example_1_overwriting_an_attribute">Example: Overwriting an Attribute</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;!--</span> <span style="color: #000000; font-weight: bold;">This</span> will overwrite the <span style="color: #000000; font-weight: bold;">class</span> attribute value <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;initialClass&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicClass}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicClass <span style="color: #339933;">=</span> <span style="color: #0000ff;">'newClass'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;newClass&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium" />
<h3 id="example_2_creating_a_new_attribute">Example: Creating a New Attribute</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;!--</span> <span style="color: #000000; font-weight: bold;">This</span> will create a data<span style="color: #339933;">-</span>values attribute <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">aria</span><span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${dynamicValues}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming dynamicValues <span style="color: #339933;">=</span> <span style="color: #0000ff;">'exampleValue'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>tag aria<span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;exampleValue&quot;</span><span style="color: #339933;">&gt;&lt;/</span>tag<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2 id="injecting_multiple_attributes">5. Injecting Multiple Attributes</h2>
<p>The <span class="code-highlight-primary">data-sly-attribute</span> block element, when used without specifying an attribute name, allows the injection of multiple attributes that have been prepared in a map object containing key-value pairs.</p>
<hr class="spacer-medium" />
<h3 id="example_3_injecting_multiple_attributes">Example: Injecting Multiple Attributes</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>input data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${attributeMap}&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming attributeMap <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicId'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'dynamicClass'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicId&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dynamicClass&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">/&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2 id="more_examples">6. More Examples</h2>
<hr class="spacer-medium" />
<h3 id="example_4_setting_multiple_attributes_on_a_button">Example: Setting Multiple Attributes on a Button</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>button data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${buttonAttributes}&quot;</span><span style="color: #339933;">&gt;</span>Click Me<span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Assuming buttonAttributes <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'submitButton'</span>, <span style="color: #0000ff;">'class'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'btn btn-primary'</span>, <span style="color: #0000ff;">'disabled'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output<span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>button id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submitButton&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;btn btn-primary&quot;</span> disabled<span style="color: #339933;">&gt;</span>Click Me<span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium" />
<h3 id="example_5_conditional_attribute_setting">Example: Conditional Attribute Setting</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">#example<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/home&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">target</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${openInNewTab ? '_blank' : ''}&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming openInNewTab <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;!--</span> Output <span style="color: #000000; font-weight: bold;">if</span> openInNewTab is <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/home&quot;</span> target<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_blank&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;noopener&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Output <span style="color: #000000; font-weight: bold;">if</span> openInNewTab is <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">:</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/home&quot;</span><span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
#example<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/example-2&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">aria</span><span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${properties.ariaLabelText}&quot;</span><span style="color: #339933;">&gt;</span>Example <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">ariaLabelText</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This is a custom aria-label'</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/example-2&quot;</span> data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>attribute.<span style="color: #006633;">aria</span><span style="color: #339933;">-</span>label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;This is a custom aria-label&quot;</span><span style="color: #339933;">&gt;</span>Example <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">ariaLabelText</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/example-2&quot;</span><span style="color: #339933;">&gt;</span>Example <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<br />
#example<span style="color: #339933;">:</span> <span style="color: #cc66cc;">3</span><br />
<span style="color: #339933;">&lt;</span>iframe data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>atribute.<span style="color: #006633;">allowfullscreen</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${properties.isAllowfullscreen}&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.youtube.com/embed/hKh0MoabKvc?si=iUCcv4JYNM2lgVpF&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;YouTube video player&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">ariaLabelText</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>iframe allowfullscreen src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.youtube.com/embed/hKh0MoabKvc?si=iUCcv4JYNM2lgVpF&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;YouTube video player&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;!--</span> Assuming properties.<span style="color: #006633;">isAllowfullscreen</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>iframe src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://www.youtube.com/embed/hKh0MoabKvc?si=iUCcv4JYNM2lgVpF&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;YouTube video player&quot;</span><span style="color: #339933;">&gt;&lt;/</span>iframe<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2 id="conclusion">Conclusion</h2>
<p>The <span class="code-highlight-primary">data-sly-attribute</span> directive in HTL provides a versatile way to manage HTML attributes dynamically. Whether you&#8217;re setting a single attribute or multiple attributes at once, this feature can help you create more dynamic and flexible web components. By leveraging <span class="code-highlight-primary">data-sly-attribute</span>, you can ensure that your HTML remains clean and maintainable, while still being able to handle complex attribute logic.</p>
<p>Feel free to explore and use these examples to enhance your AEM projects, making your components more dynamic and interactive.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl">Understanding `data-sly-attribute` in AEM Sightly (HTL)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/understanding-data-sly-attribute-in-aem-sightly-htl/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Context-Aware Configurations in Java Backend Example Code</title>
		<link>https://sourcedcode.com/blog/aem/aem-context-aware-configurations-in-java-backend-example-code</link>
					<comments>https://sourcedcode.com/blog/aem/aem-context-aware-configurations-in-java-backend-example-code#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 02 Mar 2024 04:35:58 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6594</guid>

					<description><![CDATA[<p>AEM Context-Aware Configurations to enable developers to define adaptable application settings based on specific site or content contexts. This feature significantly simplifies the management of environment-specific configurations, allowing for dynamic application behavior adjustment without changing the core application code. In this article, we will step through how developers can incorporate and retrieve context-aware configurations from [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-context-aware-configurations-in-java-backend-example-code">AEM Context-Aware Configurations in Java Backend Example Code</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>AEM Context-Aware Configurations to enable developers to define adaptable application settings based on specific site or content contexts. This feature significantly simplifies the management of environment-specific configurations, allowing for dynamic application behavior adjustment without changing the core application code.</p>
<p>In this article, we will step through how developers can incorporate and retrieve context-aware configurations from AEM backend development.</p>
<div class="mention-block">
    <strong>Quick Links</strong></p>
<ol>
<li><a href="#overview_of_context-aware_configurations">Overview of Context-Aware Configurations</a></li>
<li><a href="#accessing_configurations_via_java">Accessing Configurations via Java</a></li>
<li><a href="#configuration_interface_example">Configuration Interface Example</a></li>
<li><a href="#utilizing_the_configuration_in_an_osgi_component">Utilizing the Configuration in an OSGi Component</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<h2 id="overview_of_context-aware_configurations">1. Overview of Context-Aware Configurations</h2>
<p>Adobe Experience Manager (AEM) introduces Context-Aware Configurations to empower developers to define adaptable application settings based on the specific contexts of sites or content. This functionality simplifies configuration management across different environments, facilitating dynamic behavior adjustments of applications without necessitating changes to the core code.</p>
<hr class="spacer-large"/>
<h2 id="accessing_configurations_via_java">2. Accessing Configurations via Java</h2>
<p>To harness context-aware configurations, the process starts with fetching the relevant content resource using the <span class=“code-highlight-primary”>ResourceResolver</span>:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Resource contentResource <span style="color: #339933;">=</span> resourceResolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/mysite/page1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Following resource retrieval, adapt it to a <span class=“code-highlight-primary”>ConfigurationBuilder</span> to fetch the specific configuration:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">MyConfig config <span style="color: #339933;">=</span> contentResource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>ConfigurationBuilder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span>MyConfig.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><span class=“code-highlight-primary”>MyConfig</span> is a developer-defined interface that encapsulates the configuration parameters influencing the application&#8217;s functionality.</p>
<hr class="spacer-large"/>
<h2 id="configuration_interface_example">4. Configuration Interface Example</h2>
<p>Define the <span class=“code-highlight-primary”>MyConfig</span> interface with configuration parameters as follows from the code below. Making sure that my code is scalable, I usually place CaConfig under the path com.sourcedcode.core.caconfig.*</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.caconfig</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.caconfig.annotation.Configuration</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.caconfig.annotation.Property</span><span style="color: #339933;">;</span><br />
<br />
@Configuration<span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;My Configuration&quot;</span>, description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Configuration example for a component&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> MyConfig <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Property<span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Feature Toggle&quot;</span>, description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Enable or disable the feature&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> featureEnabled<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Property<span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Feature Name&quot;</span>, description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Specifies the feature name&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> featureName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;defaultFeature&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="utilizing_the_configuration_in_an_osgi_component">5. Utilizing the Configuration in an OSGi Component</h2>
<p>Implement the configuration within an AEM component or service as shown below:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.caconfig.ConfigurationBuilder</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> MyComponent.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolver resourceResolver<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> applyConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Resource contentResource <span style="color: #339933;">=</span> resourceResolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/mysite/page1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MyConfig config <span style="color: #339933;">=</span> contentResource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>ConfigurationBuilder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span>MyConfig.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>config.<span style="color: #006633;">featureEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Feature is enabled: &quot;</span> <span style="color: #339933;">+</span> config.<span style="color: #006633;">featureName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>This example demonstrates the dynamic adjustment of application functionality based on retrieved configurations, highlighting the flexibility and maintainability that Context-Aware Configurations bring to AEM development.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-context-aware-configurations-in-java-backend-example-code">AEM Context-Aware Configurations in Java Backend Example Code</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-context-aware-configurations-in-java-backend-example-code/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>HTL caconfig Global Variable for Context-Aware Configuration in AEM</title>
		<link>https://sourcedcode.com/blog/aem/htl-caconfig-global-variable-for-context-aware-configuration-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/htl-caconfig-global-variable-for-context-aware-configuration-in-aem#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 02 Mar 2024 04:11:10 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6586</guid>

					<description><![CDATA[<p>Context-Aware configuration contains a Scripting Binding Values provider with automatically registeres a caconfig variable in your HTL/Sightly scripts to directly access context-aware configurations. It supports both singleton configurations and configuration lists. Please note that configuration lists are only supported when configuration metadata is present (e.g. via an annotation class). In this article we will step [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/htl-caconfig-global-variable-for-context-aware-configuration-in-aem">HTL caconfig Global Variable for Context-Aware Configuration in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Context-Aware configuration contains a Scripting Binding Values provider with automatically registeres a caconfig variable in your HTL/Sightly scripts to directly access context-aware configurations. It supports both singleton configurations and configuration lists. Please note that configuration lists are only supported when configuration metadata is present (e.g. via an annotation class).</p>
<p>In this article we will step through how to use the caconfig global variable in HTL Sightly.</p>
<div class="blog-article">
<div class="mention-block">
        <strong>Quick Links</strong></p>
<ol>
<li><a href="#accessing_singleton_configurations">Accessing Singleton Configurations</a></li>
<li><a href="#accessing_configuration_lists">Accessing Configuration Lists</a></li>
<li><a href="#accessing_nested_configurations">Accessing Nested Configurations</a></li>
<li><a href="#adding_necessary_dependencies">Adding Necessary Dependencies</a></li>
</ol></div>
<hr class="spacer-large"/>
<h2 id="accessing_singleton_configurations">1. Accessing Singleton Configurations</h2>
<p>    Singleton configurations are those that you expect to have a single instance per context or configuration resource. To access a property of a singleton configuration in HTL, you can use the caconfig variable followed by the configuration&#8217;s fully qualified name. For example, if you have a configuration named x.y.z.ConfigSample, you can access its stringParam property as follows:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dl<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dt<span style="color: #339933;">&gt;</span>stringParam<span style="color: #339933;">:&lt;/</span>dt<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dd<span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#123;</span>caconfig<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'x.y.z.ConfigSample'</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">stringParam</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>dd<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dl<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="accessing_configuration_lists">2. Accessing Configuration Lists</h2>
<p>    Configuration lists are useful when you have a series of similar configurations that you want to access as a collection. To access properties of configuration items in a list, you iterate over the configuration list using the data-sly-list attribute in HTL. For example, for a configuration list named x.y.z.ConfigSampleList, you can access the stringParam of each item as follows:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>ul data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>list.<span style="color: #006633;">item</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${caconfig['x.y.z.ConfigSampleList']}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>stringParam<span style="color: #339933;">:</span> $<span style="color: #009900;">&#123;</span>item.<span style="color: #006633;">stringParam</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="accessing_nested_configurations">3. Accessing Nested Configurations</h2>
<p>    For nested configurations, HTL allows you to traverse the configuration hierarchy using a slash (/) as a separator. For example, to access a stringParam nested within a nestedConfig configuration, you would use:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">$<span style="color: #009900;">&#123;</span>caconfig<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'x.y.z.ConfigSample'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nestedConfig/stringParam'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="adding_necessary_dependencies">4. Adding Necessary Dependencies</h2>
<p>    To enable the automatic registration of the caconfig variable and the scanning of configuration annotation classes, you need to include the Context-Aware Configuration bnd plugin in your project&#8217;s build configuration. This bnd plugin scans the classpath of a bundle Maven project at build time and automatically generates a Sling-ContextAware-Configuration-Classes bundle header for all annotation classes annotated with @Configuration.</p>
<p>    Here are the configurations for the Maven Bundle Plugin and the bnd Maven Plugin:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">felix</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>maven<span style="color: #339933;">-</span>bundle<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>extensions<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>extensions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>instructions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> Generate bundle header containing all configuration annotation classes <span style="color: #339933;">--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>_plugin<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bndplugin</span>.<span style="color: #006633;">ConfigurationClassScannerPlugin</span><span style="color: #339933;">&lt;/</span>_plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>instructions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>1.0.2<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>bnd<span style="color: #339933;">-</span>maven<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>bnd<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-</span>plugin org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bndplugin</span>.<span style="color: #006633;">ConfigurationClassScannerPlugin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>bnd<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>1.0.2<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
</div>
<p>References: <a href="https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html" rel="noopener" target="_blank">https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration.html</a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/htl-caconfig-global-variable-for-context-aware-configuration-in-aem">HTL caconfig Global Variable for Context-Aware Configuration in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/htl-caconfig-global-variable-for-context-aware-configuration-in-aem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AuthenticationSupport service missing. Cannot authenticate request.</title>
		<link>https://sourcedcode.com/blog/aem/authenticationsupport-service-missing-cannot-authenticate-request</link>
					<comments>https://sourcedcode.com/blog/aem/authenticationsupport-service-missing-cannot-authenticate-request#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 28 Feb 2024 02:07:16 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Trouble Shooting]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6561</guid>

					<description><![CDATA[<p>Encountering the &#8220;AuthenticationSupport service missing. Cannot authenticate request&#8221; OR the &#8220;HTTP ERROR 404 Not Found org.apache.felix.http.base.internal.dispatch.DispatcherServlet&#8221; errors in Adobe Experience Manager (AEM) can halt your development progress, presenting a significant obstacle. This error often points to underlying issues with the AEM instance&#8217;s ability to access or initialize critical repository services. Fortunately, there&#8217;s a practical approach [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/authenticationsupport-service-missing-cannot-authenticate-request">AuthenticationSupport service missing. Cannot authenticate request.</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Encountering the &#8220;AuthenticationSupport service missing. Cannot authenticate request&#8221; OR the &#8220;HTTP ERROR 404 Not Found org.apache.felix.http.base.internal.dispatch.DispatcherServlet&#8221; errors in Adobe Experience Manager (AEM) can halt your development progress, presenting a significant obstacle. This error often points to underlying issues with the AEM instance&#8217;s ability to access or initialize critical repository services. Fortunately, there&#8217;s a practical approach to resolving this problem, ensuring your local development environment gets back on track swiftly.</p>
<div class="mention-block">
  <strong>Follow steps below can resolve your problem:</strong></p>
<ol>
<li><a href="#root-cause-of-the-issue">Root Cause of the Issue</a></li>
<li><a href="#removing-lock-files">Removing Lock Files</a></li>
<li><a href="#clearing-repository-index-files">Clearing Repository Index Files</a></li>
<li><a href="#resetting-custom-initialization-scripts">Resetting Custom Initialization Scripts</a></li>
<li><a href="#restarting-your-aem-instance">Restarting Your AEM Instance</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</div>
<hr class="spacer-large"/>
<h2 id="root-cause-of-the-issue">1. Root Cause of the Issue</h2>
<p>This error typically arises when AEM&#8217;s repository encounters problems, either due to corrupted data, locking issues, or misconfigurations in the initialization scripts. Such issues prevent AEM from authenticating requests, leading to the aforementioned error.</p>
<hr class="spacer-large"/>
<h3 id="removing-lock-files">2. Removing Lock Files</h3>
<p>Lock files are created to ensure exclusive access to the repository by an AEM instance. However, if these files become corrupted or are not released properly upon a shutdown, they can cause startup issues.</p>
<ul>
<li><strong>Files to Delete:</strong>
<ul>
<li>crx-quickstart/repository/segmentstore/repo.lock</li>
<li>crx-quickstart/launchpad/felix/cache.lock</li>
</ul>
</li>
</ul>
<p>Deleting these lock files can free up the repository and allow the AEM instance to start correctly.</p>
<hr class="spacer-large"/>
<h3 id="clearing-repository-index-files">3. Clearing Repository Index Files</h3>
<p>Index files are essential for AEM&#8217;s search capabilities. Corruption or outdated index files can lead to significant errors, including authentication issues.</p>
<ul>
<li><strong>Paths to Clear:</strong>
<ul>
<li>crx-quickstart/repository/index/*</li>
</ul>
</li>
</ul>
<p>Removing these files prompts AEM to rebuild the indexes, potentially resolving the authentication issue.</p>
<hr class="spacer-large"/>
<h3 id="resetting-custom-initialization-scripts">4. Resetting Custom Initialization Scripts</h3>
<p>Custom repoinit scripts under the crx-quickstart/launchpad/config/org/apache/sling/jcr/repoinit directory can interfere with repository initialization, causing authentication and other services to fail.</p>
<ul>
<li><strong>Paths to Clear:</strong>
<ul>
<li>crx-quickstart/launchpad/config/org/apache/sling/jcr/repoinit/*</li>
</ul>
</li>
</ul>
<p>By deleting these scripts, you ensure that no custom initialization interferes with the repository&#8217;s proper startup process.</p>
<hr class="spacer-large"/>
<h2 id="restarting-your-aem-instance">5. Restarting Your AEM Instance</h2>
<p>After performing the above steps, restart your AEM instance. This process will initiate a clean startup sequence, allowing AEM to rebuild necessary files and indexes.</p>
<hr class="spacer-large"/>
<h2 id="conclusion">Conclusion</h2>
<p>The &#8220;AuthenticationSupport service missing. Cannot authenticate request&#8221; OR the &#8220;HTTP ERROR 404 Not Found org.apache.felix.http.base.internal.dispatch.DispatcherServlet&#8221;errors can be a daunting obstacle, but by following the outlined steps, you can swiftly return your AEM development environment to a functional state. This guide provides a comprehensive approach to troubleshooting and resolving one of the more perplexing issues in AEM development, ensuring you can continue your work with minimal interruption.</p>
<p>Remember, careful manipulation of the file system and adherence to the recommended procedures are paramount to successfully overcoming this challenge. This guide aims to empower AEM developers, particularly those in the early stages of their journey, with the knowledge to tackle such issues confidently.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/authenticationsupport-service-missing-cannot-authenticate-request">AuthenticationSupport service missing. Cannot authenticate request.</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/authenticationsupport-service-missing-cannot-authenticate-request/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Generate Custom Oak Indexes with the Oak Index Definition Generator</title>
		<link>https://sourcedcode.com/blog/aem/generate-custom-oak-indexes-with-the-oak-index-definition-generator</link>
					<comments>https://sourcedcode.com/blog/aem/generate-custom-oak-indexes-with-the-oak-index-definition-generator#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 26 Feb 2024 02:28:19 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6568</guid>

					<description><![CDATA[<p>Indexing in Adobe Experience Manager is very important. It&#8217;s not just about making things faster; it totally changes how we handle and find data online. With the Oak Index Definition Generator, developers get a really handy tool to shape how searches work behind the scenes. This tool isn&#8217;t just about making indexes, it&#8217;s about making [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/generate-custom-oak-indexes-with-the-oak-index-definition-generator">Generate Custom Oak Indexes with the Oak Index Definition Generator</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Indexing in Adobe Experience Manager is very important. It&#8217;s not just about making things faster; it totally changes how we handle and find data online. With the Oak Index Definition Generator, developers get a really handy tool to shape how searches work behind the scenes. This tool isn&#8217;t just about making indexes, it&#8217;s about making them just right for each project&#8217;s specific needs. By using this tool, developers can create indexes that fit perfectly with what they&#8217;re trying to do, making searches faster and more efficient. This smart way of indexing helps AEM websites be faster and more flexible, keeping them ahead of the game in the digital world.</p>
<div class="mention-block">
    <strong>Quick Links</strong></p>
<ol>
<li><a href="#importance_of_indexing">Importance of Indexing</a></li>
<li><a href="#creating_custom_oak_indexes">Creating Custom Oak Indexes</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</div>
<hr class="spacer-large"/>
<h2 id="importance_of_indexing">Why Indexing is Important</h2>
<p>Indexing AEM is critical for optimizing performance and managing content efficiently. The Oak Index, a key feature of AEM, improves search query speed by organizing data for quicker retrieval. This not only boosts system performance but also supports customization for specific project requirements. Efficient indexing enables scalable and responsive AEM sites, ensuring they can handle growing content without compromising on speed. Understanding and utilizing the Oak Index effectively is essential for maintaining high-performance AEM projects that meet modern digital experience demands.</p>
<hr class="spacer-large"/>
<h3 id="creating_custom_oak_indexes">Using the Oak Index Definition Generator</h3>
<p><a href="https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot.png"><img fetchpriority="high" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot.png" alt="Oak Index Definition Generator" width="1486" height="898" class="alignnone size-full wp-image-6575" srcset="https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot.png 1486w, https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot-300x181.png 300w, https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot-1024x619.png 1024w, https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot-768x464.png 768w, https://sourcedcode.com/wp-content/uploads/2024/02/oak-index-generator-tool-screenshot-600x363.png 600w" sizes="(max-width: 1486px) 100vw, 1486px" /></a></p>
<p>Creating custom Oak indexes with the Oak Index Definition Generator is a straightforward process:</p>
<ol>
<li>Open the Oak Index Definition Generator at <a href="http://oakutils.appspot.com/generate/index" rel="noopener" target="_blank">http://oakutils.appspot.com/generate/index</a>.</li>
<li>Input your query in the Queries field.</li>
<li>Click &#8220;Generate&#8221; to create your custom Oak index.</li>
<li>Copy the XML into your AEM project for further adjustments.</li>
</ol>
<hr class="spacer-large"/>
<h4 id="conclusion">Conclusion</h4>
<p>It&#8217;s essential for developers to familiarize themselves with the AEM index definition structure to maximize the effectiveness of their custom indexes. Adobe provides resources such as a cheat sheet on AEM index definition structure, offering guidance on how to properly configure indexes for optimal performance.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/generate-custom-oak-indexes-with-the-oak-index-definition-generator">Generate Custom Oak Indexes with the Oak Index Definition Generator</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/generate-custom-oak-indexes-with-the-oak-index-definition-generator/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Handling Http Requests, HttpClient, in AEM</title>
		<link>https://sourcedcode.com/blog/aem/handling-http-requests-httpclient-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/handling-http-requests-httpclient-in-aem#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 24 Feb 2024 18:13:27 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sling Models]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6538</guid>

					<description><![CDATA[<p>When integrating with external services or APIs from Adobe Experience Manager (AEM), utilizing the HttpClient for outbound HTTP requests is a common requirement. It&#8217;s crucial to handle these connections efficiently, securely, and in a way that is compatible with AEM&#8217;s architecture to ensure optimal performance and maintainability of your code. AEM provides a specialized factory, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/handling-http-requests-httpclient-in-aem">Handling Http Requests, HttpClient, in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When integrating with external services or APIs from Adobe Experience Manager (AEM), utilizing the HttpClient for outbound HTTP requests is a common requirement. It&#8217;s crucial to handle these connections efficiently, securely, and in a way that is compatible with AEM&#8217;s architecture to ensure optimal performance and maintainability of your code. </p>
<p>AEM provides a specialized factory, HttpClientFactory, designed to streamline the creation and configuration of HttpClient instances. This factory not only simplifies the process of instantiating HttpClient objects but also ensures that the instances are optimized for use within the AEM environment. </p>
<p>By leveraging HttpClientFactory, developers can take advantage of built-in connection pooling and configuration optimizations that are specifically tailored for AEM applications. Furthermore, using AEM&#8217;s HttpClientFactory significantly facilitates the <a href="https://sourcedcode.com/blog/aem/junit-5-mocking-the-httpclient-in-java" rel="noopener" target="_blank">unit testing</a> of code that makes HTTP requests, allowing for more maintainable and testable codebases.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ul>
<li><a href="#UtilizeAEMsHttpClientFactory">1. Utilize AEM&#8217;s HttpClientFactory</a></li>
<li><a href="#OSGiComponentsSlingServlets">1.1 OSGi Components &#038; Sling Servlets</a></li>
<li><a href="#SlingModelsWorkflows">12 Sling Models &#038; Workflows</a></li>
<li><a href="#EnsureProperResourceManagement">2. Ensure Proper Resource Management</a></li>
<li><a href="#ConfigureHttpClientSecurely">3. Configure HttpClient Securely</a></li>
<li><a href="#ReuseHttpClientInstancesWisely">4. Reuse HttpClient Instances Wisely</a></li>
<li><a href="#MonitorAndLogHttpClientActivity">5. Monitor and Log HttpClient Activity</a></li>
<ul>
</div>
<hr class="spacer-large" />
<h2 id="UtilizeAEMsHttpClientFactory">1. Utilize AEM&#8217;s HttpClientFactory</h2>
<p>Leverage AEM’s HttpClientFactory or the OSGi HttpClientBuilderFactory for creating instances of HttpClient. This ensures you benefit from connection pooling, proper configuration, and optimizations tailored for AEM. Avoid manually creating HttpClient instances as it bypasses these optimizations and can lead to resource leakage and scalability issues.</p>
<h3 id="OSGiComponentsSlingServlets">1.1 OSGi Components &#038; Sling Servlets</h3>
<p><strong>OSGi Components</strong>: Custom services, event handlers, schedulers, and any other Java class defined as an OSGi component can use this code pattern below. OSGi components are the backbone for modular development in AEM, allowing for dynamic module management within the application.</p>
<p><strong>Sling Servlets</strong>: Sling Servlets are another type of OSGi component that can use HttpClientBuilderFactory for making HTTP requests; using the code pattern below. Sling Servlets handle HTTP requests and can be used for various purposes, including interfacing with external systems.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@<span style="color: #003399;">Reference</span><br />
<span style="color: #000000; font-weight: bold;">private</span> HttpClientBuilderFactory httpClientBuilderFactory<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> executeHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>CloseableHttpClient httpClient <span style="color: #339933;">=</span> httpClientBuilderFactory.<span style="color: #006633;">newBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Perform HTTP operations with httpClient</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium" />
<h3 id="SlingModelsWorkflows">1.2 Sling Models &#038; Workflows</h3>
<p><strong>Sling Models</strong>: While not typically using @Reference (as they are not OSGi components themselves), Sling Models can still access OSGi services like HttpClientBuilderFactory through the use of the @OSGiService annotation or by adapting from a Sling resource or request; using the code pattern below. This allows Sling Models to utilize services for fetching or sending data to external systems as part of their logic.</p>
<p><strong>Workflows</strong>: Custom workflow steps can interact with OSGi services, including HttpClientBuilderFactory, to perform operations like sending data to external systems or integrating with RESTful services as part of the workflow process. These custom steps are developed as OSGi components and can use the @Reference annotation to inject necessary services.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleSlingModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @OSGiService<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HttpClientBuilderFactory httpClientBuilderFactory<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> executeHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>CloseableHttpClient httpClient <span style="color: #339933;">=</span> httpClientBuilderFactory.<span style="color: #006633;">newBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Perform HTTP operations with httpClient</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h2 id="EnsureProperResourceManagement">2. Ensure Proper Resource Management</h2>
<p>Always close HttpClient, HttpResponse, and any InputStream or Entity objects to release system resources and avoid connection leaks. Utilize try-with-resources or finally blocks to ensure resources are closed even if exceptions occur.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>CloseableHttpResponse response <span style="color: #339933;">=</span> httpClient.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>httpGet<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the response</span><br />
&nbsp; &nbsp; EntityUtils.<span style="color: #006633;">consume</span><span style="color: #009900;">&#40;</span>response.<span style="color: #006633;">getEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h2 id="ConfigureHttpClientSecurely">3. Configure HttpClient Securely</h2>
<p>Pay attention to security configurations when setting up your HttpClient. This includes setting up SSL context correctly, enabling hostname verification, and configuring timeouts to prevent attacks that target resource consumption. Avoid disabling SSL verification or other security features unless absolutely necessary and understood.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">RequestConfig requestConfig <span style="color: #339933;">=</span> RequestConfig.<span style="color: #006633;">custom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; .<span style="color: #006633;">setConnectTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; .<span style="color: #006633;">setSocketTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; .<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>CloseableHttpClient httpClient <span style="color: #339933;">=</span> httpClientBuilderFactory.<span style="color: #006633;">newBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setDefaultRequestConfig</span><span style="color: #009900;">&#40;</span>requestConfig<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Securely configured HttpClient</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h2 id="ReuseHttpClientInstancesWisely">4. Reuse HttpClient Instances Wisely</h2>
<p>For efficiency, reuse HttpClient instances across requests whenever possible. This approach benefits from the HTTP connection pooling managed by AEM, reducing the overhead of establishing connections for each request. However, ensure that any client-specific configurations do not unintentionally affect subsequent requests.</p>
<hr class="spacer-large" />
<h2 id="MonitorAndLogHttpClientActivity">5. Monitor and Log HttpClient Activity</h2>
<p>Implement logging and monitoring around your HTTP requests to diagnose issues, track performance, and understand dependencies on external services. Use AEM’s logging capabilities to log request details, response times, and errors. This can aid in troubleshooting and optimizing the use of HttpClient in your application.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>CloseableHttpResponse response <span style="color: #339933;">=</span> httpClient.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>httpGet<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Log the status line</span><br />
&nbsp; &nbsp; LOG.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP response status: {}&quot;</span>, response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; LOG.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP request execution failed&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>By adhering to these five rules, developers can ensure their AEM projects make the most out of HttpClient for external communications, balancing efficiency with robust security practices. Utilizing AEM&#8217;s HttpClientFactory not only streamlines the development process but also enhances the ease of <a href="https://sourcedcode.com/blog/aem/junit-5-mocking-the-httpclient-in-java" rel="noopener" target="_blank">unit testing</a>, making it an indispensable practice for AEM development.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/handling-http-requests-httpclient-in-aem">Handling Http Requests, HttpClient, in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/handling-http-requests-httpclient-in-aem/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>AEM 6.5.5 Not Indexing Problem *Fixed*</title>
		<link>https://sourcedcode.com/blog/aem/aem-6-5-5-not-indexing-problem-fixed</link>
					<comments>https://sourcedcode.com/blog/aem/aem-6-5-5-not-indexing-problem-fixed#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 16 Dec 2023 20:00:01 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6376</guid>

					<description><![CDATA[<p>In the course of establishing a new multitenant website, we opted to re-use the search mechanism for both site1 and site2. However, following the deployment of our code to the cloud QA environment, a significant hurdle surfaced: site2&#8217;s search consistently failed to produce results. This revelation made us to invest considerable effort in a detailed [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-6-5-5-not-indexing-problem-fixed">AEM 6.5.5 Not Indexing Problem *Fixed*</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<section>
In the course of establishing a new multitenant website, we opted to re-use the search mechanism for both site1 and site2. However, following the deployment of our code to the cloud QA environment, a significant hurdle surfaced: site2&#8217;s search consistently failed to produce results. This revelation made us to invest considerable effort in a detailed debugging journey.</p>
<p>Follow this step-by-step guide below as we transparently outline each phase of our process to resolve this issue.</p>
<div class="mention-block">
Navigating the challenges posed by the AEM 6.5.5 indexing problem, we&#8217;ve acquired invaluable insights that we believe will prove highly beneficial to the broader community. It&#8217;s crucial to emphasize that the focus of this article is specifically on the on-premises AEM 6.5.5 solution, distinct from the AEMaaCS solution.
</div>
</section>
<hr class="spacer-large"/>
<section>
<h2>Step 1: Identifying the Issue with the Query Performance Tool</h2>
<p>Our initial step involved using the query performance tool provided by AEM 6.5.5: <span class="code-highlight-secodary">/libs/granite/operations/content/diagnosistools/queryPerformance.html</span>. This tool allowed us to pinpoint the queries in use. As we focused on the search entry for site2, we discovered that the Lucene index was incorrectly utilizing the index intended for site1. This realization prompted us to proceed to the next step.</p>
</section>
<hr class="spacer-large"/>
<section>
<h2>Step 2: Updating Lucene Index Properties</h2>
<p>In the second step, we accessed <span class="code-highlight-secodary">crx/de</span> and located the Lucene index entry under <span class="code-highlight-secodary">/oak:index/*</span>. After finding the node, we updated the node properties, setting <span class="code-highlight-secodary">resync = false</span>. Monitoring the indexing logs, we confirmed a successful reindex. Despite obtaining the exact query for site2&#8217;s request, using the explain query tool revealed that the results were not as expected. Undeterred, we proceeded to the next step.</p>
</section>
<hr class="spacer-large"/>
<section>
<h2>Step 3: Deleting and Remaking %_TARGET_FOLDER_%</h2>
<p>With the issue persisting, we decided to take more decisive action in the third step. We shut down AEM, deleted <span class="code-highlight-secodary">./crx-quickstart/repository/index/%_TARGET_FOLDER_%</span>, and restarted the environment. After waiting for 5-10 minutes, the logs indicated that the <span class="code-highlight-secodary">%_TARGET_FOLDER_%</span> had been remade. Unfortunately, using the explain query tool still showed unexpected results, prompting us to move on to the next approach.</p>
</section>
<hr class="spacer-large"/>
<section>
<h2>Step 4: Complete Index Folder Deletion</h2>
<p>For the fourth step, we took a more extensive approach by shutting down AEM and deleting the entire index folder: <span class="code-highlight-secodary">./crx-quickstart/repository/index/*</span>. After restarting and patiently waiting for 10-30 minutes, the logs confirmed the successful recreation of the index folder. However, the query results were still not meeting our expectations.</p>
</section>
<hr class="spacer-large"/>
<section>
<h2>Step 5: Unconventional Solution</h2>
<p>By the fifth step, conventional options exhausted, we attempted an unconventional approach. Authorizing into <span class="code-highlight-secodary">crx/de</span>, we forcefully deleted both site1 and site2&#8217;s <span class="code-highlight-secodary">oak:index</span> rules. Subsequently, we reinstalled the rules for both sites. The result? A surprising success, with site2&#8217;s search now functioning as expected.</p>
</section>
<hr class="spacer-large"/>
<section>
<h2>Conclusion</h2>
<p>Navigating the intricacies of AEM 6.5.5&#8217;s indexing system can be challenging. However, with a systematic approach and a willingness to explore unconventional solutions, it&#8217;s possible to overcome seemingly insurmountable issues. By sharing our step-by-step journey, we hope this article proves valuable to others facing similar challenges in the realm of AEM development.</p>
</section>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-6-5-5-not-indexing-problem-fixed">AEM 6.5.5 Not Indexing Problem *Fixed*</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-6-5-5-not-indexing-problem-fixed/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Targeting CSS in the Editor.html for AEM Components for AEMaaCS</title>
		<link>https://sourcedcode.com/blog/aem/targeting-css-in-the-editor-html-for-aem-components-for-aemaacs</link>
					<comments>https://sourcedcode.com/blog/aem/targeting-css-in-the-editor-html-for-aem-components-for-aemaacs#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 08 Dec 2023 00:31:46 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6307</guid>

					<description><![CDATA[<p>Sometimes as developers, we would need to inject some CSS into our pages in the edit-modes to enhance the experience of our authors. One key skill as an AEM developer knowing how to customize the authoring experience in the editor.html (while content authors are editing the page). This article explores the techniques of targeting CSS [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/targeting-css-in-the-editor-html-for-aem-components-for-aemaacs">Targeting CSS in the Editor.html for AEM Components for AEMaaCS</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes as developers, we would need to inject some CSS into our pages in the edit-modes to enhance the experience of our authors. One key skill as an AEM developer knowing how to customize the authoring experience in the editor.html (while content authors are editing the page). This article explores the techniques of targeting CSS for AEM components in various authoring modes to optimize the content creation process.</p>
<p><strong style="code-highlight-primary">This has only been tested on AEMaaCS.</strong></p>
<div class="mention-block">
  <strong>Quick Links</strong></p>
<ol>
<li><a href="#understanding-authoring-modes">Understanding Authoring Modes in AEM</a></li>
<li><a href="#targeting-components">Targeting Components in Different Authoring Modes</a></li>
<li><a href="#benefits-of-targeting-css">Benefits of Targeting CSS in AEM Editor</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</div>
<hr class="spacer-large" />
<h2 id="understanding-authoring-modes">1. Understanding Authoring Modes in AEM:</h2>
<p>AEM&#8217;s editor.html supports multiple authoring modes, each serving a specific purpose in the content creation workflow. These modes include edit mode, preview mode, layout mode, developer mode, MSM (Multi-Site Manager) mode, and time warp mode. To enhance the authoring experience, it&#8217;s crucial to apply targeted CSS to components based on the current authoring mode.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/12/authoring-modes.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/12/authoring-modes.png" alt="edit mode, preview mode, layout mode, developer mode, MSM (Multi-Site Manager) mode, and time warp mode" width="305" height="297" class="alignnone size-full wp-image-6317" srcset="https://sourcedcode.com/wp-content/uploads/2023/12/authoring-modes.png 305w, https://sourcedcode.com/wp-content/uploads/2023/12/authoring-modes-300x292.png 300w" sizes="(max-width: 305px) 100vw, 305px" /></a></p>
<hr class="spacer-large" />
<h2 id="targeting-components">2. Targeting Components in Different Authoring Modes:</h2>
<p>To achieve a seamless authoring experience, developers can leverage specific CSS classes associated with each authoring mode in AEM. The following example demonstrates how to target a custom component called &#8220;.my-component&#8221; in different authoring modes:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #66cc66;">/</span>* Edit Mode *<span style="color: #66cc66;">/</span><br />
.aem-AuthorLayer-Edit .my-component <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066;">background</span>: red;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">/</span>* Preview Mode *<span style="color: #66cc66;">/</span><br />
.aem-AuthorLayer-Preview .my-component <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066;">background</span>: blue;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">/</span>* Layout Mode *<span style="color: #66cc66;">/</span><br />
.aem-AuthorLayer-Layouting .my-component <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066;">background</span>: green;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">/</span>* Developer Mode *<span style="color: #66cc66;">/</span><br />
.aem-AuthorLayer-Developer .my-component <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066;">border</span>: 2px solid yellow;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">/</span>* Time Warp Mode *<span style="color: #66cc66;">/</span><br />
.aem-AuthorLayer-Timewarp .my-component <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;opacity: <span style="color: #cc66cc;">0.7</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">/</span>* MSM Mode *<span style="color: #66cc66;">/</span><br />
.aem-AuthorLayer-MSM .my-component <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000066;">background</span>: purple;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>In the above example, each CSS rule targets the &#8220;.my-component&#8221; class in a specific authoring mode, applying distinct styles to improve visibility or provide context for authors working in that mode.</p>
<hr class="spacer-large" />
<h2 id="benefits-of-targeting-css">3. Benefits of Targeting CSS in AEM Editor:</h2>
<ol>
<li><strong>Improved Visibility: </strong>By applying different background colors or borders in various authoring modes, developers can enhance the visibility of components, making it easier for authors to identify and manipulate them.</li>
<li><strong>Contextual Styling: </strong>Tailoring styles based on the authoring mode provides contextual information to content authors. For instance, applying a distinctive style in developer mode can signify that the component is currently being modified at a code level.<br />
Optimized Workflows:</li>
<li><strong>Optimized Workflows: </strong>Targeted CSS in the editor.html file optimizes authoring workflows by reducing confusion and streamlining the content creation process. Authors can quickly grasp the current mode and focus on the relevant tasks.
</li>
</ol>
<hr class="spacer-large" />
<h2 id="conclusion">4. Conclusion:</h2>
<p>Customizing the authoring experience in AEM by targeting CSS in the editor.html file is a powerful way to enhance usability and streamline content creation workflows. By understanding and leveraging the specific CSS classes associated with each authoring mode, developers can provide a more intuitive and visually informative environment for content authors using AEMaaCS.</p>
<p><em>And one more last thing to note is, please ensure that these rules are added into your clientlibs.author structure, so that these rules will never be exposed on production.</em></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/targeting-css-in-the-editor-html-for-aem-components-for-aemaacs">Targeting CSS in the Editor.html for AEM Components for AEMaaCS</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/targeting-css-in-the-editor-html-for-aem-components-for-aemaacs/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Benefits of SlingSafeMethodsServlet with Code Examples</title>
		<link>https://sourcedcode.com/blog/aem/benefits-of-slingsafemethodsservlet-with-code-examples</link>
					<comments>https://sourcedcode.com/blog/aem/benefits-of-slingsafemethodsservlet-with-code-examples#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 02 Dec 2023 19:34:29 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6275</guid>

					<description><![CDATA[<p>A robust security strategy is pivotal to safeguarding applications. As an AEM developer, we must really understand the SlingSafeMethodsServlet, an invaluable feature within the Apache Sling framework. This article explores the core concepts, practical benefits, and the heightened security it brings to servlet development. The org.apache.sling.api.servlets.SlingSafeMethodsServlet is an extension of the trusted HttpServlet in Apache [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/benefits-of-slingsafemethodsservlet-with-code-examples">Benefits of SlingSafeMethodsServlet with Code Examples</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<section>
<p>A robust security strategy is pivotal to safeguarding applications. As an AEM developer, we must really understand the <strong>SlingSafeMethodsServlet</strong>, an invaluable feature within the Apache Sling framework. This article explores the core concepts, practical benefits, and the heightened security it brings to servlet development.</p>
<p>The <strong>org.apache.sling.api.servlets.SlingSafeMethodsServlet</strong> is an extension of the trusted HttpServlet in Apache Sling, introduces a focused approach to reinforcing security by limiting HTTP methods to read-only operations. This deep dive into its functionality unveils the foundation upon which secure servlets can be built.</p>
</section>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#advanntages">Advantages of SlingSafeMethodsServlet</a></li>
<li><a href="#code-sample">SlingSafeMethodsServlet in Action: Example Use Case</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<section>
<h2 id="advanntages">Advantages of SlingSafeMethodsServlet</h2>
<ol>
<li>
                <strong>Read-Only Operations:</strong></p>
<p>At its core, SlingSafeMethodsServlet champions a read-only paradigm. This deliberate limitation ensures that servlets exclusively respond to safe HTTP methods, fortifying applications against unintentional data modifications.</p>
</li>
<li>
                <strong>Guard Against CSRF Attacks:</strong></p>
<p>By constraining actions to safe methods, SlingSafeMethodsServlet provides an inherent defense against Cross-Site Request Forgery (CSRF) attacks. This proactive measure significantly reduces the risk of unauthorized manipulations.</p>
</li>
<li>
                <strong>Built-In Support for Idempotent Methods:</strong></p>
<p>The servlet seamlessly integrates with idempotent methods like GET and HEAD, aligning with industry best practices. This default behavior enhances the predictability and reliability of request handling.</p>
</li>
<li>
                <strong>Resource-Based Permissions:</strong></p>
<p>Leveraging Sling&#8217;s resource resolution capabilities, SlingSafeMethodsServlet dynamically inherits permissions tied to resolved resources. This ensures a granular and secure access control model.</p>
</li>
</ol>
</section>
<hr class="spacer-larger"/>
<h2 id="code-sample">SlingSafeMethodsServlet in Action: Example Use Case</h2>
<p>In this practical example, the <span class="code-highlight-primary">ContentDisplayServlet:line17</span> showcases the seamless integration of SlingSafeMethodsServlet. The provided code exemplifies its application in retrieving and securely rendering content, encapsulating the essence of secure servlet development.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.resourceTypes=yourapp/components/content&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContentDisplayServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Fetch and render content</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Send JSON response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;success&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/benefits-of-slingsafemethodsservlet-with-code-examples">Benefits of SlingSafeMethodsServlet with Code Examples</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/benefits-of-slingsafemethodsservlet-with-code-examples/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Try-With-Resources: Ensuring Session Closure, AEM Code Example</title>
		<link>https://sourcedcode.com/blog/aem/try-with-resources-ensuring-session-closure-aem-code-example</link>
					<comments>https://sourcedcode.com/blog/aem/try-with-resources-ensuring-session-closure-aem-code-example#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 22 Nov 2023 05:53:06 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6239</guid>

					<description><![CDATA[<p>In the dynamic realm of Java programming in AEM, effective resource management is a cornerstone of writing robust and reliable code. The &#8220;try-with-resources&#8221; statement, introduced in Java 7, emerges as a powerful ally in simplifying resource handling. This article delves into the practical implementation of &#8220;Try-With-Resources&#8221; within the context of a specific code snippet, emphasizing [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/try-with-resources-ensuring-session-closure-aem-code-example">Try-With-Resources: Ensuring Session Closure, AEM Code Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the dynamic realm of Java programming in AEM, effective resource management is a cornerstone of writing robust and reliable code. The &#8220;try-with-resources&#8221; statement, introduced in Java 7, emerges as a powerful ally in simplifying resource handling. This article delves into the practical implementation of &#8220;Try-With-Resources&#8221; within the context of a specific code snippet, emphasizing the importance of never forgetting to close the session.</p>
<p>The adoption of &#8220;Try-With-Resources&#8221; in your code exemplifies a commitment to clean, efficient, and error-resistant Java programming. By embracing this feature, you not only reduce boilerplate code but also mitigate the risk of resource leaks, ensuring the reliable closure of the session. The article underscores the significance of &#8220;Try-With-Resources&#8221; within the broader theme of never forgetting to close the session, offering developers valuable insights into crafting resilient and maintainable code.</p>
<hr class="spacer-large" />
<h2>Try-With-Resources AEM Example Code</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resolver <span style="color: #339933;">=</span> factory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Session session <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Node contentNode <span style="color: #339933;">=</span> session.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Objects.<span style="color: #006633;">nonNull</span><span style="color: #009900;">&#40;</span>contentNode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;newProperty&quot;</span>, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;existingProperty&quot;</span>, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;existingProperty&quot;</span>, <span style="color: #009900;">&#40;</span>Value<span style="color: #009900;">&#41;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Remove property</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; session.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>In the spirit of &#8220;Try-With-Resources,&#8221; your code exemplifies the essence of effective resource management. The central focus is on ensuring the closure of the session resource, a critical component in Java Content Repository (JCR) operations.</p>
<div class="mention-block">
<strong>Exploring AEM Service Users: A Simple Setup Guide</strong><br />
Dive into the world of Adobe Experience Manager with our blog post, &#8220;Exploring AEM Service Users.&#8221; Whether you&#8217;re on AEMaaCS or AEM 6.5.4+, we&#8217;ve got you covered with an easy-to-follow guide on setting up a system user. No jargon, just straightforward steps to demystify the AEM service user. Enhance your AEM experience effortlessly – check out our blog and learn today -> <a href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations">https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations</a>
</div>
<hr class="spacer-large" />
<h3>Understanding the Code:</h3>
<p>Within the try block, the &#8220;ResourceResolver&#8221; and its associated &#8220;Session&#8221; resource are declared using &#8220;Try-With-Resources.&#8221; The factory object, presumably an instance of a ResourceResolverFactory, facilitates obtaining a service resource resolver with specific authentication information (authInfo). The resolver is seamlessly adapted to a session, streamlining the process.</p>
<p>As the code interacts with the JCR node located at &#8220;/content/sourcedcode/jcr:content,&#8221; the session enables the manipulation of node properties. The try-with-resources statement guarantees that both the &#8220;ResourceResolver&#8221; and the &#8220;Session&#8221; are automatically closed at the conclusion of the block, eliminating the need for explicit closure statements.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/try-with-resources-ensuring-session-closure-aem-code-example">Try-With-Resources: Ensuring Session Closure, AEM Code Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/try-with-resources-ensuring-session-closure-aem-code-example/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Convert Excel to JSON Simple Servlet Example</title>
		<link>https://sourcedcode.com/blog/aem/aem-convert-excel-to-json-simple-servlet-example</link>
					<comments>https://sourcedcode.com/blog/aem/aem-convert-excel-to-json-simple-servlet-example#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 02 Nov 2023 01:28:53 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Short Post]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6192</guid>

					<description><![CDATA[<p>In this article, I present a straightforward yet powerful solution that demonstrates how to seamlessly convert Excel data into JSON format using Adobe Experience Manager (AEM). By implementing a custom servlet, I will illustrate the process of converting an Excel sheet named &#8216;example.xlsx&#8217; into structured JSON data; it can be downloaded below for you following [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-convert-excel-to-json-simple-servlet-example">AEM Convert Excel to JSON Simple Servlet Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, I present a straightforward yet powerful solution that demonstrates how to seamlessly convert Excel data into JSON format using Adobe Experience Manager (AEM). By implementing a custom servlet, I will illustrate the process of converting an Excel sheet named &#8216;example.xlsx&#8217; into structured JSON data; it can be downloaded below for you following this tutorial. This tutorial is validated on both AEM 6.5 with the latest Service Pack and AEM as a Cloud Service (AEMaaCS), ensuring its compatibility with diverse AEM environments.</p>
<p><strong>Resource File:</strong><br />
<a href="https://sourcedcode.com/blog/aem/aem-convert-excel-to-json-simple-servlet-example/attachment/example" rel="attachment wp-att-6196">example.xlsx</a></p>
<hr class="spacer-large"/>
<p><strong>Request URI:</strong><br />
The request URI for accessing the JSON output through the ExampleServlet that we&#8217;ve been discussing would typically look like this:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/bin/exportexcelfortext.json</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<p><strong>JSON Output:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;people&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Brian&quot;</span>, <span style="color: #0000ff;">&quot;age&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;100&quot;</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Doris&quot;</span>, <span style="color: #0000ff;">&quot;age&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;20&quot;</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Stuart&quot;</span>, <span style="color: #0000ff;">&quot;age&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;103&quot;</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;David&quot;</span>, <span style="color: #0000ff;">&quot;age&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;5&quot;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<p><strong>Servlet Implementation ExcelExampleServlet.java:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.fasterxml.jackson.databind.ObjectMapper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.poi.ss.usermodel.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.poi.xssf.usermodel.XSSFWorkbook</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.LinkedHashMap</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Objects</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.dam.api.Asset</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/exportexcelfortext&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.extensions=json&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExcelExampleServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the Excel file path in DAM</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> excelFilePath <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/content/dam/example/example.xlsx&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the resource resolver</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResourceResolver resourceResolver <span style="color: #339933;">=</span> request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if the Excel file exists</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Resource excelResource <span style="color: #339933;">=</span> resourceResolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>excelFilePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>excelResource <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>HttpServletResponse.<span style="color: #006633;">SC_NOT_FOUND</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Adapt the resource to an Asset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Asset asset <span style="color: #339933;">=</span> Objects.<span style="color: #006633;">requireNonNull</span><span style="color: #009900;">&#40;</span>excelResource<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Asset.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>asset <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>HttpServletResponse.<span style="color: #006633;">SC_INTERNAL_SERVER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get an InputStream from the Asset's original</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">InputStream</span> excelInputStream <span style="color: #339933;">=</span> Objects.<span style="color: #006633;">requireNonNull</span><span style="color: #009900;">&#40;</span>asset<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getOriginal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the Excel content and convert it to JSON</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Workbook workbook <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XSSFWorkbook<span style="color: #009900;">&#40;</span>excelInputStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;&gt;</span> jsonData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Iterate through the Excel rows and columns</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sheet sheet <span style="color: #339933;">=</span> workbook.<span style="color: #006633;">getSheetAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Assuming it's the first sheet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row headerRow <span style="color: #339933;">=</span> sheet.<span style="color: #006633;">getRow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Assuming the first row is the header row</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> totalColumns <span style="color: #339933;">=</span> headerRow.<span style="color: #006633;">getLastCellNum</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> sheet.<span style="color: #006633;">getPhysicalNumberOfRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Row dataRow <span style="color: #339933;">=</span> sheet.<span style="color: #006633;">getRow</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> rowMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedHashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> totalColumns<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cell headerCell <span style="color: #339933;">=</span> headerRow.<span style="color: #006633;">getCell</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cell dataCell <span style="color: #339933;">=</span> dataRow.<span style="color: #006633;">getCell</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>headerCell <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> dataCell <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check the cell type to handle numeric and string values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dataCell.<span style="color: #006633;">getCellType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> CellType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rowMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>headerCell.<span style="color: #006633;">getStringCellValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, dataCell.<span style="color: #006633;">getStringCellValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dataCell.<span style="color: #006633;">getCellType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> CellType.<span style="color: #006633;">NUMERIC</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle numeric values as integers (remove decimals)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> age <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> dataCell.<span style="color: #006633;">getNumericCellValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rowMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>headerCell.<span style="color: #006633;">getStringCellValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>age<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonData.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>rowMap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Prepare the JSON response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;&gt;</span> peopleList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> personData <span style="color: #339933;">:</span> jsonData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedHashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; person.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>, personData.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; person.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;age&quot;</span>, personData.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Age&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peopleList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, List<span style="color: #339933;">&lt;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;&gt;&gt;</span> jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedHashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;people&quot;</span>, peopleList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set response content type and write JSON content to the response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">writeValueAsString</span><span style="color: #009900;">&#40;</span>jsonResponse<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>HttpServletResponse.<span style="color: #006633;">SC_INTERNAL_SERVER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<p><strong>Servlet Depdendencies:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> Apache POI <span style="color: #000000; font-weight: bold;">for</span> Excel processing <span style="color: #339933;">--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">poi</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>poi<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>5.2.3<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">poi</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>poi<span style="color: #339933;">-</span>ooxml<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>5.2.3<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> Jackson <span style="color: #000000; font-weight: bold;">for</span> JSON processing <span style="color: #339933;">--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">fasterxml</span>.<span style="color: #006633;">jackson</span>.<span style="color: #006633;">core</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>jackson<span style="color: #339933;">-</span>core<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>2.13.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">fasterxml</span>.<span style="color: #006633;">jackson</span>.<span style="color: #006633;">core</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>jackson<span style="color: #339933;">-</span>databind<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>2.13.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-convert-excel-to-json-simple-servlet-example">AEM Convert Excel to JSON Simple Servlet Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-convert-excel-to-json-simple-servlet-example/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>JCR SQL2 ISDESCENDANTNODE Multiple Paths Example</title>
		<link>https://sourcedcode.com/blog/aem/jcr-sql2-isdescendantnode-multiple-paths-example</link>
					<comments>https://sourcedcode.com/blog/aem/jcr-sql2-isdescendantnode-multiple-paths-example#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 18 Oct 2023 02:01:56 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6203</guid>

					<description><![CDATA[<p>While working with the JCR SQL2 Queries, you may encounter scenarios where content is distributed across various branches of the repository. Querying these branches efficiently is key to implement features to capture requirements. In this article, we will focus o how to collect and query for distributed across various branches of the repository. Using the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/jcr-sql2-isdescendantnode-multiple-paths-example">JCR SQL2 ISDESCENDANTNODE Multiple Paths Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>While working with the JCR SQL2 Queries, you may encounter scenarios where content is distributed across various branches of the repository. Querying these branches efficiently is key to implement features to capture requirements. In this article, we will focus o how to collect and query for distributed across various branches of the repository. Using the ISDESCENDANTNODE feature of the JCR SQL Query proves it possible.</p>
<p><strong>Understanding ISDESCENDANTNODE</strong></p>
<p>ISDESCENDANTNODE is a condition in JCR SQL2 that checks if a node is a descendant of another, based on their paths. It is particularly beneficial for querying content hierarchies. Imagine you have content in different branches (content tree) of your AEM repository. You want to search across these branches simultaneously, without running separate queries. This is where ISDESCENDANTNODE shines.</p>
<p>By specifying multiple paths within the ISDESCENDANTNODE condition, you can search for content across these paths concurrently, streamlining your queries. This powerful feature simplifies and optimizes the content retrieval process in AEM.</p>
<hr class="spacer-large" />
<p><strong>Finding all cq:Pages under 1 path</strong><br />
with the jcr:content/jcr:title CONTAINS %terms%</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">SELECT <span style="color: #339933;">*</span> FROM <span style="color: #009900;">&#91;</span>cq<span style="color: #339933;">:</span>Page<span style="color: #009900;">&#93;</span><br />
WHERE ISDESCENDANTNODE<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/content/sourcedcode/us/'</span><span style="color: #009900;">&#41;</span><br />
AND CONTAINS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>jcr<span style="color: #339933;">:</span>title<span style="color: #009900;">&#93;</span>, <span style="color: #0000ff;">'terms'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<p><strong>Finding all cq:Pages under 2 paths</strong><br />
with the jcr:content/jcr:title CONTAINS %terms%</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">SELECT <span style="color: #339933;">*</span> FROM <span style="color: #009900;">&#91;</span>cq<span style="color: #339933;">:</span>Page<span style="color: #009900;">&#93;</span><br />
WHERE <span style="color: #009900;">&#40;</span>ISDESCENDANTNODE<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/content/sourcedcode/us/'</span><span style="color: #009900;">&#41;</span> <br />
OR ISDESCENDANTNODE<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/content/sourcedcode/ca/'</span><span style="color: #009900;">&#41;</span> <br />
AND CONTAINS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>jcr<span style="color: #339933;">:</span>title<span style="color: #009900;">&#93;</span>, <span style="color: #0000ff;">'terms'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<p><strong>Finding all cq:Pages under 3 paths</strong><br />
with the jcr:content/jcr:title CONTAINS %terms%</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">SELECT <span style="color: #339933;">*</span> FROM <span style="color: #009900;">&#91;</span>cq<span style="color: #339933;">:</span>Page<span style="color: #009900;">&#93;</span><br />
WHERE <span style="color: #009900;">&#40;</span>ISDESCENDANTNODE<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/content/sourcedcode/us/'</span><span style="color: #009900;">&#41;</span> <br />
OR ISDESCENDANTNODE<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/content/sourcedcode/ca/'</span><span style="color: #009900;">&#41;</span> <br />
OR ISDESCENDANTNODE<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/content/sourcedcode/pl/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
AND CONTAINS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>jcr<span style="color: #339933;">:</span>title<span style="color: #009900;">&#93;</span>, <span style="color: #0000ff;">'terms'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/jcr-sql2-isdescendantnode-multiple-paths-example">JCR SQL2 ISDESCENDANTNODE Multiple Paths Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/jcr-sql2-isdescendantnode-multiple-paths-example/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Optimizing &#038; Debugging Search Queries, Explain Query Tool AEM</title>
		<link>https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem</link>
					<comments>https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 09 Sep 2023 03:29:56 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6092</guid>

					<description><![CDATA[<p>The &#8220;Explain Query Tool&#8221; tool assists developers in understanding, optimizing, and debugging search queries, which are crucial for the AEM&#8217;s performance and accurate content delivery. Understanding the Explain Query Tool The Explain Query Tool essentially breaks down and explains the steps and processes a query goes through in AEM. Think of it as a &#8216;debug [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem">Optimizing &#038; Debugging Search Queries, Explain Query Tool AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The &#8220;Explain Query Tool&#8221; tool assists developers in understanding, optimizing, and debugging search queries, which are crucial for the AEM&#8217;s performance and accurate content delivery.</p>
<hr class="spacer-larger"/>
<h2>Understanding the Explain Query Tool</h2>
<p>The Explain Query Tool essentially breaks down and explains the steps and processes a query goes through in AEM. Think of it as a &#8216;debug mode&#8217; for your search queries. It provides insights into how the system interprets the query, the indexes it leverages, the estimated cost of the query, and other essential metrics.</p>
<hr class="spacer-larger"/>
<h2>Benefits of Using the Explain Query Tool:</h2>
<ul>
<li><strong>Performance Analysis</strong>: By revealing how the system interprets and executes the query, developers can identify bottlenecks or inefficiencies.</li>
<li><strong>Better Indexing</strong>: Developers can understand which indexes are being used and optimize or create new ones accordingly.</li>
<li><strong>Debugging</strong>: It becomes easier to pinpoint issues in complex queries when developers can visualize each step.</li>
</ul>
<hr class="spacer-larger"/>
<h2>Using Explain Query Tool with Different AEM Backend Search APIs</h2>
<h3>1. SQL2:</h3>
<p>SQL2 is the SQL-like query language used in AEM, and it&#8217;s one of the primary ways developers retrieve data from the JCR (Java Content Repository).</p>
<h4>How to Use:</h4>
<p>Navigate to the AEM Query Performance Tool, and select on the &#8220;Explain Query&#8221; tab. Choose the &#8220;Language&#8221; drop down to be SQL-JCR2, and input the JCR-SQL2 query that you are trying to test. Now click on explain, and you&#8217;ll see a breakdown of the query&#8217;s interpretation and execution.</p>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-large"/>
<h3>2. Query Builder API:</h3>
<p>Query Builder API allows developers to build search queries programmatically using a more intuitive map-based syntax. It abstracts some complexities of the JCR, offering a more accessible way to retrieve content.</p>
<h4>How to Use:</h4>
<p>Navigate to the AEM Query Performance Tool, and select on the &#8220;Explain Query&#8221; tab. Choose the &#8220;Language&#8221; drop down to be Query Builder, and input your Query Builder query that you are trying to test. Now click on explain, and you&#8217;ll see a breakdown of the query&#8217;s interpretation and execution.</p>
<div class="mention-block--gold">
<strong>Note</strong><br />
For Query Builder queries, only the generated XPath is included in the explanation and result counts. For an in-depth analysis (including filtering and facets extraction), use the <a href="http://localhost:4502/libs/cq/search/content/querydebug.html" rel="noopener" target="_blank">Query Builder Debugger tool</a>.
</div>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-large"/>
<h3>3. XPath:</h3>
<p>XPath is another way of querying the JCR in AEM. While it&#8217;s less commonly used than SQL2, it can be more expressive and powerful for certain hierarchical data structures.</p>
<h4>How to Use:</h4>
<p>Navigate to the AEM Query Performance Tool, and select on the &#8220;Explain Query&#8221; tab. Choose the &#8220;Language&#8221; drop down to be XPath, and input the XPath Query that you are trying to test. Now click on explain, and you&#8217;ll see a breakdown of the query&#8217;s interpretation and execution.</p>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-larger"/>
<h2>Other Options for the AEM Query Performance Tool</h2>
<ol>
<li><strong>Include Execution Time</strong>: Execution time will be reported after running the query. Please note that long running queries will report an explanation with a delay.</li>
<li><strong>Read first page of results</strong>: The first 20 results will be read after running the query.  Please note that long running queries will report an explanation with a delay, and the overall execution will timeout after 60 seconds.</li>
<li><strong>Include Node Count</strong>: The node count is calculated by iterating the full result set of the query. Please note that long running queries will report an explanation with a delay, and the overall execution will timeout after 60 seconds.</li>
</ol>
<p>AEM Query Performance Tool<br />
<a href="http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html" rel="noopener" target="_blank">http://localhost:4502/libs/granite/operations/content/diagnosistools/queryPerformance.html</a></p>
<hr class="spacer-larger"/>
<h2>Conclusion</h2>
<p>The Explain Query Tool in AEM is a powerful ally for developers, especially those heavily invested in ensuring the performance and accuracy of their search queries. By familiarizing oneself with this tool across the various backend search APIs, developers can optimize their AEM platform for both performance and maintainability, ensuring that the content delivery is swift and relevant.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem">Optimizing &#038; Debugging Search Queries, Explain Query Tool AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/optimizing-debugging-search-queries-explain-query-tool-aem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Retrieving the Current Page in an AEM Servlet via ResourceType</title>
		<link>https://sourcedcode.com/blog/aem/retrieving-the-current-page-in-an-aem-servlet-via-resourcetype</link>
					<comments>https://sourcedcode.com/blog/aem/retrieving-the-current-page-in-an-aem-servlet-via-resourcetype#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 06 Sep 2023 03:48:43 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6104</guid>

					<description><![CDATA[<p>In the context of &#8220;Retrieving the Current Page in an AEM Servlet via ResourceType&#8221;, it is great to understand how this is done. This guide provides a simplified walkthrough on how you can adeptly achieve this. In the code example, we will associating the servlet with a resourceType. 123456789101112131415161718192021222324252627282930313233343536373839package com.example.aem.servlets; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/retrieving-the-current-page-in-an-aem-servlet-via-resourcetype">Retrieving the Current Page in an AEM Servlet via ResourceType</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the context of &#8220;Retrieving the Current Page in an AEM Servlet via ResourceType&#8221;, it is great to understand how this is done. This guide provides a simplified walkthrough on how you can adeptly achieve this. In the code example, we will associating the servlet with a resourceType.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.aem.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.Self</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.Page</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.PageManager</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Optional</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
@SlingServletResourceTypes<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; resourceTypes<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;example/components/content/mycomponent&quot;</span>,<br />
&nbsp; &nbsp; methods<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GET&quot;</span>,<br />
&nbsp; &nbsp; extensions<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;html&quot;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ResourceTypeServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Self<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest request<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Page currentPage <span style="color: #339933;">=</span> Optional.<span style="color: #006633;">ofNullable</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>PageManager.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.<span style="color: #006633;">map</span><span style="color: #009900;">&#40;</span>pm <span style="color: #339933;">-&gt;</span> pm.<span style="color: #006633;">getContainingPage</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.<span style="color: #006633;">orElse</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currentPage <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gotcha! Current page is: &quot;</span> <span style="color: #339933;">+</span> currentPage.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Oops, couldn't find the current page.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2>Understanding the AEM Code Snippet</h2>
<h3>1. <span class="code-highlight-secondary">request.getResourceResolver().adaptTo(PageManager.class)</span>:</h3>
<p><span class="code-highlight-secondary">request.getResourceResolver()</span>: This fetches a <span class="code-highlight-secondary">ResourceResolver</span> from the servlet&#8217;s request. A <span class="code-highlight-secondary">ResourceResolver</span> in AEM assists in translating resource paths to actual resources.</p>
<p><span class="code-highlight-secondary">.adaptTo(PageManager.class)</span>: This method tries to adapt or convert the <span class="code-highlight-secondary">ResourceResolver</span> into another type, specifically a <span class="code-highlight-secondary">PageManager</span>. The <span class="code-highlight-secondary">PageManager</span> in AEM offers utilities for working with pages, such as fetching, creating, or deleting pages.</p>
<hr class="spacer-large" />
<h3>2. <span class="code-highlight-secondary">Optional.ofNullable(&#8230;)</span></h3>
<p>This wraps the value returned by the preceding code (which might be a <span class="code-highlight-secondary">PageManager</span> object or <span class="code-highlight-secondary">null</span> if the adaptation failed) within an <span class="code-highlight-secondary">Optional</span> object. <span class="code-highlight-secondary">Optional</span> is a container that may or may not contain a value.</p>
<hr class="spacer-large" />
<h3>3. <span class="code-highlight-secondary">.map(pm -> pm.getContainingPage(request.getResource()))</span></h3>
<p>If the <span class="code-highlight-secondary">Optional</span> contains a non-null <span class="code-highlight-secondary">PageManager</span> value, the <span class="code-highlight-secondary">.map</span> method applies the given function to it. Here, it uses the <span class="code-highlight-secondary">PageManager</span> (denoted as <span class="code-highlight-secondary">pm</span> in the lambda) to retrieve the containing page of the present resource.</p>
<p><span class="code-highlight-secondary">pm.getContainingPage(request.getResource())</span>: This extracts the AEM Page that encompasses the current resource.</p>
<hr class="spacer-large" />
<h3>4. <span class="code-highlight-secondary">.orElse(null)</span></h3>
<p>Lastly, if any prior steps don&#8217;t succeed (i.e., if the adaptation to <span class="code-highlight-secondary">PageManager</span> was unsuccessful or if no containing page for the resource exists), the <span class="code-highlight-secondary">orElse</span> method ensures <span class="code-highlight-secondary">currentPage</span> is set to <span class="code-highlight-secondary">null</span>.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/retrieving-the-current-page-in-an-aem-servlet-via-resourcetype">Retrieving the Current Page in an AEM Servlet via ResourceType</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/retrieving-the-current-page-in-an-aem-servlet-via-resourcetype/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM 6.5 On-Prem, Embed AEM Core Component&#8217;s to the Project</title>
		<link>https://sourcedcode.com/blog/aem/aem-6-5-on-prem-embed-aem-core-components-to-the-project</link>
					<comments>https://sourcedcode.com/blog/aem/aem-6-5-on-prem-embed-aem-core-components-to-the-project#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 31 Aug 2023 03:25:57 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6058</guid>

					<description><![CDATA[<p>The AEMaaCS platform contains the Adobe AEM Core Components pre-installed into the /libs folder, but however, AEM 6.5 on-prem does automatically contain this; we must install it manually. For legacy AEM 6.5 project utilizing the Adobe AEM Core Components, they must configure &#038; install this library to each environment (authors, publishers) with the correct version. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-6-5-on-prem-embed-aem-core-components-to-the-project">AEM 6.5 On-Prem, Embed AEM Core Component&#8217;s to the Project</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The AEMaaCS platform contains the <a href="https://github.com/adobe/aem-core-wcm-components" rel="noopener" target="_blank">Adobe AEM Core Components</a> pre-installed into the /libs folder, but however, AEM 6.5 on-prem does automatically contain this; we must install it manually. For legacy AEM 6.5 project utilizing the <a href="https://github.com/adobe/aem-core-wcm-components" rel="noopener" target="_blank">Adobe AEM Core Components</a>, they must configure &#038; install this library to each environment (authors, publishers) with the correct version. Manual installation is teedius and prone to errors, so its best practice to automatically install the correct versions. </p>
<p>In this article we will walk through step by step how to embed the <a href="https://github.com/adobe/aem-core-wcm-components" rel="noopener" target="_blank">Adobe AEM Core Components</a> into your project, so when your code is built via maven, your maven module will contain instructions for your AEM environment to install the <a href="https://github.com/adobe/aem-core-wcm-components" rel="noopener" target="_blank">Adobe AEM Core Components</a> as expected.</p>
<div class="mention-block--gold">
<strong>Important!</strong><br />
Specific versions of Adobe Core Components only support specific AEM 6.5 service pack versions, so please take a look at Adobe&#8217;s documentation to understand exactly which version you need. <a href="https://experienceleague.adobe.com/docs/experience-manager-core-components/using/versions.html?lang=en" rel="noopener" target="_blank">Check Version</a>.
</div>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#step-1">Add dependencies to parent pom.xml</a></li>
<li><a href="#step-2">Add dependencies to your target maven module</a></li>
<li><a href="#step-3">Configure com.day.jcr.vault&#8217;s &lt;embeded&gt; to target maven module</a></li>
<li><a href="#step-4">Add template to create and manage wcm.io caConfigs</a></li>
</ol>
</div>
<hr class="spacer-larger" />
<h3 id="step-1">1. Add dependencies to parent pom.xml</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependencyManagement<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">adobe</span>.<span style="color: #006633;">cq</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>core.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">components</span>.<span style="color: #006633;">all</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>type<span style="color: #339933;">&gt;</span>zip<span style="color: #339933;">&lt;/</span>type<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>2.20.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependencyManagement<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-2">2. Add dependencies to your target maven module</h3>
<p>In this example, we will target all/pom.xml</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">adobe</span>.<span style="color: #006633;">cq</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>core.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">components</span>.<span style="color: #006633;">core</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>scope<span style="color: #339933;">&gt;</span>provided<span style="color: #339933;">&lt;/</span>scope<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-3">3. Configure com.day.jcr.vault&#8217;s &lt;subPackages&gt;&lt;subPackage&gt; to target maven module</h3>
<p>In this example, we will target all/pom.xml</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">day</span>.<span style="color: #006633;">jcr</span>.<span style="color: #006633;">vault</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>content<span style="color: #339933;">-</span>package<span style="color: #339933;">-</span>maven<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>extensions<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>extensions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>subPackages<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>subPackage<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">adobe</span>.<span style="color: #006633;">cq</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>core.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">components</span>.<span style="color: #006633;">all</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>filter<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>filter<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>subPackage<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>subPackages<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>targetURL<span style="color: #339933;">&gt;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//${crx.host}:${crx.port}/crx/packmgr/service.jsp&lt;/targetURL&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-6-5-on-prem-embed-aem-core-components-to-the-project">AEM 6.5 On-Prem, Embed AEM Core Component&#8217;s to the Project</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-6-5-on-prem-embed-aem-core-components-to-the-project/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Embed wcm.io Context-Aware Configuration Editor</title>
		<link>https://sourcedcode.com/blog/aem/how-to-embed-wcm-io-context-aware-configuration-editor</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-embed-wcm-io-context-aware-configuration-editor#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 29 Aug 2023 03:11:53 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6050</guid>

					<description><![CDATA[<p>This blog article serves as your guide to seamlessly integrate and deploy the wcm.io Context-Aware Configuration Editor – a powerful tool that streamlines configuration management within AEM projects. Throughout this article, we will delve into the step-by-step process of configuring, installing, embedding, and deploying the wcm.io Context-Aware Configuration Editor. By following these instructions, you&#8217;ll be [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-embed-wcm-io-context-aware-configuration-editor">How to Embed wcm.io Context-Aware Configuration Editor</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This blog article serves as your guide to seamlessly integrate and deploy the wcm.io Context-Aware Configuration Editor – a powerful tool that streamlines configuration management within AEM projects.</p>
<p>Throughout this article, we will delve into the step-by-step process of configuring, installing, embedding, and deploying the wcm.io Context-Aware Configuration Editor. By following these instructions, you&#8217;ll be able to harness the capabilities of this editor to automatically install configuration changes across all environments when your code is built via Maven and deployed to AEM. When it comes to deploying the wcm.io Context-Aware Configuration Editor, automation is key.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#step-1">Add dependencies to parent pom.xml</a></li>
<li><a href="#step-2">Add dependencies to your target maven module</a></li>
<li><a href="#step-3">Configure com.day.jcr.vault&#8217;s &lt;embeded&gt; to target maven module</a></li>
<li><a href="#step-4">Add template to create and manage wcm.io caConfigs</a></li>
<li><a href="#step-5">Context-Aware Configuration bnd plugin</a></li>
<li><a href="#step-6">Absolute Parent Context Path Strategy</a></li>
<li><a href="#step-7">Root Template Context PathStrategy</a></li>
<li><a href="#step-8">Page Persistence Strategy</a></li>
</ol>
</div>
<hr class="spacer-larger" />
<h3 id="step-1">1. Add dependencies to parent pom.xml</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependencyManagement<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">editor</span>.<span style="color: #006633;">package</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>1.8.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>type<span style="color: #339933;">&gt;</span>zip<span style="color: #339933;">&lt;/</span>type<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">extensions</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>1.8.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-2">2. Add dependencies to your target maven module</h3>
<p>In this example, we will target all/pom.xml</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">editor</span>.<span style="color: #006633;">package</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>type<span style="color: #339933;">&gt;</span>zip<span style="color: #339933;">&lt;/</span>type<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">extensions</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-3">3. Configure com.day.jcr.vault&#8217;s &lt;embeded&gt; to target maven module</h3>
<p>In this example, we will target all/pom.xml, and yes, step 2 and 3 are configuration added to the same file.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugins<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">day</span>.<span style="color: #006633;">jcr</span>.<span style="color: #006633;">vault</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>content<span style="color: #339933;">-</span>package<span style="color: #339933;">-</span>maven<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>extensions<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>extensions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>group<span style="color: #339933;">&gt;</span>sourcedcode<span style="color: #339933;">-</span>packages<span style="color: #339933;">&lt;/</span>group<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>filterSource<span style="color: #339933;">&gt;</span>src<span style="color: #339933;">/</span>main<span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>META<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>vault<span style="color: #339933;">/</span>filter.<span style="color: #006633;">xml</span><span style="color: #339933;">&lt;/</span>filterSource<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>embeddeds<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>embedded<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">editor</span>.<span style="color: #006633;">package</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>type<span style="color: #339933;">&gt;</span>zip<span style="color: #339933;">&lt;/</span>type<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>target<span style="color: #339933;">&gt;/</span>apps<span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>install<span style="color: #339933;">&lt;/</span>target<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>embedded<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>embedded<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">extensions</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>target<span style="color: #339933;">&gt;/</span>apps<span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>install<span style="color: #339933;">&lt;/</span>target<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>embedded<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>embeddeds<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>targetURL<span style="color: #339933;">&gt;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//${crx.host}:${crx.port}/crx/packmgr/service.jsp&lt;/targetURL&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugins<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-4">4. Add template to create and manage wcm.io caConfigs</h3>
<p>./ui.apps/src/main/content/jcr_root/apps/sourcedcode/templates/caconfig-template/content.xml</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span><br />
<span style="color: #339933;">&lt;</span>jcr<span style="color: #339933;">:</span>root xmlns<span style="color: #339933;">:</span>sling<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>cq<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>jcr<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jcp.org/jcr/1.0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq:Template&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Context-Aware Configuration Page&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allowedPaths<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;[^/content/sourcedcode(/.*)?$]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ranking<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Long}110&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>jcr<span style="color: #339933;">:</span>content<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq:PageContent&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;wcm-io/caconfig/editor/components/page/editor&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;/</span>jcr<span style="color: #339933;">:</span>root<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-5">5. Context-Aware Configuration bnd plugin</h3>
<p>A bnd plugin is provided that scans the classpath of a bundle Maven project at build time and automatically generates a Sling-ContextAware-Configuration-Classes bundle header for all annotation classes annotated with @Configuration. It can be used by both maven-bundle-plugin and bnd-maven-plugin, as both use the bnd library internally.</p>
<p><strong>Standard Configuration</strong><br />
Place the configuration from the root pom.xml as such:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">felix</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>maven<span style="color: #339933;">-</span>bundle<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>extensions<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>extensions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>instructions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;!--</span> Generate bundle header containing all configuration annotation classes <span style="color: #339933;">--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>_plugin<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bndplugin</span>.<span style="color: #006633;">ConfigurationClassScannerPlugin</span><span style="color: #339933;">&lt;/</span>_plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>instructions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>1.0.2<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer" />
<p><strong>If you use the bnd-maven-plugin and raw bnd statements, you have to configure it with this bnd statement:</strong><br />
Place the configuration from the root pom.xml as such:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>bnd<span style="color: #339933;">-</span>maven<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>bnd<span style="color: #339933;">&gt;&lt;!</span><span style="color: #009900;">&#91;</span>CDATA<span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">-</span>plugin org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bndplugin</span>.<span style="color: #006633;">ConfigurationClassScannerPlugin</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;&lt;/</span>bnd<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>1.0.2<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer" />
<p><strong>Sling Context Aware Configuration context-aware-configuration-bnd-plugin not working as expected</strong><br />
If both installations from the top are not working as expected, please try the configuration as below. Place the configuration from the root pom.xml as such. Take a look at line 21, where you can see we have kept org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin, org.apache.sling.bnd.models.ModelsScannerPlugin in one line of code, with a comma as the delimiter.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>bnd<span style="color: #339933;">-</span>maven<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#123;</span>bnd.<span style="color: #006633;">version</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>executions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>execution<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>id<span style="color: #339933;">&gt;</span>bnd<span style="color: #339933;">-</span>process<span style="color: #339933;">&lt;/</span>id<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>goals<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>goal<span style="color: #339933;">&gt;</span>bnd<span style="color: #339933;">-</span>process<span style="color: #339933;">&lt;/</span>goal<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>goals<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>bnd<span style="color: #339933;">&gt;&lt;!</span><span style="color: #009900;">&#91;</span>CDATA<span style="color: #009900;">&#91;</span><br />
Bundle<span style="color: #339933;">-</span>Category<span style="color: #339933;">:</span> $<span style="color: #009900;">&#123;</span>componentGroupName<span style="color: #009900;">&#125;</span><br />
<br />
# export all versioned packages except <span style="color: #000000; font-weight: bold;">for</span> conditional ones <span style="color: #009900;">&#40;</span>https<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//github.com/bndtools/bnd/issues/3721#issuecomment-579026778)</span><br />
<span style="color: #339933;">-</span>exportcontents<span style="color: #339933;">:</span> $<span style="color: #009900;">&#123;</span>removeall<span style="color: #339933;">;</span>$<span style="color: #009900;">&#123;</span>packages<span style="color: #339933;">;</span>VERSIONED<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>$<span style="color: #009900;">&#123;</span>packages<span style="color: #339933;">;</span>CONDITIONAL<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><br />
<br />
...<br />
<br />
<span style="color: #006633;">Bundle</span><span style="color: #339933;">-</span>DocURL<span style="color: #339933;">:</span><br />
<span style="color: #339933;">-</span>plugin org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">caconfig</span>.<span style="color: #006633;">bndplugin</span>.<span style="color: #006633;">ConfigurationClassScannerPlugin</span>, org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">bnd</span>.<span style="color: #006633;">models</span>.<span style="color: #006633;">ModelsScannerPlugin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>bnd<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>execution<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>executions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3 id="step-6">6. Absolute Parent Context Path Strategy</h3>
<p>io.wcm.caconfig.extensions.contextpath.impl.AbsoluteParentContextPathStrategy-sourcedcode.config</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">contextPathBlacklistRegex<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><br />
service.<span style="color: #006633;">ranking</span><span style="color: #339933;">=</span>I<span style="color: #0000ff;">&quot;2000&quot;</span><br />
unlimited<span style="color: #339933;">=</span>B<span style="color: #0000ff;">&quot;false&quot;</span><br />
configPathPatterns<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;/conf$1&quot;</span><span style="color: #009900;">&#93;</span><br />
levels<span style="color: #339933;">=</span>i<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;1&quot;</span>,<span style="color: #0000ff;">&quot;2&quot;</span>,<span style="color: #0000ff;">&quot;3&quot;</span>,<span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #009900;">&#93;</span><br />
contextPathRegex<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;^/content(/sourcedcode|/experience-fragments/sourcedcode/.*)$&quot;</span><br />
templatePathsBlacklist<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#93;</span></div></td></tr></tbody></table></div>
<p>In this crucial step, we introduce the Absolute Parent Context Path Strategy, found in the io.wcm.caconfig.extensions.contextpath.impl.AbsoluteParentContextPathStrategy-<UNIQUE_IDENTIFIER>.config. This feature allows you to create tailored configurations for specific folders within your content repository. For instance, you can now establish separate configurations for &#8216;/content/sourcedcode/en&#8217; and &#8216;/content/sourcedcode/fr,&#8217; effectively breaking the chain of inheritance. This newfound freedom permits you to cancel inheritance at various levels, from 1 to 4, enabling you to fine-tune configurations to align with your folder structure. This level of precision and customization is pivotal in optimizing your content management experience.</p>
<hr class="spacer-larger" />
<h3 id="step-7">7. Root Template Context PathStrategy</h3>
<p>io.wcm.caconfig.extensions.contextpath.impl.RootTemplateContextPathStrategy-sourcedcode.config</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">maxLevel<span style="color: #339933;">=</span>I<span style="color: #0000ff;">&quot;4&quot;</span><br />
service.<span style="color: #006633;">ranking</span><span style="color: #339933;">=</span>I<span style="color: #0000ff;">&quot;2000&quot;</span><br />
templatePaths<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;/conf/sourcedcode/settings/wcm/templates/content-page&quot;</span>,<span style="color: #0000ff;">&quot;/conf/sourcedcode/settings/wcm/templates/blank-page&quot;</span><span style="color: #009900;">&#93;</span><br />
configPathPatterns<span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;/conf$1&quot;</span><span style="color: #009900;">&#93;</span><br />
contextPathRegex<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;^/content/sourcedcode.*)$&quot;</span><br />
templateMatchAllLevels<span style="color: #339933;">=</span>B<span style="color: #0000ff;">&quot;true&quot;</span><br />
minLevel<span style="color: #339933;">=</span>I<span style="color: #0000ff;">&quot;1&quot;</span></div></td></tr></tbody></table></div>
<p>In this step, we focus on configuring the io.wcm.caconfig.extensions.contextpath.impl.RootTemplateContextPathStrategy-<name>.config. This feature allows you to establish a foundational template for your content, ensuring a well-structured content hierarchy in your AEM project. By defining a root template, you simplify content management and maintain consistency throughout your project. Whether you&#8217;re building a website, an application, or a digital experience, configuring a root template is a fundamental step in aligning your content with your project&#8217;s objectives.</p>
<hr class="spacer-larger" />
<h3 id="step-8">8. Absolute Parent Context Path Strategy, Folder Level Ca Configs</h3>
<p>io.wcm.caconfig.extensions.persistence.impl.PagePersistenceStrategy.config</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">service.<span style="color: #006633;">ranking</span><span style="color: #339933;">=</span>I<span style="color: #0000ff;">&quot;1500&quot;</span><br />
enabled<span style="color: #339933;">=</span>B<span style="color: #0000ff;">&quot;true&quot;</span><br />
resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span></div></td></tr></tbody></table></div>
<p>If you intend to maintain the default Sling implementation, there are two options for handling the configurations: you can either package them from the author environment to the publish environment or replicate them from CRXDE Lite. If you opt for the wcm.io editor, it offers a feature that facilitates configuration replication by saving configurations as cq:Page nodes. To activate replication within the editor page, you should utilize the &#8220;PagePersistenceStrategy&#8221; provided by the &#8220;caconfig.extension&#8221; package, which must be deployed in AEM. Additionally, you need to enable the &#8220;io.wcm.caconfig.extensions.persistence.impl.PagePersistenceStrategy&#8221; OSGi configuration within the ui.apps module. Failing to complete this step will result in ca configurations being stored as folders, which necessitates setting the resourceType to nt:unstructured.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-embed-wcm-io-context-aware-configuration-editor">How to Embed wcm.io Context-Aware Configuration Editor</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-embed-wcm-io-context-aware-configuration-editor/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sling Servlet: resourceTypes for POST &#038; GET Code Example Code</title>
		<link>https://sourcedcode.com/blog/aem/aem-sling-servlet-resource-type-for-post-get-code-example-code</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sling-servlet-resource-type-for-post-get-code-example-code#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 28 Aug 2023 06:37:48 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=6020</guid>

					<description><![CDATA[<p>When working with Sling Servlets in AEM, the choice between using a resource type or a sling path as the basis for your servlet&#8217;s operation is crucial. This article delves into the benefits of utilizing resource types and provides practical examples of how resource types can streamline your development process for both POST and GET [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-servlet-resource-type-for-post-get-code-example-code">AEM Sling Servlet: resourceTypes for POST &#038; GET Code Example Code</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When working with Sling Servlets in AEM, the choice between using a resource type or a sling path as the basis for your servlet&#8217;s operation is crucial. This article delves into the benefits of utilizing resource types and provides practical examples of how resource types can streamline your development process for both POST and GET templates.</p>
<hr class="spacer-larger" />
<h2>Resource Type vs. Sling Path</h2>
<p>The decision between using a resource type and a sling path as the foundation of your servlet&#8217;s functionality can significantly impact your development approach. A resource type is a more flexible and future-proof choice due to its abstraction from specific URLs. Resource types abstract the underlying storage structure, enabling your servlets to work consistently even if the content hierarchy changes. On the other hand, relying on sling paths can lead to brittle implementations, as they are tied to specific URLs that might change over time.</p>
<hr class="spacer-larger" />
<h2>Advantages of Resource Types</h2>
<ol>
<li><strong>Abstraction: </strong>Resource types provide an abstraction layer, separating the servlet&#8217;s logic from the actual URL structure. This ensures that your servlet remains functional even when the content structure evolves.
</li>
<li><strong>Adaptability: </strong>With resource types, your servlet can adapt to different parts of the content hierarchy without requiring modifications. This adaptability becomes crucial in scenarios where content structures are reorganized or repurposed.</li>
<li><strong>Consistency: </strong>By using resource types, you promote consistency in your application. Different components or pages with the same resource type can share the same servlet logic, enhancing maintainability.
</li>
</ol>
<hr class="spacer-large" />
<h2>Caveats when using @SlingServletPaths</h2>
<ol>
<li>Path-bound servlets cannot be access-controlled using the default JCR repository ACLs.</i>
<li>Path-bound servlets can only be registered to a path and not a resource type (i.e. no suffix handling).</i>
<li>If a path-bound servlet is not active, e.g. if the bundle is missing or not started, a POST might result in unexpected results. usually creating a node at /bin/xyz which subsequently overlays the servlets path binding. The mapping is not transparent to a developer looking just at the repository.</i>
</ol>
<hr class="spacer-larger" />
<h3>POST Template using Resource Type</h3>
<p>Consider a scenario where you want to handle form submissions via a POST request for multiple types of components. By utilizing resource types, you can create a centralized servlet that handles these submissions consistently, regardless of the content&#8217;s location.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.resourceTypes=yourapp/components/form&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=POST&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FormSubmitServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process form submission</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Send JSON response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;success&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h3>GET Template using Resource Type</h3>
<p>Imagine you need to retrieve data from different types of resources, such as articles and videos, and display them using a single servlet. Utilizing resource types allows you to create a unified servlet to serve diverse content.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.resourceTypes=yourapp/components/content&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContentDisplayServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Fetch and render content</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// ...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Send JSON response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;success&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h2>Conclusion</h2>
<p>Resource types stand as a powerful tool in AEM&#8217;s arsenal, offering a versatile and robust approach to developing Sling Servlets for both POST and GET templates. By abstracting the underlying URL structure, resource types enable consistent servlet behavior across different content hierarchies. This approach enhances code maintainability, adaptability, and future-proofing. In contrast, sling paths can result in rigid implementations tied to specific URLs. By embracing resource types, developers can create more flexible, reliable, and adaptable solutions in Adobe Experience Manager.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-servlet-resource-type-for-post-get-code-example-code">AEM Sling Servlet: resourceTypes for POST &#038; GET Code Example Code</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sling-servlet-resource-type-for-post-get-code-example-code/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM JCR SQL2 Full Text Search Case Insensitive</title>
		<link>https://sourcedcode.com/blog/aem/aem-jcr-sql2-full-text-search-case-insensitive</link>
					<comments>https://sourcedcode.com/blog/aem/aem-jcr-sql2-full-text-search-case-insensitive#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 28 Aug 2023 06:06:51 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5999</guid>

					<description><![CDATA[<p>One of the key features of AEM is its support for searching and querying content stored in its Java Content Repository (JCR). In this article, we will explore how to perform a case-insensitive full-text search using the JCR_SQL2 query language in AEM and provide a practical example of achieving this through a servlet. Performing Case-Insensitive [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-jcr-sql2-full-text-search-case-insensitive">AEM JCR SQL2 Full Text Search Case Insensitive</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>One of the key features of AEM is its support for searching and querying content stored in its Java Content Repository (JCR). In this article, we will explore how to perform a case-insensitive full-text search using the JCR_SQL2 query language in AEM and provide a practical example of achieving this through a servlet.</p>
<hr class="spacer-large"/>
<h2>Performing Case-Insensitive Full Text Search</h2>
<p>A case-insensitive full-text search is a common requirement when you want to retrieve content regardless of the letter casing used in the search query. In AEM, the JCR_SQL2 query language is used to interact with the JCR repository. To perform a case-insensitive full-text search, you can utilize the<span class="code-highlight-secondary">LOWER()</span>function to convert both the search query and the content being searched to lowercase. This ensures that the search is not case-sensitive.</p>
<hr class="spacer-larger"/>
<h2>Example Query Code</h2>
<p>Consider a scenario where you want to search for assets that are descendants of a specific path and meet certain criteria, while also performing a case-insensitive search for specific keywords. Below is an example of a JCR_SQL2 query code block that achieves this:</p>
<div class="code-1200">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONArray</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Session</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryResult</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.RowIterator</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/mysearchservlet&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySearchServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Retrieve the search query parameter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryParameter <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;query&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Validate if the query parameter is not null or empty</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>queryParameter <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> queryParameter.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject errorResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span>, <span style="color: #0000ff;">&quot;Missing query parameter&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>errorResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Retrieve the JCR session</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Session session <span style="color: #339933;">=</span> request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Define your query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM [cq:Page] AS page &quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;WHERE ISDESCENDANTNODE(page, '/content/myproject')&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp;AND (&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;LOWER(page.[jcr:content/jcr:title]) LIKE '%&quot;</span> <span style="color: #339933;">+</span> queryParameter <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%'&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;OR LOWER(page.[jcr:content/cq:template]) LIKE '%&quot;</span> <span style="color: #339933;">+</span> queryParameter <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%'&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;OR LOWER(page.[jcr:content/jcr:description]) LIKE '%&quot;</span> <span style="color: #339933;">+</span> queryParameter <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%'&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp;)&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;ORDER BY [jcr:score] DESC&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the QueryManager and create the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryManager queryManager <span style="color: #339933;">=</span> session.<span style="color: #006633;">getWorkspace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQueryManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>queryString, Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Execute the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryResult result <span style="color: #339933;">=</span> query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the results and build JSON response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONArray resultsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RowIterator rows <span style="color: #339933;">=</span> result.<span style="color: #006633;">getRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rows.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node pageNode <span style="color: #339933;">=</span> rows.<span style="color: #006633;">nextRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject pageData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span>, pageNode.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content/jcr:title&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;template&quot;</span>, pageNode.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content/cq:template&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span>, pageNode.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content/jcr:description&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultsArray.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>pageData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Respond with JSON search results</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>resultsArray.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject errorResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span>, e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>errorResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Close the JCR session</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session.<span style="color: #006633;">logout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large" />
<h2>Example Try Catch</h2>
<div class="mention-block">
When utilizing service users in Java, it&#8217;s essential to incorporate try-catch blocks for exception handling. Java introduced enhanced try-catch blocks, which allow you to catch multiple exceptions using a single catch block, in version 7. Before Java 7, try-catch blocks could only handle one exception type per catch block. With the improvements in Java 7, developers gained the ability to efficiently catch and manage various types of exceptions within a structured framework. These enhanced try-catch blocks serve as a powerful means of error management, preventing application crashes, facilitating user-friendly error messages, assisting in the debugging process, and bolstering overall code reliability.</p>
<p>Moreover, when working with service users, it&#8217;s important to remember that the JCR session should always be properly closed. Failing to close the session can lead to lingering threads and resource leaks. Incorporating try-with-resources or explicit session closure ensures that resources are released and system resources are utilized optimally. This practice contributes to maintaining the stability and efficiency of your application.
</p></div>
<div class="code-1200">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolverFactory</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONArray</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/mysearchservlet&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySearchServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolverFactory resolverFactory<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Retrieve the search query parameter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryParameter <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;query&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Validate if the query parameter is not null or empty</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>queryParameter <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> queryParameter.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject errorResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span>, <span style="color: #0000ff;">&quot;Missing query parameter&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>errorResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resourceResolver <span style="color: #339933;">=</span> resolverFactory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Define your query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM [cq:Page] AS page &quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;WHERE ISDESCENDANTNODE(page, '/content/myproject')&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp;AND (&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;LOWER(page.[jcr:content/jcr:title]) LIKE '%&quot;</span> <span style="color: #339933;">+</span> queryParameter <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%'&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;OR LOWER(page.[jcr:content/cq:template]) LIKE '%&quot;</span> <span style="color: #339933;">+</span> queryParameter <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%'&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;OR LOWER(page.[jcr:content/jcr:description]) LIKE '%&quot;</span> <span style="color: #339933;">+</span> queryParameter <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%'&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot; &nbsp; &nbsp;)&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;ORDER BY [jcr:score] DESC&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the QueryManager and create the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryManager queryManager <span style="color: #339933;">=</span> resourceResolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>QueryManager.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>queryString, Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Execute the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryResult result <span style="color: #339933;">=</span> query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the results and build JSON response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONArray resultsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RowIterator rows <span style="color: #339933;">=</span> result.<span style="color: #006633;">getRows</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rows.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node pageNode <span style="color: #339933;">=</span> rows.<span style="color: #006633;">nextRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject pageData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span>, pageNode.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content/jcr:title&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;template&quot;</span>, pageNode.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content/cq:template&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;description&quot;</span>, pageNode.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content/jcr:description&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultsArray.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>pageData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Respond with JSON search results</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>resultsArray.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject errorResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span>, <span style="color: #0000ff;">&quot;An error occurred while processing the request.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>errorResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p><strong>Curl Example:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl <span style="color: #0000ff;">&quot;http://localhost:4502/bin/mysearchservlet?query=my_search_keyword&quot;</span></div></td></tr></tbody></table></div>
<p><strong>Output:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Page Title 1&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;template&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;/conf/phonak/settings/wcm/templates/mytemplate&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;This is the description of Page 1&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Page Title 2&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;template&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;/conf/phonak/settings/wcm/templates/anothertemplate&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Description for Page 2&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#93;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<p>In this example, the<span class="code-highlight-secondary">LOWER()</span>function is applied to both the properties being searched and the search query<span class="code-highlight-secondary">fulltext</span> This ensures that the search is case-insensitive, allowing you to retrieve relevant assets regardless of letter casing.</p>
<p>Practical Example: Implementing the Search in a Servlet</p>
<p>To practically implement the above query within a servlet in AEM, you would typically perform the following steps:</p>
<li>Create a Java servlet that extends<span class="code-highlight-secondary">SlingAllMethodsServlet</span>or implements<span class="code-highlight-secondary">SlingServlet</span></li>
<li>In the servlet&#8217;s<span class="code-highlight-secondary">doGet</span>or<span class="code-highlight-secondary">doPost</span>method, create an instance of the<span class="code-highlight-secondary">QueryManager</span>to execute the JCR_SQL2 query.</li>
<li>Use the query string from the example above, replacing placeholders like<span class="code-highlight-secondary">productCFsRootPath</span>and<span class="code-highlight-secondary">fulltext</span>with actual values.</li>
<li>Process the query result, extract the relevant data, and respond to the client with the search results.</li>
<hr class="spacer-large"/>
<h2>Conclusion</h2>
<p>Performing a case-insensitive full-text search using the JCR_SQL2 query language in Adobe Experience Manager allows you to provide a seamless search experience for users regardless of their choice of letter casing. By utilizing the<span class="code-highlight-secondary">LOWER()</span>function, you can effectively eliminate case sensitivity from your search queries and retrieve the most relevant content. Incorporating this technique into your AEM projects can enhance user experience and ensure that content discovery is efficient and user-friendly.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-jcr-sql2-full-text-search-case-insensitive">AEM JCR SQL2 Full Text Search Case Insensitive</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-jcr-sql2-full-text-search-case-insensitive/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to access Design Dialogue Properties in Sling Model</title>
		<link>https://sourcedcode.com/blog/aem/how-to-access-design-dialogue-properties-in-sling-model</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-access-design-dialogue-properties-in-sling-model#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 25 Aug 2023 21:37:11 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Short Post]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5962</guid>

					<description><![CDATA[<p>Design Dialogs are especially useful for creating components that need to be easily configurable through editable template and policies without directly editing the underlying code. They enable a clear separation between content and presentation, allowing content authors to make changes without needing technical expertise. Design Dialogs are defined using the AEM Touch UI Dialog, which [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-access-design-dialogue-properties-in-sling-model">How to access Design Dialogue Properties in Sling Model</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Design Dialogs are especially useful for creating components that need to be easily configurable through editable template and policies without directly editing the underlying code. They enable a clear separation between content and presentation, allowing content authors to make changes without needing technical expertise. Design Dialogs are defined using the AEM Touch UI Dialog, which is an integral part of the component development process.</p>
<p>In this article we will talk through how to access the design dialogue settings that is configured in editable template policies within Sling Models. This article will be a quick reference, which means we will provide you code examples for the solution.</p>
<hr class="spacer-larger"/>
<h2>1. Example _cq_design_dialog.xml configuration</h2>
<p>This is a snippet that resides in /apps/core/wcm/components/title/v1/title/_cq_design_dialog.xml</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>advancedSettings<br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Advanced Settings&quot;</span><br />
&nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/container&quot;</span><br />
&nbsp; &nbsp; margin<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>renderLayoutAs<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldDescription<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Forcing the component to render column layouts as&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Render Layout As&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./renderLayoutAs&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>oneColumn<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Default (One Column)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selected<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;oneColumn&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>twoColumns<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Two Columns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selected<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;twoColumns&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>threeColumns<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Three Columns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;threeColumns&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>fourColumns<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Four Columns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fourColumns&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>renderLayoutAs<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>advancedSettings<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h2>2. Accessing Design Dialog Properties in Sling Models:</h2>
<p>In AEM, Sling Models provide a way to map resource properties to Java objects, making it easier to work with the content of a page. To access Design Dialog properties within a Sling Model, take a look at the example code below.</p>
<p>Take notice, in line:17, we are using <a href="/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide" rel="noopener" target="_blank">Sling Model Specific Annotations, @ScriptVariable</a>, to initiate the currentStyle object. In line:22, we are calling the get method() which is a public method, which here we will attempt to find configuration set via design dialog &#8220;renderLayoutAs&#8221;. If &#8220;renderLayoutAs&#8221; is not configured, then String renderLayoutAs == null. Finally in line:24, we will use a switch statement to execute code based on what is configured.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.internal.components</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Style</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">commons</span>.<span style="color: #006633;">lang3</span>.<span style="color: #006633;">StringUtils</span>.<span style="color: #006633;">isNotEmpty</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LayoutColumn <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> RENDER_LAYOUT_AS_PROP <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;renderLayoutAs&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Style</span> currentStyle<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> renderLayoutAs <span style="color: #339933;">=</span> currentStyle.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>RENDER_LAYOUT_AS_PROP, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isNotEmpty<span style="color: #009900;">&#40;</span>renderLayoutAs<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>renderLayoutAs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;oneColumn&quot;</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;twoColumns&quot;</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;threeColumns&quot;</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #0000ff;">&quot;fourColumns&quot;</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Default case&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-access-design-dialogue-properties-in-sling-model">How to access Design Dialogue Properties in Sling Model</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-access-design-dialogue-properties-in-sling-model/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>JUNIT 5: JCR SQL 2 Unit Tests w/ Sling Servlet</title>
		<link>https://sourcedcode.com/blog/aem/junit-5-jcr-sql-2-unit-tests-w-sling-servlet</link>
					<comments>https://sourcedcode.com/blog/aem/junit-5-jcr-sql-2-unit-tests-w-sling-servlet#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 09 Aug 2023 12:30:05 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JUNIT]]></category>
		<category><![CDATA[JUNIT5]]></category>
		<category><![CDATA[Premium Content]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5855</guid>

					<description><![CDATA[<p>I&#8217;ve dedicated quite a chunk of my personal time to crafting this blog post, and yes, I&#8217;ve rigorously tested all useful test cases that you can learn from. Why, you ask? It&#8217;s all for you, my awesome readers! I want to ensure that you not only find value in this post but also gain useful [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/junit-5-jcr-sql-2-unit-tests-w-sling-servlet">JUNIT 5: JCR SQL 2 Unit Tests w/ Sling Servlet</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve dedicated quite a chunk of my personal time to crafting this blog post, and yes, I&#8217;ve rigorously tested all useful test cases that you can learn from. Why, you ask? It&#8217;s all for you, my awesome readers! I want to ensure that you not only find value in this post but also gain useful knowledge that you can easily share with your fellow devs.</p>
<p>I&#8217;m here to make it super simple for you. This JCR SQL 2 Unit Tests w/ Sling Servlet blog post will only cover the modern approach to unit testing using JUnit 5 and the io.wcm.testing.aem-mock.junit5 library. I&#8217;m excited to show you a live example of a Servlet utilizing the Java Search, JCR SQL 2 API. By the time we&#8217;re done, you&#8217;ll be equipped with the tools to write tests that not only work but also rock!</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#what-to-test-for-when-testing-a-servlet-or-osgi-service-that-utilizes-the-java-jcr-sql-2-api">What to test for when testing a Servlet or OSGI Service that utilizes the Java, JCR SQL 2 API?</a>
<ol>
<li>a. <a href="#query-string">Query String</a></li>
<li>b. <a href="#results-of-the-query-nodes">Results of the Query, Nodes</a></li>
</ol>
</li>
<li><a href="#code-examples">Code Examples</a>
<ol>
<li>a. <a href="#get-paged-by-path-servlet-java">GetPagedByPathServlet.java</a></li>
<li>b. <a href="#get-paged-by-path-servlet-test-java">GetPagedByPathServletTest.java</a></li>
</ol>
</li>
</ol>
</div>
<div class="mention-block--gold">
<strong>Pre-requirement</strong><br />
&#8211; JUnit 5<br />
&#8211; io.wcm.testing.aem-mock.junit5 library.</p>
<p>Additionally, if you want to learn more about JCR SQL 2, <a href="/blog/aem/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet" target="_blank" rel="noopener">click here</a> to view the blog. Or if you want to explore and learn all other existing AEM Java Search APIs, <a href="/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality" rel="noopener" target="_blank">click here</a>.
</div>
<hr class="spacer-larger"/>
<h2 id="what-to-test-for-when-testing-a-servlet-or-osgi-service-that-utilizes-the-java-jcr-sql-2-api">1. What to test for when testing a Servlet or OSGI Service that utilizes the Java, JCR SQL 2 API?</h2>
<div style="height:50px;"></div>
<h4 id="query-string">1a. Query String</h4>
<p>In my opinion, it&#8217;s crucial to focus on two main areas. First, you should thoroughly test the <strong>query string</strong> that gets executed. This query string is like the roadmap guiding your code&#8217;s behavior. Ensuring its accuracy is essential since it forms the backbone of your code&#8217;s functionality.</p>
<h4 id="results-of-the-query-nodes">2b. Results of the Query, Nodes</h4>
<p>The second area of emphasis lies in the <strong>results of the query</strong>, which are obtained through the nodeIterator. This is where the real action happens – think of it as the hub where your code processes data. Testing this part of your code involves ensuring that the data processing via the nodeIterator is in line with your intended modifications.</p>
<p>To sum up, when testing a Servlet or OSGi Service, your primary focus should revolve around two core elements: meticulously verifying the accuracy of the query string and confirming that the data processing through the nodeIterator meets your expectations. By honing in on these aspects, you&#8217;re building a solid foundation of trust in your code.</p>
<hr class="spacer-larger"/>
<h2 id="code-examples">2. Code Examples</h2>
<div style="height:50px;"></div>
<h3 id="get-paged-by-path-servlet-java">2a. GetPagedByPathServlet.java</h3>
<p>Here in this example, you&#8217;d see a AEM Sling Servlet being created, and within doGet you&#8217;d see us utilizing the JCR SQL2 API, which captures and transforms the results into a JSON object.</p>
<div class="code-1200">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.NodeIterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.RepositoryException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Session</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryResult</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gson.JsonArray</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gson.JsonObject</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span>.<span style="color: #000000; font-weight: bold;">class</span>, property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/getpagedbypath&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GetPagedByPathServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the JCR session</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Session session <span style="color: #339933;">=</span> request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Query statement</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT page.* FROM [cq:Page] AS page &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;INNER JOIN [cq:PageContent] AS jcrContentNode ON ISCHILDNODE(jcrContentNode, page) &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;WHERE ISDESCENDANTNODE(page, '/content/we-retail') &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;AND jcrContentNode.[cq:lastModified] &lt;= CAST('2023-01-01T00:00:00.000+00:00' AS DATE)&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the query object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryManager queryManager <span style="color: #339933;">=</span> session.<span style="color: #006633;">getWorkspace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQueryManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>queryString, Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Execute the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryResult result <span style="color: #339933;">=</span> query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the nodes from the query result</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NodeIterator nodeIterator <span style="color: #339933;">=</span> result.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Collect the paths of the first ten pages in a list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> pagePaths <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node pageNode <span style="color: #339933;">=</span> nodeIterator.<span style="color: #006633;">nextNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> pagePath <span style="color: #339933;">=</span> pageNode.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pagePaths.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>pagePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create a JSON object to hold the results</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JsonObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JsonArray resultsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add the paths to the JSON array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path <span style="color: #339933;">:</span> pagePaths<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultsArray.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add the JSON array to the response object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;results&quot;</span>, resultsArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the response content type</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Write the JSON response to the output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">PrintWriter</span> writer <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>RepositoryException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exception</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>SlingHttpServletResponse.<span style="color: #006633;">SC_INTERNAL_SERVER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error executing query: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p><strong>JSON response</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">&quot;results&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page1&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page2&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page3&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page4&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page5&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page6&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page7&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page8&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page9&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page10&quot;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Curl call</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl -X GET http://localhost:4502/bin/getpagedbypath</div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3 id="get-paged-by-path-servlet-test-java">2b. GetPagedByPathServletTest.java</h3>
<p>Here in this unit test examples. In my opinion, what is mostly effective unit tested for the JCR SQL 2 API, and to test the query string, and next, test the query result. This example does just it. I have tested the code, and it is working as expected.</p>
<div class="code-2000">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">io.wcm.testing.mock.aem.junit5.AemContext</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">io.wcm.testing.mock.aem.junit5.AemContextExtension</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.jupiter.api.BeforeEach</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.jupiter.api.Test</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.jupiter.api.extension.ExtendWith</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.ArgumentCaptor</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.Captor</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.Mock</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.MockitoAnnotations</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.NodeIterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.RepositoryException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Session</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Workspace</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryResult</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.StringWriter</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">junit</span>.<span style="color: #006633;">jupiter</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Assertions</span>.<span style="color: #006633;">assertEquals</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">mockito</span>.<span style="color: #006633;">Mockito</span>.<span style="color: #339933;">*;</span><br />
<br />
@ExtendWith<span style="color: #009900;">&#40;</span>AemContextExtension.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> GetPagedByPathServletTest <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> AemContext context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AemContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> GetPagedByPathServlet underTest <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GetPagedByPathServlet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest request<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletResponse response<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> QueryManager queryManager<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Query query<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> QueryResult queryResult<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Session session<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolver resourceResolver<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Captor<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ArgumentCaptor<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> queryCaptor<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">PrintWriter</span> printWriter<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @BeforeEach<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MockitoAnnotations.<span style="color: #006633;">openMocks</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">registerService</span><span style="color: #009900;">&#40;</span>QueryManager.<span style="color: #000000; font-weight: bold;">class</span>, queryManager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">registerService</span><span style="color: #009900;">&#40;</span>Query.<span style="color: #000000; font-weight: bold;">class</span>, query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">registerService</span><span style="color: #009900;">&#40;</span>QueryResult.<span style="color: #000000; font-weight: bold;">class</span>, queryResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>resourceResolver<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>resourceResolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Workspace workspace <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Workspace.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>session.<span style="color: #006633;">getWorkspace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>workspace<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>workspace.<span style="color: #006633;">getQueryManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>queryManager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>anyString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, eq<span style="color: #009900;">&#40;</span>Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>queryResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>printWriter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* In this test, we will only focus on the query string that is executed. This is a particularly<br />
&nbsp; &nbsp; &nbsp;* important step, because we would like to ensure that our query string is correct before<br />
&nbsp; &nbsp; &nbsp;* query.execute() is called.<br />
&nbsp; &nbsp; &nbsp;* @throws Exception<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> testDoGet_executedQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NodeIterator nodeIterator <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>NodeIterator.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>queryResult.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>nodeIterator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest.<span style="color: #006633;">doGet</span><span style="color: #009900;">&#40;</span>request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Verify that the correct query string was executed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; verify<span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Capture the argument passed to queryManager.createQuery</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; verify<span style="color: #009900;">&#40;</span>queryManager<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>queryCaptor.<span style="color: #006633;">capture</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, eq<span style="color: #009900;">&#40;</span>Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Compare the captured query string with the expected query string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> executedQueryString <span style="color: #339933;">=</span> queryCaptor.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> expectedQueryString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT page.* FROM [cq:Page] AS page &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;INNER JOIN [cq:PageContent] AS jcrContentNode ON ISCHILDNODE(jcrContentNode, page) &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;WHERE ISDESCENDANTNODE(page, '/content/we-retail') &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;AND jcrContentNode.[cq:lastModified] &lt;= CAST('2023-01-01T00:00:00.000+00:00' AS DATE)&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span>expectedQueryString, executedQueryString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* In this test, we are actually going to mock the response from query.execute() and verify<br />
&nbsp; &nbsp; &nbsp;* that the results has been processed, and the output of the servlet is correct. Here you<br />
&nbsp; &nbsp; &nbsp;* can see us mocking the NodeIterator, and then mocking the next node calls.<br />
&nbsp; &nbsp; &nbsp;* @throws Exception<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> testDoGet_successfulJsonResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NodeIterator nodeIterator <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>NodeIterator.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">nextNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>mock<span style="color: #009900;">&#40;</span>javax.<span style="color: #006633;">jcr</span>.<span style="color: #006633;">Node</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">nextNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/we-retail/page1&quot;</span>, <span style="color: #0000ff;">&quot;/content/we-retail/page2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>queryResult.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>nodeIterator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest.<span style="color: #006633;">doGet</span><span style="color: #009900;">&#40;</span>request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> expectedOutput <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{&quot;</span>results<span style="color: #0000ff;">&quot;:[&quot;</span><span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">/</span>page1<span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">/</span>page2<span style="color: #0000ff;">&quot;]}&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; printWriter.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>expectedOutput<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* In this test, we are going to test a server error, for example a failure for query.execute(),<br />
&nbsp; &nbsp; &nbsp;* and verify that the response status is set to 500, and the error message is printed.<br />
&nbsp; &nbsp; &nbsp;* @throws Exception<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> testDoGet_serverError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>anyString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, eq<span style="color: #009900;">&#40;</span>Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenThrow</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RepositoryException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Test exception&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">StringWriter</span> stringWriter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">PrintWriter</span> printWriter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">PrintWriter</span><span style="color: #009900;">&#40;</span>stringWriter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span>printWriter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest.<span style="color: #006633;">doGet</span><span style="color: #009900;">&#40;</span>request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Verify that the response status is set to 500</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; verify<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>SlingHttpServletResponse.<span style="color: #006633;">SC_INTERNAL_SERVER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Verify that the error message is printed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> expectedErrorMessage <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Error executing query: Test exception<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span>expectedErrorMessage, stringWriter.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/junit-5-jcr-sql-2-unit-tests-w-sling-servlet">JUNIT 5: JCR SQL 2 Unit Tests w/ Sling Servlet</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/junit-5-jcr-sql-2-unit-tests-w-sling-servlet/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Search in AEM</title>
		<link>https://sourcedcode.com/blog/aem/search-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/search-in-aem#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 04 Aug 2023 05:32:45 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5676</guid>

					<description><![CDATA[<p>This comprehensive guide offers AEM developers like you a roadmap to implement powerful search functionality using AEM Search APIs. Unravel the potential of three core AEM Search APIs: XPath Search API, JCR SQL2 Search API, and Query Builder Search API. Each API brings unique features to the table, and we&#8217;ll guide you through their capabilities [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/search-in-aem">Search in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This comprehensive guide offers AEM developers like you a roadmap to implement powerful search functionality using AEM Search APIs.</p>
<p>Unravel the potential of three core AEM Search APIs: XPath Search API, JCR SQL2 Search API, and Query Builder Search API. Each API brings unique features to the table, and we&#8217;ll guide you through their capabilities to help you make the right choice for your projects.</p>
<p>To ensure a seamless learning experience, we present practical Java examples for each API. These real-world scenarios will solidify your understanding and enable you to apply the concepts with confidence.</p>
<p>Ready to supercharge your AEM development skills? Dive into the world of AEM Search APIs and embark on a journey to enhance your content search capabilities. Join us in &#8220;Search in AEM &#8211; A Simple Guide to AEM Search APIs: Exploring Your Options for Powerful Search Functionality.&#8221;</p>
<p>Read the full article here: <a href="https://sourcedcode.com/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality">Search in AEM &#8211; A Simple Guide to AEM Search APIs: Exploring Your Options for Powerful Search Functionality</a>.</p>
<p>Unlock the true potential of AEM&#8217;s search capabilities and elevate your projects to new heights!</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/search-in-aem">Search in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/search-in-aem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Query Builder API Exclude Pages or Paths</title>
		<link>https://sourcedcode.com/blog/aem/query-builder-api-exclude-pages-or-paths</link>
					<comments>https://sourcedcode.com/blog/aem/query-builder-api-exclude-pages-or-paths#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 04 Aug 2023 05:01:29 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5652</guid>

					<description><![CDATA[<p>This blog article focuses on searching cq:Page under a particular path, but exclude sub pages. In this article we will share you the Query Builder API&#8217;s Query, and share with you the Java code implementation of a servlet. At the end of this article, you should be able to search cq:Page nodes under a particular [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/query-builder-api-exclude-pages-or-paths">Query Builder API Exclude Pages or Paths</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This blog article focuses on searching cq:Page under a particular path, but exclude sub pages. In this article we will share you the Query Builder API&#8217;s Query, and share with you the Java code implementation of a servlet. At the end of this article, you should be able to search cq:Page nodes under a particular path, but exclude particular resources under some paths, under the sub tree.</p>
<hr class="spacer-larger"/>
<h3>Query Builder API&#8217;s Query:</h3>
<p>Find all cq:Page nodes under /content/my-site/us/en<br />
<strong>NOT</strong> cq:Page nodes under /content/my-site/us/en/services<br />
<strong>NOT</strong> cq:Page nodes under /content/my-site/us/en/products</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>site<span style="color: #339933;">/</span>us<span style="color: #339933;">/</span>en<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
<br />
group.1_group.<span style="color: #006633;">p</span>.<span style="color: #006633;">not</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
group.1_group.<span style="color: #006633;">path</span><span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>site<span style="color: #339933;">/</span>us<span style="color: #339933;">/</span>en<span style="color: #339933;">/</span>services<br />
group.1_group.<span style="color: #006633;">path</span>.<span style="color: #006633;">self</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
<br />
group.2_group.<span style="color: #006633;">p</span>.<span style="color: #006633;">not</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
group.2_group.<span style="color: #006633;">path</span><span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>site<span style="color: #339933;">/</span>us<span style="color: #339933;">/</span>en<span style="color: #339933;">/</span>products<br />
group.2_group.<span style="color: #006633;">path</span>.<span style="color: #006633;">self</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span></div></td></tr></tbody></table></div>
<p><strong>XPath Output:</strong><br />
<a href="https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query.png"><img decoding="async" width="2032" height="422" src="https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query.png" alt="XPath Output" class="alignnone size-full wp-image-5662" srcset="https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query.png 2032w, https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query-300x62.png 300w, https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query-1024x213.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query-768x159.png 768w, https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query-1536x319.png 1536w, https://sourcedcode.com/wp-content/uploads/2023/08/x-path-query-600x125.png 600w" sizes="(max-width: 2032px) 100vw, 2032px" /></a></p>
<hr class="spacer-larger"/>
<h3>Query Builder API Servlet Example:</h3>
<div class="code-750">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.query.QueryBuilder</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashMap</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/getPages&quot;</span> <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GetPagesServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ITEMS_PER_PAGE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> pageNumber <span style="color: #339933;">=</span> getPageNumber<span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pageNumber&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> contentPath <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/content/my-site/us/en&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Root path for the pages.</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the predicate using a Map</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> predicateMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span>, contentPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span>, <span style="color: #0000ff;">&quot;cq:Page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add additional predicate groups if needed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.1_group.p.not&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.1_group.path&quot;</span>, contentPath <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/services&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.1_group.path.self&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.2_group.p.not&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.2_group.path&quot;</span>, contentPath <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/products&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.2_group.path.self&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> paths <span style="color: #339933;">=</span> getPathsForPage<span style="color: #009900;">&#40;</span>contentPath, pageNumber, predicateMap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Convert the list of paths to JSON using Gson</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> jsonResponse <span style="color: #339933;">=</span> convertListToJson<span style="color: #009900;">&#40;</span>paths<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the JSON response in the HTTP response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> getPathsForPage<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> contentPath, <span style="color: #000066; font-weight: bold;">int</span> pageNumber, Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> predicateMap<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Use QueryBuilder to retrieve pages based on the given predicates.</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> paths <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> startIndex <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>pageNumber <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> ITEMS_PER_PAGE<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; QueryBuilder queryBuilder <span style="color: #339933;">=</span> getResourceResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>QueryBuilder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>queryBuilder <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the limit and offset for pagination</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;p.limit&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>ITEMS_PER_PAGE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; predicateMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;p.offset&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>startIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryBuilder.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>predicateMap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Iterator<span style="color: #339933;">&lt;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;&gt;</span> result <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getHits</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Fetch the paths for the current page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> hit <span style="color: #339933;">=</span> result.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> path <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> hit.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; paths.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> paths<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Rest of the methods remain the same as in the previous version.</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// getPageNumber, convertListToJson, etc.</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p><strong>Curl Command</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl <span style="color: #339933;">-</span>X GET <span style="color: #0000ff;">&quot;http://localhost:4502/bin/getPages?pageNumber=1&quot;</span></div></td></tr></tbody></table></div>
<p><strong>JSON Output</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#91;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-1&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-2&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-3&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-4&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-5&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-6&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-7&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-8&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-9&quot;</span>,<br />
&nbsp; <span style="color: #0000ff;">&quot;/content/my-site/us/en/item-10&quot;</span><br />
<span style="color: #009900;">&#93;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/query-builder-api-exclude-pages-or-paths">Query Builder API Exclude Pages or Paths</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/query-builder-api-exclude-pages-or-paths/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>50 Visual Studio &#124; VS Code Hot Key / Shortcuts for Mac 2023</title>
		<link>https://sourcedcode.com/blog/aem/deployment/50-visual-studio-code-hot-key-shortcuts-for-mac-2023</link>
					<comments>https://sourcedcode.com/blog/aem/deployment/50-visual-studio-code-hot-key-shortcuts-for-mac-2023#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 31 Jul 2023 06:55:50 +0000</pubDate>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5540</guid>

					<description><![CDATA[<p>Welcome to our guide on 50 Visual Studio Code shortcuts for Mac users. Whether you&#8217;re a seasoned developer or just starting, mastering these keyboard shortcuts will significantly enhance your coding productivity. Let&#8217;s dive in and discover the most efficient key combinations for a seamless coding experience! For Window users, visit this article, 50 Visual Studio [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/deployment/50-visual-studio-code-hot-key-shortcuts-for-mac-2023">50 Visual Studio | VS Code Hot Key / Shortcuts for Mac 2023</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Welcome to our guide on 50 Visual Studio Code shortcuts for Mac users. Whether you&#8217;re a seasoned developer or just starting, mastering these keyboard shortcuts will significantly enhance your coding productivity. Let&#8217;s dive in and discover the most efficient key combinations for a seamless coding experience!</p>
<div class="mention-block--gold">
For Window users, visit this article, <a href="https://sourcedcode.com/blog/aem/development/50-visual-studio-code-hot-key-shortcuts-for-windows-2023" rel="noopener" target="_blank">50 Visual Studio Code Hot Key / Shortcuts for Mac 2023</a>.
</div>
<hr class="spacer-larger"/>
<h2>Shortcuts List:</h2>
<ul>
<li><strong>(Command + P)</strong>: Quickly open files by typing their names in the Quick Open dialog.</li>
<li><strong>(Command + N)</strong>: Create a new file in the current workspace.</li>
<li><strong>(Command + Shift + P)</strong>: Open the Command Palette to access various commands and settings.</li>
<li><strong>(Command + B)</strong>: Toggle the visibility of the Side Bar.</li>
<li><strong>(Command + Shift + E)</strong>: Focus and show the File Explorer in the Side Bar.</li>
<li><strong>(Command + Shift + F)</strong>: Search across files in the entire workspace.</li>
<li><strong>(Command + J)</strong>: Toggle the Panel (Output, Terminal, or Debug Console).</li>
<li><strong>(Command + /)</strong>: Toggle line comments for the selected code.</li>
<li><strong>(Option + Shift + Up/Down Arrow)</strong>: Move lines of code up or down.</li>
<li><strong>(Option + Click)</strong>: Add multiple cursors at different positions to edit multiple lines at once.</li>
<li><strong>(Command + Shift + L)</strong>: Select all occurrences of the current selection.</li>
<li><strong>(Command + D)</strong>: Add the next occurrence of the current word to the selection.</li>
<li><strong>(Command + G)</strong>: Jump to a specific line number in the active file.</li>
<li><strong>(Option + Left/Right Arrow)</strong>: Move the cursor to the beginning/end of the current word.</li>
<li><strong>(Option + Up/Down Arrow)</strong>: Move the cursor up or down by paragraph.</li>
<li><strong>(Command + Shift + K)</strong>: Delete the current line.</li>
<li><strong>(Command + Shift + T)</strong>: Reopen the last closed tab.</li>
<li><strong>(Command + Tab / Command + Shift + Tab)</strong>: Cycle through open tabs.</li>
<li><strong>(Command + F2)</strong>: Set multiple cursors to the same word in the file.</li>
<li><strong>(Command + Shift + [ / Command + Shift + ])</strong>: Indent or unindent lines of code.</li>
<li><strong>(Option + Shift + O)</strong>: Sort lines in ascending order.</li>
<li><strong>(Option + Command + Down Arrow)</strong>: Copy lines down.</li>
<li><strong>(Option + Shift + Down Arrow)</strong>: Move lines down.</li>
<li><strong>(Option + Shift + Up Arrow)</strong>: Move lines up.</li>
<li><strong>(Option + Shift + F)</strong>: Format the selected code.</li>
<li><strong>(Option + Command + U)</strong>: Transform to uppercase.</li>
<li><strong>(Option + Command + L)</strong>: Transform to lowercase.</li>
<li><strong>(Command + Enter)</strong>: Insert a new line below the current line.</li>
<li><strong>(Command + Shift + Enter)</strong>: Insert a new line above the current line.</li>
<li><strong>(Command + Shift + \)</strong>: Jump to matching bracket.</li>
<li><strong>(Command + Shift + G)</strong>: Open the Source Control view.</li>
<li><strong>(Command + Shift + E)</strong>: Show Explorer/Files view.</li>
<li><strong>(Command + Shift + X)</strong>: Open the Extensions view.</li>
<li><strong>(Option + Shift + F)</strong>: Format document in the editor.</li>
<li><strong>(Command + F)</strong>: Find and replace text.</li>
<li><strong>(Command + Shift + H)</strong>: Replace in files (Find and replace across multiple files).</li>
<li><strong>(Command + Shift + M)</strong>: Show Problems panel.</li>
<li><strong>(Command + Shift + U)</strong>: Show output panel.</li>
<li><strong>(Command + K + W)</strong>: Close all editor tabs.</li>
<li><strong>(Command + Shift + [ / Command + Shift + ])</strong>: Fold or unfold region.</li>
<li><strong>(Option + F12)</strong>: Show all references of a symbol in the workspace.</li>
<li><strong>(Command + Shift + F10)</strong>: Run a specific test.</li>
<li><strong>(Command + Shift + D)</strong>: Open the Debugger panel.</li>
<li><strong>(Command + Shift + O)</strong>: Go to Symbol in File.</li>
<li><strong>(Command + Shift + U)</strong>: Go to a symbol&#8217;s implementation.</li>
<li><strong>(Command + K + R)</strong>: Show keyboard shortcuts reference.</li>
<li><strong>(Command + Shift + F)</strong>: Show keyboard shortcuts reference.</li>
</ul>
<hr class="spacer-larger"/>
<h2>Conclusion:</h2>
<p>Boost your coding productivity with these 50 essential Visual Studio Code shortcuts, tailored for Mac users. Incorporate these time-saving key combinations into your coding workflow, and watch as you breeze through tasks with remarkable speed and efficiency. Happy coding!</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/deployment/50-visual-studio-code-hot-key-shortcuts-for-mac-2023">50 Visual Studio | VS Code Hot Key / Shortcuts for Mac 2023</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/deployment/50-visual-studio-code-hot-key-shortcuts-for-mac-2023/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>50 Visual Studio &#124; VS Code Hot Key / Shortcuts for Windows 2023</title>
		<link>https://sourcedcode.com/blog/aem/development/50-visual-studio-code-hot-key-shortcuts-for-windows-2023</link>
					<comments>https://sourcedcode.com/blog/aem/development/50-visual-studio-code-hot-key-shortcuts-for-windows-2023#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 31 Jul 2023 06:47:50 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5531</guid>

					<description><![CDATA[<p>Welcome to our guide on 50 Visual Studio Code shortcuts for Windows users. Whether you&#8217;re a seasoned developer or just starting, mastering these keyboard shortcuts will significantly enhance your coding productivity. Let&#8217;s dive in and discover the most efficient key combinations for a seamless coding experience! For Mac users, visit this article, 50 Visual Studio [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/development/50-visual-studio-code-hot-key-shortcuts-for-windows-2023">50 Visual Studio | VS Code Hot Key / Shortcuts for Windows 2023</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Welcome to our guide on 50 Visual Studio Code shortcuts for Windows users. Whether you&#8217;re a seasoned developer or just starting, mastering these keyboard shortcuts will significantly enhance your coding productivity. Let&#8217;s dive in and discover the most efficient key combinations for a seamless coding experience!</p>
<div class="mention-block--gold">
For Mac users, visit this article, <a href="https://sourcedcode.com/blog/aem/deployment/50-visual-studio-code-hot-key-shortcuts-for-mac-2023" rel="noopener" target="_blank">50 Visual Studio Code Hot Key / Shortcuts for Mac 2023</a>.
</div>
<hr class="spacer-larger"/>
<h2>Shortcuts List:</h2>
<ul>
<li><strong>Control + P</strong>: Quickly open files by typing their names in the Quick Open dialog.</li>
<li><strong>Control + N</strong>: Create a new file in the current workspace.</li>
<li><strong>Control + Shift + P</strong>: Open the Command Palette to access various commands and settings.</li>
<li><strong>Control + B</strong>: Toggle the visibility of the Side Bar.</li>
<li><strong>Control + Shift + E</strong>: Focus and show the File Explorer in the Side Bar.</li>
<li><strong>Control + Shift + F</strong>: Search across files in the entire workspace.</li>
<li><strong>Control + J</strong>: Toggle the Panel (Output, Terminal, or Debug Console).</li>
<li><strong>Control + /</strong>: Toggle line comments for the selected code.</li>
<li><strong>Alt + Shift + Up/Down Arrow</strong>: Move lines of code up or down.</li>
<li><strong>Alt + Click</strong>: Add multiple cursors at different positions to edit multiple lines at once.</li>
<li><strong>Control + Shift + L</strong>: Select all occurrences of the current selection.</li>
<li><strong>Control + D</strong>: Add the next occurrence of the current word to the selection.</li>
<li><strong>Control + G</strong>: Jump to a specific line number in the active file.</li>
<li><strong>Alt + Left/Right Arrow</strong>: Move the cursor to the beginning/end of the current word.</li>
<li><strong>Alt + Up/Down Arrow</strong>: Move the cursor up or down by paragraph.</li>
<li><strong>Control + Shift + K</strong>: Delete the current line.</li>
<li><strong>Control + Shift + T</strong>: Reopen the last closed tab.</li>
<li><strong>Control + Tab/Control + Shift + Tab</strong>: Cycle through open tabs.</li>
<li><strong>Control + F2</strong>: Set multiple cursors to the same word in the file.</li>
<li><strong>Control + Shift + [ / Control + Shift + ]</strong>: Indent or unindent lines of code.</li>
<li><strong>Alt + Shift + O</strong>: Sort lines in ascending order.</li>
<li><strong>Alt + Shift + Down Arrow</strong>: Copy lines down.</li>
<li><strong>Alt + Shift + Down Arrow</strong>: Move lines down.</li>
<li><strong>Alt + Shift + Up Arrow</strong>: Move lines up.</li>
<li><strong>Alt + Shift + F</strong>: Format the selected code.</li>
<li><strong>Alt + Shift + U</strong>: Transform to uppercase.</li>
<li><strong>Alt + Shift + L</strong>: Transform to lowercase.</li>
<li><strong>Control + Enter</strong>: Insert a new line below the current line.</li>
<li><strong>Control + Shift + Enter</strong>: Insert a new line above the current line.</li>
<li><strong>Control + Shift + \</strong>: Jump to matching bracket.</li>
<li><strong>Control + Shift + G</strong>: Open the Source Control view.</li>
<li><strong>Control + Shift + E</strong>: Show Explorer/Files view.</li>
<li><strong>Control + Shift + X</strong>: Open the Extensions view.</li>
<li><strong>Alt + Shift + F</strong>: Format document in the editor.</li>
<li><strong>Control + F</strong>: Find and replace text.</li>
<li><strong>Control + Shift + H</strong>: Replace in files (Find and replace across multiple files).</li>
<li><strong>Control + Shift + M</strong>: Show Problems panel.</li>
<li><strong>Control + Shift + U</strong>: Show output panel.</li>
<li><strong>Control + K + W</strong>: Close all editor tabs.</li>
<li><strong>Control + Shift + [ / Control + Shift + ]</strong>: Fold or unfold region.</li>
<li><strong>Alt + F12</strong>: Show all references of a symbol in the workspace.</li>
<li><strong>Control + Shift + F10</strong>: Run a specific test.</li>
<li><strong>Control + Shift + D</strong>: Open the Debugger panel.</li>
<li><strong>Control + Shift + O</strong>: Go to Symbol in File.</li>
<li><strong>Control + Shift + U</strong>: Go to a symbol&#8217;s implementation.</li>
<li><strong>Control + K + R</strong>: Show keyboard shortcuts reference.</li>
<li><strong>Control + Shift + F</strong>: Show keyboard shortcuts reference.</li>
</ul>
<hr class="spacer-larger"/>
<h2>Conclusion:</h2>
<p>Boost your coding productivity with these 50 essential Visual Studio Code shortcuts, tailored for Windows users. Incorporate these time-saving key combinations into your coding workflow, and watch as you breeze through tasks with remarkable speed and efficiency. Happy coding!</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/development/50-visual-studio-code-hot-key-shortcuts-for-windows-2023">50 Visual Studio | VS Code Hot Key / Shortcuts for Windows 2023</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/development/50-visual-studio-code-hot-key-shortcuts-for-windows-2023/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sightly Official Documentation: Everything You Need to Know</title>
		<link>https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 31 Jul 2023 06:21:42 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5513</guid>

					<description><![CDATA[<p>This blog particularly promotes Adobe&#8217;s AEM Sightly documentation, which lives inside of their github repository. In this article, we&#8217;ll explore the significance of AEM Sightly and how its official documentation can be a valuable resource for developers working with Adobe Experience Manager. With understanding Adobe&#8217;s Sightly documentation, you will be equipped with the right tools [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know">AEM Sightly Official Documentation: Everything You Need to Know</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This blog particularly promotes Adobe&#8217;s AEM Sightly documentation, which lives inside of their github repository. In this article, we&#8217;ll explore the significance of AEM Sightly and how its official documentation can be a valuable resource for developers working with Adobe Experience Manager. With understanding Adobe&#8217;s Sightly documentation, you will be equipped with the right tools to effectively and efficiently write AEM Sightly code.
</p>
<p>As per this article is written, Sightly is versioned as 1.4. If you wish to find out what version sightly your AEM environment is using, <a href="https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using#:~:text=Visit%20the%20system%20console%20bundles,see%20the%20versions%20being%20used." rel="noopener" target="_blank">you can refer to this article here, which it will explain you how to find out the Sightly Version</a>.</p>
<p>
   If you want to dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</p>
<div class="mention-block">
   <strong>Quick Links</strong></p>
<ol>
<li><a href="#what-is-sightly">What is AEM Sightly?</a></li>
<li><a href="#understanding-documentation">Understanding the Official Documentation</a></li>
<li><a href="#getting-started">Getting Started with AEM Sightly</a></li>
<li><a href="#sightly-syntax">Sightly Syntax and Expressions</a></li>
<li><a href="#templating-features">Templating Language Features</a></li>
<li><a href="#working-with-components">Working with Sightly in AEM Components</a></li>
<li><a href="#best-practices">Best Practices and Tips</a></li>
<li><a href="#extending-sightly">Extending Sightly</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<div id="what-is-sightly">
<h2>1. What is AEM Sightly?</h2>
<p>
      AEM Sightly is a templating language used for building components in Adobe Experience Manager. It offers a clean and efficient way to separate the presentation layer from the business logic, resulting in more maintainable and reusable code.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="understanding-documentation">
<h2>2. Understanding the Official Documentation</h2>
<p>
      The official documentation provided by Adobe for AEM Sightly is a comprehensive guide that covers all aspects of working with Sightly. It is organized into different sections, making it easy to find the information you need.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="getting-started">
<h2>3. Getting Started with AEM Sightly</h2>
<p>
      If you are new to AEM Sightly, the official documentation provides resources to help you get started. You&#8217;ll find step-by-step instructions on setting up your development environment for Sightly projects.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="sightly-syntax">
<h2>4. Sightly Syntax and Expressions</h2>
<p>
      Sightly introduces its own syntax, different from JSP, for creating templates. The documentation explains the Sightly syntax and how expressions are used within templates to dynamically render content.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="templating-features">
<h2>5. Templating Language Features</h2>
<p>
      Sightly offers a range of templating language features like conditionals, loops, and variable declarations. The official documentation provides clear examples and explanations of each feature to help you use them effectively in your projects.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="working-with-components">
<h2>6. Working with Sightly in AEM Components</h2>
<p>
      Learn how to create AEM components using Sightly and integrate them with HTML to build reusable components that enhance the overall user experience.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="best-practices">
<h2>7. Best Practices and Tips</h2>
<p>
      To make the most out of Sightly, the documentation shares best practices for efficient development and tips to avoid common mistakes.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="extending-sightly">
<h2>8. Extending Sightly</h2>
<p>
      For advanced users, the official documentation covers how to extend Sightly by writing custom Java Use-API classes to add additional functionality.
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<hr class="spacer-larger"/>
<div id="conclusion">
<h2>Conclusion</h2>
<p>
      AEM Sightly is a powerful templating language that empowers developers in Adobe Experience Manager projects. The official documentation provided by Adobe is an essential resource to understand and leverage the full potential of Sightly in your AEM development journey.
   </p>
<p>
      Throughout this article, we&#8217;ve explored the different aspects of the official documentation and how it can benefit developers. From getting started with Sightly to mastering its templating language features, the documentation acts as a comprehensive guide to help you build robust and efficient AEM components.
   </p>
<p>
      One of the significant advantages of the official documentation is that it is regularly updated by the Adobe team, ensuring that you have access to the latest features and best practices. Additionally, the documentation encourages a collaborative community, where you can contribute and share your insights to improve the experience for all users.
   </p>
<p>
      As you embark on your AEM Sightly development projects, we encourage you to make the most of the official documentation. By referring to it as your go-to resource, you&#8217;ll be equipped with the knowledge and skills needed to create outstanding experiences with Adobe Experience Manager.
   </p>
<p>
      Now that you know where to find the official documentation, dive in, explore, and take advantage of this invaluable resource. Whether you are a beginner or an experienced developer, the AEM Sightly official documentation will undoubtedly be your trusted companion on your journey to building exceptional AEM components.
   </p>
<p>
      Thank you for reading our blog article, and we hope it has inspired you to leverage AEM Sightly&#8217;s capabilities to create amazing digital experiences!
   </p>
<p>   Dive straight into the official documentation, you can access it on GitHub:<br />
   <a href="https://bit.ly/3OAzFIp" target="_blank" rel="noopener">AEM Sightly Documentation</a>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know">AEM Sightly Official Documentation: Everything You Need to Know</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sightly-official-documentation-everything-you-need-to-know/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM RichText Remove P Tag on Sightly</title>
		<link>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly</link>
					<comments>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 29 Jul 2023 03:29:27 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5365</guid>

					<description><![CDATA[<p>You may have been trying to search the internet for an out of box solution to remove the single paragraph container for Touch UI, and have found something like removeSingleParagraphContainer. But however, this attribute was for the Classic UI and deprecated. From my knowledge, there isn&#8217;t anything out of the box that can remove the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly">AEM RichText Remove P Tag on Sightly</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You may have been trying to search the internet for an out of box solution to remove the single paragraph container for Touch UI, and have found something like removeSingleParagraphContainer. But however, this attribute was for the Classic UI and deprecated. From my knowledge, there isn&#8217;t anything out of the box that can remove the p single paragraph container tag. However, I have spent some time and found a very lucrative solution. Lets remove the p tag from the rich text editor!</p>
<p>In this article, we will step through my implementation for us to remove the p tag once and for all, from being rendered. </p>
<p>My solution to this problem will be dealt with in the backend, Sling Model. Some may argue that the solution can be done using Javascript, but that can be very troublesome. Let&#8217;s Keep it Simple Stupid (KISS). There&#8217;s one caveat to this approach; scroll to the bottom of the page to see what it is.</p>
<p>Follow my 3 steps below to remove the P tag wrapper from what is being produced by the cq/gui/components/authoring/dialog/richtext.</p>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/WSS1Tfau4dc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<hr class="spacer-large"/>
<h3>Step 1. Add Custom Option In the Paraformat Options</h3>
<p>Under the _cq_dialog.xml, <strong>cq/gui/components/authoring/dialog/richtext</strong>, add a new format option under the paraformat list of options. </p>
<p>The selected paraformat option will be a custom HTML element that wraps onto the highlighted or selected text from the author. In this case, when the author have selected text, and then click on the new paraformat option, the Html will look something like this <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// new paraformt to be added into line:77<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notextformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;No - Text Format&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;notextformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
// the complete _cq_dialog.xml configuration for the cq/gui/components/authoring/dialog/richtext<br />
// new paraformt to be added into line:77<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog/richtext&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./text&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">useFixedInlineToolbar</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rtePlugins</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;format</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;bold,italic&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;justify</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;links</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;modifylink,unlink&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lists</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paraformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;formats</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_p</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Paragraph&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;p&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h1</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 1&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h2</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 2&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h3</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 3&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h4</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 4&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h4&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h5</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 5&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h5&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h6</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 6&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h6&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_blockquote</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Quote&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;blockquote&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_pre</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Preformatted&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;pre&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notextformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;No - Text Format&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;notextformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/formats<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paraformat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rtePlugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uiSettings</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cui</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inline</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">toolbar</span>=<span style="color: #ff0000;">&quot;[format#bold,format#italic,format#underline,#justify,#lists,links#modifylink,links#unlink,#paraformat]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;popovers</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;justify</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;[justify#justifyleft,justify#justifycenter,justify#justifyright]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;justify&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lists</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;[lists#unordered,lists#ordered,lists#outdent,lists#indent]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paraformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;paraformat:getFormats:paraformat-pulldown&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;paraformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/popovers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inline<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cui<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uiSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3>Step 2. Create the Backend, Sling Model, to Text Transform</h3>
<p>The backend Sling Model will read the ./text property that has been set by the user&#8217;s input. Using the String.ReplaceAll(), we can replace all <span class="code-highlight-secondary">&lt;/?notextformat&gt;</span>, regex pattern, with nothing (meaning that this element will be removed).</p>
<p>For example <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>. -> <span class="code-highlight-primary">sometext</span>.</p>
<p>We next save the formatted text into a variable of <span class="code-highlight-secondary"richText</span>, which can be used by sightly to display HTML on the page.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Default</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Optional</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ValueMapValue</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables<span style="color: #339933;">=</span>Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyTextComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Optional<br />
&nbsp; &nbsp; @ValueMapValue<br />
&nbsp; &nbsp; @<span style="color: #000000; font-weight: bold;">Default</span><span style="color: #009900;">&#40;</span>values <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> text<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> richText<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>text.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richText <span style="color: #339933;">=</span> text.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/?notextformat&gt;&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getRichText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> richText<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3>Step 3. Render Text Transform from Sightly</h3>
<p>Now finally we just need to utilise sightly to print the text transformed, <span class="code-highlight-primary">richText</span>, to the screen.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;sly data-sly-use.myTextComponent<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.MyTextComponent&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br />
${myTextComponent.richText @ context='html'}<br />
<span style="color: #009900;">&lt;sly data-sly-use.templates<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-call<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${templates.placeholder @ isEmpty = !myTextComponent.richText}&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<div class="mention-block">
<strong>Last Thoughts?</strong><br />
The caveat with this approach is that when you are trying to export JSON format from this component, you will be stuck with this block of text, <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>, unless if you text to transform the export as well.</p>
<p>The reason why I did not overwrite the JCR values is that I wanted to retain the natural editing experience for the authors. With my solution when the author decides to make changes to the rich text field, they would not have a werid experience.
</p></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly">AEM RichText Remove P Tag on Sightly</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-on-sightly/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Why Indexing in AEM is so important for Search</title>
		<link>https://sourcedcode.com/blog/aem/why-indexing-in-aem-is-so-important-for-search</link>
					<comments>https://sourcedcode.com/blog/aem/why-indexing-in-aem-is-so-important-for-search#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 29 Jul 2023 03:27:33 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5362</guid>

					<description><![CDATA[<p>As we are developers implement search, I would like to share the importance of indexing in AEM. I would like to express that this is a simple post, but enough information to get you to understand the importance of indexing. Continue and read the article below to see the significance &#038; Importance of Indexing in [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/why-indexing-in-aem-is-so-important-for-search">Why Indexing in AEM is so important for Search</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As we are developers implement search, I would like to share the importance of indexing in AEM. I would like to express that this is a simple post, but enough information to get you to understand the importance of indexing. Continue and read the article below to see the significance &#038; Importance of Indexing in AEM.</p>
<ol>
<li><strong>Improved Search Performance:</strong> Indexing enables rapid content searches, even in large repositories, improving search speed and efficiency.</li>
<li><strong>Enhanced User Experience:</strong> Quick and relevant search results lead to a seamless and satisfying user experience.</li>
<li><strong>Efficient Content Retrieval:</strong> Indexing enables swift access to specific content items, streamlining content management.</li>
<li><strong>Scalability and Performance:</strong> Indexing supports AEM&#8217;s scalability while maintaining high performance levels.</li>
<li><strong>Complex Querying Support:</strong> Indexing efficiently handles complex search queries with multiple filters and conditions.</li>
</ol>
<hr class="spacer-larger" />
<h2>Best Practices for Indexing</h2>
<ul>
<li><strong>Regular Updates:</strong> Schedule frequent index updates to reflect the latest content changes.</li>
<li><strong>Monitor Index Health:</strong> Keep track of index size and performance metrics to identify issues.</li>
<li><strong>Use Index Filters:</strong> Optimize the index&#8217;s size and relevancy by defining specific filters.</li>
<li><strong>Configure Indexing Properties:</strong> Properly configure indexing settings based on content nature and usage patterns.</li>
</ul>
<hr class="spacer-larger" />
<h2>Conclusion</h2>
<p>Indexing is a critical component of AEM, ensuring efficient content retrieval and enhanced user experiences. By following indexing best practices, organizations can fully unlock the potential of AEM for seamless content management and delivery.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/why-indexing-in-aem-is-so-important-for-search">Why Indexing in AEM is so important for Search</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/why-indexing-in-aem-is-so-important-for-search/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Effective Pagination with Query Builder API</title>
		<link>https://sourcedcode.com/blog/aem/aem-effective-pagination-with-query-builder-api</link>
					<comments>https://sourcedcode.com/blog/aem/aem-effective-pagination-with-query-builder-api#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 26 Jul 2023 03:23:47 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5359</guid>

					<description><![CDATA[<p>There are many ways to implement pagination for AEM content. Effectively choosing the right solution will indeed Bu decrease development time, and promote a performant experience to your end users. AEM has multiple search API&#8217;s like xPath, JCR SQL2, Node JCR, Query Builder, etc&#8230; But in my opinion, the Query Builder API would be the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-effective-pagination-with-query-builder-api">AEM Effective Pagination with Query Builder API</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are many ways to implement pagination for AEM content. Effectively choosing the right solution will indeed Bu decrease development time, and promote a performant experience to your end users. AEM has multiple search API&#8217;s like xPath, JCR SQL2, Node JCR, Query Builder, etc&#8230; But in my opinion, the Query Builder API would be the most effective decision when building a solution with pagination. In AEM, the Query Builder API has emerged as the preferred solution for creating pagination experiences. In this article, we will explore why the Query Builder API stands out as the go-to choice for pagination in AEM.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#understanding-pagination-in-aem">1. Understanding Pagination in AEM</a></li>
<li><a href="#the-query-builder-api-an-overview">2. The Query Builder API: An Overview</a></li>
<li>
        <a href="#benefits-of-the-query-builder-api-for-pagination">3. Benefits of the Query Builder API for Pagination</a></p>
<ul>
<li><a href="#performance-optimization">3a. Performance Optimization</a></li>
<li><a href="#flexibility-and-customization">3b. Flexibility and Customization</a></li>
<li><a href="#support-for-dynamic-content">3c. Support for Dynamic Content</a></li>
<li><a href="#facilitating-search-functionality">3d. Facilitating Search Functionality</a></li>
</ul>
</li>
<li>
        <a href="#pagination-and-more-features-with-query-builder-api">4. Pagination and More Features with Query Builder API</a></p>
<ul>
<li><a href="#offset-and-limit">4a.Offset and Limit</a></li>
<li><a href="#sorting">4b.Sorting</a></li>
<li><a href="#search-filters">4c.Search Filters</a></li>
<li><a href="#query-aggregation">4d.Query Aggregation</a></li>
<li><a href="#content-pre-fetching">4e. Content Pre-fetching</a></li>
</ul>
</li>
<li><a href="#a-simple-servlet-for-querying-pages-in-java">A Simple Servlet for Querying Pages in Java</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<h2 id="understanding-pagination-in-aem">1. Understanding Pagination in AEM</h2>
<p>What is pagination? In general, pagination is a process that divides large sets of content into smaller, more manageable sections, commonly referred to as &#8220;pages&#8221;; but however, with AEM, anything can be paginated. By doing so, users can navigate through content easily, without being presented with an exhaustive list all at once. In AEM, pagination is particularly crucial for content-heavy websites or applications, ensuring that visitors can access desired information quickly. You can probably imagine, when the page first loads, you can see the first 10 results, and clicking on &#8220;next&#8221;, you are able to see the next 10 results, and so on&#8230;</p>
<hr class="spacer-larger"/>
<h2 id="the-query-builder-api-an-overview">2. The Query Builder API: An Overview</h2>
<p>The Query Builder API is a powerful tool within AEM that allows developers to construct complex queries to retrieve content from the AEM repository. It is designed to provide a more flexible and efficient way of searching and fetching content than traditional JCR-SQL2 queries. The Query Builder API abstracts the underlying technology and provides an easy-to-use interface to interact with the AEM repository.</p>
<hr class="spacer-larger"/>
<h2 id="benefits-of-the-query-builder-api-for-pagination">3. Benefits of the Query Builder API for Pagination</h2>
<h3 id="performance-optimization">3a. Performance Optimization</h3>
<p>One of the primary reasons the Query Builder API is preferred for pagination in AEM is its ability to optimize performance. When dealing with large repositories, traditional queries can be resource-intensive and slow, impacting the page loading time and user experience. The Query Builder API, on the other hand, leverages optimized query execution, resulting in faster response times and enhanced page performance.</p>
<h3 id="flexibility-and-customization">3b. Flexibility and Customization</h3>
<p>The Query Builder API offers developers a wide range of parameters and options to fine-tune their queries. This level of flexibility enables developers to customize the pagination logic based on specific use cases. Whether it&#8217;s setting the number of items per page, defining sorting criteria, or filtering results, the Query Builder API empowers developers to tailor pagination experiences according to project requirements.</p>
<h3 id="support-for-dynamic-content">3c. Support for Dynamic Content</h3>
<p>In dynamic environments where content changes frequently, pagination needs to adapt to reflect these updates accurately. The Query Builder API can seamlessly handle dynamic content by providing real-time results based on the most recent data in the AEM repository. This ensures that the user always receives the latest content, maintaining an up-to-date and engaging user experience.</p>
<h3 id="facilitating-search-functionality">3d. Facilitating Search Functionality</h3>
<p>Pagination is often used in conjunction with search functionality to improve content discovery. The Query Builder API&#8217;s capability to perform complex searches across various content attributes makes it a natural fit for integrating search with pagination. By combining these features, users can easily find and navigate to the exact content they need.</p>
<hr class="spacer-larger"/>
<h2 id="pagination-and-more-features-with-query-builder-api">4. Pagination and More Features with Query Builder API</h2>
<h3 id="offset-and-limit">4a. Offset and Limit</h3>
<p>The Query Builder API allows developers to define the starting point (offset) and the maximum number of items (limit) to fetch for each page. This enables seamless navigation between pages, allowing users to access content beyond the first page of results.</p>
<h3 id="sorting">4b. Sorting</h3>
<p>To enhance user experience, pagination often goes hand in hand with sorting. The Query Builder API allows developers to specify sorting criteria based on content attributes. For example, you can sort content by date, popularity, or any other relevant property to ensure a logical order for the paginated results.</p>
<h3 id="search-filters">4c. Search Filters</h3>
<p>Incorporating search filters along with pagination empowers users to refine their search queries and find specific content efficiently. The Query Builder API enables developers to apply various filters and constraints to narrow down the results, creating a more personalized experience for users.</p>
<h3 id="query-aggregation">4d. Query Aggregation</h3>
<p>The Query Builder API also supports query aggregation, which enables developers to group results based on specific attributes. This feature is particularly useful when presenting aggregated data, such as categories or tags, in a paginated manner.</p>
<h3 id="content-pre-fetching">4e. Content Pre-fetching</h3>
<p>To further optimize user experience, the Query Builder API allows developers to implement content pre-fetching. By fetching additional content in the background, users experience faster loading times when navigating between pages, reducing any perceived delays.</p>
<hr class="spacer-larger"/>
<h2 id="a-simple-servlet-for-querying-pages-in-java">5. A Simple Servlet for Querying Pages in Java</h2>
<p>Below is an example of a simple Java servlet that uses the Query Builder API to query pages from the AEM repository for pagination purposes:</p>
<div class="code-750">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.propertytypes.ServiceRanking</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.PredicateGroup</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.QueryBuilder</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.result.SearchResult</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashMap</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/findPagePaths&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.extensions=json&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
@ServiceRanking<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1001</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Adjust the service ranking as per your requirement</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PaginatedPagesServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> QueryBuilder queryBuilder<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get request parameters for search and pagination</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> searchTerm <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;q&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> currentPage <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> pageSize <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Number of items per page</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Calculate the offset to start retrieving items</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> offset <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>currentPage <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> pageSize<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Build the query map for the QueryBuilder API</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> queryMap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; queryMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span>, <span style="color: #0000ff;">&quot;/content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Replace with your desired root path</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; queryMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span>, <span style="color: #0000ff;">&quot;cq:Page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; queryMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fulltext.relPath&quot;</span>, <span style="color: #0000ff;">&quot;jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; queryMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fulltext&quot;</span>, searchTerm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Use the &quot;q&quot; parameter for search terms</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; queryMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;p.offset&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>offset<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; queryMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;p.limit&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>pageSize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Execute the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryBuilder.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>PredicateGroup.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>queryMap<span style="color: #009900;">&#41;</span>, request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">SearchResult</span> result <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the paths of the pages from the search result using GJSON</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JSONArray pathsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result.<span style="color: #006633;">getHits</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000000; font-weight: bold;">forEach</span><span style="color: #009900;">&#40;</span>hit <span style="color: #339933;">-&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> path <span style="color: #339933;">=</span> hit.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pathsArray.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Send the paginated content (paths of the pages) to the response</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>pathsArray.<span style="color: #006633;">toJSONString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p>Curl</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"># Replace <span style="color: #0000ff;">&quot;http://your_server&quot;</span> with the base <span style="color: #003399;">URL</span> of your AEM instance.<br />
# Replace <span style="color: #0000ff;">&quot;/bin/findPagePaths?q=search_term&amp;page=1&quot;</span> with the path to your servlet,<br />
# the desired search term <span style="color: #009900;">&#40;</span>search_term<span style="color: #009900;">&#41;</span>, and the desired page number.<br />
<br />
# Search with <span style="color: #0000ff;">&quot;your_search_term&quot;</span> and get results <span style="color: #000000; font-weight: bold;">for</span> Page <span style="color: #cc66cc;">1</span><br />
curl <span style="color: #339933;">-</span>X GET <span style="color: #0000ff;">&quot;http://your_server/bin/findPagePaths?q=your_search_term&amp;page=1&quot;</span><br />
<br />
# Search with <span style="color: #0000ff;">&quot;another_search_term&quot;</span> and get results <span style="color: #000000; font-weight: bold;">for</span> Page <span style="color: #cc66cc;">2</span><br />
curl <span style="color: #339933;">-</span>X GET <span style="color: #0000ff;">&quot;http://your_server/bin/findPagePaths?q=another_search_term&amp;page=2&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h2 id="conclusion">5. Conclusion</h2>
<p>In conclusion, the Query Builder API in Adobe Experience Manager is a versatile and powerful tool that provides an ideal solution for implementing pagination experiences. With its performance optimization, flexibility, and support for dynamic content, the Query Builder API ensures that users can navigate through content-rich websites or applications seamlessly.</p>
<p>By incorporating features like offset and limit, sorting, search filters, query aggregation, and content pre-fetching, developers can create highly customizable and efficient pagination experiences for their AEM projects. Additionally, the provided Java servlet example demonstrates how the Query Builder API can be used to retrieve paginated content from the AEM repository. As AEM continues to evolve, leveraging the Query Builder API will remain essential for maintaining an excellent user experience and keeping users engaged with your content.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-effective-pagination-with-query-builder-api">AEM Effective Pagination with Query Builder API</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-effective-pagination-with-query-builder-api/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A Simple Guide to AEM Search APIs: Exploring Your Options for Powerful Search Functionality</title>
		<link>https://sourcedcode.com/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality</link>
					<comments>https://sourcedcode.com/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 01 Jul 2023 04:44:35 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=5330</guid>

					<description><![CDATA[<p>As an AEM developer, the ability and skill to identify solutions and implementations to quickly and efficiently search through vast amounts of content is crucial. Understanding the all the AEM platform&#8217;s search API capabilities will ensure you are a effective developer, when implementing solutions for AEM search. In this article, we will explore the various [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality">A Simple Guide to AEM Search APIs: Exploring Your Options for Powerful Search Functionality</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As an AEM developer, the ability and skill to identify solutions and implementations to quickly and efficiently search through vast amounts of content is crucial. Understanding the all the AEM platform&#8217;s search API capabilities will ensure you are a effective developer, when implementing solutions for AEM search. In this article, we will explore the various options provided by AEM Search APIs, enabling you to make informed decisions while implementing search capabilities within your AEM projects. Throughout each search API topic, we will provide code examples as well, so you know exactly what to expect.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#xpath-search-api">XPath Search API</a></li>
<li><a href="#jcr-sql2-search-api">JCR SQL2 Search API</a></li>
<li><a href="#query-builder-search-api">Query Builder Search API</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<h2 id="xpath-search-api">1. XPath Search API</h2>
<p>XPath is a query language that allows you to navigate through the nodes and elements of an XML document. In the context of AEM, XPath queries can be used to search for content within the JCR (Java Content Repository) repository. While XPath is a powerful and flexible query language, it is essential to use it judiciously, as complex queries can have performance implications.</p>
<p><strong>Some Benefits and Features:</strong></p>
<ol>
<li>XPath Queries: XPath is a versatile query language that enables you to navigate through XML documents and locate specific nodes or elements within the content repository.</li>
<li>Flexibility: XPath queries offer high flexibility and allow you to search content based on various criteria, making it suitable for complex search requirements.</li>
<li>Node Structure: XPath queries rely on the hierarchical structure of nodes, making it well-suited for navigating and filtering content with a fixed structure.</li>
<li>Rich Expressions: With XPath, you can employ a wide range of expressions, such as text matching, attribute filtering, and range-based searches.<br />
Dynamic Content: XPath can handle dynamic content, but developers should be cautious with complex queries as they may impact performance.</li>
</ol>
<p><strong>JAVA Example:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.NodeIterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryResult</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Assuming you have access to the JCR Session object (session)</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; QueryManager queryManager <span style="color: #339933;">=</span> session.<span style="color: #006633;">getWorkspace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQueryManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> xpathQuery <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/jcr:root/content//*[@jcr:contains(., 'searchKeyword')]&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>xpathQuery, Query.<span style="color: #006633;">XPATH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; QueryResult result <span style="color: #339933;">=</span> query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; NodeIterator nodeIterator <span style="color: #339933;">=</span> result.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Node node <span style="color: #339933;">=</span> nodeIterator.<span style="color: #006633;">nextNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the node that matches the search criteria</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>node.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h2 id="jcr-sql2-search-api">2. JCR SQL2 Search API</h2>
<p>JCR SQL2 is a structured query language designed specifically for the Java Content Repository. It provides an SQL-like syntax for querying content stored in the repository. JCR SQL2 queries are generally more straightforward to use compared to XPath and are often preferred for basic search requirements due to their familiarity to developers familiar with SQL.</p>
<p><strong>Some Benefits and Features:</strong></p>
<ol>
<li>SQL-Like Syntax: JCR SQL2 provides a structured query language with an SQL-like syntax, making it more familiar to developers experienced in working with relational databases.</li>
<li>Simplicity: JCR SQL2 queries are generally more straightforward to use compared to XPath, especially for developers already familiar with SQL.</li>
<li>Dynamic Queries: JCR SQL2 supports dynamic queries, allowing you to parameterize search criteria and adapt to changing requirements.</li>
<li>Performance Optimization: When used appropriately, JCR SQL2 can offer better performance for complex queries that involve multiple content nodes and properties.</li>
<li>Full-Text Search: JCR SQL2 supports full-text search using the CONTAINS function, enabling text-based searches on content.</li>
</ol>
<p><strong>JAVA Example:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.NodeIterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryResult</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Assuming you have access to the JCR Session object (session)</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; QueryManager queryManager <span style="color: #339933;">=</span> session.<span style="color: #006633;">getWorkspace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQueryManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> sql2Query <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM [nt:unstructured] AS node WHERE CONTAINS(node.*, 'searchKeyword')&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>sql2Query, Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; QueryResult result <span style="color: #339933;">=</span> query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; NodeIterator nodeIterator <span style="color: #339933;">=</span> result.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Node node <span style="color: #339933;">=</span> nodeIterator.<span style="color: #006633;">nextNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the node that matches the search criteria</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>node.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h2 id="query-builder-search-api">3. Query Builder Search API</h2>
<p>The Query Builder API is a high-level API provided by AEM to build and execute queries against the repository. It acts as a wrapper around the underlying query languages (XPath or JCR SQL2) and provides a more intuitive and developer-friendly interface for constructing complex queries. The Query Builder API abstracts away the complexity of query languages and is recommended for most search scenarios in AEM.</p>
<p><strong>Some Benefits and Features:</strong></p>
<ol>
<li>High-Level API: The Query Builder API is a powerful and high-level abstraction for constructing and executing queries against the repository.</li>
<li>Developer-Friendly: The Query Builder API provides a more intuitive interface compared to raw query languages, making it easier for developers to build complex queries.</li>
<li>Abstraction of Complexity: The API abstracts away the underlying query language, making it more accessible to developers without extensive knowledge of XPath or JCR SQL2.</li>
<li>Faceted Search: The Query Builder API supports faceted search, enabling users to filter search results based on predefined categories or facets.</li>
<li>Spell Checker and Suggestions: The API includes built-in support for spell checking and real-time suggestions, improving the search experience for users.</li>
<li>Great for Pagination: The Query Builder API offers built-in pagination support, allowing you to retrieve search results in manageable chunks. This is particularly useful when dealing with large result sets, as it enhances performance and reduces memory consumption.</li>
</ol>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.PredicateGroup</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.QueryBuilder</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Assuming you have access to the ResourceResolver object (resourceResolver)</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; QueryBuilder queryBuilder <span style="color: #339933;">=</span> resourceResolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>QueryBuilder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> searchKeyword <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;searchKeyword&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Building the predicate for the query</span><br />
&nbsp; &nbsp; PredicateGroup predicateGroup <span style="color: #339933;">=</span> PredicateGroup.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;group.1_property&quot;</span>, <span style="color: #0000ff;">&quot;jcr:content/@jcr:title&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;group.1_property.operation&quot;</span>, <span style="color: #0000ff;">&quot;fulltext&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;group.1_property.value&quot;</span>, searchKeyword<br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryBuilder.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>predicateGroup, resourceResolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">search</span>.<span style="color: #006633;">result</span>.<span style="color: #003399;">SearchResult</span> result <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">search</span>.<span style="color: #006633;">result</span>.<span style="color: #006633;">Hit</span> hit <span style="color: #339933;">:</span> result.<span style="color: #006633;">getHits</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> path <span style="color: #339933;">=</span> hit.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Process the hit node that matches the search criteria</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exceptions</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality">A Simple Guide to AEM Search APIs: Exploring Your Options for Powerful Search Functionality</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/a-simple-guide-to-aem-search-apis-exploring-your-options-for-powerful-search-functionality/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Query Builder Examples with Content Fragments</title>
		<link>https://sourcedcode.com/blog/aem/aem-query-builder-examples-with-content-fragments</link>
					<comments>https://sourcedcode.com/blog/aem/aem-query-builder-examples-with-content-fragments#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 02 May 2023 03:34:23 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Content Fragment]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4804</guid>

					<description><![CDATA[<p>In this article, I will share some example AEM Query Builder API Search Queries that queries for Content Fragments. 1. Find all Content Fragments with Content Fragment Model 123456type=dam:Asset path=/content/dam/sourcedcode boolproperty=jcr:content/contentFragment boolproperty.value=true property=jcr:content/data/cq:model property.value=/conf/sourcedcode/settings/dam/cfm/models/model1 http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1 2. Find all Content Fragments with Content Fragment Model &#038; Property 12345678type=dam:Asset path=/content/dam/sourcedcode boolproperty=jcr:content/contentFragment boolproperty.value=true 1_property=jcr:content/data/cq:model 1_property_1.value=/conf/sourcedcode/settings/dam/cfm/models/model1 2_property=jcr:content/data/master/title 2_property.value=example http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fdam%2Fsourcedcode%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0A1_property%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0A1_property_1.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1%0D%0A2_property%3Djcr%3Acontent%2Fdata%2Fmaster%2Ftitle%0D%0A2_property.value%3Dexample [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-query-builder-examples-with-content-fragments">AEM Query Builder Examples with Content Fragments</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, I will share some example AEM Query Builder API Search Queries that queries for Content Fragments.</p>
<hr class="spacer-large" />
<h3>1. Find all Content Fragments with Content Fragment Model</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">type<span style="color: #339933;">=</span>dam<span style="color: #339933;">:</span>Asset<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>sourcedcode<br />
boolproperty<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>contentFragment<br />
boolproperty.<span style="color: #006633;">value</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>model<br />
property.<span style="color: #006633;">value</span><span style="color: #339933;">=/</span>conf<span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>settings<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>cfm<span style="color: #339933;">/</span>models<span style="color: #339933;">/</span>model1</div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1</a></p>
<hr class="spacer-large" />
<h3>2. Find all Content Fragments with Content Fragment Model &#038; Property</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">type<span style="color: #339933;">=</span>dam<span style="color: #339933;">:</span>Asset<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>sourcedcode<br />
boolproperty<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>contentFragment<br />
boolproperty.<span style="color: #006633;">value</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
<span style="color: #cc66cc;">1</span>_property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>model<br />
<span style="color: #cc66cc;">1</span>_property_1.<span style="color: #006633;">value</span><span style="color: #339933;">=/</span>conf<span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>settings<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>cfm<span style="color: #339933;">/</span>models<span style="color: #339933;">/</span>model1<br />
<span style="color: #cc66cc;">2</span>_property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>master<span style="color: #339933;">/</span>title<br />
<span style="color: #cc66cc;">2</span>_property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span>example</div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fdam%2Fsourcedcode%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0A1_property%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0A1_property_1.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1%0D%0A2_property%3Djcr%3Acontent%2Fdata%2Fmaster%2Ftitle%0D%0A2_property.value%3Dexample" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fdam%2Fsourcedcode%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0A1_property%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0A1_property_1.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1%0D%0A2_property%3Djcr%3Acontent%2Fdata%2Fmaster%2Ftitle%0D%0A2_property.value%3Dexample</a></p>
<hr class="spacer-large" />
<h3>4. Find all Content Fragments with Content Fragment Model &#038; Full Text Search</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">type<span style="color: #339933;">=</span>dam<span style="color: #339933;">:</span>Asset<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>dam<br />
boolproperty<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>contentFragment<br />
boolproperty.<span style="color: #006633;">value</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>model<br />
property.<span style="color: #006633;">value</span><span style="color: #339933;">=/</span>conf<span style="color: #339933;">/</span>wknd<span style="color: #339933;">-</span>shared<span style="color: #339933;">/</span>settings<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>cfm<span style="color: #339933;">/</span>models<span style="color: #339933;">/</span>adventure<br />
fulltext<span style="color: #339933;">=</span>a<br />
fulltext.<span style="color: #006633;">relPath</span><span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>master</div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;facets=on&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fwknd-shared%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fadventure%0D%0Afulltext%3Da%0D%0Afulltext.relPath%3Djcr%3Acontent%2Fdata%2Fmaster%0D%0A" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;facets=on&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fwknd-shared%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fadventure%0D%0Afulltext%3Da%0D%0Afulltext.relPath%3Djcr%3Acontent%2Fdata%2Fmaster%0D%0A</a></p>
<hr class="spacer-large" />
<h3>4. Find all Content Fragments &#038; Full Text Search</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">type<span style="color: #339933;">=</span>dam<span style="color: #339933;">:</span>Asset<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>sourcedcode<br />
boolproperty<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>contentFragment<br />
boolproperty.<span style="color: #006633;">value</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>model<br />
property.<span style="color: #006633;">value</span><span style="color: #339933;">=/</span>conf<span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>settings<span style="color: #339933;">/</span>dam<span style="color: #339933;">/</span>cfm<span style="color: #339933;">/</span>models<span style="color: #339933;">/</span>model1<br />
fulltext<span style="color: #339933;">=</span>full text</div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;facets=on&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%2Fsourcedcode%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1%0D%0Afulltext%3Dfull+text">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;facets=on&#038;query=type%3Ddam%3AAsset%0D%0Apath%3D%2Fcontent%2Fdam%2Fsourcedcode%0D%0Aboolproperty%3Djcr%3Acontent%2FcontentFragment%0D%0Aboolproperty.value%3Dtrue%0D%0Aproperty%3Djcr%3Acontent%2Fdata%2Fcq%3Amodel%0D%0Aproperty.value%3D%2Fconf%2Fsourcedcode%2Fsettings%2Fdam%2Fcfm%2Fmodels%2Fmodel1%0D%0Afulltext%3Dfull+text</a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-query-builder-examples-with-content-fragments">AEM Query Builder Examples with Content Fragments</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-query-builder-examples-with-content-fragments/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>@SlingServletPaths Example Code in AEM</title>
		<link>https://sourcedcode.com/blog/aem/slingservletpaths-example-code-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/slingservletpaths-example-code-in-aem#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 02 May 2023 03:01:49 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4796</guid>

					<description><![CDATA[<p>This is a quick reference to example code, which will show you how to use the most base instantiation of @SlingServletPaths. The output is a simple JSON response with application/JSON, 200 OK, and response body = { &#8220;property1&#8221;: &#8220;value1&#8221; }. Quick note: it&#8217;s not recommended to use @SlingServletPaths. Check out the caveats when implementing servlets [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/slingservletpaths-example-code-in-aem">@SlingServletPaths Example Code in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This is a quick reference to example code, which will show you how to use the most base instantiation of @SlingServletPaths. The output is a simple JSON response with application/JSON, 200 OK, and response body = { &#8220;property1&#8221;: &#8220;value1&#8221; }.</p>
<div class="mention-block">
<strong>Quick note:</strong><br />
it&#8217;s not recommended to use @SlingServletPaths. Check out the caveats when implementing servlets with path, @SlingServletPaths, <a href="https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type">https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type</a>
</div>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gson.JsonObject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.servlets.annotations.SlingServletPaths</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
@SlingServletPaths<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/bin/example&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FindContentFragmentServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JsonObject jo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jo.<span style="color: #006633;">addProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;property1&quot;</span>, <span style="color: #0000ff;">&quot;value1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jo.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>SlingHttpServletResponse.<span style="color: #006633;">SC_OK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger" />
<h3>Example of Servlet Being Called</h3>
<p><strong>Test:</strong> When I call http://localhost:4502/bin/example, I expect to see a JSON response with application/JSON, 200 OK, and response body = { &#8220;property1&#8221;: &#8220;value1&#8221; }. The example shows that the tests are passing.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example.png" alt="" width="1974" height="1534" class="alignnone size-full wp-image-4798" srcset="https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example.png 1974w, https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example-300x233.png 300w, https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example-1024x796.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example-768x597.png 768w, https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example-1536x1194.png 1536w, https://sourcedcode.com/wp-content/uploads/2023/05/SlingServletPaths-example-600x466.png 600w" sizes="(max-width: 1974px) 100vw, 1974px" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/slingservletpaths-example-code-in-aem">@SlingServletPaths Example Code in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/slingservletpaths-example-code-in-aem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Style System Component Information with Code Sling Models</title>
		<link>https://sourcedcode.com/blog/aem/aem-style-system-component-information-with-code-sling-models</link>
					<comments>https://sourcedcode.com/blog/aem/aem-style-system-component-information-with-code-sling-models#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 13 Apr 2023 00:41:21 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4606</guid>

					<description><![CDATA[<p>As an AEM full-stack web developer who frequently works with AEM components, it&#8217;s not uncommon to require access to the AEM Style System configuration of a specific component. This information can prove invaluable when writing conditional algorithms to manipulate data output. However, the question remains: how can one retrieve the necessary AEM Style System information [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-style-system-component-information-with-code-sling-models">AEM Style System Component Information with Code Sling Models</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As an AEM full-stack web developer who frequently works with AEM components, it&#8217;s not uncommon to require access to the AEM Style System configuration of a specific component. This information can prove invaluable when writing conditional algorithms to manipulate data output. However, the question remains: how can one retrieve the necessary AEM Style System information from within the components themselves via the backend?</p>
<p>Thankfully, Adobe offers a useful tool in the form of the com.adobe.cq.wcm.style.ComponentStyleInfo Sling model utility class. This class provides a straightforward means of accessing vital information about the styles applied to a component via Style System. By utilizing the methods provided by ComponentStyleInfo, developers can quickly and easily obtain the style information necessary to enhance the functionality of their AEM components.</p>
<p>In this blog article you will find examples on how to get the AEM Component&#8217;s Style System configuration from the backend using sling models or just with the resource object itself.</p>
<hr class="spacer-large"/>
<h4>A. Code Example of resource.adaptTo(ComponentStyleInfo.class)</h4>
<p>In the examples below we will observe a targeted component as a &#8220;Resource&#8221; which we will adapt the ComponentStyleInfo.class.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">ComponentStyleInfo componentStyleInfo <span style="color: #339933;">=</span> resource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>ComponentStyleInfo.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Once the resource have been adapted, you can see all these available properties. Here you can access the entire component&#8217;s policies, like the ability to view:</p>
<ul>
<li><strong>appliedCssClasses</strong>: list of applied CSS classes (this is a String type).</li>
<li><strong>styles</strong>: Which is a list of the AEM Style System items that has been selected, with all the meta data involved (this is a LinkedList type)</li>
<li><strong>contentPolicyStyleInfo</strong>: this an object that exposes the entire AEM Style System, Style Groups, that is configured for this given component.</li>
</ul>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/04/ComponentStyleInfo-debug-example.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/04/ComponentStyleInfo-debug-example.png" alt="Screenshot of the ComponentStyleInfo-debug" width="500" class="alignnone size-full wp-image-4610" srcset="https://sourcedcode.com/wp-content/uploads/2023/04/ComponentStyleInfo-debug-example.png 732w, https://sourcedcode.com/wp-content/uploads/2023/04/ComponentStyleInfo-debug-example-287x300.png 287w, https://sourcedcode.com/wp-content/uploads/2023/04/ComponentStyleInfo-debug-example-600x627.png 600w" sizes="(max-width: 732px) 100vw, 732px" /></a></p>
<hr class="spacer-large"/>
<div class="mention-block">
It&#8217;s common that developers would only want to retrieve the list of appliedCssClasses, and so, here&#8217;s an example below where only the appliedCssClasses will be returned to the backend developer. The appliedCssClasses is then used to validate if my class exists, and if so, execute some code&#8230; if not, do nothing.
</div>
<hr class="spacer-large"/>
<h4>B. Code Example of testing appliedCssClasses</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #003399;">String</span> appliedCssClasses <span style="color: #339933;">=</span> Optional.<span style="color: #006633;">ofNullable</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">resource</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>ComponentStyleInfo.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp;.<span style="color: #006633;">map</span><span style="color: #009900;">&#40;</span>ComponentStyleInfo<span style="color: #339933;">::</span>getAppliedCssClasses<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp;.<span style="color: #006633;">filter</span><span style="color: #009900;">&#40;</span>StringUtils<span style="color: #339933;">::</span>isNotBlank<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp;.<span style="color: #006633;">orElse</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>appliedCssClasses.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my-class&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">// execute</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">// do nothing</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-style-system-component-information-with-code-sling-models">AEM Style System Component Information with Code Sling Models</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-style-system-component-information-with-code-sling-models/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Checking run mode from Sightly HTL in AEM in 2023</title>
		<link>https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023</link>
					<comments>https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 07 Apr 2023 00:45:32 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4625</guid>

					<description><![CDATA[<p>While we are developing in the modern world of AEM, sometimes we may want to understand if our backend implementation is being executed under &#8220;development&#8221;, &#8220;staging&#8221;, and &#8220;production&#8221;. In the past, we use the SlingSettingsService, but unfortunately, the SlingSettingsService is flagged as a deprecated service in AEM. According to one of the most prominent AEM [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023">Checking run mode from Sightly HTL in AEM in 2023</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>While we are developing in the modern world of AEM, sometimes we may want to understand if our backend implementation is being executed under &#8220;development&#8221;, &#8220;staging&#8221;, and &#8220;production&#8221;. In the past, we use the SlingSettingsService, but unfortunately, the SlingSettingsService is flagged as a deprecated service in AEM. According to one of the most prominent AEM enthusiasts in the AEM world, he says &#8220;I would go so far as to say, that the use of slingSettings.getRunModes() should be considered bad practice in AEM project code.&#8221;&#8230; for whatever reason.</p>
<p>However, sometimes in our implementation, we are actually likely to get the current run mode from the AEM backend so that we can execute some unique operations. In this article, I will share with you my very simple solution for retrieving the current run mode, so you can do what you need to do.</p>
<div class="mention-block">
<strong>slingSettingsService is a deprecated service</strong><br />
In our last <a href="https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem" rel="noopener" target="_blank">blog</a> post, We understand that the slingSettingsService is a deprecated service, and you would still like to find a way to retrieve the run mode where it equals to “development”, “staging”, or “production”, This is our response to it.
</div>
<hr class="spacer-large" />
<h3>Solution:</h2>
<p>Create an AEM run mode OSGI service which will have the ability to return us to either &#8220;development&#8221;, &#8220;staging&#8221;, &#8220;production&#8221;. This OSGI service will be a very simple service where it behaves like a configuration service in AEM; we will name this the RunModeIdentifierService. </p>
<p>Where with the help of the @ObjectClassDefinition and @Designate we will declare the &#8220;runMode&#8221; property in the OSGI Service. Next using the standard AEM configuration for defining configuration properties for a run mode, we will place the service configuration inside of the run mode configuration folders. The run mode is indicated by a suffix on the folder name. This allows you to store all configurations in one repository as. For example:</p>
<p>/apps/sourcedcode/config.development<br />
/apps/sourcedcode/config.staging<br />
/apps/sourcedcode/config.production</p>
<hr class="spacer-large" />
<h3>A. Create an interface for your RunModeIdentifierService</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.glob.sourcedcode.core.services</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> RunModeIdentifierService <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* @return runMode that is configured in the com.glob.sourcedcode.core.services.impl.RunModeIdentifierServiceImpl.cfg.json within it's run mode configuration folder.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> getRunMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h3>B. Create an implementation for your RunModeIdentifierService</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.glob.sourcedcode.core.services.impl</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.glob.sourcedcode.core.services.RunModeIdentifierService</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Activate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.AttributeDefinition</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.AttributeType</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.Designate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.ObjectClassDefinition</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> RunModeIdentifierService.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
@Designate<span style="color: #009900;">&#40;</span>ocd <span style="color: #339933;">=</span> RunModeIdentifierServiceImpl.<span style="color: #006633;">Config</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RunModeIdentifierServiceImpl <span style="color: #000000; font-weight: bold;">implements</span> RunModeIdentifierService <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @ObjectClassDefinition<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Run Mode Identifier Service&quot;</span>, description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This service is used to identify the run mode which this context is currently running on.&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> Config <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Run Mode&quot;</span>, description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;The current run mode identifier for this current context e.g. &quot;</span>development<span style="color: #0000ff;">&quot;,&quot;</span>staging<span style="color: #0000ff;">&quot;,&quot;</span>production<span style="color: #0000ff;">&quot;&quot;</span>, type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> runMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> runMode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Activate<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> active<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Config config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; runMode <span style="color: #339933;">=</span> config.<span style="color: #006633;">runMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getRunMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> runMode<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h3>C. Create 3 configuration files, and place them under the run mode configuration folders</h3>
<p>/apps/sourcedcode/config.development/com.sonova.advancedbionics.core.services.impl.RunModeIdentifierServiceImpl.cfg.json</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;runMode&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;development&quot;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>/apps/sourcedcode/config.staging/com.sonova.advancedbionics.core.services.impl.RunModeIdentifierServiceImpl.cfg.json</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;runMode&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;staging&quot;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>/apps/sourcedcode/config.production/com.sonova.advancedbionics.core.services.impl.RunModeIdentifierServiceImpl.cfg.json</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;runMode&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;production&quot;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h3>D. Example Sling Model using the RunModeIdentifierService</h3>
<p>And finally, in this example, we are using the @OSGiService RunModeIdentifierService that calls runModeIdentifierService.getRunMode(), which returns the correct value set in com.sonova.advancedbionics.core.services.impl.RunModeIdentifierServiceImpl.cfg.json for the given run mode folder, /apps/sourcedcode/config.${runmode-folder}</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.glob.sourcedcode.core.internal.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.export.json.ExporterConstants</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.fasterxml.jackson.annotation.JsonGetter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.glob.sourcedcode.core.services.RunModeIdentifierService</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.glob.base.core.components.util.AbstractComponentImpl</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Exporter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.OSGiService</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, resourceType <span style="color: #339933;">=</span> ExampleComponentImpl.<span style="color: #006633;">RESOURCE_TYPE</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
@Exporter<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> ExporterConstants.<span style="color: #006633;">SLING_MODEL_EXPORTER_NAME</span>, extensions <span style="color: #339933;">=</span> ExporterConstants.<span style="color: #006633;">SLING_MODEL_EXTENSION</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponentImpl <span style="color: #000000; font-weight: bold;">extends</span> AbstractComponentImpl <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> RESOURCE_TYPE <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sourcedcode/components/examplecomponent&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> runMode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @OSGiService<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> RunModeIdentifierService runModeIdentifierService<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; runMode <span style="color: #339933;">=</span> runModeIdentifierService.<span style="color: #006633;">getRunMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @JsonGetter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;runMode&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> getRunMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> runMode<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023">Checking run mode from Sightly HTL in AEM in 2023</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Set AEM Local Environment and Secret Variables AEMaaCS</title>
		<link>https://sourcedcode.com/blog/aem/set-aem-local-environment-and-secret-variables-aemaacs</link>
					<comments>https://sourcedcode.com/blog/aem/set-aem-local-environment-and-secret-variables-aemaacs#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 30 Mar 2023 00:39:10 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[AEMaaCS]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4545</guid>

					<description><![CDATA[<p>As an AEM developer developing for the AEMaaCS SDK, it&#8217;s essential to have a local environment properly set up for development purposes. You may encounter environment-specific and secret variables in your OSGI configuration files. As an AEM developer trying to familiarize new features of the AEMaaCS SDK development environment, setting up environment-specific and secret variables [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/set-aem-local-environment-and-secret-variables-aemaacs">Set AEM Local Environment and Secret Variables AEMaaCS</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As an AEM developer developing for the AEMaaCS SDK, it&#8217;s essential to have a local environment properly set up for development purposes. You may encounter environment-specific and secret variables in your OSGI configuration files. As an AEM developer trying to familiarize new features of the AEMaaCS SDK development environment, setting up environment-specific and secret variables is non-trivial at first. Once you have done it once, it will be much easier to move forward. </p>
<p>In this article, I will show you how to set up environment-specific and secret variables. If you would like to understand when to use environment-specific and secret variables effectively, check out the official AEM Adobe git documentation. At the end of this article, you are equipped to run your AEM local development environment with environment-specific and secret variables!</p>
<p>One last thing, it looks like only AEMaaCS SDK has environment-specific and secret variables feature enabled for OSGI configurations.</p>
<hr class="spacer-large"/>
<h5>Examples of what OSGI configurations would look like with environment and secret variables set in your code base:</h5>
<p><strong>Environment-specific variable</strong><br />
high-level use-case: Values that are specific to a particular environment and may vary between different development environments cannot be targeted accurately by run mode, as AEMaaCS only has a single development run mode. For instance:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[env:SERVER_API_URL]&quot;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Secret variable</strong><br />
high-level use-case: Sensitive information, such as confidential data or authentication credentials, should not be stored in Git repositories due to security concerns. For instance:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;api-key&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[secret:SERVER_API_KEY]&quot;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Example of an OSGI configuration with the combination of the environment-specific and secret variables being used:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;connection.timeout&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;api-key&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[secret:SERVER_API_KEY]&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[env:SERVER_API_URL]&quot;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
Please note that environment-specific and secret variables allow defaults, so if your environment is not set up properly with the right configuration, it will use the default settings.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;connection.timeout&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;api-key&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[secret:SERVER_API_KEY;default=https://api.sourcedcode.com&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #3366CC;">&quot;,<br />
&nbsp; &nbsp;&quot;</span>url<span style="color: #3366CC;">&quot;: &quot;</span>$<span style="color: #009900;">&#91;</span>env<span style="color: #339933;">:</span>SERVER_API_URL<span style="color: #339933;">;</span><span style="color: #000066; font-weight: bold;">default</span><span style="color: #339933;">=</span>23u1kn1jbkjs789fds8f_ewrqasd<span style="color: #009900;">&#93;</span><span style="color: #3366CC;">&quot;<br />
}<br />
From the &lt;a href=&quot;</span>https<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//github.com/AdobeDocs/experience-manager-cloud-service.en/blob/main/help/implementing/deploying/configuring-osgi.md&quot; rel=&quot;noopener&quot; target=&quot;_blank&quot;&gt;documentation&lt;/a&gt;, it looks like only AEMaaCS has environment-specific and secret variables feature enabled for OSGI configurations.</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large"/>
<p>So how we can actually set these environments and secret variables into AEM? Well, it&#8217;s simple. We will be using a Linux environment to set this up. In the examples below, we will be setting up one environment-specific variable and one secret variable.</p>
<ul>
<li>$[env:SERVER_API_URL]</li>
<li>$[secret:SERVER_API_KEY]</li>
</ul>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;connection.timeout&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[env:SERVER_API_URL]&quot;</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;api-key&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$[secret:SERVER_API_KEY]&quot;</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2>1. set AEM Environment variables on local AEM instance</h2>
<ol>
<li>Close down your local AEM environment.</li>
<li>open git bash or terminal.</li>
<li>cd to the AEM folder, where the executable jar file exists.</li>
<li>run <span class="code-highlight-primary">export SERVER_API_URL=https://api.sourcedcode.com</span></li>
<li>run <span class="code-highlight-primary">echo ${SERVER_API_URL}</span>// you should see the environment variable being set as this call will echo out what the environment variable is for SERVER_API_URL.</li>
<li>now restart your local AEM environment.</li>
<li>done.</li>
</ol>
<hr class="spacer-large"/>
<h2>2. set AEM Secret variables on local AEM instance</h2>
<ol>
<li>Close down your local AEM environment.</li>
<li>open git bash or terminal.</li>
<li>cd to the AEM folder, where the executable jar file exists.</li>
<li>run <span class="code-highlight-primary">vim ./crx-quickstart/conf/quickstart.properties</span></li>
<li>add this to the last line <span class="code-highlight-primary">org.apache.felix.configadmin.plugin.interpolation.secretsdir=${sling.home}/secretsdir</span></li>
<li>save in vim.</li>
<li>run <span class="code-highlight-primary">mkdir ./crx-quickstart/secretsdir</span></li>
<li>run <span class="code-highlight-primary">cd ./crx-quickstart/secretsdir</span></li>
<li>run <span class="code-highlight-primary">echo &#8220;23u1kn1jbkjs789fds8f_ewrqasd&#8221; > SERVER_API_KEY</span></li>
<li>repeat the step-9 to add more secret variables into your AEM local environment. run <span class="code-highlight-primary">echo &#8220;secret_value&#8221; > secret_key</span></li>
<li>You may have more than 1 secret variable stored in the secretsdir folder: <a href="https://sourcedcode.com/wp-content/uploads/2023/03/secretsdir.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/03/secretsdir.png" alt="Example of showing many instances of secret variables declared" width="50%" height="auto" class="alignnone size-full wp-image-4569" srcset="https://sourcedcode.com/wp-content/uploads/2023/03/secretsdir.png 890w, https://sourcedcode.com/wp-content/uploads/2023/03/secretsdir-300x75.png 300w, https://sourcedcode.com/wp-content/uploads/2023/03/secretsdir-768x192.png 768w, https://sourcedcode.com/wp-content/uploads/2023/03/secretsdir-600x150.png 600w" sizes="(max-width: 890px) 100vw, 890px" /></a></li>
<li>now restart your local AEM environment.</li>
<li>done.</li>
</ol>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/set-aem-local-environment-and-secret-variables-aemaacs">Set AEM Local Environment and Secret Variables AEMaaCS</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/set-aem-local-environment-and-secret-variables-aemaacs/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sightly Component(s) Empty CQ PlaceHolder</title>
		<link>https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 25 Feb 2023 21:55:28 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4453</guid>

					<description><![CDATA[<p>In almost all cases, component&#8217;s that are not configured, dragged onto the page should have some sort of indicator telling content authors that they should configure the component; a few of us calls this the empty component placeholder or &#8220;cq-placeholder&#8221;. A novice AEM full-stack may not be geared with the right tools, and so they [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder">AEM Sightly Component(s) Empty CQ PlaceHolder</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In almost all cases, component&#8217;s that are not configured, dragged onto the page should have some sort of indicator telling content authors that they should configure the component; a few of us calls this the empty component placeholder or &#8220;cq-placeholder&#8221;. A novice AEM full-stack may not be geared with the right tools, and so they add unnecessary Sightly HTL code into the .html file, and try to create this indicator experience. Let&#8217;s not re-create the wheel. There&#8217;s actually an Adobe way to create the &#8220;placeholder&#8221; AEM component experience. This is using the Adobe WCM Core Component&#8217;s &#8220;core/wcm/components/commons/v1/templates.html” script; what exactly is the &#8220;core/wcm/components/commons/v1/templates.html”?</p>
<p>In the <a href="https://github.com/adobe/aem-core-wcm-components" rel="noopener" target="_blank">Adobe Core Component&#8217;s Library</a>, you will be able to find this particular file &#8220;<a href="https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/commons/v1/templates.html" rel="noopener" target="_blank">core/wcm/components/commons/v1/templates.html</a>&#8220;. This file is a template that renders an HTML element on the page with the &#8220;cq-placeholder&#8221; cssClass that makes the rendered element on the page look something like this.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html" width="1106" height="274" class="alignnone size-full wp-image-4478" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png 1106w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-300x74.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-1024x254.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-768x190.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-600x149.png 600w" sizes="(max-width: 1106px) 100vw, 1106px" /></a></p>
<p>When we inspect the <a href="https://github.com/adobe/aem-core-wcm-components/blob/main/content/src/content/jcr_root/apps/core/wcm/components/commons/v1/templates.html" rel="noopener" target="_blank">Adobe code</a>, you will see the sightly HTL code as like this:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>template.<span style="color: #006633;">placeholder</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${@ isEmpty, classAppend, emptyTextAppend}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>div data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>test<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${(wcmmode.edit || wcmmode.preview) &amp;&amp; isEmpty}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq-placeholder ${classAppend}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>emptytext<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${component.properties.jcr:title}${emptyTextAppend &amp;&amp; ' - '}${emptyTextAppend}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>We understand that we are using Sightly HTL Version: 1.4; where this version enables the feature &#8220;template &#038; calls&#8221;, and templates. From the code above, you can see that &#8220;core/wcm/components/commons/v1/templates.html&#8221; is a Sightly template, and its main purpose is to be called via &#8220;data-sly-use&#8221;. Line-1: This template accepts 3 parameters: isEmpty, classAppend, emptyTextAppend. Line-2: This template is declaring a new div, and <span style="color: red;">only rendered when (edit or preview mode) and isEmpty = true</span>. Line-3: This appends the cq-placeholder cssClass for this &lt;div&gt;, and include custom ${classAppend} if exists. Finally Line-4: renders the resource&#8217;s component.properties.jcr:title (component who calls this script) on the screen, and also appends ${emptyTextAppend} to the cq-placeholder&#8217;s text if present.</p>
<div class="mention-block">
<strong>core/wcm/components/commons/v1/templates.html accepts 3 parameters:</strong></p>
<ul>
<li>isEmpty: This value must be a boolean, which true will force the cq-template to appear.</li>
<li>classAppend: This value must be a string, where it will be appended to the rendered HTML cq-placeholder.</li>
<li>emptyTextAppend: This value must be a string, where text will be appended into the cq-placeholder.</li>
</ul>
</div>
<hr class="spacer-larger" />
<h2>Examples:</h2>
<p>&nbsp;</p>
<h3>1. Basic call example to &#8220;core/wcm/components/commons/v1/templates.html&#8221;</h3>
<p>In this example, you can see us calling the Sling Model backend &#8220;com.sourcedcode.core.components.models.Teaser&#8221;, and capturing the Sling Model in a &#8220;model&#8221; variable. Line-3, we understand that the templates.html is accepting the &#8220;isEmpty&#8221; parameter. The &#8220;isEmpty&#8221; parameter is evaluated with &#8220;!model.titleText&#8221; (this means if the model.titleText is empty or null it will return true). When &#8220;isEmpty&#8221; is true, then the cq-placeholder will be rendered, and if false. It will never be rendered.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">model</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.core.components.models.Teaser&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">template</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>call<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${template.placeholder @ isEmpty=!model.titleText}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html" width="1106" height="274" class="alignnone size-full wp-image-4478" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png 1106w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-300x74.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-1024x254.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-768x190.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-600x149.png 600w" sizes="(max-width: 1106px) 100vw, 1106px" /></a></p>
<hr class="spacer-larger" />
<h3>2. Second example to &#8220;core/wcm/components/commons/v1/templates.html&#8221;</h3>
<p>In this example, Line-3, you will notice that model.titleText &#038;&#038; model.descriptionText are being evaluated, and must not be null or empty. If the evaluation of isEmpty is true, cq-placeholder will be visible.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">model</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.core.components.models.Teaser&quot;</span><span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">template</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>call<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${template.placeholder @ isEmpty=!(model.titleText &amp;&amp; model.descriptionText)}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html" width="1106" height="274" class="alignnone size-full wp-image-4478" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal.png 1106w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-300x74.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-1024x254.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-768x190.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-normal-600x149.png 600w" sizes="(max-width: 1106px) 100vw, 1106px" /></a></p>
<hr class="spacer-larger" />
<h3>3. Third example to &#8220;core/wcm/components/commons/v1/templates.html&#8221;</h3>
<p>In this example, Line-3, notice that we are using other parameters to construct the cq-placeholder; classAppend, where we are passing in cmp-teaser as a customCSSClass. Line-4, we are utilizing the parameter, emptyTextAppend, where we can add custom description to the cq-placeholder. The expected behavior here is, when the evaluation of isEmpty is true, we expect to see the rendered cq-placeholder with some description test. See the screenshot below for an example.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">model</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.core.components.models.Teaser&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">template</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span> <br />
&nbsp; &nbsp; &nbsp;data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>call<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${template.placeholder @ isEmpty=!(model.titleText &amp;&amp; model.descriptionText), classAppend='cmp-teaser', <br />
&nbsp; &nbsp; &nbsp;emptyTextAppend='This component must be configured'}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description.png" alt="Screenshot of the place holder using core/wcm/components/commons/v1/templates.html with custom description" width="1070" height="328" class="alignnone size-full wp-image-4468" srcset="https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description.png 1070w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-300x92.png 300w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-1024x314.png 1024w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-768x235.png 768w, https://sourcedcode.com/wp-content/uploads/2023/02/screenshot-placeholder-teaser-custom-description-600x184.png 600w" sizes="(max-width: 1070px) 100vw, 1070px" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder">AEM Sightly Component(s) Empty CQ PlaceHolder</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sightly-components-empty-cq-placeholder/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Developers Courses 2023 That Really Helped Me</title>
		<link>https://sourcedcode.com/blog/aem/aem-developers-courses-2023-that-really-helped-me</link>
					<comments>https://sourcedcode.com/blog/aem/aem-developers-courses-2023-that-really-helped-me#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 22 Feb 2023 00:00:55 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3913</guid>

					<description><![CDATA[<p>There are a couple of courses that I would like to share that have really helped me, not just in interviews, but also in my daily AEM development regime. In my opinion, I think these are the best courses for anyone who is either getting started as an AEM developer or who is already working [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-developers-courses-2023-that-really-helped-me">AEM Developers Courses 2023 That Really Helped Me</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are a couple of courses that I would like to share that have really helped me, not just in interviews, but also in my daily AEM development regime. In my opinion, I think these are the best courses for anyone who is either getting started as an AEM developer or who is already working as an AEM developer for more than 2+ years. Even right now, today, since I started my AEM career in 2015, this course by far has really helped me by re-aligning AEM concepts and AEM development practices that are not in my every AEM development cycle. At the bottom of this article, take a look at the reasons <a href="#how-this-course-helped-me">how this course helped me</a>.</p>
<p>I believe any AEM developers at any level will benefit from these courses.</p>
<p>I put together a <span class="code-highlight-secondary"><strong>course roadmap, step by step</strong></span>, that you should follow, to really help you learn. <span class="code-highlight-secondary">You should step through each and every course from 1&#8230;the-end-of-the-table-of-contents</span>; I recommend this order. All these courses are offered by Plural Sight. Plural Sightly is a paid company that offers online video training courses for software developers, IT administrators, and creative professionals. If you subscribe to their training services, you will obtain more than just the courses I am listing below. </p>
<p>I did have a look at the udemy.com AEM courses. From my analysis, the udemy.com courses do not provide the same level of detail as the Plural Sight&#8217;s online training videos; udemy.com provides extremely high-level concepts with training material that does not include too many follow-me-code tutorials. So, I really appreciate the content that Plural Sight is offering, and it will really help any level of AEM developers refresh or upgrade their skills. If you use Plural Sight, you will not only get access to every AEM course listed below, but other technical courses that suits your needs.<!-- At the end of this article, you will find, "other helpful resources", which will link to other resources that you should checkout after you step through 1...the-end-of-the-table-of-contents. !--></p>
<ul>
<li><a href="#fundamentals-of-building-from-projects-in-aem">1. Fundamentals of Building from Projects in AEM</a></li>
<li><a href="#extending-adobe-experience-manager-foundations-backend">2. Fundamentals of Extending Adobe Experience Manager &#8211; Backend</a></li>
<li><a href="#develop-websites-and-components-in-adobe-experience-manager">3. Develop Websites and Components in Adobe Experience Manager</a></li>
<li><a href="#develop-websites-and-components-in-adobe-experience-manager-advanced">4. Develop Websites and Components in Adobe Experience Manager Advanced</a></li>
<li><a href="#extending-adobe-experience-manager-advanced">5. Extending Adobe Experience Manager Advanced</a></li>
<li><a href="#introduction-advanced-dialogs-with-granite-ui">6. Introduction &#038; Advanced Dialogs with Granite UI</a></li>
<li><a href="#aem-building-full-stack-components">7. AEM Building Full Stack Components</a></li>
<li><a href="#additional=resources">Additional Resources</a></li>
<li><a href="#how-this-course-helped-me">How this course helped me</a></li>
</ul>
<div class="mention-block" style="text-align:center">
The courses below are all <strong>PAID</strong> only, but you can get a 10-day free trial today from my affiliate link here, <a href="https://bit.ly/3DYcJw6" rel="noopener" target="_blank">Get PluralSight 10 Days for Free</a>.
</div>
<hr class="spacer-large" />
<h3 id="fundamentals-of-building-from-projects-in-aem">1. Fundamentals of Building from Projects in AEM</h3>
<p><strong>Course Length: (3.5hrs)</strong><br />
This course will teach you how to build and debug Adobe Experience Manager (AEM) packages and how you can use them to import and export content to and from AEM&#8217;s Java Content Repository (JCR.) Software required: Adobe Experience Manager, Maven.</p>
<p>This course includes learning of:</p>
<ul>
<li>Fundamentals of building projects in AEM</li>
<li>Pushing code and content into AEM with import and export</li>
<li>Building AEM projects with Maven</li>
<li>Understanding Maven pom.xml</li>
<li>Setting up IDE environments like IntelliJ and Eclipse</li>
<li>Enable AEM for debug mode with IntelliJ or Eclipse</li>
<li>Understanding what is happening with code and content is built in AEM</li>
<li>Working with the content package manager and content packages via filters</li>
<li>Fundamentals of OSGI cofigurations</li>
</ul>
<p><a href="https://pluralsight.pxf.io/5bVb2o" rel="noopener" target="_blank">https://www.pluralsight.com/courses/aem-fundamentals-building-projects</a></p>
<hr class="spacer-large" />
<h3 id="extending-adobe-experience-manager-foundations-backend">2. Fundamentals Extending Adobe Experience Manager &#8211; Backend</h3>
<p><strong>Course Length: (2hrs)</strong><br />
This course is extending #1 Fundamentals of Building from Projects in AEM. This course is ideal for backend developers and focuses on developing services, servlets, and jobs in AEM. This course is retired, but it does have some concepts that I think AEM developers should understand.</p>
<p>This course includes learning of:</p>
<ul>
<li>What exactly is AEM</li>
<li>Introduction of the OSGI Framework</li>
<li>Introduction to the Java Content Repository (JCR)</li>
<li>Introduction to Apache Sling</li>
<li>Introduction to Granite UI (Touch UI)</li>
<li>Installing AEM Locally</li>
<li>Introduction to AEM Run modes</li>
<li>Introduction to AEM Package Manager</li>
<li>Introduction to OSGI Services (backend)</li>
<li>Introduction to AEM Configuration</li>
</ul>
<p><a href="https://pluralsight.pxf.io/6bJyob" rel="noopener" target="_blank">https://www.pluralsight.com/courses/extending-aem-foundations</a></p>
<hr class="spacer-large" />
<h3 id="develop-websites-and-components-in-adobe-experience-manager">3. Develop Websites and Components in Adobe Experience Manager</h3>
<p><strong>Course Length: (3.5hrs)</strong><br />
This course will teach you the basics for developing websites using AEM, including structure component development, understanding Apache Sling and the JCR, and using HTL.</p>
<p>This course includes learning of:</p>
<ul>
<li>The architecture and overview of AEM and it&#8217;s technical stack</li>
<li>Concepts of JCR and Apache Sling</li>
<li>Development tools in AEM; like CRX/DE</li>
<li>Introduction to AEM JCR</li>
<li>Introduction to AEM content rendering</li>
<li>Basic AEM templates</li>
<li>Basic AEM content &#038; structure components with Sightly</li>
<li>Basic AEM component inheritance</li>
<li>Basic AEM touch UI</li>
<li>Basic AEM design dialog</li>
<li>Basic AEM logging</li>
</ul>
<p><a href="https://pluralsight.pxf.io/RykGmR" rel="noopener" target="_blank">https://www.pluralsight.com/courses/develop-websites-components-aem</a></p>
<hr class="spacer-large" />
<p><!-- 

<div class="mention-block">
The courses below are all <strong>PAID</strong> only, but you can get a 10-day free trial today from my affiliate link here, <a href="https://bit.ly/3DYcJw6" rel="noopener" target="_blank">Get PluralSight 10 Days for Free</a>. 10 days completely free!</div>

 !--></p>
<div class="mention-block" style="text-align:center">
The courses below are all <strong>PAID</strong> only, but you can get a 10-day free trial today from my affiliate link here, <a href="https://bit.ly/3DYcJw6" rel="noopener" target="_blank">Get PluralSight 10 Days for Free</a>.
</div>
<hr class="spacer-large" />
<h3 id="develop-websites-and-components-in-adobe-experience-manager-advanced">4. Develop Websites and Components in Adobe Experience Manager Advanced</h3>
<p><strong>Course Length: (3.5hrs)</strong><br />
This course teaches you the advanced methods for developing websites, including using AEM&#8217;s responsive grid, advanced content component development, debugging, and testing.</p>
<p>In this course, I recommend to skip the &#8220;Using Brackets for Developmment&#8221;, because this IDE is not as efficient than Visual Studio Code and IntelliJ, in my opinion.</p>
<p>This course includes learning of:</p>
<ul>
<li>Introduction of response design in AEM</li>
<li>Introduction of the responsive grid layout</li>
<li>Introduction of response design in AEM</li>
<li>AEM sling selectors with components</li>
<li>Handling AEM 404 error pages</li>
<li>AEM sling redirects</li>
<li>AEM translations via internalization (i18n)</li>
<li>Touch UI dialogs</li>
<li>Creating AEM Component with intermediate concepts</li>
<li>Creating AEM Component with advanced concepts</li>
<li>Concepts for AEM client libraries</li>
<li>Client Libraries</li>
<li>Backend Core: JCR Search API</li>
<li>Frontend asynchronous development with AEM components</li>
<li>Testing and debugging AEM components</li>
</ul>
<p><a href="https://pluralsight.pxf.io/4e1Gor" rel="noopener" target="_blank">https://www.pluralsight.com/courses/develop-websites-components-aem-advanced</a></p>
<hr class="spacer-large" />
<h3 id="extending-adobe-experience-manager-advanced">5. Extending Adobe Experience Manager Advanced</h3>
<p><strong>Course Length: (6hrs)</strong><br />
This course is an extension of #4, developing AEM websites and components (advanced). This course includes advanced methods for developing websites, including using AEM&#8217;s backend offerings like: content migration, AEM Workflows, OSG backend services and servlets, and unit testing.<br />
This course includes learning of:</p>
<ul>
<li>Configuration of your development environemnt</li>
<li>OSGI Overview and Deep Dive</li>
<li>OSGI advanced concepts like annotations, bundle activator, create and use custom services, code OSGI configurations</li>
<li>Deep dive into the Apache Sling Framework</li>
<li>Concepts of Sling Architecture, system users, sling servlets, sling resolution process</li>
<li>Backend event handling</li>
<li>Advanced concepts for the JCR</li>
<li>JCR Model, event handling, observation listener</li>
<li>Search: configuration of indexes, using AEM indexing tools, and query synax</li>
<li>Search: creation of an AEM search servlet</li>
<li>Polling importers</li>
<li>AEM Workflows: workflow models, workflow steps, workflow launchers</li>
<li>Programically create pages and assets in AEM</li>
<li>Programically creating a website in AEM</li>
<li>Unit testing with JUNIT for AEM backend</li>
<li>Understanding AEM content ingestion and migration</li>
<li>User permissions and groups</li>
</ul>
<p><a href="https://pluralsight.pxf.io/NKr94b" rel="noopener" target="_blank">https://www.pluralsight.com/courses/extending-aem-advanced</a></p>
<hr class="spacer-large" />
<div class="mention-block" style="text-align:center">
The courses below are all <strong>PAID</strong> only, but you can get a 10-day free trial today from my affiliate link here, <a href="https://bit.ly/3DYcJw6" rel="noopener" target="_blank">Get PluralSight 10 Days for Free</a>.
</div>
<hr class="spacer-large" />
<h3 id="introduction-advanced-dialogs-with-granite-ui">6. Introduction &#038; Advanced Dialogs with Granite UI</h3>
<p><strong>Course Length: (2hrs)</strong><br />
This course will teach you to build AEM dialogs &#038; custom AEM dialogs, including Granite UI, understand dialog node structure, apply input validation, and tracing input back to AEM&#8217;s JCR.<br />
This course includes learning of:</p>
<ul>
<li>Introduction of Granite UI</li>
<li>Understanding the Granite UI documentation</li>
<li>Understanding the Granite UI on the server</li>
<li>Granite UI containers, layout, and multifield items</li>
<li>Migration from Coral2 to Coral3</li>
<li>Follow-me, building tab Granite UI components</li>
<li>Granite UI form fields such as checkbox, dropdown, etc&#8230;</li>
<li>Advanced Granite UI with custom Javascript validations</li>
<li>Introduction to Datasources</li>
<li>Follow-me, Datasource lists with ACS Commons</li>
</ul>
<p><a href="https://pluralsight.pxf.io/yR7q9b" rel="noopener" target="_blank">https://www.pluralsight.com/courses/adobe-experience-manager-advanced-dialogs-granite-ui</a></p>
<hr class="spacer-large" />
<h3 id="aem-building-full-stack-components">7. AEM Building Full Stack Components</h3>
<p><strong>Course Length: (2hrs)</strong><br />
Learn to leverage AEM&#8217;s rendering lifecycle to architect solutions based on designs. You&#8217;ll work with components, editable templates, and page properties to build content structures that are returned as JSON from an API endpoint.<br />
This course includes learning of:</p>
<ul>
<li>AEM Full Stack development introduction</li>
<li>Translating designs into AEM components</li>
<li>Building AEM Components from HTML Mockups</li>
<li>Static and Editable templates</li>
<li>Building an API Endpoint to Handle AJAX requests</li>
<li>Sling Servlets, Query Builder, and JSON</li>
<li>AEM components tying to backend servlets</li>
</ul>
<p><a href="https://www.pluralsight.com/courses/aem-building-full-stack-components?clickid=Sry1Gq1aYxyNWHQzKgxhwRaIUkDXadS2NTFuTo0&#038;irgwc=1&#038;mpid=3205385&#038;aid=7010a000001xAKZAA2&#038;utm_medium=digital_affiliate&#038;utm_campaign=3205385&#038;utm_source=impactradius" rel="noopener" target="_blank">https://www.pluralsight.com/courses/aem-building-full-stack-components</a></p>
<hr class="spacer-large" />
<h3 id="additional=resources">Additional Resources</h3>
<p>After completing all the steps above, enhance your learning with other training and resources on the web, specifically for AEM.</p>
<p><strong><a href="https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-blogs/bg-p/adobe-experience-manager-blogs" rel="noopener" target="_blank">Adobe Experience Manager Forums</a></strong> &#8211; This is a platform created by Adobe to provide AEM knowledge to the public. This includes a community forum where AEM developers can share ideas, discuss problems, find new AEM technical blog articles, and much more. You can learn a lot here by reading about problems and how they are solved. This is a community that I stand by, and commit my own ideas, help answer AEM technical questions, and participate. <a href="https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-blogs/bg-p/adobe-experience-manager-blogs" rel="noopener" target="_blank">https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-blogs/bg-p/adobe-experience-manager-blogs</a></p>
<h5>More Video Training Series</h5>
<p>These are free online video training materials that the AEM community and I find very useful for learning &#038; reviewing AEM development practices. If you run through the entire playlist for each and every Youtube video playlist below, you should be reinforced, moving your way up to a best-in-class, AEM developer.</p>
<ul>
<li><a href="https://www.youtube.com/playlist?list=PLEaEQSM_Y4tmJjQICTFDm2lU5mNmd_Oar" rel="noopener" target="_blank"><strong>AEM Geeks</strong></a> &#8211; Strengthening your learning by reviewing <a href="https://www.youtube.com/playlist?list=PLEaEQSM_Y4tmJjQICTFDm2lU5mNmd_Oar" rel="no opener noopener" target="_blank">AEMGEEKS&#8217;s youtube AEM series</a>, <a href="https://www.youtube.com/playlist?list=PLEaEQSM_Y4tmJjQICTFDm2lU5mNmd_Oar" rel="noopener" target="_blank">https://www.youtube.com/playlist?list=PLEaEQSM_Y4tmJjQICTFDm2lU5mNmd_Oar</a>. AEMGeeks really did a great job by sharing full-stack AEM topics and should provide more knowledge. </li>
<li><a href="https://www.youtube.com/c/SGAEM/playlists" rel="noopener" target="_blank"><strong>SG AEM</strong></a> &#8211; This youtube channel offers easy-to-understand AEM full-stack web development tutorials that can help you fine-tune your AEM skills. <a href="https://www.youtube.com/c/SGAEM/playlists" rel="noopener" target="_blank">https://www.youtube.com/c/SGAEM/playlists</a></li>
</ul>
<hr class="spacer-large" />
<h3 id="how-this-course-helped-me">How this course helped me</h3>
<ul>
<li>Prepare for interviews. Before jumping into technical interviews, I would go all of the courses at 2x the speed. These courses help me review all the major technicalities of AEM. I would just watch all the videos starting from the fundamentals of building AEM web components &#038; services to advanced concepts and practices.</li>
<li>During my daily work regime, this course helped me re-align my AEM concepts and coding practices. After watching the videos, I understood exactly what AEM-specific technologies I was trying to re-align and was able to immediately start putting my knowledge the practice.</li>
<li>The easy-to-follow and understanding courses include the entire AEM technical stack, which refreshes my learning for AEM sites; regarding AEM sightly components, OSGI configurations, editable templates, touch UI, and more.</li>
</ul>
<style>
#custom_html-9 {display:none;}
</style>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-developers-courses-2023-that-really-helped-me">AEM Developers Courses 2023 That Really Helped Me</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-developers-courses-2023-that-really-helped-me/feed</wfw:commentRss>
			<slash:comments>38</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Programmatically Write/Update/Modify AEM JCR node property/properties</title>
		<link>https://sourcedcode.com/blog/aem/aem-programmatically-write-update-modify-aem-jcr-node-property-properties</link>
					<comments>https://sourcedcode.com/blog/aem/aem-programmatically-write-update-modify-aem-jcr-node-property-properties#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 15 Jan 2023 08:54:59 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4145</guid>

					<description><![CDATA[<p>In this article, I will be presenting code snippets for how we can programmatically update AEM JCR nodes in AEM using Java; using the org.apache.sling.api.resource.ModifiableValueMap and javax.jcr.Node API. In this article, we are showcasing the way that you would programmatically update AEM JCR nodes in your local machine, logged in as a System Users in [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-programmatically-write-update-modify-aem-jcr-node-property-properties">AEM Programmatically Write/Update/Modify AEM JCR node property/properties</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, I will be presenting code snippets for how we can programmatically update AEM JCR nodes in AEM using Java; using the org.apache.sling.api.resource.ModifiableValueMap and javax.jcr.Node API.</p>
<p>In this article, we are showcasing the way that you would programmatically update AEM JCR nodes in your local machine, logged in as a System Users in AEM. If you would like <a href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations" rel="noopener" target="_blank">how to setup your system user programmatically with code configurations, read this article here</a>.</p>
<div class="mention-block">
<b>Quick Links</b></p>
<ol>
<li><a href="#org.apache.sling.api.resource.ModifiableValueMap">Method 1, Programmatically Update AEM JCR nodes in JAVA with org.apache.sling.api.resource.ModifiableValueMap</a></li>
<li><a href="#javax.jcr.Node">Method 2, Programmatically Update AEM JCR nodes in JAVA with, javax.jcr.Node</a></li>
</ol>
</div>
<div class="mention-block--gold">
<strong>Exploring AEM Service Users: A Simple Setup Guide</strong><br />
Dive into the world of Adobe Experience Manager with our blog post, &#8220;Exploring AEM Service Users.&#8221; Whether you&#8217;re on AEMaaCS or AEM 6.5.4+, we&#8217;ve got you covered with an easy-to-follow guide on setting up a system user. No jargon, just straightforward steps to demystify the AEM service user. Enhance your AEM experience effortlessly – check out our blog and learn today -> <a href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations">https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations</a></p>
</div>
<hr class="spacer-large"/>
<h2 id="org.apache.sling.api.resource.ModifiableValueMap">Method 1, Programmatically Update AEM JCR nodes in JAVA with org.apache.sling.api.resource.ModifiableValueMap</h2>
<p>Take a look at line 7,8 where we adapt the resource object to ModifiableValueMap.class, make the change in the existingProperty using the ModifiableValueMap API, put&#8230; In line 9, we are updating an existing property, and in line 10, we are removing an existingProperty. Finally, in line 11, using the resolver to commit the changes. The commit method will Persist all pending changes into the JCR, documentation <a href="https://sling.apache.org/apidocs/sling11/org/apache/sling/api/resource/ResourceResolver.html" rel="noopener" target="_blank">here</a>.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resolver <span style="color: #339933;">=</span> factory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Resource resource <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Objects.<span style="color: #006633;">nonNull</span><span style="color: #009900;">&#40;</span>resource<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ModifiableValueMap map <span style="color: #339933;">=</span> resource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>ModifiableValueMap.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;newProperty&quot;</span>, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;existingProperty&quot;</span>, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; map.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;existingProperty&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//remove</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resolver.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
<b>try-with-resources statement line:4</b><br />
The <b>try-with-resources</b> statement is a try statement that declares one or more resources. A resource is as an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource. <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/language/try-with-resources.html" rel="noopener" target="_blank">reference documentation</a>.
</div>
<hr class="spacer-large"/>
<h2 id="javax.jcr.Node">Method 2, Programmatically Update AEM JCR nodes in JAVA with, javax.jcr.Node</h2>
<p>Take a look at line 6, where we will get the JCR node as a javax.jcr.Node object, in line 7 we will check if that Node exists, and line 8, we create a new property. On line 9, we will update an existing property, and in line 10, we will remove an existing property, in line 11, we will save all changes into the repository.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resolver <span style="color: #339933;">=</span> factory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Session session <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Node contentNode <span style="color: #339933;">=</span> session.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Objects.<span style="color: #006633;">nonNull</span><span style="color: #009900;">&#40;</span>contentNode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;newProperty&quot;</span>, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;existingProperty&quot;</span>, <span style="color: #0000ff;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;existingProperty&quot;</span>, <span style="color: #009900;">&#40;</span>Value<span style="color: #009900;">&#41;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//remove</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; session.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>This article covers questions like</h3>
<ul>
<li>How to modify AEM JCR node property/properties programmatically?</li>
<li>Modify AEM JCR node property/properties programmatically with code</li>
<li>Use AEM Sling API to modify AEM JCR node property/properties</li>
<li>Use AEM Node JCR to modify AEM JCR node property/properties</li>
</ul>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-programmatically-write-update-modify-aem-jcr-node-property-properties">AEM Programmatically Write/Update/Modify AEM JCR node property/properties</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-programmatically-write-update-modify-aem-jcr-node-property-properties/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Deploying Core Module of the AEM Project</title>
		<link>https://sourcedcode.com/blog/aem/deploying-core-module-of-the-aem-project</link>
					<comments>https://sourcedcode.com/blog/aem/deploying-core-module-of-the-aem-project#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 22 Dec 2022 04:33:04 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4102</guid>

					<description><![CDATA[<p>For rapid AEM backend developer, we would like to build the AEM core module bundle to our running local AEM instance. In this article, we will configure the core bundle with an automated script. Simple build the project with mvn clean install -PautoInstallBundle. This is actually a standard that is shipped from the aem-project-archetype-39, but [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/deploying-core-module-of-the-aem-project">Deploying Core Module of the AEM Project</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>For rapid AEM backend developer, we would like to build the AEM core module bundle to our running local AEM instance. In this article, we will configure the core bundle with an automated script. Simple build the project with mvn clean install -PautoInstallBundle. This is actually a standard that is shipped from the aem-project-archetype-39, but not configured to the AEM core module.</p>
<p>At the creation of this article, I have used <a href="https://github.com/adobe/aem-project-archetype/tree/aem-project-archetype-39" rel="noopener" target="_blank">https://github.com/adobe/aem-project-archetype/tree/aem-project-archetype-39</a>. </p>
<h3>1. Add a new profile in your core/pom.xml</h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>autoInstallBundle<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;activation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;activeByDefault<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/activeByDefault<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/activation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pluginManagement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.sling<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sling-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.4.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>install-bundle<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>install<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;slingUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${aem.host}:${aem.port}/system/console<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/slingUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pluginManagement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>2. Change directory to the core bundle folder, and then run the command below:</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">cd ~<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span><span style="color: #cc66cc;">2023</span><span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>core<br />
<br />
mvn clean install <span style="color: #339933;">-</span>PautoInstallBundle</div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>3. What&#8217;s the difference between Maven plugins vs dependencies?</h3>
<p><strong>Plugins</strong> are used during the code build phase, when code is being built by Maven; plugins are where much of the real action is performed, plugins are used to: create jar files, create war files, compile code, unit test code, create project documentation, and on and on. Almost any action that you can think of performing on a project is implemented as a Maven plugin.</p>
<p><strong>Dependencies</strong> are declared and used by Maven. During the build, Maven will download the dependencies to your local repository and then use this to compile your JAR. We use the &lt;scope&#038;;gt;test/&lt;scope&#038;;gt;t to indicate that dependency is not required at the runtime of the application but is used only for test purposes; this dependency will not be bundled with the .jar producted.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/deploying-core-module-of-the-aem-project">Deploying Core Module of the AEM Project</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/deploying-core-module-of-the-aem-project/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create System &#124; Service Users in AEM 6.5 with Code Configurations</title>
		<link>https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations</link>
					<comments>https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 27 Nov 2022 00:35:46 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4026</guid>

					<description><![CDATA[<p>In this article we will walk through how to configure your AEM project to have the AEM environment self configure System Users in AEM with code, so that you would not need to do it the manual way. With the leverage of the org.apache.sling.jcr.api v2.4.0 bundle provided by AEM 6.5.4+ or AEM as a Cloud [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations">Create System | Service Users in AEM 6.5 with Code Configurations</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article we will walk through how to configure your AEM project to have the AEM environment self configure System Users in AEM with code, so that you would not need to do it the <a href="https://experienceleague.adobe.com/docs/experience-manager-65/administering/security/security-service-users.html?lang=en" rel="noopener" target="_blank">manual way</a>. </p>
<p>With the leverage of the org.apache.sling.jcr.api v2.4.0 bundle provided by <strong>AEM 6.5.4+</strong> or <strong>AEM as a Cloud Service</strong>, we are able to utilize the Repository Initialization (repoinit) feature. At the start of this article, we will quickly provide a review of what a system user is, next we will explain what actually is the Repository Initialization (repoinit) feature and it&#8217;s dependencies, and finally, we will be providing some code examples on how to setup this feature on your own AEM instance with a code follow through.</p>
<p>AEM System Users are also referred as Service Users.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#aem-system-user-quick-review" rel="noopener">AEM System User Quick Review</a></li>
<li><a href="#what-is-repository-initialization-repoinit" rel="noopener">What Is Repository Initialization (repoinit)?</a></li>
<li><a href="#aem-dependencies-for-the-repository-initialization-feature-sling-repo-init">AEM Dependencies for the Repository Initialization Feature(Sling RepoInit)</a></li>
<li><a href="#code-follow-through">Code Follow Through</a>
<ul>
<li><a href="#configure-org-apache-sling-jcr-repoinit-repository-initializer-pid">A. Configure org.apache.sling.jcr.repoinit.RepositoryInitializer PID</a></li>
<li><a href="#configure-org-apache-sling-serviceusermapping-impl-service-user-mapper-impl-amended-pid">B. Configure org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended PID</a></li>
<li><a href="#register-basic-servlet-get-request">C. Register Basic Servlet (GET Request)</a></li>
<li><a href="#test-and-validate-the-servlet-response">D. Test and Validate the Servlet Response</a></li>
<li><a href="#service-user-in-user-admin">E. ServiceUser in UserAdmin</a></li>
</ul>
</li>
</ol>
</div>
<hr class="spacer-large"/>
<h3 id="aem-system-user-quick-review">1. AEM System User Quick Review</h3>
<p>Before we begin, let&#8217;s reiterate what a System User in AEM is. A system user is a JCR user with no password set and a minimal set of privileges that are necessary to perform a specific task. Having no password set means that it will not be possible to login with a system user. A system user is typically utilized by the AEM backend code which have privileges to create, read, update, and delete nodes in the JCR; the backend code will authenticate as a system user as a session when needed, and is required to session logout right when the task or tasks have been completed. Not logging out of a system user from the AEM backend will cause issues. If you do not logout of a session that you have opened, your AEM will be flooded by opened sessions, your AEM will start complaining with *INFO* [Apache Sling Resource Resolver Finalizer Thread] org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl Unclosed ResourceResolver, and eventually your AEM environment will run out of memory and crash; to learn more about this topic, take a look at this blog article, <a href="https://cqdump.joerghoh.de/2018/11/12/resourceresolvers-and-sessions-you-open-it-you-close-it/" rel="noopener" target="_blank">ResourceResolvers and Sessions — “you open it</a>, you close it”, by Jörg Hoh. The rule of thumb for creating System Users is to keep the privileges very specific; ensure you have a plan for this system user.</p>
<hr class="spacer-large"/>
<h2 id="what-is-repository-initialization-repoinit">2. What Is Repository Initialization (repoinit)?</h2>
<p>Sling RepoInit is a mechanism that allows configuration code to run before the SlingRepository service is registered. Configuration code is registered under the org.apache.sling.jcr.repoinit.RepositoryInitializer factory PID, and written in a mini-language.</p>
<p>The org.apache.sling.repoinit.parser implements a mini-language meant to create paths, system users and manage access control in a content repository, as well as registering JCR namespaces, node types and privileges. Defining access control content consists of setting and deleting policies of type access control lists (ACL) for which individual access control entries (ACE) can be added and removed.</p>
<p>Full documentation found <a href="https://sling.apache.org/documentation/bundles/repository-initialization.html" rel="noopener" target="_blank">here</a>.</p>
<hr class="spacer-large"/>
<h2 id="aem-dependencies-for-the-repository-initialization-feature-sling-repo-init">3. AEM Dependencies for the Repository Initialization Feature(Sling RepoInit)</h2>
<p>To be able to use this feature, you must have <strong>AEM 6.5.4+</strong> or <strong>AEM as a Cloud Service</strong>.</p>
<p>From out of the box AEM 6.5, it already includes a version of Sling RepoInit, but this is likely an older version without the service pack. If you are not able to replicate the <a href="#code-follow-through">code follow through</a> mentioned on this article, consider upgrading your AEM service pack to the supported version <strong>AEM 6.5.4+</strong>. Take a look at my bundle versions found in /system/console/bundles (as these installed versions are working as expected on my machine):</p>
<ul>
<li>org.apache.sling.jcr.api @ 2.4.0</li>
<li>org.apache.sling.jcr.repoinit @ 1.1.28</li>
<li>org.apache.sling.repoinit.parser @ 1.6.2</li>
</ul>
<hr class="spacer-larger"/>
<h2 id="code-follow-through">4. Code Follow Through</h2>
<p>In the code follow through, you will create a system user with code configurations. Next, with the system user, you will write code for a simple AEM Servlet which will be a GET request, which will write a new property into an existing node in AEM.</p>
<hr class="spacer-large"/>
<h3 id="configure-org-apache-sling-jcr-repoinit-repository-initializer-pid">A. Configure org.apache.sling.jcr.repoinit.RepositoryInitializer PID</h3>
<p>With the org.apache.sling.jcr.repoinit.RepositoryInitializer factory PID, we will be creating a new configuration file.</p>
<p>With this configuration, we are creating a system user named sourcedCodeSystemUser, and will be placed into the folder structure of /home/users/system/sourcedCode. The system user, sourcedCodeSystemUser, will have ACL (Access Control List) privileges configured to:</p>
<ul>
<li>allow read,write,replicate for all JCR resources which exists under /content/sourcedcode</li>
<li>allow read,write,replicate for all JCR resources which exists under /conf/sourcedcode</li>
<li>allow ALL-CRUD-ACTIONS for all JCR resources which exists under /content/we-retail</li>
</ul>
<p><strong>filename: </strong>/apps/sourcedcode/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~sourcedcodeSystemUser.config</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">scripts=[&quot;<br />
&nbsp; &nbsp; create service user sourcedCodeSystemUser with path /home/users/system/sourcedCode<br />
&nbsp; &nbsp; set ACL for sourcedCodeSystemUser<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /content/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /conf/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:all on /content/we-retail<br />
&nbsp; &nbsp; end<br />
&quot;]</div></td></tr></tbody></table></div>
<p><strong>filename: </strong>/apps/sourcedcode/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~sourcedcodeSystemUser.cfg.json</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066;">scripts</span>=<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;<br />
&nbsp; &nbsp; create service user sourcedCodeSystemUser with path /home/users/system/sourcedCode<br />
&nbsp; &nbsp; set ACL for sourcedCodeSystemUser<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /content/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:read,rep:write,crx:replicate on /conf/sourcedcode<br />
&nbsp; &nbsp; &nbsp; &nbsp; allow jcr:all on /content/we-retail<br />
&nbsp; &nbsp; end<br />
&quot;</span><span style="color: #66cc66;">&#93;</span></div></td></tr></tbody></table></div>
<p>Such configurations have two optional fields:<br />
A multi-value <strong>references</strong> field with each value providing the URL (as a String) of raw repoinit statements.<br />
A multi-value <strong>scripts</strong> field with each value providing repoinit statements as plain text in a String.</p>
<hr class="spacer-large"/>
<h3 id="configure-org-apache-sling-serviceusermapping-impl-service-user-mapper-impl-amended-pid">B. Configure org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended PID</h3>
<p>To add a mapping from your service to the corresponding System Users you need to create a factory configuration for the [ServiceUserMapper](https://sling.apache.org/apidocs/sling7/org/apache/sling/serviceusermapping/ServiceUserMapper.html) service. To keep this modular such configurations can be provided using the Sling amend mechanism. </p>
<p>Below, you will see us mapping the sourcedcode.core backend to the sourcedCodeSystemUser.</p>
<p>filename: org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-sourcedcodeSystemUser.config</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000066;">user.mapping</span>=<span style="color: #66cc66;">&#91;</span> \<br />
&nbsp; <span style="color: #ff0000;">&quot;sourcedcode.core:sourcedCodeSystemUser\=[sourcedCodeSystemUser]&quot;</span><br />
<span style="color: #66cc66;">&#93;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3 id="register-basic-servlet-get-request">C. Register Basic Servlet (GET Request)</h3>
<p>line:38, we are creating the Map<String, Object> authInfo class with ResourceResolverFactory.SUBSERVICE set to the system user that we have just created, &#8220;sourcedCodeSystemUser&#8221;.</p>
<p>line:41, we will utilize the Java 7 API, “try-wth-resource”, best practice, to ensure that when we open a new session, we are never forgetting to close the session after the use of it; Since Sling9 (roughly 2016) the ResourceResolver interface implements the AutoCloseable marker interface, so the try-with-resource idiom can be used. Here we are obtaining the resolver via ResourceResolverFactory.getServiceResourceResolver() method.</p>
<p>line:42, we are adapting the resolver into a javax.jcr.Session.class.</p>
<p>line:44-50, we are getting the AEM JCR node, writing new properties to /content/sourcedcode/jcr:content, and replicating the node. And on succeess, we will return the message of &#8220;Test is saved and replicated&#8221;.</p>
<p><strong>filename</strong>: sourcedcode/core/src/main/java/com/sourcedcode/core/servlets/SimpleGetServlet.java</p>
<div class="code-750">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.replication.ReplicationActionType</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.replication.Replicator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolverFactory</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.HttpConstants</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Session</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Objects</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/simple-get&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=&quot;</span> <span style="color: #339933;">+</span> HttpConstants.<span style="color: #006633;">METHOD_GET</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleGetServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolverFactory factory<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Replicator replicator<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletRequest req, <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resolver <span style="color: #339933;">=</span> factory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Session session <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node contentNode <span style="color: #339933;">=</span> session.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Objects.<span style="color: #006633;">nonNull</span><span style="color: #009900;">&#40;</span>contentNode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contentNode.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test&quot;</span>, <span style="color: #0000ff;">&quot;works&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; replicator.<span style="color: #006633;">replicate</span><span style="color: #009900;">&#40;</span>session, ReplicationActionType.<span style="color: #006633;">ACTIVATE</span>, contentNode.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Test is saved and replicated.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to save.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large"/>
<h4>D. Test and Validate the Servlet Response</h3>
<p>Now use your maven skills to build the project!</p>
<p>Next, after a successful build, you would want to make a call to your AEM servlet, via <a href="http://localhost:4502/bin/simple-get" rel="noopener" target="_blank">http://localhost:4502/bin/simple-get</a>. With the service system successfully configured in your environment, you should be able to see a successful message.</p>
<p><strong>Test is saved and replicated.</strong></p>
<p>Revealing the changes in the JCR content, <a href="http://localhost:4502/crx/de/index.jsp#/content/sourcedcode/jcr%3Acontent" rel="noopener" target="_blank">http://localhost:4502/crx/de/index.jsp#/content/sourcedcode/jcr%3Acontent</a>, you should be able to see the changes.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet.png" alt="Screenshot of the crx/de properties for the JCR node, /content/sourcedcode/jcr%3Acontent" width="3840" height="2070" class="alignnone size-full wp-image-4065" srcset="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet.png 3840w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-300x162.png 300w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-1024x552.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-768x414.png 768w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-1536x828.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-2048x1104.png 2048w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-successful-servlet-600x323.png 600w" sizes="(max-width: 3840px) 100vw, 3840px" /></a></p>
<hr class="spacer-large"/>
<h4 id="service-user-in-user-admin">E. ServiceUser in UserAdmin</h3>
<p>If you like, take a look at <a href="http://localhost:4502/useradmi" rel="noopener" target="_blank">http://localhost:4502/useradmin</a>. Search for the sourcedcodeSystemUser and review the permissions for this system user. You should be able to see permissions reflected for this system user:</p>
<ul>
<li>allow read,write,replicate for all JCR resources which exists under /content/sourcedcode</li>
<li>allow read,write,replicate for all JCR resources which exists under /conf/sourcedcode</li>
<li>allow ALL-CRUD-ACTIONS for all JCR resources which exists under /content/we-retail</li>
</ul>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser.png" alt="In the AEM useradmin console, showcasing the sourcedcodeSystemUser with correct permissions." width="100%" height="2067" class="alignnone size-full wp-image-4061" srcset="https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser.png 3835w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-300x162.png 300w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-1024x552.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-768x414.png 768w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-1536x828.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-2048x1104.png 2048w, https://sourcedcode.com/wp-content/uploads/2022/11/sourcedCodeSystemUser-600x323.png 600w" sizes="(max-width: 3835px) 100vw, 3835px" /></a></p>
<hr class="spacer-large"/>
<h3>This article covers questions like</h3>
<ul>
<li>How to create AEM System User Programmatically</li>
<li>How to create AEM System User Automatically</li>
<li>How to create AEM System User on AEMaaCS</li>
<li>How to create AEM System User with Code</li>
<li>How to create AEM System User that is not manual</li>
<li>How to create AEM System User the preferred way</li>
<li>How to create AEM Service User Programmatically</li>
<li>How to create AEM Service User Automatically</li>
<li>How to create AEM Service User on AEMaaCS</li>
<li>How to create AEM Service User with Code</li>
<li>How to create AEM Service User that is not manual</li>
<li>How to create AEM Service User the preferred way</li>
</ul>
<hr class="spacer-large"/>
<h3>Path not found by AEMaaCS</h3>
<p>Sometimes you may find errors in the AEMaaCS pipelines due to the reason that when reference to path that you are allowing system user permissions to, path does not exist. And so, the node must declare creation of these path&#8217;s in the repo-init script. Although the path&#8217;s are already installed inside of AEM, it wouldn&#8217;t do anything anyways&#8230; this is to fix the repo-init system user pipeline errors.</p>
<p>Here&#8217;s an example of us creating a repo-init system user which allows permissions for the system user, and includes the creation of paths:</p>
<ul>
<li>allow jcr:all on /content/sourcedcode</li>
<li>allow jcr:all on /conf/sourcedcode</li>
<li>allow jcr:all on /content/dam/sourcedcode</li>
<li>allow jcr:all on /content/cq:tags/sourcedcode</li>
</ul>
<h3>repoinit cfg json example for creating system user</h3>
<p><strong>filename: </strong>/apps/sourcedcode/config/org.apache.sling.jcr.repoinit.RepositoryInitializer~sourcedcodeSystemUser.cfg.json</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;scripts&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (sling:OrderedFolder) /content/dam/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (nt:unstructured) /content/dam/sourcedcode/jcr:content&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (cq:Page) /content/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (cq:PageContent) /content/sourcedcode/jcr:content&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (sling:Folder) /conf/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create path (cq:Tag) /content/cq:tags/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;set properties on /conf/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;set jcr:title{String} to &quot;</span>Sourced Code<span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>end&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;set properties on /content/dam/sourcedcode/jcr:content<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;set cq:conf{String} to /conf/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;set jcr:title{String} to &quot;</span>Sourced Code<span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>end&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;create service user sourcedcodeSystemUser with path /home/users/system/sourcedcode&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #0000ff;">&quot;set ACL for sourcedcodeSystemUser <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /content/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /conf/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /content/dam/sourcedcode<span style="color: #000099; font-weight: bold;">\n</span> &nbsp;allow jcr:all on /content/cq:tags/sourcedcode<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>end&quot;</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations">Create System | Service Users in AEM 6.5 with Code Configurations</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/create-system-service-users-in-aem-6-5-with-code-configurations/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>resourceResolverFactory.getAdministrativeResourceResolver(null) WhiteList Bundle for Administrative Login</title>
		<link>https://sourcedcode.com/blog/aem/whitelist-bundle-for-administrative-login</link>
					<comments>https://sourcedcode.com/blog/aem/whitelist-bundle-for-administrative-login#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 17 Nov 2022 02:18:06 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=4076</guid>

					<description><![CDATA[<p>When working for organizations with the goal of migrating from AEM 6X to 6.5 or to AEM Cloud as a Service. It&#8217;s very common that the AEM backend code still utilizes the deprecated resourceResolverFactory.getAdministrativeResourceResolver(null) @depricated API. This method has been deprecated as of 2.4 (bundle version 2.5.0) because of inherent security issues. Services requiring specific [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/whitelist-bundle-for-administrative-login">resourceResolverFactory.getAdministrativeResourceResolver(null) WhiteList Bundle for Administrative Login</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When working for organizations with the goal of migrating from AEM 6X to 6.5 or to AEM Cloud as a Service. It&#8217;s very common that the AEM backend code still utilizes the deprecated resourceResolverFactory.getAdministrativeResourceResolver(null) <a href="https://sling.apache.org/apidocs/sling12/org/apache/sling/api/resource/ResourceResolverFactory.html#getAdministrativeResourceResolver-java.util.Map-" rel="noopener" target="_blank">@depricated API</a>. This method has been deprecated as of 2.4 (bundle version 2.5.0) because of inherent security issues. Services requiring specific permissions should use the getServiceResourceResolver(), AEM service users <a href="https://experienceleague.adobe.com/docs/experience-manager-64/administering/security/security-service-users.html?lang=en" rel="noopener" target="_blank">instead</a>.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resolver <span style="color: #339933;">=</span> resourceResolverFactory.<span style="color: #006633;">getAdministrativeResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// do something</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>LoginException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>In the later versions of AEM, from the default AEM environment configurations, it has disabled the use of resourceResolverFactory.getAdministrativeResourceResolver(null) because of inherent security issues and has disabled the API. Without any configurations made on AEM, the AEM environment will causes the API call to not work as expected, and the resourceResolverFactory.getAdministrativeResourceResolver(null) returns as a null object. </p>
<hr class="spacer-large"/>
<h2>Solving the Issue</h2>
<p>During times of rapid development, developers are not positions to refactor the deprecated API. That&#8217;s okay. AEM provides configuration to re-enable this disabled feature as a temporary solution for the environment to allow the deprecated API. You have two options.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#apache-sling-login-admin-whitelist">Apache Sling Login Admin Whitelist</a></li>
<li><a href="#apache-sling-login-admin-whitelist-configuration-fragment">Apache Sling Login Admin Whitelist Configuration Fragment</a></li>
</ol>
</div>
<hr class="spacer-large"/>
<h3 id="apache-sling-login-admin-whitelist">1. Apache Sling Login Admin Whitelist</h3>
<p><a href="http://localhost:4502/system/console/configMgr/org.apache.sling.jcr.base.internal.LoginAdminWhitelist" rel="noopener" target="_blank">Visit http://localhost:4502/system/console/configMgr/org.apache.sling.jcr.base.internal.LoginAdminWhitelist</a><br />
<a href="https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist.png" alt="" width="300px" class="alignnone size-full wp-image-4078" srcset="https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist.png 1925w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-300x218.png 300w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-1024x746.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-768x559.png 768w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-1536x1119.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-600x437.png 600w" sizes="(max-width: 1925px) 100vw, 1925px" /></a><br />
<strong>whitelist.bypass</strong>: {Boolean} if true, by default all the bundles will be allowed to use getAdministrativeResourceResolver() deprecated API.<br />
<strong>whitelist.bundles.regexp</strong>: Regular expression for bundle symbolic names for which loginAdministrative() is allowed. NOT recommended for production use, but useful for testing with generated bundles.</p>
<hr class="spacer-large"/>
<h3 id="apache-sling-login-admin-whitelist-configuration-fragment">2. Apache Sling Login Admin Whitelist Configuration Fragment</h3>
<p><a href="http://localhost:4502/system/console/configMgr/org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment" rel="noopener" target="_blank">http://localhost:4502/system/console/configMgr/org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment</a><br />
<a href="https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment.png" alt="" width="300px" class="alignnone size-full wp-image-4077" srcset="https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment.png 1901w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment-300x221.png 300w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment-1024x755.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment-768x566.png 768w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment-1536x1133.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/11/apache-sling-login-admin-whitelist-configuration-fragment-600x443.png 600w" sizes="(max-width: 1901px) 100vw, 1901px" /></a><br />
<strong>whitelist.name</strong>: Optional name to disambiguate configurations.<br />
<strong>whitelist.bundles</strong>: A list of bundle symbolic names allowed to use loginAdministrative().</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/whitelist-bundle-for-administrative-login">resourceResolverFactory.getAdministrativeResourceResolver(null) WhiteList Bundle for Administrative Login</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/whitelist-bundle-for-administrative-login/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sightly Comments with Examples</title>
		<link>https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 20 Oct 2022 01:58:54 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3868</guid>

					<description><![CDATA[<p>When writing comments in your Sightly HTL file, it&#8217;s best practice not to use HTML comments, but to use the sightly, HTML Template Language. 1. HTL comments are not evaluated and returned back as an empty string in the server-side rendered results. This is best practice when developers are including some comments for other developers [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples">AEM Sightly Comments with Examples</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When writing comments in your Sightly HTL file, it&#8217;s best practice not to use HTML comments, but to use the sightly, HTML Template Language.</p>
<p><strong>1. HTL comments are not evaluated and returned back as an empty string in the server-side rendered results.</strong></p>
<p>This is best practice when developers are including some comments for other developers in their organization.</p>
<p>Sightly HTL comments combine HTML and JavaScript multi-line comments: &lt;!&#8211;/* */&#8211;&gt;</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!--<span style="color: #66cc66;">/</span>* The <span style="color: #000066;">content</span> of this comment will be removed from the output. *<span style="color: #66cc66;">/</span>--&gt;<br />
<span style="color: #66cc66;">//</span> output: <span style="color: #ff0000;">&quot;&quot;</span><br />
<br />
&lt;!--<span style="color: #66cc66;">/</span>* <br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output.<br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output.<br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output.<br />
&nbsp; &nbsp; &nbsp; The <span style="color: #000066;">content</span> of this comment will be removed from the output. <br />
&nbsp; &nbsp; &nbsp; Page <span style="color: #000066;">title</span>: $<span style="color: #66cc66;">&#123;</span>currentPage.jcr:<span style="color: #000066;">title</span><span style="color: #66cc66;">&#125;</span><br />
*<span style="color: #66cc66;">/</span>--&gt;<br />
<span style="color: #66cc66;">//</span> output: <span style="color: #ff0000;">&quot;&quot;</span></div></td></tr></tbody></table></div>
<p><strong>2. Standard HTML comments, the comments are evaluated and are server-side rendered with the expected results.</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!-- Page <span style="color: #000066;">title</span>: $<span style="color: #66cc66;">&#123;</span>currentPage.jcr:<span style="color: #000066;">title</span><span style="color: #66cc66;">&#125;</span> --&gt;<br />
<br />
<span style="color: #66cc66;">//</span>output &lt;!-- Page <span style="color: #000066;">title</span>: Home Page --&gt;</div></td></tr></tbody></table></div>
<p>Available for HTML Template Language Specification 1.4<br />
Release Date: 18 June 2018<br />
Reference: <a href="https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md" rel="noopener" target="_blank">https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md</a> </p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples">AEM Sightly Comments with Examples</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sightly-comments-with-examples/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What are AEM ExtraClientlibs?</title>
		<link>https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs</link>
					<comments>https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 20 Sep 2022 04:51:05 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Client Libraries]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3796</guid>

					<description><![CDATA[<p>When dealing with cq:ClientLibraryFolder (node type), you may have come across a property called extraClientlibs. What are extraClientlibs and how does it work? As you may recall, when you want to add custom functionality or styling to the Touch Dialogues (in edit author mode, editor.html), we must include cq.authoring.editor.sites.page as a dependency and cq.authoring.editor.sites.page.hook as [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs">What are AEM ExtraClientlibs?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When dealing with cq:ClientLibraryFolder (node type), you may have come across a property called extraClientlibs. What are extraClientlibs and how does it work?</p>
<p>As you may recall, when you want to add custom functionality or styling to the Touch Dialogues (in edit author mode, editor.html), we must include cq.authoring.editor.sites.page as a dependency and cq.authoring.editor.sites.page.hook as a category to our client library&#8217;s configuration. The configuration would look something like this:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;cq:ClientLibraryFolder&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">dependencies</span>=<span style="color: #ff0000;">&quot;[cq.authoring.editor.sites.page]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">categories</span>=<span style="color: #ff0000;">&quot;[cq.authoring.editor.sites.page.hook]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_.png" alt="Diagram of how the ccq.authoring.editor.sites will be triggered." width="100%" class="alignnone size-full wp-image-3801" srcset="https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_.png 1638w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-300x116.png 300w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-1024x395.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-768x296.png 768w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-1536x593.png 1536w, https://sourcedcode.com/wp-content/uploads/2022/09/cq.authoring.editor.sites_.page_.click_-600x232.png 600w" sizes="(max-width: 1638px) 100vw, 1638px" /></a></p>
<p>This configuration above will evoke the client library every time the Touch UI dialogue is triggered, for all components. Illustrated above, from the author (editor.html), clicking on any component throughout the entire AEM platform, will invoke the client library.</p>
<p><strong>Benefits of using cq.authoring.editor.sites.page:</strong></p>
<ol>
<li>Client libraries created like this will be invoked for all components (when the Touch UI is open)</li>
</ol>
<hr class="spacer-large" />
<p><strong>But however, what happens if you only want your custom functionality or styling to be only called by ONE component? Well, we use the extraClientlibs property from the component&#8217;s Touch UI dialogue.</strong></p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_.png" alt="Diagram of how the extraClientlibs will be triggered." width="100%" height="451" class="alignnone size-full wp-image-3803" srcset="https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_.png 1452w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-300x93.png 300w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-1024x318.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-768x239.png 768w, https://sourcedcode.com/wp-content/uploads/2022/09/my.example.clientlib.calls_-600x186.png 600w" sizes="(max-width: 1452px) 100vw, 1452px" /></a></p>
<p>Illustrated above, you will notice that adding String[] extraClientlibs to the cq:dialog (root node) of the component, the client library will only be invoked, only targeting the Touch UI dialogue that is associated to a specific component.</p>
<p><strong>Benefits of using extraClientlibs:</strong></p>
<ol>
<li>Touch UI will only invoke the targeted client library that is configured.</li>
<li>Client libraries can be created to be specifically used for a particular component.</li>
</ol>
<p><strong>Example of usage of extraClientlibs in line:6</strong></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:sling</span>=<span style="color: #ff0000;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> <span style="color: #000066;">xmlns:granite</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/jcr/granite/1.0&quot;</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> <span style="color: #000066;">xmlns:nt</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span><br />
&nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; <span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Component's Granite UI&quot;</span><br />
&nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog&quot;</span><br />
&nbsp; <span style="color: #000066;">extraClientlibs</span>=<span style="color: #ff0000;">&quot;[my.custom.clientlib]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;content</span><br />
&nbsp; &nbsp; <span style="color: #000066;">granite:class</span>=<span style="color: #ff0000;">&quot;cmp-teaser__editor cmp-image__editor&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;tabs</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/tabs&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;layout</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Layout&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">margin</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:orderBefore</span>=<span style="color: #ff0000;">&quot;actions&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;columns</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/fixedcolumns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">margin</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;column</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;layout</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Layout&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./layout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
...</div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs">What are AEM ExtraClientlibs?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/what-are-aem-extraclientlibs/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What Version Sightly, Apache Sling Scripting HTL Engine, is my AEM Using?</title>
		<link>https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using</link>
					<comments>https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 15 Sep 2022 03:30:47 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3760</guid>

					<description><![CDATA[<p>How do I find out which Sightly, Apache Sling Scripting HTL Engine (runtime) version is being used in my AEM environment? You may want to know because while writing code, you would want to know which API is avaiable to use. The Apache Sling Scripting HTL Runtime provides support for executing HTL Java compiled units [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using">What Version Sightly, Apache Sling Scripting HTL Engine, is my AEM Using?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>How do I find out which Sightly, Apache Sling Scripting HTL Engine (runtime) version is being used in my AEM environment? You may want to know because while writing code, you would want to know which API is avaiable to use.</p>
<p>The Apache Sling Scripting HTL Runtime provides support for executing HTL Java compiled units produced by the org.apache.sling.scripting.sightly.compiler.java module.</p>
<p>In this article, I will help you find out which versions of the Apache Sling Scripting HTL engine is being installed on your AEM instance.</p>
<h2>There&#8217;s two ways to find out this information.</h2>
<ol>
<li><a href="http://system-console-bundles-ui">System Console Bundles UI</a></li>
<li><a href="#adobe-documentation">Read the documentation below that is provided by Adobe</a></li>
</ol>
<hr class="spacer-larger"/>
<h4 id="system-console-bundles-ui">1. System Console Bundles UI</h4>
<p>Visit the system console bundles UI. <a href="http://localhost:4502/system/console/bundles" rel="noopener" target="_blank">http://localhost:4502/system/console/bundles</a>.</p>
<p>Search for the word &#8220;sightly&#8221; you should be able to see the versions being used.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot.png" alt="In system console bundle, search for the word 'sightly' you should be able to see the versions being used." width="100%" class="alignnone size-full wp-image-3761" srcset="https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot.png 1219w, https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot-300x146.png 300w, https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot-1024x498.png 1024w, https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot-768x374.png 768w, https://sourcedcode.com/wp-content/uploads/2022/09/osgi-sightly-runtime-screenshot-600x292.png 600w" sizes="(max-width: 1219px) 100vw, 1219px" /></a><br />
<em>In system console bundle, search for the word &#8216;sightly&#8217; you should be able to see the versions being used.</em></p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2022/09/comparing-sling-org-apache-sling-scripting-sightly-compiler-versions.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/09/comparing-sling-org-apache-sling-scripting-sightly-compiler-versions.png" alt="Taking a look at the release tags from git for org.apache.sling.scripting.sightly.compiler" width="200" class="alignnone size-full wp-image-3761" /></a><br />
<em>Apache&#8217;s release tags from Github for <a href="https://github.com/apache/sling-org-apache-sling-scripting-sightly-compiler/tags" rel="noopener" target="_blank">org.apache.sling.scripting.sightly.compiler</a></em></p>
<p>From what I analyzed here, looking at the <strong>build number</strong>, it looks like this number is in fact the version of the Sling Scripting HTL Engine. Take a closer look at the system console bundle screenshot and compare it with the <a href="https://github.com/apache/sling-org-apache-sling-scripting-sightly-compiler/tags" rel="noopener" target="_blank">Apache documentation</a> presented on Github, you can see &lt;major>.&lt;minor&gt;.&lt;patch&gt;-&lt;qualifier&gt;-<strong>&lt;build number&gt;</strong>.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;major<span style="color: #000000; font-weight: bold;">&gt;</span></span>.<span style="color: #000000; font-weight: bold;">&lt;minor<span style="color: #000000; font-weight: bold;">&gt;</span></span>.<span style="color: #000000; font-weight: bold;">&lt;patch<span style="color: #000000; font-weight: bold;">&gt;</span></span>-<span style="color: #000000; font-weight: bold;">&lt;qualifier<span style="color: #000000; font-weight: bold;">&gt;</span></span>-<span style="color: #000000; font-weight: bold;">&lt;build</span> number<span style="color: #000000; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h4 id="adobe-documentation">2. Read the documentation below that is provided by Adobe</h4>
<p>If you take a closer look at Adobe&#8217;s own documentation from git, it actually says:</p>
<ol>
<li>An implementation of version <a href="https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md" rel="noopener" target="_blank">1.1 of the language specification</a> will be made available in AEM 6.1; release 16 February 2015.</li>
<li>An implementation of version <a href="https://github.com/adobe/htl-spec/blob/1.2/SPECIFICATION.md" rel="noopener" target="_blank">1.2 of the language specification</a> will be made available in AEM 6.2; release 30 March 2016.</li>
<li>An implementation of version <a href="https://github.com/adobe/htl-spec/blob/1.3/SPECIFICATION.md" rel="noopener" target="_blank">1.3 of the language specification</a> is available in AEM 6.3; release 15 December 2016.</li>
<li>An implementation of version <a href="https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md" rel="noopener" target="_blank">1.4 of the language specification</a> is available in AEM 6.3 SP3 and AEM 6.4 SP1; release 18 June 2018.</li>
</ol>
<p>Reference: <a href="https://github.com/adobe/htl-spec" rel="noopener" target="_blank">HTML Template Language Specification</a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using">What Version Sightly, Apache Sling Scripting HTL Engine, is my AEM Using?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/what-version-sightly-apache-sling-scripting-htl-engineis-my-aem-using/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Find all AEM Pages with Specific Page Properties with Query Builder API</title>
		<link>https://sourcedcode.com/blog/aem/find-all-aem-pages-with-specific-page-properties-with-query-builder-api</link>
					<comments>https://sourcedcode.com/blog/aem/find-all-aem-pages-with-specific-page-properties-with-query-builder-api#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 21 Aug 2022 16:23:16 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3707</guid>

					<description><![CDATA[<p>The Query Builder is a great tool that allows us to search for nodes in the JCR. We often as AEM developers use this tool to build a query for us to use in the backend to build query descriptions (predicates); the set of predicates produced will call the Predicate Evaluator which knows how to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/find-all-aem-pages-with-specific-page-properties-with-query-builder-api">Find all AEM Pages with Specific Page Properties with Query Builder API</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The Query Builder is a great tool that allows us to search for nodes in the JCR. We often as AEM developers use this tool to build a query for us to use in the backend to build query descriptions (predicates); the set of predicates produced will call the Predicate Evaluator which knows how to handle that specific predicate for XPath, filtering, and facet extraction.</p>
<p>In this article, we will be sharing query examples to find all AEM pages with specific page page properties using the<strong> Query Builder Debugger</strong> tool.</p>
<hr class="spacer-large" />
<h2>1. Find all AEM pages with a single page property</h2>
<p>Find all pages under /content/we-retail,<br />
and has page properties set with cq:productMaster == &#8216;/var/commerce/products/we-retail/wo/pants/faba_running_pants&#8217;<br />
show max results.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>productMaster<br />
property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span> <br />
<span style="color: #339933;">/</span>var<span style="color: #339933;">/</span>commerce<span style="color: #339933;">/</span>products<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">/</span>wo<span style="color: #339933;">/</span>pants<span style="color: #339933;">/</span>faba_running_pants<br />
p.<span style="color: #006633;">limit</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Aproperty%3Djcr%3Acontent%2Fcq%3AproductMaster%0D%0Aproperty.value%3D%09%0D%0A%2Fvar%2Fcommerce%2Fproducts%2Fwe-retail%2Fwo%2Fpants%2Ffaba_running_pants%0D%0Ap.limit%3D-1" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Aproperty%3Djcr%3Acontent%2Fcq%3AproductMaster%0D%0Aproperty.value%3D%09%0D%0A%2Fvar%2Fcommerce%2Fproducts%2Fwe-retail%2Fwo%2Fpants%2Ffaba_running_pants%0D%0Ap.limit%3D-1</a></p>
<h3>Example Code</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolverFactory</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.QueryBuilder</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.result.SearchResult</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.result.Hit</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.Query</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONArray</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/queryservlet&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> QueryServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolverFactory resolverFactory<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> QueryBuilder queryBuilder<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resourceResolver <span style="color: #339933;">=</span> resolverFactory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryPath <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryType <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;cq:Page&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryProperty <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jcr:content/cq:productMaster&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryPropertyValue <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/var/commerce/products/we-retail/wo/pants/faba_running_pants&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> queryParams <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span>, queryPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span>, queryType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;property&quot;</span>, queryProperty<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;property.value&quot;</span>, queryPropertyValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryBuilder.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>PredicateGroup.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>queryParams<span style="color: #009900;">&#41;</span>, resourceResolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>javax.<span style="color: #006633;">jcr</span>.<span style="color: #006633;">Session</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">SearchResult</span> result <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONArray resultsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Hit hit <span style="color: #339933;">:</span> result.<span style="color: #006633;">getHits</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Resource resource <span style="color: #339933;">=</span> hit.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject pageData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span>, resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultsArray.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>pageData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;results&quot;</span>, resultsArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject errorResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span>, <span style="color: #0000ff;">&quot;An error occurred while processing the request.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>errorResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Curl Example</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl <span style="color: #339933;">-</span>X GET http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/bin/queryservlet</span></div></td></tr></tbody></table></div>
<p><strong>Output</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">&quot;results&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;path&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;/content/we-retail/en&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;path&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;/content/we-retail/de&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// ... more paths</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h2>2. Find all AEM pages with multiple page properties</h2>
<p>Find all pages under /content/we-retail,<br />
and has page properties set with cq:productMaster == &#8216;/var/commerce/products/we-retail/wo/pants/faba_running_pants&#8217;<br />
and has page properties set with cq:template == &#8216;/conf/we-retail/settings/wcm/templates/product-page&#8217;<br />
show max results.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
group.1_property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>productMaster<br />
group.1_property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span> <br />
<span style="color: #339933;">/</span>var<span style="color: #339933;">/</span>commerce<span style="color: #339933;">/</span>products<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">/</span>wo<span style="color: #339933;">/</span>pants<span style="color: #339933;">/</span>faba_running_pants<br />
group.2_property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>cq<span style="color: #339933;">:</span>template<br />
group.2_property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span> <br />
<span style="color: #339933;">/</span>conf<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">/</span>settings<span style="color: #339933;">/</span>wcm<span style="color: #339933;">/</span>templates<span style="color: #339933;">/</span>product<span style="color: #339933;">-</span>page<br />
p.<span style="color: #006633;">limit</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Agroup.1_property%3Djcr%3Acontent%2Fcq%3AproductMaster%0D%0Agroup.1_property.value%3D%09%0D%0A%2Fvar%2Fcommerce%2Fproducts%2Fwe-retail%2Fwo%2Fpants%2Ffaba_running_pants%0D%0Agroup.2_property%3Djcr%3Acontent%2Fcq%3Atemplate%0D%0Agroup.2_property.value%3D%09%0D%0A%2Fconf%2Fwe-retail%2Fsettings%2Fwcm%2Ftemplates%2Fproduct-page%0D%0Ap.limit%3D-1" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Agroup.1_property%3Djcr%3Acontent%2Fcq%3AproductMaster%0D%0Agroup.1_property.value%3D%09%0D%0A%2Fvar%2Fcommerce%2Fproducts%2Fwe-retail%2Fwo%2Fpants%2Ffaba_running_pants%0D%0Agroup.2_property%3Djcr%3Acontent%2Fcq%3Atemplate%0D%0Agroup.2_property.value%3D%09%0D%0A%2Fconf%2Fwe-retail%2Fsettings%2Fwcm%2Ftemplates%2Fproduct-page%0D%0Ap.limit%3D-1</a></p>
<h3>Example Code</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolverFactory</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.QueryBuilder</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.result.SearchResult</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.result.Hit</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.search.Query</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONArray</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collections</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/queryservlet&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sling.servlet.methods=GET&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> QueryServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolverFactory resolverFactory<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> QueryBuilder queryBuilder<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> authInfo <span style="color: #339933;">=</span> <span style="color: #003399;">Collections</span>.<span style="color: #006633;">singletonMap</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResourceResolverFactory.<span style="color: #006633;">SUBSERVICE</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;sourcedCodeSystemUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#40;</span>ResourceResolver resourceResolver <span style="color: #339933;">=</span> resolverFactory.<span style="color: #006633;">getServiceResourceResolver</span><span style="color: #009900;">&#40;</span>authInfo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, String<span style="color: #339933;">&gt;</span> queryParams <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span>, <span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span>, <span style="color: #0000ff;">&quot;cq:Page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.1_property&quot;</span>, <span style="color: #0000ff;">&quot;jcr:content/cq:productMaster&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.1_property.value&quot;</span>, <span style="color: #0000ff;">&quot;/var/commerce/products/we-retail/wo/pants/faba_running_pants&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.2_property&quot;</span>, <span style="color: #0000ff;">&quot;jcr:content/cq:template&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;group.2_property.value&quot;</span>, <span style="color: #0000ff;">&quot;/conf/we-retail/settings/wcm/templates/product-page&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; queryParams.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;p.limit&quot;</span>, <span style="color: #0000ff;">&quot;-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryBuilder.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>PredicateGroup.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>queryParams<span style="color: #009900;">&#41;</span>, resourceResolver.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>javax.<span style="color: #006633;">jcr</span>.<span style="color: #006633;">Session</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">SearchResult</span> result <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONArray resultsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Hit hit <span style="color: #339933;">:</span> result.<span style="color: #006633;">getHits</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Resource resource <span style="color: #339933;">=</span> hit.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject pageData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageData.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path&quot;</span>, resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultsArray.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>pageData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;results&quot;</span>, resultsArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject errorResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span>, <span style="color: #0000ff;">&quot;An error occurred while processing the request.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>errorResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block"><strong>For other ways to find AEM pages on AEM using the query builder</strong>, checkout this article -><br />
<a href="/blog/aem/find-all-aem-pages-with-tags-with-query-builder" rel="noopener" target="_blank">Find all AEM Pages with Tags with Query Builder API</a>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/find-all-aem-pages-with-specific-page-properties-with-query-builder-api">Find all AEM Pages with Specific Page Properties with Query Builder API</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/find-all-aem-pages-with-specific-page-properties-with-query-builder-api/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Granite UI Multifield Sightly Traverse &#124; Iterate Simple Example</title>
		<link>https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example</link>
					<comments>https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 24 Jun 2022 01:58:27 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3526</guid>

					<description><![CDATA[<p>In this article, we will share an example on on how we can iterate and traverse through multifield nodes that have been generated by the Touch UI using Sightly in a very simple way. Going through this article, we will be setting up multifield Granite UI links (as if we are building a menu navigation). [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example">Granite UI Multifield Sightly Traverse | Iterate Simple Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, we will share an example on on how we can iterate and traverse through multifield nodes that have been generated by the Touch UI using Sightly in a very simple way.</p>
<p>Going through this article, we will be setting up multifield Granite UI links (as if we are building a menu navigation). Each link will define it&#8217;s own path, label, and target. Take a look at both screenshots below. One screenshot indicates how a multifield Granite UI field will look like, and in the second screenshot displays how saved nodes would look like in the crx/de console.</p>
<p><a class="foobox fbx-instance fbx-link" href="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-1-1.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-1-1.png" alt="Touch UI - show casing multifield link configurations screenshot" /></a><br />
<a  class="foobox fbx-instance fbx-link"  href="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-2.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-2.png" alt="CRX/DE saved link nodes from the Touch UI screenshot" /></a></p>
<hr class="spacer-large"/>
<h3>Step 1. Touch UI Configuration</h3>
<p>Putting together a very basic Touch UI configuration using tabs to organize our Granite UI fields. Here we will place the entire configuration under:<br />
<strong>/apps/sourcedcode/components/content/multilistexample/_cq_dialog/.content.xml</strong>. </p>
<p>line: 34, declaring a multifield<br />
line: 42, declaring multifield > label<br />
line: 48, declaring multifield > path<br />
line: 55, declaring multifield > target</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:sling</span>=<span style="color: #ff0000;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> <span style="color: #000066;">xmlns:nt</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Multi List Example&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/layouts/tabs&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;nav&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generalSettings</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;General Settings&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/section&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layout</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/layouts/fixedcolumns&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;nav&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkOptions</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Links Options&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/fieldset&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;links</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/multifield&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">composite</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Links&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./links&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkLabel</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Label&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkLabel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkPath</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/pathfield&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Path&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkPath&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">rootPath</span>=<span style="color: #ff0000;">&quot;/content&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkTarget</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Target&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkTarget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;self</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">selected</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Same Page&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_self&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;blank</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;New Tab&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_blank&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkTarget<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/links<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkOptions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/generalSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jcr:root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Step 2. Sightly HTL Front-end</h3>
<p>A very simple way to get a list of objects to iterate through will be to use Sling Model&#8217;s backend and Sling Specific Annotations. Together the mechanism combined will enable the Sightly HTL code to receive a List<Resource>, which you can use this list to iterate through each item, to display nav link configurations that were set by the authors.</p>
<p>Using the Sightly <strong>data-sly-list</strong> API, we can traverse through each item from the List<Resources>. Iterating through each item returns an Resource.class onbject, which it has a getValueMap() public getter method. With this getter method we can get the valueMap object and reveal the configurations that are set by the authors.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-multilistexample&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.cmp<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.content.MultiListExample&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;sly data-sly-list.<span style="color: #000066;">link</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${cmp.links}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${link.valueMap.linkPath}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${link.valueMap.linkTarget}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span>${link.valueMap.linkLabel}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>sly&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Step 3. Sling Model Java Backend</h3>
<p>Sling Model&#8217;s backend and Sling Specific Annotations. Together the mechanism combined will enable the Sightly HTL code to receive a List<Resource>.</p>
<div class="mention-block">
<strong>Pro Tip:</strong><br />
<strong>Decrease your AEM development time using our AEM Sling Model Cheat Sheet Reference Guide! <a href="https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide" rel="noopener" target="_blank">View Guide</a></strong>.
</div>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models.content</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ChildResource</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MultiListExample <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; @ChildResource<br />
&nbsp; &nbsp; @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;links&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> links<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Step 4. Results</h3>
<p>Work your maven magic, and build the code. Once your backend bundle and Sightly HTL code are aligned, you should be able to see the links like here in the screenshot.<br />
<a class="foobox fbx-instance fbx-link"  href="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-3.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2022/06/multi-list-3.png" alt="Links Results" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example">Granite UI Multifield Sightly Traverse | Iterate Simple Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/granite-ui-multifield-sightly-traverse-iterate-simple-example/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>HTL Java Use-API Code Example</title>
		<link>https://sourcedcode.com/blog/aem/htl-java-use-api-code-example</link>
					<comments>https://sourcedcode.com/blog/aem/htl-java-use-api-code-example#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 21 Jun 2022 22:49:32 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sightly]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3473</guid>

					<description><![CDATA[<p>The HTML Template Language (HTL) Java Use-API allows an HTL file to use data-sly-use to access helper functions in a custom Java class. This allows any sophisticated business logic to be wrapped in Java code, while the HTL code is just responsible for direct markup generation. A simple POJO can be used as a Java [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/htl-java-use-api-code-example">HTL Java Use-API Code Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The HTML Template Language (HTL) Java Use-API allows an HTL file to use data-sly-use to access helper functions in a custom Java class. This allows any sophisticated business logic to be wrapped in Java code, while the HTL code is just responsible for direct markup generation.</p>
<p>A simple POJO can be used as a Java Use-API object, which is instantiated by a specific implementation using the POJO&#8217;s default constructor.</p>
<p>In this article, you will find an example of how the Java Use-API can be bind with a component in AEM. In detail, we will be associating the Java Use-API with the header component.</p>
<hr class="spacer-large">
<h2>Java Use-API Example Code</h2>
<h4>Step 1</h4>
<p>We will place a small little snippet from lines:2-4 which will bind into the simple POJO; inside of the given component,<br />
<strong>/apps/sourcedcode/components/structure/header/header.html</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> data-sly-use.header<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;HeaderJavaUseExample&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>${header.path}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; <span style="color: #808080; font-style: italic;">&lt;!--/* header Sightly HTL code implementation below */--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium">
<h4>Step 2</h4>
<p>We will create a simple Java POJO under,<br />
<strong>/apps/sourcedcode/components/structure/header/HeaderJavaUseExample.java</strong></p>
<p>Taking a look closer, line:1 has the package that is the same path as the targeted component.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">apps.sourcedcode.components.structure.header</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.WCMUsePojo</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HeaderJavaUseExample <span style="color: #000000; font-weight: bold;">extends</span> WCMUsePojo <span style="color: #009900;">&#123;</span><br />
<br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getPath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;This is an example path&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium">
<h4>Step 3</h4>
<p>The Java Pojo extends the WCMUsePojo which makes available all the Global Objects in this naming convention:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">getComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getComponentContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentDesign<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentNode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getCurrentStyle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getDesigner<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getEditContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getLog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getOut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getPageManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResource<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResourceDesign<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResourcePage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getSling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getSlyWcmHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getWcmmode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
getXssAPI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/htl-java-use-api-code-example">HTL Java Use-API Code Example</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/htl-java-use-api-code-example/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Checking run mode from Sightly HTL in AEM</title>
		<link>https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 23 May 2022 04:10:08 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3513</guid>

					<description><![CDATA[<p>Sometimes during development, we would need to check the run mode in our AEM environment, so we can show different content based on the context. From the Sightly HTL API, it&#8217;s possible to check for the wcmmode, but not the runmode. In this article, we will set up a sling model helper which will be [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem">Checking run mode from Sightly HTL in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes during development, we would need to check the run mode in our AEM environment, so we can show different content based on the context. From the Sightly HTL API, it&#8217;s possible to check for the wcmmode, but not the runmode.</p>
<p>In this article, we will set up a sling model helper which will be a sling model, and then use Sightly HTL, data-sly-use, API, to access which run mode we are in. How to check runmode in AEM Sightly HTL can never be this easy.</p>
<div class="mention-block--gold-solid">
<strong>slingSettingsService is a deprecated service</strong><br />
We understand that the slingSettingsService is a deprecated service, and you would still like to find a way to retrieve the run mode where it equals to “development”, “staging”, or “production”, I wrote a new article that can solve this issue, <a href="https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023" rel="noopener" target="_blank">https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem-in-2023</a>. Take a look!
</div>
<hr class="spacer-large" />
<h2>Sightly Code</h2>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">&lt;!--/* Production */--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>In Development<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
<span style="color: #ddbb00;">&amp;nbsp;</span><br />
<br />
<span style="color: #808080; font-style: italic;">&lt;!--/* Staging */--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>In Staging<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
<span style="color: #ddbb00;">&amp;nbsp;</span><br />
<br />
<span style="color: #808080; font-style: italic;">&lt;!--/* Production */--&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>In Production<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
<span style="color: #ddbb00;">&amp;nbsp;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium" />
<h3>Java Sling Model</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models.utils</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Default</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.OSGiService</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.RequestAttribute</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.settings.SlingSettingsService</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RunModeHelper <span style="color: #009900;">&#123;</span><br />
<br />
@OSGiService<br />
<span style="color: #000000; font-weight: bold;">private</span> SlingSettingsService slingSettingsService<span style="color: #339933;">;</span><br />
<br />
@RequestAttribute<br />
@<span style="color: #000000; font-weight: bold;">Default</span><span style="color: #009900;">&#40;</span>values <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> runmode<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> hasRunMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
@PostConstruct<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #003399;">String</span> runModes <span style="color: #339933;">=</span> slingSettingsService.<span style="color: #006633;">getRunModes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
hasRunMode <span style="color: #339933;">=</span> runModes.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>runmode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> getHasRunMode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">return</span> hasRunMode<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem">Checking run mode from Sightly HTL in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/checking-run-mode-from-sightly-htl-in-aem/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>How to Generate Unique AEM Component ID with Confidence</title>
		<link>https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 03 Apr 2022 04:24:28 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Sightly]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3518</guid>

					<description><![CDATA[<p>You frequently require a special ID for the AEM component. Either a backend server-side call or a custom JS action trigger are required. If the component is dragged and placed on the page more than once, the hard-coded field ID is not guaranteed to be unique. When considering ID, you might consider directly using the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence">How to Generate Unique AEM Component ID with Confidence</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You frequently require a special ID for the AEM component. Either a backend server-side call or a custom JS action trigger are required. If the component is dragged and placed on the page more than once, the hard-coded field ID is not guaranteed to be unique. </p>
<p>When considering ID, you might consider directly using the global HTL objects and getters, such as ${currentNode.name}. If the component is used in other containers on the same page, this will not, however, fix the issue. Despite the fact that the JCR node level API produces a distinct id for the current node, the id also includes the node path and forward slashes, exposing the internal content structure and making it challenging to utilize in CSS and JS without escaping.</p>
<p>The id element is made simple to use by CSS and JS by the hash code, which also encapsulates and hides internal path information from the end-user. The developer passes in the ID prefix to make the ID property easier for humans to read. Example code of a Java Sling Model class is provided below. </p>
<div class="mention-block--gold">
<strong>Note</strong>: Please note that this blog article was created in 2022, and so, preferred to create the id is via extending the AbstractComponentImpl object, which provides you the getId method. This method will be the best practice while trying to generate an id for your component. Example code can be found here -> <a href="https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TitleImpl.java#L21" rel="noopener" target="_blank">https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TitleImpl.java#L21</a>
</div>
<hr class="spacer-large"/>
<h3>Sightly</h3>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;sly data-sly-use.componentId<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.utils.ComponentId&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;<br />
&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${componentId.id}&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;<br />
<br />
<span style="color: #66cc66;">//</span> this produces<br />
&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmpheader3901793341&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h3>Java Sling Model</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models.utils</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ComponentId <span style="color: #009900;">&#123;</span><br />
&nbsp; <br />
&nbsp; @ScriptVariable<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Component</span> component<span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; @SlingObject<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource resource<span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> component.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;-&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">hashCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h3>Last Thoughts</h3>
<p>You can improve this setup by adding an &#8220;advanced&#8221; tab in the component&#8217;s Touch UI dialog to have authors insert their own custom component ID. If the author&#8217;s configuration is empty, this mechanism will be kicked in to use the ComponentId Sling Model to generate the Ids.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;sly data-sly-use.componentId<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.utils.ComponentId&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${properties.customComponentId || componentId.id}&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<br />
// this produces<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmpheader3901793341&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-header&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence">How to Generate Unique AEM Component ID with Confidence</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-generate-unique-aem-component-id-with-confidence/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Find all AEM Pages with Tags with Query Builder API</title>
		<link>https://sourcedcode.com/blog/aem/find-all-aem-pages-with-tags-with-query-builder</link>
					<comments>https://sourcedcode.com/blog/aem/find-all-aem-pages-with-tags-with-query-builder#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 25 Jan 2022 23:31:17 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[Short Post]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3414</guid>

					<description><![CDATA[<p>The Query Builder is a great tool that allows us to search for nodes in the JCR. We often as AEM developers use this tool to build a query for us to use in the backend to build query descriptions (predicates); the set of predicates produced will call the Predicate Evaluator which knows how to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/find-all-aem-pages-with-tags-with-query-builder">Find all AEM Pages with Tags with Query Builder API</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The Query Builder is a great tool that allows us to search for nodes in the JCR. We often as AEM developers use this tool to build a query for us to use in the backend to build query descriptions (predicates); the set of predicates produced will call the Predicate Evaluator which knows how to handle that specific predicate for XPath, filtering, and facet extraction.</p>
<p>In this article, we will be sharing query examples to find all AEM pages with single-tag &#038;&#038; multi-tags using the<strong> Query Builder Debugger</strong> tool.</p>
<hr class="spacer-large" />
<h2>1. Find all AEM pages with a single cq:tag</h2>
<p>Find all pages under /content/we-retail,<br />
and has the tag of we-retail:apparel/pants,<br />
show max results.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>@cq<span style="color: #339933;">:</span>tags<br />
property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">:</span>apparel<span style="color: #339933;">/</span>pants<br />
p.<span style="color: #006633;">limit</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Aproperty%3Djcr%3Acontent%2F%40cq%3Atags%0D%0Aproperty.value%3Dwe-retail%3Aapparel%2Fpants%0D%0A%0D%0A" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Aproperty%3Djcr%3Acontent%2F%40cq%3Atags%0D%0Aproperty.value%3Dwe-retail%3Aapparel%2Fpants%0D%0A%0D%0A</a></p>
<hr class="spacer-large" />
<h2>1. Find all AEM pages with multiple cq:tags</h2>
<p>Find all pages under /content/we-retail, a<br />
and<br />
((has the tag of we-retail:apparel/pants) or<br />
(has the tag of we-retail:apparel/pants)),<br />
show max results.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
group.1_property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>@cq<span style="color: #339933;">:</span>tags<br />
group.1_property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">:</span>apparel<span style="color: #339933;">/</span>pants<br />
group.2_property<span style="color: #339933;">=</span>jcr<span style="color: #339933;">:</span>content<span style="color: #339933;">/</span>@cq<span style="color: #339933;">:</span>tags<br />
group.2_property.<span style="color: #006633;">value</span><span style="color: #339933;">=</span>we<span style="color: #339933;">-</span>retail<span style="color: #339933;">:</span>apparel<span style="color: #339933;">/</span>shirt<br />
group.<span style="color: #006633;">p</span>.<span style="color: #006633;">or</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><br />
p.<span style="color: #006633;">limit</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p><a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Agroup.1_property%3Djcr%3Acontent%2F%40cq%3Atags%0D%0Agroup.1_property.value%3Dwe-retail%3Aapparel%2Fpants%0D%0Agroup.2_property%3Djcr%3Acontent%2F%40cq%3Atags%0D%0Agroup.2_property.value%3Dwe-retail%3Aapparel%2Fshirt%0D%0Agroup.p.or%3Dtrue%0D%0Ap.limit%3D-1%0D%0A%0D%0A%0D%0A" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Agroup.1_property%3Djcr%3Acontent%2F%40cq%3Atags%0D%0Agroup.1_property.value%3Dwe-retail%3Aapparel%2Fpants%0D%0Agroup.2_property%3Djcr%3Acontent%2F%40cq%3Atags%0D%0Agroup.2_property.value%3Dwe-retail%3Aapparel%2Fshirt%0D%0Agroup.p.or%3Dtrue%0D%0Ap.limit%3D-1%0D%0A%0D%0A%0D%0A</a></p>
<hr class="spacer-large" />
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/find-all-aem-pages-with-tags-with-query-builder">Find all AEM Pages with Tags with Query Builder API</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/find-all-aem-pages-with-tags-with-query-builder/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Send Out Emails with AEM Servlet</title>
		<link>https://sourcedcode.com/blog/aem/send-out-emails-with-aem-servlet</link>
					<comments>https://sourcedcode.com/blog/aem/send-out-emails-with-aem-servlet#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 21 Jan 2022 03:31:31 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[OSGI]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3339</guid>

					<description><![CDATA[<p>In this article, we will be setting up the local AEM author developer&#8217;s environment to send out an email utilizing the Day CQ Mail Service. This article includes code snippets to a Sling Servlet that will be used to send out the email. We will be using a Google Gmail account as the SMTP Mail [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/send-out-emails-with-aem-servlet">Send Out Emails with AEM Servlet</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, we will be setting up the local AEM author developer&#8217;s environment to send out an email utilizing the Day CQ Mail Service. This article includes code snippets to a Sling Servlet that will be used to send out the email.</p>
<div class="mention-block">
We will be using a Google Gmail account as the SMTP Mail Server in this article. To learn how to set up your Google Gmail account as the SMTP server, <a href="https://sourcedcode.com/blog/general-web/how-to-use-the-gmail-smtp-server-to-send-emails-for-free" rel="noopener" target="_blank">click here</a>.
</div>
<hr class="spacer-large" />
<h2>1. Configure the Day CQ Mail Service</h2>
<p>a. Visit <a href="http://localhost:4502/system/console/configMgr/com.day.cq.mailer.DefaultMailService" rel="noopener" target="_blank">http://localhost:4502/system/console/configMgr/com.day.cq.mailer.DefaultMailService</a></p>
<p><a class="foobox fbx-instance fbx-link" href="https://sourcedcode.com/wp-content/uploads/2022/01/step-1-send-email-aem.png"><img decoding="async" width="300" src="https://sourcedcode.com/wp-content/uploads/2022/01/step-1-send-email-aem.png" alt="This is a screenshot of the Apache Felix Console, Day CQ Mail Service Configuration"/></a></p>
<p>b. Include the configurations below:<br />
<strong>Google SMTP Configurations</strong><br />
SMTP server hostname: smtp.gmail.com<br />
SMTP server port: 465, 25 or 587 (test in that order)<br />
SMTP user: @@YOUR_EMAIL_ADDRESS@@<br />
SMTP from emai: @@YOUR_EMAIL_ADDRESS@@<br />
SMTP password: @@YOUR_PASSWORD@@<br />
SMTP TLS/SSL: true</p>
<p>To automate this configuration, you can run a Curl command like the example below. But please be aware, you must use your own Google Gmail account. </p>
<p>To update the Curl command below, use this tool here, <a class="code-highlight-primary" href="https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations?aemUrl=http://localhost:4502&#038;username=admin&#038;password=admin&#038;pid=com.day.cq.mailer.DefaultMailService&#038;osgiKeys=smtp.host,smtp.port,smtp.user,smtp.password,from.address,smtp.ssl&#038;osgiValues=smtp.gmail.com,587,contact@sourcedcode.com,p4ssw0rd,contact@sourcedcode.com,true#curltool" target="_blank" rel="noopener">Tool: Generate Curl Command to Update OSGI Configurations</a></p>
<pre style="white-space: pre-wrap; font-size: 12px; padding: 5px;">
curl -u admin:admin 'http://localhost:4502/system/console/configMgr/com.day.cq.mailer.DefaultMailService' --data-raw 'apply=true&action=ajaxConfigManager&%24location=&smtp.host=smtp.gmail.com&smtp.port=587&smtp.user=contact@sourcedcode.com&smtp.password=p4ssw0rd&from.address=contact@sourcedcode.com&smtp.ssl=true&propertylist=smtp.host%2Csmtp.port%2Csmtp.user%2Csmtp.password%2Cfrom.address%2Csmtp.ssl'
</pre >
<hr class="spacer-large" />
<h2>2. Create the SendEmailServletExample AEM Servlet</h2>
<p>Create a Java class named, SendEmailServletExample.java, copy and paste the code below, replace line:44 with your own email, and then use your Java Maven skills to build the servlet in AEM.</p>
<p>Once when the SendEmailServletExample.java is built into AEM, visit <a class="code-highlight-primary" href="http://localhost:4502/bin/sendemail" rel="noopener" target="_blank">http://localhost:4502/bin/sendemail</a>,</p>
<div class="code-1000">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlet</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.mailer.MessageGateway</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.mailer.MessageGatewayService</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.mail.Email</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.mail.EmailException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.mail.HtmlEmail</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Reference</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.Logger</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.LoggerFactory</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">servlets</span>.<span style="color: #006633;">ServletResolverConstants</span>.<span style="color: #006633;">SLING_SERVLET_PATHS</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; SLING_SERVLET_PATHS <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=/bin/sendemail&quot;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SendEmailServletExample <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger log <span style="color: #339933;">=</span> LoggerFactory.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>SendEmailServletExample.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; @<span style="color: #003399;">Reference</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> MessageGatewayService messageGatewayService<span style="color: #339933;">;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> sent <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> recipients <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;contact@sourcedcode.com&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; sendEmail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;This is an test email&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;This is the email body&quot;</span>, recipients<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; sent <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>EmailException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;result&quot;</span>, sent <span style="color: #339933;">?</span> <span style="color: #0000ff;">&quot;done&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;something went wrong&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> sendEmail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> subjectLine, <span style="color: #003399;">String</span> msgBody, <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> recipients<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> EmailException <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Email email <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlEmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> recipient <span style="color: #339933;">:</span> recipients<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; email.<span style="color: #006633;">addTo</span><span style="color: #009900;">&#40;</span>recipient, recipient<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; email.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span>subjectLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; email.<span style="color: #006633;">setMsg</span><span style="color: #009900;">&#40;</span>msgBody<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; MessageGateway<span style="color: #339933;">&lt;</span>Email<span style="color: #339933;">&gt;</span> messageGateway <span style="color: #339933;">=</span> messageGatewayService.<span style="color: #006633;">getGateway</span><span style="color: #009900;">&#40;</span>HtmlEmail.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>messageGateway <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sending out email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; messageGateway.<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Email<span style="color: #009900;">&#41;</span> email<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; log.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The message gateway could not be retrieved.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/send-out-emails-with-aem-servlet">Send Out Emails with AEM Servlet</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/send-out-emails-with-aem-servlet/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Set Cookie Example of AEM Servlet and Sling Model</title>
		<link>https://sourcedcode.com/blog/aem/set-cookie-example-of-aem-servlet-and-sling-model</link>
					<comments>https://sourcedcode.com/blog/aem/set-cookie-example-of-aem-servlet-and-sling-model#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 19 Jan 2022 04:28:30 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Short Post]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3269</guid>

					<description><![CDATA[<p>In this short article, we will show two code examples; for example, one will be showcasing how cookies values can be set for an AEM Servlet, and for example two, Sling Model. 1. AEM Servlet Set Cookie Example 12345678910111213141516171819202122232425262728293031323334353637package com.sourcedcode.core.servlets; import com.cat.wcm.core.util.JSONObject; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.osgi.service.component.annotations.Component; import javax.servlet.Servlet; import javax.servlet.http.Cookie; import [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/set-cookie-example-of-aem-servlet-and-sling-model">Set Cookie Example of AEM Servlet and Sling Model</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this short article, we will show two code examples; for example, one will be showcasing how cookies values can be set for an AEM Servlet, and for example two, Sling Model.</p>
<hr class="spacer-large" />
<h2>1. AEM Servlet Set Cookie Example</h2>
<div class="code-500">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.cat.wcm.core.util.JSONObject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingAllMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.Cookie</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">servlets</span>.<span style="color: #006633;">ServletResolverConstants</span>.<span style="color: #006633;">SLING_SERVLET_PATHS</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span><br />
&nbsp; service <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#125;</span>,<br />
&nbsp; property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; SLING_SERVLET_PATHS <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;=/bin/setCookieExample&quot;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SetCookieServletExample <span style="color: #000000; font-weight: bold;">extends</span> SlingAllMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Cookie cookie <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Cookie<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;visitedCookieServletExample&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; cookie.<span style="color: #006633;">setMaxAge</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// in seconds, 86400 = 24 hours.</span><br />
&nbsp; &nbsp; response.<span style="color: #006633;">addCookie</span><span style="color: #009900;">&#40;</span>cookie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// server response</span><br />
&nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; JSONObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; jsonResponse.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;success&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large" />
<h2>2. Sling Model Set Cookie Example</h2>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.models.pages.page</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.Cookie</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span><br />
&nbsp; adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; @SlingObject<br />
&nbsp; <span style="color: #000000; font-weight: bold;">protected</span> SlingHttpServletResponse response<span style="color: #339933;">;</span><br />
<br />
&nbsp; @PostConstruct<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Cookie cookie <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Cookie<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;visitedExampleModel&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; cookie.<span style="color: #006633;">setMaxAge</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// in seconds, 86400 = 24 hours.</span><br />
&nbsp; &nbsp; response.<span style="color: #006633;">addCookie</span><span style="color: #009900;">&#40;</span>cookie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/set-cookie-example-of-aem-servlet-and-sling-model">Set Cookie Example of AEM Servlet and Sling Model</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/set-cookie-example-of-aem-servlet-and-sling-model/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Dynamically Include an Experience Fragment in Sightly</title>
		<link>https://sourcedcode.com/blog/aem/dynamically-include-an-experience-fragment-in-sightly</link>
					<comments>https://sourcedcode.com/blog/aem/dynamically-include-an-experience-fragment-in-sightly#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 13 Jan 2022 22:51:32 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Short Post]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3255</guid>

					<description><![CDATA[<p>In this article, we will dynamically reference an AEM experience fragment to a page, dynamically using code. Sightly Implementation Hard Coded Example The first example uses sightly to reference an experience fragment, /content/experience-fragments/we-retail/equipment, and the required variation, master. This will only work when the path includes the experience fragment variation path. The value here is [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/dynamically-include-an-experience-fragment-in-sightly">How to Dynamically Include an Experience Fragment in Sightly</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, we will dynamically reference an AEM experience fragment to a page, dynamically using code.</p>
<hr class="spacer-large" />
<h2>Sightly Implementation</h2>
<p><strong>Hard Coded Example</strong><br />
The first example uses sightly to reference an experience fragment, /content/experience-fragments/we-retail/equipment, and the required variation, master. This will only work when the path includes the experience fragment variation path. The value here is hard coded.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>resource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${@path='/content/experience-fragments/we-retail/equipment/master', <br />
&nbsp; &nbsp;selectors='content', wcmmode='disabled'}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Dynamic Example</strong><br />
In the second example, we can see that our component adapts to the com.mysite.models.component.MyCustomComponent, Sling Model backend, and then it exposes the experience fragment in the exPath property. The value returned from the exPath is &#8216;/content/experience-fragments/we-retail/equipment/master&#8217;.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">cmp</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.mysite.models.component.MyCustomComponent&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>resource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${@path=cmp.exPath, <br />
&nbsp; &nbsp;selectors='content', wcmmode='disabled'}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<p><strong>Removing &lt;html&gt;&lt;body&gt; unwanted tags and client library imports</strong><br />
When you include wcmmode=&#8217;disabled&#8217;, it will cause your page to render the &lt;html&gt;&lt;body&gt; unwanted tags and client library imports that you probably do not want apart of the page. To fix this issue, you would just need to dismiss wcmmode=&#8217;disabled&#8217;.</p>
<p>Use this line of text instead:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>use.<span style="color: #006633;">cmp</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.mysite.models.component.MyCustomComponent&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;</span>sly data<span style="color: #339933;">-</span>sly<span style="color: #339933;">-</span>resource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${@path=cmp.exPath, <br />
&nbsp; &nbsp;selectors='content'}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>sly<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/dynamically-include-an-experience-fragment-in-sightly">How to Dynamically Include an Experience Fragment in Sightly</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/dynamically-include-an-experience-fragment-in-sightly/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Find AEM JCR Nodes with Full Text Search</title>
		<link>https://sourcedcode.com/blog/aem/find-aem-jcr-nodes-with-full-text-search</link>
					<comments>https://sourcedcode.com/blog/aem/find-aem-jcr-nodes-with-full-text-search#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 12 Jan 2022 02:07:03 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Search]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3108</guid>

					<description><![CDATA[<p>Every AEM developer knows that a JCR node consists of properties and values. Whenever a component is configured or whenever page properties are set, the value is saved in the JCR node as properties and values. There are times when we would like to search all the JCR node properties, to match the value with [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/find-aem-jcr-nodes-with-full-text-search">Find AEM JCR Nodes with Full Text Search</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Every AEM developer knows that a JCR node consists of properties and values. Whenever a component is configured or whenever page properties are set, the value is saved in the JCR node as properties and values. </p>
<p>There are times when we would like to search all the JCR node properties, to match the value with some kind of string. We can do this with fulltext search in AEM. This action is most useful when trying to find unused components in the code.</p>
<p>When performing a fulltext search, please be aware that you will be using Jackrabbit Oak, Apache Lucene. You will search via the Apache Lucene indexes, cached in the JCR. Update and Delete operations in the repository are followed by the Lucene reindexing.</p>
<p>In this article, we will cover 2 ways of performing a full-text search, with examples.</p>
<div class="mention-block">
<strong>Quick Links</strong></p>
<ol>
<li><a href="#fulltext-search-AEM_Query_Builder">AEM FullText Search with the Query Builder</a></li>
<li><a href="#fulltext-search-JCR_SQL2">AEM FullText Search with the JCR_SQL2</a></li>
</ol>
</div>
<hr class="spacer-larger"/>
<h3 id="fulltext-search-AEM_Query_Builder">1. AEM FullText Search with the Query Builder</h3>
<p><strong>Example 1: In this example we will find all [nt:base] JCR nodes matching any %pants%</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Search <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">:</span><br />
anything under <span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><br />
and any.<span style="color: #006633;">properties</span> with values LIKE <span style="color: #0000ff;">&quot;%pants%&quot;</span><br />
and show me more than <span style="color: #cc66cc;">10</span> results.<br />
<br />
<span style="color: #339933;">-------------</span><br />
<br />
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/libs/cq/search/content/querydebug.html</span><br />
<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
fulltext<span style="color: #339933;">=</span>pants<br />
p.<span style="color: #006633;">limit</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p>Visit localhost: <a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Afulltext%3Dpants%0D%0Ap.limit%3D-1" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Afulltext%3Dpants%0D%0Ap.limit%3D-1</a></p>
<hr class="spacer-large"/>
<p><strong>Example 2: In this example we will find all [cq:Page] JCR nodes matching any %weretail/components/structure/page%</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Search <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">:</span><br />
anything under <span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><br />
and only <span style="color: #0000ff;">&quot;cq:Page&quot;</span> nodes<br />
and any.<span style="color: #006633;">properties</span> with values LIKE <span style="color: #0000ff;">&quot;%weretail/components/structure/page%&quot;</span><br />
and show me more than <span style="color: #cc66cc;">10</span> results.<br />
<br />
<span style="color: #339933;">-------------</span><br />
<br />
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/libs/cq/search/content/querydebug.html</span><br />
<br />
path<span style="color: #339933;">=/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<br />
type<span style="color: #339933;">=</span>cq<span style="color: #339933;">:</span>Page<br />
fulltext<span style="color: #339933;">=</span>weretail<span style="color: #339933;">/</span>components<span style="color: #339933;">/</span>structure<span style="color: #339933;">/</span>page<br />
p.<span style="color: #006633;">limit</span><span style="color: #339933;">=-</span><span style="color: #cc66cc;">1</span></div></td></tr></tbody></table></div>
<p>Visit localhost: <a href="http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Afulltext%3Dweretail%2Fcomponents%2Fstructure%2Fpage%0D%0Ap.limit%3D-1" rel="noopener" target="_blank">http://localhost:4502/libs/cq/search/content/querydebug.html?_charset_=UTF-8&#038;query=path%3D%2Fcontent%2Fwe-retail%0D%0Atype%3Dcq%3APage%0D%0Afulltext%3Dweretail%2Fcomponents%2Fstructure%2Fpage%0D%0Ap.limit%3D-1</a></p>
<hr class="spacer-larger"/>
<h3 id="fulltext-search-JCR_SQL2">2. AEM FullText Search with the JCR_SQL2</h3>
<div class="mention-block">
For a quick review on how to query using the JCR SQL console from CRX/DE, click on each step below.<br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2022/01/1.how-to-aem-jcr-sql2.png" data-caption-desc="Step 1. Visit CRX/DE, from the CRX/DE main navigation, Tools &gt; Query." alt="Step 1. Visit CRX/DE, from the CRX/DE main navigation, Tools &gt; Query.">Step 1. Visit CRX/DE, from the CRX/DE main navigation, Tools &gt; Query.</a><br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2022/01/2.how-to-aem-jcr-sql2.png" data-caption-desc="Step 2. From the Query Console, change the path to JCR_SQL2." alt="Step 2. From the Query Console, change the path to JCR_SQL2.">Step 2. From the Query Console, change the path to JCR_SQL2.</a><br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2022/01/3.how-to-aem-jcr-sql2.png" data-caption-desc="Step 3. Insert your JCR_SQL2 query, and click on Execute. The results should be shown." alt="Step 3. Insert your JCR_SQL2 query, and click on Execute. The results should be shown.">Step 3. Insert your JCR_SQL2 query, and click on Execute. The results should be shown.</a>
</div>
<p class="spacer-large">
<p><strong>Example 1: In this example we will find all [nt:base] JCR nodes matching any %pants%</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Search <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">:</span><br />
anything under <span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><br />
and any.<span style="color: #006633;">properties</span> with values LIKE <span style="color: #0000ff;">&quot;%pants%&quot;</span><br />
and show me more than <span style="color: #cc66cc;">10</span> results.<br />
<br />
<span style="color: #339933;">-------------</span><br />
<br />
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/crx/de/index.jsp</span><br />
<br />
SELECT <span style="color: #339933;">*</span> FROM <span style="color: #009900;">&#91;</span>nt<span style="color: #339933;">:</span>base<span style="color: #009900;">&#93;</span> AS nodes <br />
WHERE ISDESCENDANTNODE <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
AND CONTAINS<span style="color: #009900;">&#40;</span>nodes .<span style="color: #339933;">*</span>, <span style="color: #0000ff;">'pants'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>Visit localhost: <a href="http://localhost:4502/crx/de/index.jsp" rel="noopener" target="_blank">http://localhost:4502/crx/de/index.jsp</a></p>
<hr class="spacer-large"/>
<p><strong>Example 2: In this example we will find all [cq:Page] JCR nodes matching any %weretail/components/structure/page%</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Search <span style="color: #000000; font-weight: bold;">for</span><span style="color: #339933;">:</span><br />
anything under <span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><br />
and only <span style="color: #0000ff;">&quot;cq:Page&quot;</span> nodes<br />
and any.<span style="color: #006633;">properties</span> with values LIKE <span style="color: #0000ff;">&quot;%weretail/components/structure/page%&quot;</span><br />
and show me more than <span style="color: #cc66cc;">10</span> results.<br />
<br />
<span style="color: #339933;">-------------</span><br />
<br />
http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/libs/cq/search/content/querydebug.html</span><br />
<br />
SELECT <span style="color: #339933;">*</span> FROM <span style="color: #009900;">&#91;</span>cq<span style="color: #339933;">:</span>Page<span style="color: #009900;">&#93;</span> AS nodes <br />
WHERE ISDESCENDANTNODE <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>we<span style="color: #339933;">-</span>retail<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
AND CONTAINS<span style="color: #009900;">&#40;</span>nodes .<span style="color: #339933;">*</span>, <span style="color: #0000ff;">'weretail/components/structure/page'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>Visit localhost: <a href="http://localhost:4502/crx/de/index.jsp" rel="noopener" target="_blank">http://localhost:4502/crx/de/index.jsp</a></p>
<hr class="spacer"/>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/find-aem-jcr-nodes-with-full-text-search">Find AEM JCR Nodes with Full Text Search</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/find-aem-jcr-nodes-with-full-text-search/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>AEM IntelliJ Debug Error:osgi: [sourcedcode.core] Classes found in the wrong directory: {META-INF/versions/9/javax/xml/bind/ModuleUtil.class=javax.xml.bind.ModuleUtil}</title>
		<link>https://sourcedcode.com/blog/aem/aem-intellij-debug-error-osgi-error-modelutil</link>
					<comments>https://sourcedcode.com/blog/aem/aem-intellij-debug-error-osgi-error-modelutil#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 09 Jan 2022 19:00:02 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3085</guid>

					<description><![CDATA[<p>Writing unit tests for AEM Backend code on IntelliJ can sometimes be challenging; mocking objects, initializing OSGI components, etc&#8230; It&#8217;s most beneficial when we can write unit tests utilizing the JUnit debug feature on IntelliJ. While trying to debug code in JUnit, I was getting an error of 1Error:osgi: &#91;sourcedcode.core&#93; Classes found in the wrong [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-intellij-debug-error-osgi-error-modelutil">AEM IntelliJ Debug Error:osgi: [sourcedcode.core] Classes found in the wrong directory: {META-INF/versions/9/javax/xml/bind/ModuleUtil.class=javax.xml.bind.ModuleUtil}</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Writing unit tests for AEM Backend code on IntelliJ can sometimes be challenging; mocking objects, initializing OSGI components, etc&#8230; It&#8217;s most beneficial when we can write unit tests utilizing the JUnit debug feature on IntelliJ.</p>
<p>While trying to debug code in JUnit, I was getting an error of</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #003399;">Error</span><span style="color: #339933;">:</span>osgi<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>sourcedcode.<span style="color: #006633;">core</span><span style="color: #009900;">&#93;</span> Classes found in the wrong directory<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>META<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>versions<span style="color: #339933;">/</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">/</span>javax<span style="color: #339933;">/</span>xml<span style="color: #339933;">/</span>bind<span style="color: #339933;">/</span>ModuleUtil.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span>javax.<span style="color: #006633;">xml</span>.<span style="color: #006633;">bind</span>.<span style="color: #006633;">ModuleUtil</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Digging through the internet, I have found a solution. </p>
<p>There&#8217;s a solution online, <a href="https://issues.apache.org/jira/browse/FELIX-5592" rel="noopener" target="_blank">https://issues.apache.org/jira/browse/FELIX-5592</a></p>
<p>Personally, there&#8217;s a lot of conversation happening in the post, to offload the confusion for you, I will provide you instructions on how you can solve the problem here.</p>
<hr class="spacer-large"/>
<h4>Step 1</h4>
<p>From the core/pom.xml, find the plugin, groupId:org.apache.felix &#038;&#038; artifactId:maven-bundle-plugin. Making sure you add <span class="code-highlight-primary">_fixupmessages</span> into the <span class="code-highlight-secondary">instructions</span> XML configuration.</p>
<p>Your configuration should look like below. Add line:9, &lt;_fixupmessages&gt;&#8221;Classes found in the wrong directory&#8221;;is:=warning&lt;/_fixupmessages&gt;</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>build<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>plugins<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">felix</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>maven<span style="color: #339933;">-</span>bundle<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>extensions<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>extensions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>instructions<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>_fixupmessages<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">&quot;Classes found in the wrong directory&quot;</span><span style="color: #339933;">;</span>is<span style="color: #339933;">:=</span>warning<span style="color: #339933;">&lt;/</span>_fixupmessages<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; ...<br />
<span style="color: #339933;">&lt;/</span>build<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="mention-block">Note that the Java-9-specific parts will not be visible in OSGi, because OSGi will need enhancements to its runtime (the problem is that the Java 9 parts could have different dependencies, and OSGi does not support dependencies that are conditional upon the runtime Java version). Work on addressing this limitation is underway. In the meantime, the above snippet will allow you to keep using the maven-bundle-plugin to support OSGi users running on Java 8 and below. <a href="https://issues.apache.org/jira/browse/FELIX-5592#comment-16281169" target="_BLANK" rel="noopener">FELIX-5592#comment-16281169</a></div>
<hr class="spacer-large"/>
<h4>Step 2</h4>
<p>From the core/pom.xml, make sure you include the required dependency into the project.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bndlib</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h4>Step 3</h4>
<p>From the parent pom.xml, make sure you include the dependency into the project with the correct version.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bndlib</span><span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>3.5.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-intellij-debug-error-osgi-error-modelutil">AEM IntelliJ Debug Error:osgi: [sourcedcode.core] Classes found in the wrong directory: {META-INF/versions/9/javax/xml/bind/ModuleUtil.class=javax.xml.bind.ModuleUtil}</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-intellij-debug-error-osgi-error-modelutil/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ACS Commons multi-field extension, acs-commons-nested, checkbox is not working</title>
		<link>https://sourcedcode.com/blog/aem/acs-commons-multi-field-extension-acs-commons-nested-checkbox-not-working</link>
					<comments>https://sourcedcode.com/blog/aem/acs-commons-multi-field-extension-acs-commons-nested-checkbox-not-working#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 08 Dec 2021 21:28:31 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3097</guid>

					<description><![CDATA[<p>This article will provide a solution to the ACS Commons multi-field extension, checkbox Granite UI Component. While utilizing the ACS Commons multi-field extension, for everything I tried, I am not able to get the checkbox Granite UI component working as expected. Not an elegant way to solve the problem, but something that actually works and [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/acs-commons-multi-field-extension-acs-commons-nested-checkbox-not-working">ACS Commons multi-field extension, acs-commons-nested, checkbox is not working</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article will provide a solution to the ACS Commons multi-field extension, checkbox Granite UI Component.</p>
<p>While utilizing the ACS Commons multi-field extension, for everything I tried, I am not able to get the checkbox Granite UI component working as expected. Not an elegant way to solve the problem, but something that actually works and is sustainable.</p>
<p>I found a solution that is simple. Instead of using the checkbox Granite UI Component, use the select Granite UI Component, granite/ui/components/coral/foundation/form/select. This works; problem solved.</p>
<div class="mention-block">Scroll near the bottom of this page to find the example code where the solution can be found.</div>
<hr class="spacer-large"/>
<h3>Not Working Checkbox</h3>
<p>As you can see here, in line:24, the acs-commons-nested property is not picking up the Granite UI Component, checkbox.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>links<br />
&nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/form/multifield&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>field<br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/form/fieldset&quot;</span><br />
&nbsp; &nbsp; acs<span style="color: #339933;">-</span>commons<span style="color: #339933;">-</span>nested<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><br />
&nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./links&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>column<br />
&nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>linkTitle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Link Title&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./linkTitle&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>linkPath<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/form/pathbrowser&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Link Path&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./linkPath&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>isChecked<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/form/checkbox&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;isChecked?&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./isChecked&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;isChecked flag&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uncheckedValue<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>column<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>field<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>links<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3>Solved: Working Boolean</h3>
<p>In line:24, replacing the checkbox with the select Granite UI Component, solves the issue.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>links<br />
&nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/form/multifield&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>field<br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/form/fieldset&quot;</span><br />
&nbsp; &nbsp; acs<span style="color: #339933;">-</span>commons<span style="color: #339933;">-</span>nested<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><br />
&nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./links&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>column<br />
&nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>linkTitle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Link Title&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./linkTitle&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>linkPath<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/form/pathbrowser&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Link Path&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./linkPath&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>isChecked<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;isChecked&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./isChecked&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span><span style="color: #000066; font-weight: bold;">false</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selected<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;False&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}false&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span><span style="color: #000066; font-weight: bold;">true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;True&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>isChecked<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>column<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>field<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>links<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/acs-commons-multi-field-extension-acs-commons-nested-checkbox-not-working">ACS Commons multi-field extension, acs-commons-nested, checkbox is not working</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/acs-commons-multi-field-extension-acs-commons-nested-checkbox-not-working/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM RichText Remove P Tag, removeSingleParagraphContainer, for Touch UI</title>
		<link>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-removesingleparagraphcontainer-for-touch-ui</link>
					<comments>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-removesingleparagraphcontainer-for-touch-ui#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 29 Oct 2021 07:30:14 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=3001</guid>

					<description><![CDATA[<p>You may have been trying to search the internet for an out of box solution to remove the single paragraph container for Touch UI, and have found something like removeSingleParagraphContainer. But however, this attribute was for the Classic UI and deprecated. From my knowledge, there isn&#8217;t anything out of the box that can remove the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-removesingleparagraphcontainer-for-touch-ui">AEM RichText Remove P Tag, removeSingleParagraphContainer, for Touch UI</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You may have been trying to search the internet for an out of box solution to remove the single paragraph container for Touch UI, and have found something like removeSingleParagraphContainer. But however, this attribute was for the Classic UI and deprecated. From my knowledge, there isn&#8217;t anything out of the box that can remove the p single paragraph container tag. However, I have spent some time and found a very lucrative solution. Lets remove the p tag from the rich text editor!</p>
<p>In this article, we will step through my implementation for us to remove the p tag once and for all, from being rendered. </p>
<p>My solution to this problem will be dealt with in the backend, Sling Model. Some may argue that the solution can be done using Javascript, but that can be very troublesome. Let&#8217;s Keep it Simple Stupid (KISS). There&#8217;s one caveat to this approach; scroll to the bottom of the page to see what it is.</p>
<p>Follow my 3 steps below to remove the P tag wrapper from what is being produced by the cq/gui/components/authoring/dialog/richtext.</p>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/WSS1Tfau4dc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<hr class="spacer-large"/>
<h3>Step 1. Add Custom Option In the Paraformat Options</h3>
<p>Under the _cq_dialog.xml, <strong>cq/gui/components/authoring/dialog/richtext</strong>, add a new format option under the paraformat list of options. </p>
<p>The selected paraformat option will be a custom HTML element that wraps onto the highlighted or selected text from the author. In this case, when the author have selected text, and then click on the new paraformat option, the Html will look something like this <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// new paraformt to be added into line:77<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notextformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;No - Text Format&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;notextformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
// the complete _cq_dialog.xml configuration for the cq/gui/components/authoring/dialog/richtext<br />
// new paraformt to be added into line:77<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog/richtext&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./text&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;<span style="color: #000066;">useFixedInlineToolbar</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rtePlugins</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;format</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;bold,italic&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;justify</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;links</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;modifylink,unlink&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lists</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paraformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">features</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;formats</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_p</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Paragraph&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;p&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h1</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 1&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h2</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 2&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h3</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 3&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h4</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 4&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h4&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h5</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 5&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h5&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_h6</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Heading 6&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;h6&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_blockquote</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Quote&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;blockquote&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default_pre</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Preformatted&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;pre&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;notextformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;No - Text Format&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">tag</span>=<span style="color: #ff0000;">&quot;notextformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/formats<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/paraformat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rtePlugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uiSettings</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cui</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inline</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">toolbar</span>=<span style="color: #ff0000;">&quot;[format#bold,format#italic,format#underline,#justify,#lists,links#modifylink,links#unlink,#paraformat]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;popovers</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;justify</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;[justify#justifyleft,justify#justifycenter,justify#justifyright]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;justify&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lists</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;[lists#unordered,lists#ordered,lists#outdent,lists#indent]&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;paraformat</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;paraformat:getFormats:paraformat-pulldown&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;paraformat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/popovers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inline<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cui<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uiSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3>Step 2. Create the Backend, Sling Model, to Text Transform</h3>
<p>The backend Sling Model will read the ./text property that has been set by the user&#8217;s input. Using the String.ReplaceAll(), we can replace all <span class="code-highlight-secondary">&lt;/?notextformat&gt;</span>, regex pattern, with nothing (meaning that this element will be removed).</p>
<p>For example <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>. -> <span class="code-highlight-primary">sometext</span>.</p>
<p>We next save the formatted text into a variable of <span class="code-highlight-secondary"richText</span>, which can be used by sightly to display HTML on the page.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Default</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Optional</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ValueMapValue</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables<span style="color: #339933;">=</span>Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyTextComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Optional<br />
&nbsp; &nbsp; @ValueMapValue<br />
&nbsp; &nbsp; @<span style="color: #000000; font-weight: bold;">Default</span><span style="color: #009900;">&#40;</span>values <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> text<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> richText<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>text.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richText <span style="color: #339933;">=</span> text.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/?notextformat&gt;&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getRichText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> richText<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-larger"/>
<h3>Step 3. Render Text Transform from Sightly</h3>
<p>Now finally we just need to utilise sightly to print the text transformed, <span class="code-highlight-primary">richText</span>, to the screen.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;sly data-sly-use.myTextComponent<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.core.models.MyTextComponent&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br />
${myTextComponent.richText @ context='html'}<br />
<span style="color: #009900;">&lt;sly data-sly-use.templates<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;core/wcm/components/commons/v1/templates.html&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-call<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${templates.placeholder @ isEmpty = !myTextComponent.richText}&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>sly&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<div class="mention-block">
<strong>Last Thoughts?</strong><br />
The caveat with this approach is that when you are trying to export JSON format from this component, you will be stuck with this block of text, <span class="code-highlight-primary">&lt;notextformat&gt;sometext&lt;/notextformat&gt;</span>, unless if you text to transform the export as well.</p>
<p>The reason why I did not overwrite the JCR values is that I wanted to retain the natural editing experience for the authors. With my solution when the author decides to make changes to the rich text field, they would not have a werid experience.
</p></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-removesingleparagraphcontainer-for-touch-ui">AEM RichText Remove P Tag, removeSingleParagraphContainer, for Touch UI</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-richtext-remove-p-tag-removesingleparagraphcontainer-for-touch-ui/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>How to Pass Data Parameters to WCMUsePojo from Sightly HTL Component</title>
		<link>https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-wcmusepojo-from-sightly-htl-component</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-wcmusepojo-from-sightly-htl-component#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 24 Oct 2021 05:27:08 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2983</guid>

					<description><![CDATA[<p>You can pass data parameters from Sightly HTL component to the WCMUsePojo backend in a very simple way. You can simply call the get(String name, Class type) method from the available public methods from the com.adobe.cq.sightly.WCMUsePojo class. For implementation, use the get(String name, Class type) method, we obtain the values sent from Sightly as attributes; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-wcmusepojo-from-sightly-htl-component">How to Pass Data Parameters to WCMUsePojo from Sightly HTL Component</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You can pass data parameters from Sightly HTL component to the WCMUsePojo backend in a very simple way. You can simply call the <b>get(String name, Class<T> type)</b> method from the available public methods from the com.adobe.cq.sightly.WCMUsePojo class. For implementation, use the <b>get(String name, Class<T> type)</b> method, we obtain the values sent from Sightly as attributes; the first parameter will be the name of the attribute (passed in from the Sightly HTL component, and the second parameter will be the Object type (that we expect from the get() method). This is all there is, pretty simple; see the example below.</p>
<div class="mention-block">
As developers. We learn best by example, See the example below of an example of Sightly HTL component referencing to the WCMUsePojo backend. </p>
<p>I created the code below to showcase a real production scenario. After a selection from the TouchUI pathfinder, we are given a path of /content/sourcedcode/en/home. From sightly, we must append a .html, but when the path was not chosen with the TouchUI pathfinder with the value set manually to https://sourcedcode.com, no .html extensions should be added.</p>
<p>The example below showcases how we can logically insert the .html extensions based on conditions.
</p></div>
<h3>Sightly HTL</h3>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// expect /content/sourcedcode/home.html<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;title-text&quot;</span> data-sly-use.linkResolve<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.utils.use.LinkResolve' @ href='/content/sourcedcode/home'}&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.href}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.target}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${linkResolve.href} = ${linkResolve.target}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
// expect https://sourcedcode.com<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;title-text&quot;</span> data-sly-use.linkResolve<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.utils.use.LinkResolve' @ href='https://sourcedcode.com'}&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.href}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.target}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${linkResolve.href} = ${linkResolve.target}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
// expect https://sourcedcode.com<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> data-sly-use.linkResolve<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.models.LinkResolve' @ &nbsp;href=properties.href, &nbsp;target=properties.target}&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.href}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.target}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${linkResolve.href}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></div></td></tr></tbody></table></div>
<h3>WCMUsePojo Class : LinkResolve.class</h3>
<div class="code-large">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.utils.use</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.WCMUsePojo</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LinkResolve <span style="color: #000000; font-weight: bold;">extends</span> WCMUsePojo <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> href <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> target <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; href <span style="color: #339933;">=</span> get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;href&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; target <span style="color: #339933;">=</span> get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;target&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>href <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> href.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> isLinkExternal <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^https?://.*&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>href<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> isLinkInternalAsset <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.*<span style="color: #000099; font-weight: bold;">\\</span>.(<span style="color: #000099; font-weight: bold;">\\</span>w){1,5}$&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>href<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isLinkExternal <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>isLinkInternalAsset<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; href <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>href.<span style="color: #006633;">endsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> href.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> href <span style="color: #339933;">:</span> href <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> target.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; target <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;_self&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getHref<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> href<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTarget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> target<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-wcmusepojo-from-sightly-htl-component">How to Pass Data Parameters to WCMUsePojo from Sightly HTL Component</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-wcmusepojo-from-sightly-htl-component/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Pass Data Parameters to Sling Modal from Sightly HTL Component</title>
		<link>https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-sling-modal-from-sightly-htl-component</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-sling-modal-from-sightly-htl-component#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 23 Oct 2021 04:52:31 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2971</guid>

					<description><![CDATA[<p>You can pass data parameters from Sightly HTL component to the Sling Model backend by request attributes. For implementation, utilising the org.apache.sling.models.annotations.Model, we will add required options parameter, adaptable, with the value of SlingHttpServletRequest.class. Next, we can utilize the annotation, org.apache.sling.models.annotations.injectorspecific.RequestAttribute (@RequestAttribute), which will find the matching name of the attribute that is being passed [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-sling-modal-from-sightly-htl-component">How to Pass Data Parameters to Sling Modal from Sightly HTL Component</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You can pass data parameters from Sightly HTL component to the Sling Model backend by <b>request attributes</b>. For implementation, utilising the org.apache.sling.models.annotations.Model, we will add required options parameter, adaptable, with the value of SlingHttpServletRequest.class. Next, we can utilize the annotation, org.apache.sling.models.annotations.injectorspecific.RequestAttribute (@RequestAttribute), which will find the matching name of the attribute that is being passed from the Sightly HTL component. </p>
<div class="mention-block">
As developers. We learn best by example, See the example below of an example of Sightly HTL component referencing to the Sling Model backend. </p>
<p>I created the code below to showcase a real production scenario. After a selection from the TouchUI pathfinder, we are given a path of /content/sourcedcode/en/home. From sightly, we must append a .html, but when the path was not chosen with the TouchUI pathfinder with the value set manually to https://sourcedcode.com, no .html extensions should be added.</p>
<p>This example below showcases how we can logically insert the .html extensions based on conditions.
</p></div>
<h3>Sightly HTL</h3>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// expect /content/sourcedcode/home.html<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;title-text&quot;</span> data-sly-use.linkResolve<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.utils.use.LinkResolve' @ href='/content/sourcedcode/home'}&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.href}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.target}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${linkResolve.href}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span><br />
// expect https://sourcedcode.com<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;title-text&quot;</span> data-sly-use.linkResolve<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.utils.use.LinkResolve' @ href='https://sourcedcode.com'}&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.href}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.target}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${linkResolve.href}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
// expect https://sourcedcode.com<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> data-sly-use.linkResolve<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.models.LinkResolve' @</span><br />
<span style="color: #009900;"> &nbsp; &nbsp;href=properties.href,</span><br />
<span style="color: #009900;"> &nbsp; &nbsp;target=properties.target}&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.href}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${linkResolve.target}&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${linkResolve.href}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></div></td></tr></tbody></table></div>
<h3>Sling Model Class : LinkResolve.class</h3>
<div class="code-large">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Default</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Optional</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.RequestAttribute</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LinkResolve <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @RequestAttribute<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> href<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Optional<br />
&nbsp; &nbsp; @<span style="color: #000000; font-weight: bold;">Default</span><span style="color: #009900;">&#40;</span>values<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_self&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; @RequestAttribute<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> target<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>href <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> href.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> isLinkExternal <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^https?://.*&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>href<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> isLinkInternalAsset <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.*<span style="color: #000099; font-weight: bold;">\\</span>.(<span style="color: #000099; font-weight: bold;">\\</span>w){1,5}$&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>href<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isLinkExternal <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>isLinkInternalAsset<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; href <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>href.<span style="color: #006633;">endsWith</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> href.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> href <span style="color: #339933;">:</span> href <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getHref<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> href<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTarget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> target<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-sling-modal-from-sightly-htl-component">How to Pass Data Parameters to Sling Modal from Sightly HTL Component</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-pass-parameters-to-sling-modal-from-sightly-htl-component/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Update a Node JCR property in AEM with CURL</title>
		<link>https://sourcedcode.com/blog/aem/update-a-node-jcr-property-in-aem-with-curl</link>
					<comments>https://sourcedcode.com/blog/aem/update-a-node-jcr-property-in-aem-with-curl#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 30 Jun 2021 00:40:21 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2930</guid>

					<description><![CDATA[<p>This is a simple way to update or write a Node JCR property inside of AEM using curl. curl command: 1curl -v -u admin:admin -X POST http://localhost:4502/content/sourcedcodeaem/jcr:content --data-urlencode 'isCurlWorking=true' Result: If you wish to learn how to Update Multi-Value Node JCR properties in AEM with CURL, click here.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/update-a-node-jcr-property-in-aem-with-curl">Update a Node JCR property in AEM with CURL</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This is a simple way to update or write a Node JCR property inside of AEM using curl.</p>
<p><strong>curl command:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl <span style="color: #339933;">-</span>v <span style="color: #339933;">-</span>u admin<span style="color: #339933;">:</span>admin <span style="color: #339933;">-</span>X POST http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/content/sourcedcodeaem/jcr:content --data-urlencode 'isCurlWorking=true'</span></div></td></tr></tbody></table></div>
<p><strong>Result:</strong><br />
<a class="foobox fbx-link fbx-instance" href="https://sourcedcode.com/wp-content/uploads/2021/06/update-a-node-jcr-property-in-aem-with-curl-screenshot.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2021/06/update-a-node-jcr-property-in-aem-with-curl-screenshot.png" alt="result of the curl command"/></a></p>
<div class="mention-block">
If you wish to learn how to Update Multi-Value Node JCR properties in AEM with CURL, <a href="https://sourcedcode.com/blog/aem/update-multi-value-node-jcr-properties-in-aem-with-curl" title="Update Multi-Value Node JCR properties in AEM with CURL">click here</a>.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/update-a-node-jcr-property-in-aem-with-curl">Update a Node JCR property in AEM with CURL</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/update-a-node-jcr-property-in-aem-with-curl/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Update Multi-Value Node JCR properties in AEM with CURL</title>
		<link>https://sourcedcode.com/blog/aem/update-multi-value-node-jcr-properties-in-aem-with-curl</link>
					<comments>https://sourcedcode.com/blog/aem/update-multi-value-node-jcr-properties-in-aem-with-curl#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 30 Jun 2021 00:10:15 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2918</guid>

					<description><![CDATA[<p>This is a simple way to update or write multi-value Node JCR properties inside of AEM using curl. curl command: 12345curl -v &#34;http://localhost:4502/crx/server/crx.default/jcr%3aroot&#34; \ &#160; -u admin:admin \ &#160; -H 'Content-Type: multipart/form-data; boundary=crxde' \ &#160; --data-raw $'--crxde\r\nContent-Disposition: form-data; name=&#34;:diff&#34;\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n^/content/sourcedcodeaem/jcr:content/stringArray : [&#34;one&#34;,&#34;two&#34;,&#34;three&#34;]\r\n--crxde-- ' \ &#160; --compressed Result: If you wish to learn how to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/update-multi-value-node-jcr-properties-in-aem-with-curl">Update Multi-Value Node JCR properties in AEM with CURL</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This is a simple way to update or write multi-value Node JCR properties inside of AEM using curl.</p>
<p><strong>curl command:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl <span style="color: #339933;">-</span>v <span style="color: #0000ff;">&quot;http://localhost:4502/crx/server/crx.default/jcr%3aroot&quot;</span> \<br />
&nbsp; <span style="color: #339933;">-</span>u admin<span style="color: #339933;">:</span>admin \<br />
&nbsp; <span style="color: #339933;">-</span>H <span style="color: #0000ff;">'Content-Type: multipart/form-data; boundary=crxde'</span> \<br />
&nbsp; <span style="color: #339933;">--</span>data<span style="color: #339933;">-</span>raw $<span style="color: #0000ff;">'--crxde<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Content-Disposition: form-data; name=&quot;:diff&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Content-Type: text/plain; charset=utf-8<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>^/content/sourcedcodeaem/jcr:content/stringArray : [&quot;one&quot;,&quot;two&quot;,&quot;three&quot;]<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>--crxde-- '</span> \<br />
&nbsp; <span style="color: #339933;">--</span>compressed</div></td></tr></tbody></table></div>
<p><strong>Result:</strong><br />
<a class="foobox fbx-link fbx-instance" href="https://sourcedcode.com/wp-content/uploads/2021/06/update-multi-value-node-jcr-property-type-in-aem-with-curl-screeenshot-cleaned.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2021/06/update-multi-value-node-jcr-property-type-in-aem-with-curl-screeenshot-cleaned.png" alt="result of the curl command"/></a></p>
<div class="mention-block">
If you wish to learn how to Update a Node JCR property in AEM with CURL, <a href="https://sourcedcode.com/blog/aem/update-a-node-jcr-property-in-aem-with-curl" title="Update a Node JCR property in AEM with CURL">click here</a>.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/update-multi-value-node-jcr-properties-in-aem-with-curl">Update Multi-Value Node JCR properties in AEM with CURL</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/update-multi-value-node-jcr-properties-in-aem-with-curl/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to get Authorization: Basic Auth Header from AEM Author</title>
		<link>https://sourcedcode.com/blog/aem/how-to-get-authorization-basic-auth-header-from-aem-author</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-get-authorization-basic-auth-header-from-aem-author#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 29 Jun 2021 23:35:03 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2905</guid>

					<description><![CDATA[<p>Getting the Authorization (Basic access authentication) Basic Auth Header from AEM Author is simple. If you have curl installed on your machine, simply run the command below, and you should be able to get the Authorization header from a successful AEM login. What we are doing here is logging into the AEM author with curl [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-get-authorization-basic-auth-header-from-aem-author">How to get Authorization: Basic Auth Header from AEM Author</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Getting the Authorization (Basic access authentication) Basic Auth Header from AEM Author is simple. If you have <a href="https://curl.se" title="curl website" rel="nofollow noopener" target="_blank">curl</a> installed on your machine, simply run the command below, and you should be able to get the Authorization header from a successful AEM login.</p>
<p>What we are doing here is logging into the AEM author with curl using -v (verbose) &#038; -u (user:pass).</p>
<p><b>curl request:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl <span style="color: #339933;">-</span>v <span style="color: #339933;">-</span>u admin<span style="color: #339933;">:</span>admin http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502</span></div></td></tr></tbody></table></div>
<p><b>curl response (line::8):</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">*</span> Rebuilt <span style="color: #003399;">URL</span> to<span style="color: #339933;">:</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:4502/</span><br />
<span style="color: #339933;">*</span> &nbsp; Trying <span style="color: #339933;">::</span><span style="color: #cc66cc;">1</span>...<br />
<span style="color: #339933;">*</span> TCP_NODELAY set<br />
<span style="color: #339933;">*</span> Connected to localhost <span style="color: #009900;">&#40;</span><span style="color: #339933;">::</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> port <span style="color: #cc66cc;">4502</span> <span style="color: #009900;">&#40;</span>#<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #339933;">*</span> Server auth using Basic with user <span style="color: #0000ff;">'admin'</span><br />
<span style="color: #339933;">&gt;</span> GET <span style="color: #339933;">/</span> HTTP<span style="color: #339933;">/</span><span style="color: #cc66cc;">1.1</span><br />
<span style="color: #339933;">&gt;</span> Host<span style="color: #339933;">:</span> localhost<span style="color: #339933;">:</span><span style="color: #cc66cc;">4502</span><br />
<span style="color: #339933;">&gt;</span> Authorization<span style="color: #339933;">:</span> Basic YWRtaW46YWRtaW4<span style="color: #339933;">=</span><br />
<span style="color: #339933;">&gt;</span> User<span style="color: #339933;">-</span>Agent<span style="color: #339933;">:</span> curl<span style="color: #339933;">/</span>7.54.0<br />
<span style="color: #339933;">&gt;</span> Accept<span style="color: #339933;">:</span> <span style="color: #339933;">*</span><span style="color: #666666; font-style: italic;">/*<br />
&gt; <br />
&lt; HTTP/1.1 302 Found<br />
&lt; Location: /index.html<br />
&lt; Transfer-Encoding: chunked<br />
&lt; <br />
* Connection #0 to host localhost left intact</span></div></td></tr></tbody></table></div>
<p><b>Authorization Basic:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Authorization<span style="color: #339933;">:</span> Basic YWRtaW46YWRtaW4<span style="color: #339933;">=</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-get-authorization-basic-auth-header-from-aem-author">How to get Authorization: Basic Auth Header from AEM Author</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-get-authorization-basic-auth-header-from-aem-author/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>DRY way of using RichText Granite UI Component in AEM for Static Templates</title>
		<link>https://sourcedcode.com/blog/aem/dry-way-of-using-richtext-granite-ui-component-in-aem-for-static-templates</link>
					<comments>https://sourcedcode.com/blog/aem/dry-way-of-using-richtext-granite-ui-component-in-aem-for-static-templates#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 21 Jun 2021 01:14:04 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2811</guid>

					<description><![CDATA[<p>Every developer have experienced a situation where they are working with AEM multiple AEM components, where Touch UI dialogues consist of a common richtext Granite UI component configuration cq/gui/components/authoring/dialog/richtext. When I mention common richtext Granite UI component, I mean there are multiple AEM components that will have the richtext Granite UI component as one of [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/dry-way-of-using-richtext-granite-ui-component-in-aem-for-static-templates">DRY way of using RichText Granite UI Component in AEM for Static Templates</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Every developer have experienced a situation where they are working with AEM multiple AEM components, where Touch UI dialogues consist of a common richtext Granite UI component configuration <a href="https://gist.github.com/briankasingli/1a7e3e12deaa2e076645b09d30039b46" target="_blank" rel="noopener">cq/gui/components/authoring/dialog/richtext</a>. When I mention common richtext Granite UI component, I mean there are multiple AEM components that will have the richtext Granite UI component as one of it&#8217;s input fields, where only the &#8220;links*&#8221; and &#8220;format*&#8221; richtext features are enabled, as an example.</p>
<p>Enabling only the &#8220;links*&#8221; and &#8220;format*&#8221; richtext features, we catch ourselves repeating lines of code by copying and pasting the entire block of code for all of our Touch UI dialogues that require the richtext requirement. This works, but this is Write Everything Twice, &#8220;WET&#8221; code, and it&#8217;s not good implementation; this can be improved. What happens if there is a new requirement where the authors would like a new capability to the richtext field? Will we have to edit multiple dialogues? (like editing 20 component&#8217;s dialogues) The short answer is Yes. With this &#8220;WET&#8221; implementation, you must edit every single component&#8217;s dialogue configuration.</p>
<p><b>How can we do this better? How keep our code Don&#8217;t Repeat Yourself (DRY)?</b></p>
<p>Utilising the Granite UI component, <span class="code-highlight-secondary"><a href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/include/index.html" rel="noopener nofollow" target="_blank">granite/ui/components/coral/foundation/include</a></span>, we are able to refer to common Granite UI component configurations in the JCR (that we are going to set up). Now changing the richtext configuration in one place will provide TouchUI dialogue changes to all 20+ components; see diagram below.</p>
<div class="mention-block">
<b>Implementation Quick Links</b></p>
<ol>
<li><a href="#register">IMPL: Register the common dialog namespace</a></li>
<li><a href="#create-and-configure">IMPL: Create and configure the common Granite UI component configurations, under the “fields” structure</a></li>
<li><a href="#include">IMPL: From the targeted component, include the common Granite UI config</a></li>
<li><a href="#done">IMPL: Done</a></li>
</ol>
</div>
<p><b>Advantages of using common richtext configurations</b></p>
<ul>
<li>Ease to read and maintain</li>
<li>Reusability of the code</li>
<li>Reduces uneseccary lines of code in the repo</li>
<li>common Granite UI configs are easily accessible to manipulate</li>
</ul>
<p><a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2021/06/common-granite-ui-fields-touch-ui-ref.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2021/06/common-granite-ui-fields-touch-ui-ref.png" alt="Multiple AEM components' Touch UI dialogue utilises the common Granite UI component configuration in the JCR, for the richtext Granite UI component configurations." class="aligncenter" /></a></p>
<p>With the improvement, with the diagram above, you will notice multiple AEM components&#8217; Touch UI dialogue utilises the common Granite UI component configuration in the JCR, for the richtext Granite UI component configurations.</p>
<hr class="spacer-larger"/>
<h2 id="implementation">The Implementation</h2>
<p>In this section, code will be shared on how this configuration can be applied to your own AEM implementation. The example produced will be a summary of the diagram from <a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2021/06/common-granite-ui-fields-touch-ui-ref.png" title="Multiple AEM components' Touch UI dialogue utilises the common Granite UI component configuration in the JCR, for the richtext Granite UI component configurations.">above</a>.</p>
<div class="mention-block">We will be creating a common richtext Granite UI configuration which will be referenced by a example component.</div>
<hr class="spacer-large"/>
<h3 id="register">1. Register the common dialog namespace</h3>
<p>We typically place the common Granite UI component configurations for &#8220;content TouchUI&#8221; in the JCR under a namespaced project, for example: /apps/sourcedcodeaem/components/dialogs/content/common.</p>
<p>You will notice that there are already 3 folders that I have created.</p>
<ol>
<li><b>fields</b> &#8211; fields that are commonly used by Touch UI dialogue configs (<span class="code-highlight-primary">for this article we will only be focusing on these configs</span>)</li>
<li><b>fieldsets</b> &#8211; fieldsets that are commonly used by Touch UI dialogue configs; these consist of more than 1 Granite UI component which is wrapped around a granite/ui/components/foundation/container.</li>
<li><b>tabs</b> &#8211; tabs that are commonly used by Touch UI dialogue configs; these consist of more than 1 Granite UI component which is wrapped around a granite/ui/components/foundation/container.</li>
</ol>
<hr class="spacer-large"/>
<h3 id="create-and-configure">2. Create and configure the common Granite UI component configurations, under the &#8220;fields&#8221; structure</h3>
<p>/apps/sourcedcodeaem/components/dialogs/content/common/<span class="code-highlight-primary">fields</span>/_cq_dialog/.content.xml</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span><br />
<span style="color: #339933;">&lt;</span>jcr<span style="color: #339933;">:</span>root xmlns<span style="color: #339933;">:</span>sling<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>cq<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>jcr<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>nt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span><br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Common Field Granite UI Config for Content Components&quot;</span><br />
&nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq/gui/components/authoring/dialog&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>commonFields<br />
&nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>basicRTE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq/gui/components/authoring/dialog/richtext&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>rtePlugins jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>format<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; features<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>links<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; features<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>rtePlugins<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>uiSettings jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>cui jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>inline<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toolbar<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;[links#modifylink,links#unlink,format#bold,format#italic]&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dialogFullScreen<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toolbar<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;[links#modifylink,links#unlink,format#bold,format#italic]&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>cui<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>uiSettings<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>basicRTE<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>commonFields<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>jcr<span style="color: #339933;">:</span>root<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3 id="include">3. From the targeted component, include the common Granite UI config</h3>
<p>/apps/sourcedcodeaem/components/content/announcement</p>
<div class="modernized-box">
<ul>
<li>line:32 &#8211; the standard, cq/gui/components/authoring/dialog/richtext, Granite UI component is being referred.</li>
<li>line:38 &#8211; inclusion of the common richtext &#8220;rtePlugins&#8221; configuration, /apps/sourcedcodeaem/components/dialogs/content/common/fields/cq:dialog/commonFields/items/basicRTE/rtePlugins</li>
<li>line:42 &#8211; inclusion of the common richtext &#8220;uiSettings&#8221; configuration, /apps/sourcedcodeaem/components/dialogs/content/common/fields/cq:dialog/commonFields/items/basicRTE/uiSettings</li>
</ul>
<p><b>Together with line:32,38,42 the common richtext component will be setup and ready to be used.</b>
</div>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span><br />
<span style="color: #339933;">&lt;</span>jcr<span style="color: #339933;">:</span>root xmlns<span style="color: #339933;">:</span>sling<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>cq<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>jcr<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> xmlns<span style="color: #339933;">:</span>nt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span><br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; jcr<span style="color: #339933;">:</span>title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Announcement Component&quot;</span><br />
&nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq/gui/components/authoring/dialog&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>content<br />
&nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>layout<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/layouts/tabs&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nav&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>text<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Hero Settings&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/section&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>layout<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/layouts/fixedcolumns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}false&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>column<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>items jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>headerText<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fieldLabel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Title Text&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./headerText&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>headingDescriptionText<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cq/gui/components/authoring/dialog/richtext&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./headingDescriptionText&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; required<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; useFixedInlineToolbar<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Boolean}true&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>rtePlugins<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/include&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/apps/sourcedcodeaem/components/dialogs/content/common/fields/cq:dialog/commonFields/items/basicRTE/rtePlugins&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>uiSettings<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jcr<span style="color: #339933;">:</span>primaryType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sling<span style="color: #339933;">:</span>resourceType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;granite/ui/components/coral/foundation/include&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/apps/sourcedcodeaem/components/dialogs/content/common/fields/cq:dialog/commonFields/items/basicRTE/uiSettings&quot;</span><span style="color: #339933;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>headingDescriptionText<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>column<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>text<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>items<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>content<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>jcr<span style="color: #339933;">:</span>root<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h3 id="done">4. Done</h3>
<p>Now we have successfully referenced an AEM component to the common Touch UI dialogue field.<br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2021/06/granite-touch-ui-popup-richtext.png"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2021/06/granite-touch-ui-popup-richtext.png" alt="Announcement Component's Touch UI dialogue with a user interface of the common richtext configuration" width="920" height="543" class="aligncenter size-full wp-image-2859" srcset="https://sourcedcode.com/wp-content/uploads/2021/06/granite-touch-ui-popup-richtext.png 920w, https://sourcedcode.com/wp-content/uploads/2021/06/granite-touch-ui-popup-richtext-300x177.png 300w, https://sourcedcode.com/wp-content/uploads/2021/06/granite-touch-ui-popup-richtext-768x453.png 768w, https://sourcedcode.com/wp-content/uploads/2021/06/granite-touch-ui-popup-richtext-600x354.png 600w" sizes="(max-width: 920px) 100vw, 920px" /></a></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/dry-way-of-using-richtext-granite-ui-component-in-aem-for-static-templates">DRY way of using RichText Granite UI Component in AEM for Static Templates</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/dry-way-of-using-richtext-granite-ui-component-in-aem-for-static-templates/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>taglib prefix=&#8221;sling&#8221; to Sightly and Sling Model Non-JSP &#038; Non-JSTL implementation</title>
		<link>https://sourcedcode.com/blog/aem/taglib-prefix-sling-to-sightly-and-sling-model-non-jsp-non-jstl-implementation</link>
					<comments>https://sourcedcode.com/blog/aem/taglib-prefix-sling-to-sightly-and-sling-model-non-jsp-non-jstl-implementation#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 17 Jun 2021 03:14:13 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[jstl]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2703</guid>

					<description><![CDATA[<p>In the past, AEM developers would heavily focus on building AEM components with Java Server Pages (JSPs) &#038; JavaServer Pages Standard Tag Libraries (JSTLs). There are special JSTLs for AEM JSP components to speed up the development. One popular JSTL is called the Sling Taglib. The Sling Taglib is popular when it comes to writing [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/taglib-prefix-sling-to-sightly-and-sling-model-non-jsp-non-jstl-implementation">taglib prefix=&#8221;sling&#8221; to Sightly and Sling Model Non-JSP &#038; Non-JSTL implementation</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the past, AEM developers would heavily focus on building AEM components with Java Server Pages (JSPs) &#038; JavaServer Pages Standard Tag Libraries (JSTLs). </p>
<p>There are special JSTLs for AEM JSP components to speed up the development. One popular JSTL is called the <strong>Sling</strong> Taglib. The <strong>Sling</strong> Taglib is popular when it comes to writing AEM JSP components which provide the AEM component with the ability to invoke JSP scripts, including Resources and interact with the Sling Repository, all with JSP tags and Expression Language (EL) functions.</p>
<p>This is all great but JSP&#8217;s are becoming less common for writing AEM components as Sightly has become more mainstream and best practice. That being said, these JSPs are legacy and needs to be upgraded.</p>
<p>One common task for AEM developers is to upgrade JSP components to Sightly components. </p>
<div class="modernized-box">
The purpose of this article is to show AEM developers how to start to convert <strong>Sling</strong> Taglib business logic to Sightly and Sling Model logic, Non-JSP &#038; Non-JSTL implementation.
</div>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">Target TagLib<span style="color: #339933;">:</span> <br />
<span style="color: #339933;">&lt;%</span>@taglib prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sling&quot;</span> uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://sling.apache.org/taglibs/sling&quot;</span> <span style="color: #339933;">%&gt;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
In this article, we will step through some examples on how to convert <strong>Sling</strong> Taglib&#8217;s Expression Language Functions to Sightly and/or Sling Models logic.</p>
<p><b>Note:</b> While writing AEM Sightly components, <a href="https://sourcedcode.com/blog/aem/aem-sling-model-constructor-injection" rel="noopener" target="_blank">AEM global objects</a> are available and should have most of the AEM&#8217;s core JSTL functionalities.</p>
<p><b>Quick Links</b></p>
<ol>
<li><a href="#adaptTo">adaptTo()</a></li>
<li><a href="#encode">encode()</a></li>
<li><a href="#findResources">findResources()</a></li>
<li><a href="#getAbsoluteParent">getAbsoluteParent()</a></li>
<li><a href="#getParents">getParents()</a></li>
<li><a href="#getRelativeResource">getRelativeResource()</a></li>
<li><a href="#getResource">getResource()</a></li>
<li><a href="#getValue">getValue()</a></li>
<li><a href="#getResource">getResource()</a></li>
<li><a href="#hasChildren">hasChildren()</a></li>
<li><a href="#listChildren">listChildren()</a></li>
</ol>
</div>
<hr class="spacer-larger" />
<h3 id="adaptTo">1. adaptTo() to Sling Model &#038; Sightly</h3>
<p>Adapts an Adaptable to another class.</p>
<p><b>Returns:</b> java.lang.Object<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.adapter.Adaptable</span> &#8211; The object to adapt</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The name of the class to which to adapt the adaptable</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;valueMap&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:adaptTo(resource,'org.apache.sling.api.resource.ValueMap')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:adaptTo(resource,'com.day.cq.wcm.api.Page')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
$<span style="color: #009900;">&#123;</span>valueMap<span style="color: #009900;">&#125;</span><br />
$<span style="color: #009900;">&#123;</span>page<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp;data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${examplemodel.valueMap}<br />
&nbsp; &nbsp; ${examplemodel.page}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.Page</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ValueMap</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ValueMap valueMap<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Page page<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource resource<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; valueMap <span style="color: #339933;">=</span> resource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>ValueMap.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// example here</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; page <span style="color: #339933;">=</span> resource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Page.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="encode">2. encode() to Sling Model &#038; Sightly</h2>
<p>Writes properly Cross-Site Scripting (XSS) encoded text to the response using the OWASP ESAPI. Supports a number of encoding modes.</p>
<p><b>Returns:</b> <span class="code-highlight-secondary">java.util.String &#8211; An encoded text</span><br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The text to encode</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The encoding mode, one of HTML, HTML_ATTR, XML, XML_ATTR, JS</li>
</ul>
<p><b>Since:</b> 1.4<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">$<span style="color: #009900;">&#123;</span>sling<span style="color: #339933;">:</span>encode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;script&gt;alert(&quot;Bad Stuff!&quot;);&lt;/script&gt;'</span>,<span style="color: #0000ff;">'HTML'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly:</b></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">${'<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span>&gt;</span>alert(&quot;Bad Stuff!&quot;);<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>' @ context='html'}</div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="findResources">3. findResources() to Sling Model &#038; Sightly</h3>
<p>Searches for resources using the given query formulated in the given language.</p>
<p><b>Returns:</b> java.util.Iterator &#8211; An Iterator of Resource objects matching the query.<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.ResourceResolver</span> &#8211; The Resource Resolver to use for the query.</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The query string to use to find the resources.</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The language in which the query is formulated.</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;resourceItem&quot;</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:findResources(resourceResolver,'/jcr:root//*[jcr:contains(., 'Sling')] order by @jcr:score','xpath')&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#123;</span>resourceItem.<span style="color: #006633;">path</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> data-sly-list.resourceItem<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${examplemodel.resources}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>${resourceItem.name}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Iterator<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> resources<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resourceResolver&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ResourceResolver resolver<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resources <span style="color: #339933;">=</span> resolver<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">findResources</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/jcr:root//*[jcr:contains(., 'Sling')] order by @jcr:score&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query.<span style="color: #006633;">XPATH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Query.XPATH depricated, recommended to use Query.JCR_SQL2</span><br />
<span style="color: #666666; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp;resources = resolver</span><br />
<span style="color: #666666; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.findResources(&quot;SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/content/sourcedcode])&quot;,</span><br />
<span style="color: #666666; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Query.JCR_SQL2);</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="getAbsoluteParent">4. getAbsoluteParent() to Sling Model &#038; Sightly</h3>
<p>Method for retrieving an absolute parent resource.</p>
<p><b>Returns:</b> <span class="code-highlight-secondary">org.apache.sling.api.resource.Resource</span> &#8211; The parent resource at the specified level<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.Resource</span> &#8211; The current resource</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The absolute level for the parent resource to retrieve</li>
</ul>
<p><b>Since:</b> Bundle 2.3.0<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;absoluteParentResource&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:getAbsoluteParent(resource,'2')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
$<span style="color: #009900;">&#123;</span>absoluteParentResource.<span style="color: #006633;">title</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>${examplemodel.absoluteParentResource.title}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.Page</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Page absoluteParentResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentPage&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; absoluteParentResource <span style="color: #339933;">=</span> currentPage.<span style="color: #006633;">getAbsoluteParent</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="getParents">5. getParents() to Sling Model &#038; Sightly</h3>
<p>Function for retrieving all of the parent resources of a specified resource, returning them in hierarchy order.</p>
<p><b>Returns:</b> java.lang.Iterator &#8211; an iterator of the parent resources in order<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.Resource</span> &#8211; The current resource for which to retrieve the parents</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The depth at which to start, for example given a path of: /content/page1/page2/page3 and a start depth of 3, the parents page2/page3 would be returned</li>
</ul>
<p><b>Since:</b> Bundle 2.3.0<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;parentResources&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:getParents(resource,'2')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
<span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;parentResourceItem&quot;</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${parentResources}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#123;</span>parentResourceItem.<span style="color: #006633;">path</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> data-sly-list.parentResourceItem<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${examplemodel.parentResources}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>${parentResourceItem.name}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Iterator<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> parentResources<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource resource<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parentResources <span style="color: #339933;">=</span> getParents<span style="color: #009900;">&#40;</span>resource, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// no Sling API found, this is custom code</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Iterator<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> getParents<span style="color: #009900;">&#40;</span>Resource resource, <span style="color: #000066; font-weight: bold;">int</span> depth<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Resource currentResource <span style="color: #339933;">=</span> resource<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> depth<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentResource.<span style="color: #006633;">getParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentResource <span style="color: #339933;">=</span> currentResource.<span style="color: #006633;">getParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> resource.<span style="color: #006633;">listChildren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="getRelativeResource">6. getRelativeResource() to Sling Model &#038; Sightly</h3>
<p>Gets the resource at the relative path to the provided resource.</p>
<p><b>Returns:</b> org.apache.sling.api.resource.Resource &#8211; The resource at the relative path.<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.Resource</span> &#8211; The resource relative to which to find the path.</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The relative path at which to find the resource.</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;myResource&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:getRelativeResource(resource,'jcr:content')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
$<span style="color: #009900;">&#123;</span>myResource.<span style="color: #006633;">name</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>${examplemodel.myResource.name}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource myResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource resource<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myResource <span style="color: #339933;">=</span> resource.<span style="color: #006633;">getChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="getResource">7. getResource() to Sling Model &#038; Sightly</h3>
<p>Method allow for the retrieval of resources.</p>
<p><b>Returns:</b> org.apache.sling.api.resource.Resource &#8211; The resource at the path.<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.ResourceResolver</span> &#8211; The current resource resolver.</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The path at which to find the resource.</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;myResource&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:getResource(resourceResolver,'/content')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
$<span style="color: #009900;">&#123;</span>myResource.<span style="color: #006633;">name</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>${examplemodel.myResource.name}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource myResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resolver&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ResourceResolver resolver<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myResource <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="getValue">8. getValue() to Sling Model &#038; Sightly</h3>
<p>Gets the value of the specified key from the ValueMap and either coerses the value into the specified type or uses the specified type as a default depending on the parameter passed in.</p>
<p>If the third parameter is a class, the resulting value will be coersed into the class, otherwise, the third parameter is used as the default when retrieving the value from the ValueMap.</p>
<p><b>Returns:</b> java.lang.Object &#8211; The value.<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.ValueMap</span> &#8211; The ValueMap from which to retrieve the value.</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The key for the value to retrieve</li>
<li><span class="code-highlight-secondary">java.lang.Object</span> &#8211; Either the default value or the class to which to coerce the value.</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;myResourceTitle&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:getValue(properties,'jcr:title',resource.name)}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
$<span style="color: #009900;">&#123;</span>myResourceTitle<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${properties.jcr:title}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="getResource">9. getResource() to Sling Model &#038; Sightly</h3>
<p>Method allow for the retrieval of resources.</p>
<p><b>Returns:</b> org.apache.sling.api.resource.Resource &#8211; The resource at the path.<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.ResourceResolver</span> &#8211; The current resource resolver.</li>
<li><span class="code-highlight-secondary">java.lang.String</span> &#8211; The path at which to find the resource.</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>set var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;myResource&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:getResource(resourceResolver,'/content')}&quot;</span> <span style="color: #339933;">/&gt;</span><br />
$<span style="color: #009900;">&#123;</span>myResource.<span style="color: #006633;">name</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; data-sly-use.examplemodel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.sourcedcode.aem.core.models.ExampleModel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>${examplemodel.myResource.name}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
<p><b>Sling Model:</b></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.aem.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource myResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> ExampleModel<span style="color: #009900;">&#40;</span>@ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resolver&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ResourceResolver resolver<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myResource <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="hasChildren">10. hasChildren() to Sling Model &#038; Sightly</h3>
<p>Return true if the specified resource has child resources.</p>
<p><b>Returns:</b> java.lang.Boolean &#8211; True if there are child resource of the specified resource<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.Resource</span> &#8211; The resource of which to check for children.</li>
</ul>
<p><b>Since:</b> 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">if</span> test<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:hasChildren(resource)&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">This</span> resource has children<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>if<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> data-sly-test<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${resource.hasChildren}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>This resource has children<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-larger" />
<h3 id="listChildren">11. listChildren() to Sling Model &#038; Sightly</h3>
<p>Method for allowing the invocation of the Sling Resource listChildren method.</p>
<p><b>Returns:</b> <span class="code-highlight-secondary">java.util.Iterator</span> &#8211; The children of the resource.<br />
<b>Accepts:</b></p>
<ul>
<li><span class="code-highlight-secondary">org.apache.sling.api.resource.Resource</span> &#8211; The resource of which to list the children.</li>
</ul>
<p>Since: 1.3<br />
<b>JSP</b>: Sling Tablib example usage:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;child&quot;</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${sling:listChildren(resource)&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>$<span style="color: #009900;">&#123;</span>child.<span style="color: #006633;">path</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="modernized-box">
<h6>Non-JSP &#038; Non-JSTL implementation</h6>
<p><b>Sightly</b>:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmp-examplemodel&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> data-sly-list.child<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${resource.listChildren}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>${child.path}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></td></tr></tbody></table></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/taglib-prefix-sling-to-sightly-and-sling-model-non-jsp-non-jstl-implementation">taglib prefix=&#8221;sling&#8221; to Sightly and Sling Model Non-JSP &#038; Non-JSTL implementation</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/taglib-prefix-sling-to-sightly-and-sling-model-non-jsp-non-jstl-implementation/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Get AEM i18n Dictionary in JSON Format</title>
		<link>https://sourcedcode.com/blog/aem/how-to-get-aem-i18n-dictionary-in-json-format</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-get-aem-i18n-dictionary-in-json-format#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Tue, 30 Mar 2021 19:36:30 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2361</guid>

					<description><![CDATA[<p>AEM i18n dictionary out of the box tools does not offer an elegant way to get the JSON representation of targeted the i18n dictionary. Without out of the box AEM i18n dictionary JSON formatting tools, we first solutionize to what we know the most. As of AEM developers, we all know that we can trigger [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-get-aem-i18n-dictionary-in-json-format">How to Get AEM i18n Dictionary in JSON Format</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>AEM i18n dictionary out of the box tools does not offer an elegant way to get the JSON representation of targeted the i18n dictionary. Without out of the box AEM i18n dictionary JSON formatting tools, we first solutionize to what we know the most. </p>
<p>As of AEM developers, we all know that we can trigger the JSON default rendering by appending a .json extension to a request, which triggers the default Sling GET servlet returning application/json. And of course, we all know about using the infinity selector in combination with the .json extension, which recursively returns the entire JCR structure in JSON format. Our first attempt is likely to attempt to get the formatted JSON from .infinity.json.</p>
<p>Illustrated below, on the <span class="code-highlight-primary">left hand side</span> you can see a structured AEM i18n dictionary from the out of the box commerce components library (these nodes should exist in a clean installation of AEM 6.4+). On the <span class="code-highlight-black">right hand side</span>, you can see the attempt to get a JSON format of this structure, using the selector, &#8220;infinity&#8221;, and the extension, &#8220;json&#8221;, <i>http://localhost:4502/libs/commerce/components/search/i18n.infinity.json</i>.</p>
<table style="border:none;">
<tr style="border:none;">
<td width="49%" style="border:none;"><a href="https://sourcedcode.com/wp-content/uploads/2020/09/1-aem-dictionary-jcr-ootb-example-structure.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/09/1-aem-dictionary-jcr-ootb-example-structure-300x262.png" alt="Out of the box i18n JCR structure for commerce/search" width="auto" height="50%" class="alignnone size-medium wp-image-2363" srcset="https://sourcedcode.com/wp-content/uploads/2020/09/1-aem-dictionary-jcr-ootb-example-structure-300x262.png 300w, https://sourcedcode.com/wp-content/uploads/2020/09/1-aem-dictionary-jcr-ootb-example-structure-600x523.png 600w, https://sourcedcode.com/wp-content/uploads/2020/09/1-aem-dictionary-jcr-ootb-example-structure.png 768w" sizes="(max-width: 300px) 100vw, 300px" /></a></td>
<td width="2%" style="border:none;"></td>
<td width="49%"style="border:none;"> <a href="https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure-300x274.png" alt="infinity JSON structure of the i18n dictionary" width="auto" height="50%" class="alignnone size-medium wp-image-2362" srcset="https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure-300x274.png 300w, https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure-1024x936.png 1024w, https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure-768x702.png 768w, https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure-1536x1403.png 1536w, https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure-600x548.png 600w, https://sourcedcode.com/wp-content/uploads/2020/09/2-aem-dictionary-jcr-ootb-json-structure.png 1944w" sizes="(max-width: 300px) 100vw, 300px" /></a></td>
</tr>
</table>
<div class="mention-block">
As you can see, the default Sling GET servlet&#8217;s JSON response returns a lot of extra unwanted properties. These unwanted properties will increase file size of the outputted JSON file, which will impact load time, which will ultimately impact the overall performance of your website. Also all the unwanted JSON properties will add complexity to consumers, wether it&#8217;s a front-end or to a third-party.</p>
<p><strong>In this article, I will share with you a way that I go forward with getting a JSON representation of an AEM i18n dictionary, without the unwanted properties. The solution will make the JSON response from the above AEM i18n dictionary structure, return JSON in this format:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #66cc66;">&#123;</span><br />
&nbsp; sort: <span style="color: #ff0000;">&quot;Sort by:&quot;</span>,<br />
&nbsp; firstPage: <span style="color: #ff0000;">&quot;First&quot;</span>,<br />
&nbsp; timelessStatisticsText: <span style="color: #ff0000;">&quot;Results {0} - {1} of {2} for &lt;b&gt;{3}&lt;/b&gt;.&quot;</span>,<br />
&nbsp; lastPage: <span style="color: #ff0000;">&quot;Last&quot;</span>,<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large" />
<h2>Custom servlet to format all AEM i18N structured dictionaries</h2>
<p>That&#8217;s right. In most of my AEM project implementations, I would introduce a servlet that can be used for all AEM i18N structured dictionaries. It&#8217;s very simple. </p>
<p>Requesting on http://localhost:4502/libs/commerce/components/search/i18n.jsonform.en or http://localhost:4502/libs/commerce/components/search/i18n.jsonform.de will return me a JSON formatted AEM i18n dictionary by language, and the JSON response will only include the dictionary keys.</p>
<p><strong>Servlet Request:</strong> http://localhost:4502/libs/commerce/components/search/i18n.jsonform.en<br />
<strong>Selector:</strong> jsonform<br />
<strong>Extension:</strong> en|fr|de|kr<br />
<em>The extension is the target language that you want to receive. For example, if the extension was set for &#8220;de&#8221;, then the JCR searched would be /libs/commerce/components/search/i18n/de.</em></p>
<p><strong>Here is the implementation</strong>:</p>
<div class="code-larger">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.commons.json.JSONException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.commons.json.JSONObject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.servlets.annotations.SlingServletResourceTypes</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Activate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.ConfigurationPolicy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Deactivate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.Logger</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.slf4j.LoggerFactory</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.NodeIterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.RepositoryException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">jackrabbit</span>.<span style="color: #006633;">JcrConstants</span>.<span style="color: #006633;">NT_FOLDER</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">servlets</span>.<span style="color: #006633;">HttpConstants</span>.<span style="color: #006633;">METHOD_GET</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">jcr</span>.<span style="color: #006633;">resource</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">JcrResourceConstants</span>.<span style="color: #006633;">NT_SLING_FOLDER</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span>, configurationPolicy <span style="color: #339933;">=</span> ConfigurationPolicy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
@SlingServletResourceTypes<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resourceTypes <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> NT_FOLDER, NT_SLING_FOLDER<span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; selectors <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jsonform&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; methods <span style="color: #339933;">=</span> METHOD_GET<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JsonDictionaryFormatServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger LOGGER <span style="color: #339933;">=</span> LoggerFactory.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>JsonDictionaryFormatServlet.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; @Activate<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span><span style="color: #003399;">String</span>, Object<span style="color: #339933;">&gt;</span> properties<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Servlet activated&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Deactivate<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> deactivate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Servlet deactivated&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest req, SlingHttpServletResponse res<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonFormatDictionary<span style="color: #009900;">&#40;</span>req, res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> jsonFormatDictionary<span style="color: #009900;">&#40;</span>SlingHttpServletRequest req, SlingHttpServletResponse res<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> RepositoryException, <span style="color: #003399;">IOException</span>, JSONException <span style="color: #009900;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> language <span style="color: #339933;">=</span> req.<span style="color: #006633;">getRequestPathInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExtension</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">PrintWriter</span> writer <span style="color: #339933;">=</span> res.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>language <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node rootLanguageNode <span style="color: #339933;">=</span> req.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Node.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rootLanguageNode.<span style="color: #006633;">hasNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;i18n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rootLanguageNode <span style="color: #339933;">=</span> rootLanguageNode.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;i18n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node languageNode <span style="color: #339933;">=</span> rootLanguageNode.<span style="color: #006633;">getNode</span><span style="color: #009900;">&#40;</span>language<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>languageNode <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json; charset=UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject rootObject <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NodeIterator iterator <span style="color: #339933;">=</span> languageNode.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>iterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node languageItem <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Node<span style="color: #009900;">&#41;</span> iterator.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> key <span style="color: #339933;">=</span> languageItem.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> value <span style="color: #339933;">=</span> languageItem.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sling:message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rootObject.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>key, value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>rootObject.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{} language is not exist&quot;</span>, language<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;no language have been found in the extension&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p><strong>HTTP Get Request:</strong><br />
http://localhost:4502/libs/commerce/components/search/i18n.jsonform.en</p>
<p><strong style="margin-bottom: -20px; display: block;">JSON output:</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">{<br />
&nbsp; sort: &quot;Sort by:&quot;,<br />
&nbsp; firstPage: &quot;First&quot;,<br />
&nbsp; timelessStatisticsText: &quot;Results {0} - {1} of {2} for <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">b</span>&gt;</span>{3}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">b</span>&gt;</span>.&quot;,<br />
&nbsp; lastPage: &quot;Last&quot;,<br />
}</div></td></tr></tbody></table></div>
<div class="mention-block">
An example of an i18n served to production-live would be a path that looks like this,<br />
/etc/commerce/components/search/i18n.jsonform.en</p>
<p>Only because, /apps and /libs are reserved areas, which means for security purposes, no one should have access to these areas. Using the /etc path to access dictionaries are fine.
</p></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-get-aem-i18n-dictionary-in-json-format">How to Get AEM i18n Dictionary in JSON Format</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-get-aem-i18n-dictionary-in-json-format/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Errors while building the latest AEM Project Archetype 24 on MacOS</title>
		<link>https://sourcedcode.com/blog/aem/errors-while-building-the-latest-aem-project-archetype-24-on-macos</link>
					<comments>https://sourcedcode.com/blog/aem/errors-while-building-the-latest-aem-project-archetype-24-on-macos#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 06 Jan 2021 16:16:34 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Short Post]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2580</guid>

					<description><![CDATA[<p>I was recently trying to start up a new AEM project using the latest, AEM Project Archetype 24, but I was having having some build problems indicated in the errors below: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143$ mvn -B archetype:generate \ &#62; &#160;-D archetypeGroupId=com.adobe.aem \ &#62; &#160;-D archetypeArtifactId=aem-project-archetype \ &#62; &#160;-D archetypeVersion=24 \ &#62; &#160;-D appTitle=&#34;AEM SourcedCode&#34; \ &#62; &#160;-D [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/errors-while-building-the-latest-aem-project-archetype-24-on-macos">Errors while building the latest AEM Project Archetype 24 on MacOS</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I was recently trying to start up a new AEM project using the latest, <a href="https://github.com/adobe/aem-project-archetype" rel="noopener" target="_blank">AEM Project Archetype 24</a>, but I was having having some build problems indicated in the errors below:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">$ mvn <span style="color: #339933;">-</span>B archetype<span style="color: #339933;">:</span>generate \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D archetypeGroupId<span style="color: #339933;">=</span>com.<span style="color: #006633;">adobe</span>.<span style="color: #006633;">aem</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D archetypeArtifactId<span style="color: #339933;">=</span>aem<span style="color: #339933;">-</span>project<span style="color: #339933;">-</span>archetype \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D archetypeVersion<span style="color: #339933;">=</span><span style="color: #cc66cc;">24</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D appTitle<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;AEM SourcedCode&quot;</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D appId<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sourcedcodeaem&quot;</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D groupId<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.aem&quot;</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D aemVersion<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;6.5.0&quot;</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D frontendModule<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;none&quot;</span> \<br />
<span style="color: #339933;">&gt;</span> &nbsp;<span style="color: #339933;">-</span>D includeExamples<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;y&quot;</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Scanning <span style="color: #000000; font-weight: bold;">for</span> projects...<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">------------------&lt;</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">maven</span><span style="color: #339933;">:</span>standalone<span style="color: #339933;">-</span>pom <span style="color: #339933;">&gt;-------------------</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Building Maven <span style="color: #003399;">Stub</span> Project <span style="color: #009900;">&#40;</span>No POM<span style="color: #009900;">&#41;</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">--------------------------------</span><span style="color: #009900;">&#91;</span> pom <span style="color: #009900;">&#93;</span><span style="color: #339933;">---------------------------------</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;&gt;&gt;</span> maven<span style="color: #339933;">-</span>archetype<span style="color: #339933;">-</span>plugin<span style="color: #339933;">:</span>3.0.1<span style="color: #339933;">:</span>generate <span style="color: #009900;">&#40;</span>default<span style="color: #339933;">-</span>cli<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> generate<span style="color: #339933;">-</span>sources @ standalone<span style="color: #339933;">-</span>pom <span style="color: #339933;">&gt;&gt;&gt;</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;&lt;</span> maven<span style="color: #339933;">-</span>archetype<span style="color: #339933;">-</span>plugin<span style="color: #339933;">:</span>3.0.1<span style="color: #339933;">:</span>generate <span style="color: #009900;">&#40;</span>default<span style="color: #339933;">-</span>cli<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> generate<span style="color: #339933;">-</span>sources @ standalone<span style="color: #339933;">-</span>pom <span style="color: #339933;">&lt;&lt;&lt;</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">---</span> maven<span style="color: #339933;">-</span>archetype<span style="color: #339933;">-</span>plugin<span style="color: #339933;">:</span>3.0.1<span style="color: #339933;">:</span>generate <span style="color: #009900;">&#40;</span>default<span style="color: #339933;">-</span>cli<span style="color: #009900;">&#41;</span> @ standalone<span style="color: #339933;">-</span>pom <span style="color: #339933;">---</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Generating project in Batch mode<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Archetype repository not defined. <span style="color: #006633;">Using</span> the one from <span style="color: #009900;">&#91;</span>com.<span style="color: #006633;">adobe</span>.<span style="color: #006633;">aem</span><span style="color: #339933;">:</span>aem<span style="color: #339933;">-</span>project<span style="color: #339933;">-</span>archetype<span style="color: #339933;">:</span><span style="color: #cc66cc;">24</span><span style="color: #009900;">&#93;</span> found in catalog remote<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">----------------------------------------------------------------------------</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Using following parameters <span style="color: #000000; font-weight: bold;">for</span> creating project from Archetype<span style="color: #339933;">:</span> aem<span style="color: #339933;">-</span>project<span style="color: #339933;">-</span>archetype<span style="color: #339933;">:</span><span style="color: #cc66cc;">24</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> <span style="color: #339933;">----------------------------------------------------------------------------</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> groupId, Value<span style="color: #339933;">:</span> com.<span style="color: #006633;">sourcedcode</span>.<span style="color: #006633;">aem</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> artifactId, Value<span style="color: #339933;">:</span> sourcedcodeaem<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> version, Value<span style="color: #339933;">:</span> 1.0.0<span style="color: #339933;">-</span>SNAPSHOT<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">package</span>, Value<span style="color: #339933;">:</span> com.<span style="color: #006633;">sourcedcode</span>.<span style="color: #006633;">aem</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> packageInPathFormat, Value<span style="color: #339933;">:</span> com<span style="color: #339933;">/</span>sourcedcode<span style="color: #339933;">/</span>aem<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> frontendModule, Value<span style="color: #339933;">:</span> none<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> artifactId, Value<span style="color: #339933;">:</span> sourcedcodeaem<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">package</span>, Value<span style="color: #339933;">:</span> com.<span style="color: #006633;">sourcedcode</span>.<span style="color: #006633;">aem</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> appId, Value<span style="color: #339933;">:</span> sourcedcodeaem<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> version, Value<span style="color: #339933;">:</span> 1.0.0<span style="color: #339933;">-</span>SNAPSHOT<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> appTitle, Value<span style="color: #339933;">:</span> AEM SourcedCode<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> includeErrorHandler, Value<span style="color: #339933;">:</span> n<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> singleCountry, Value<span style="color: #339933;">:</span> y<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> datalayer, Value<span style="color: #339933;">:</span> y<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> amp, Value<span style="color: #339933;">:</span> n<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> groupId, Value<span style="color: #339933;">:</span> com.<span style="color: #006633;">sourcedcode</span>.<span style="color: #006633;">aem</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> aemVersion, Value<span style="color: #339933;">:</span> 6.5.0<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> language, Value<span style="color: #339933;">:</span> en<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> country, Value<span style="color: #339933;">:</span> us<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> includeDispatcherConfig, Value<span style="color: #339933;">:</span> y<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> commerceEndpoint, Value<span style="color: #339933;">:</span> https<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//hostname.com/graphql</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> sdkVersion, Value<span style="color: #339933;">:</span> latest<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> includeCommerce, Value<span style="color: #339933;">:</span> n<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parameter<span style="color: #339933;">:</span> includeExamples, Value<span style="color: #339933;">:</span> y<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>all<span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>core<span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>dispatcher.<span style="color: #006633;">ams</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>dispatcher.<span style="color: #006633;">cloud</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">frontend</span>.<span style="color: #006633;">general</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.frontend.general/pom.xml<br />
[INFO] Parent element not overwritten in /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.frontend.angular/pom.xml<br />
[WARNING] Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">frontend</span>.<span style="color: #006633;">angular</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">frontend</span>.<span style="color: #006633;">react</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.frontend.react/pom.xml<br />
[INFO] Parent element not overwritten in /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.apps/pom.xml<br />
[INFO] Parent element not overwritten in /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.config/pom.xml<br />
[INFO] Parent element not overwritten in /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.content/pom.xml<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">content</span><span style="color: #339933;">/</span>src<span style="color: #339933;">/</span>main<span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>jcr_root<span style="color: #339933;">/</span>content<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>_jcr_content<span style="color: #339933;">/</span>image<span style="color: #339933;">/</span>file<br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>it.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>INFO<span style="color: #009900;">&#93;</span> Parent element not overwritten in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>pom.<span style="color: #006633;">xml</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/pom.xml<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>assets<span style="color: #339933;">/</span>image.<span style="color: #006633;">png</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/specs/aem/basic.js<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>specs<span style="color: #339933;">/</span>aem<span style="color: #339933;">/</span>assets.<span style="color: #006633;">js</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/specs/aem/sites.js<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>specs<span style="color: #339933;">/</span>aem<span style="color: #339933;">/</span>login.<span style="color: #006633;">js</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/package.json<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>wdio.<span style="color: #006633;">conf</span>.<span style="color: #006633;">cloud</span>.<span style="color: #006633;">js</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/lib/commons.js<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>lib<span style="color: #339933;">/</span>wdio.<span style="color: #006633;">commands</span>.<span style="color: #006633;">js</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/lib/config.js<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>.<span style="color: #006633;">eslintrc</span>.<span style="color: #006633;">js</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/wdio.conf.local.js<br />
[WARNING] CP Don'</span>t override file <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>sourcedcodecomputer<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>bitbucket<span style="color: #339933;">/</span>sourcedcodeaem<span style="color: #339933;">/</span>ui.<span style="color: #006633;">tests</span><span style="color: #339933;">/</span>test<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>README.<span style="color: #006633;">md</span><br />
<span style="color: #009900;">&#91;</span>WARNING<span style="color: #009900;">&#93;</span> CP Don<span style="color: #0000ff;">'t override file /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.tests/test-module/wdio.conf.commons.js<br />
[INFO] Parent element not overwritten in /Users/sourcedcodecomputer/git/bitbucket/sourcedcodeaem/ui.apps.structure/pom.xml<br />
[INFO] Executing META-INF/archetype-post-generate.groovy post-generation script<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] BUILD FAILURE<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Total time: &nbsp;4.690 s<br />
[INFO] Finished at: 2021-01-06T15:58:15Z<br />
[INFO] ------------------------------------------------------------------------<br />
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project standalone-pom: Execution default-cli of goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate failed: A required class was missing while executing org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate: org/apache/ivy/core/report/ResolveReport<br />
[ERROR] -----------------------------------------------------<br />
[ERROR] realm = &nbsp; &nbsp;plugin&gt;org.apache.maven.plugins:maven-archetype-plugin:3.0.1<br />
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy<br />
[ERROR] urls[0] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin/3.0.1/maven-archetype-plugin-3.0.1.jar<br />
[ERROR] urls[1] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/archetype/archetype-catalog/3.0.1/archetype-catalog-3.0.1.jar<br />
[ERROR] urls[2] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/archetype/archetype-descriptor/3.0.1/archetype-descriptor-3.0.1.jar<br />
[ERROR] urls[3] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/archetype/archetype-common/3.0.1/archetype-common-3.0.1.jar<br />
[ERROR] urls[4] = file:/Users/sourcedcodecomputer/.m2/repository/net/sourceforge/jchardet/jchardet/1.0/jchardet-1.0.jar<br />
[ERROR] urls[5] = file:/Users/sourcedcodecomputer/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.6/plexus-component-annotations-1.6.jar<br />
[ERROR] urls[6] = file:/Users/sourcedcodecomputer/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar<br />
[ERROR] urls[7] = file:/Users/sourcedcodecomputer/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar<br />
[ERROR] urls[8] = file:/Users/sourcedcodecomputer/.m2/repository/jdom/jdom/1.0/jdom-1.0.jar<br />
[ERROR] urls[9] = file:/Users/sourcedcodecomputer/.m2/repository/commons-io/commons-io/2.2/commons-io-2.2.jar<br />
[ERROR] urls[10] = file:/Users/sourcedcodecomputer/.m2/repository/org/codehaus/plexus/plexus-velocity/1.1.8/plexus-velocity-1.1.8.jar<br />
[ERROR] urls[11] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar<br />
[ERROR] urls[12] = file:/Users/sourcedcodecomputer/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar<br />
[ERROR] urls[13] = file:/Users/sourcedcodecomputer/.m2/repository/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.jar<br />
[ERROR] urls[14] = file:/Users/sourcedcodecomputer/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar<br />
[ERROR] urls[15] = file:/Users/sourcedcodecomputer/.m2/repository/asm/asm/3.2/asm-3.2.jar<br />
[ERROR] urls[16] = file:/Users/sourcedcodecomputer/.m2/repository/asm/asm-commons/3.2/asm-commons-3.2.jar<br />
[ERROR] urls[17] = file:/Users/sourcedcodecomputer/.m2/repository/asm/asm-util/3.2/asm-util-3.2.jar<br />
[ERROR] urls[18] = file:/Users/sourcedcodecomputer/.m2/repository/asm/asm-analysis/3.2/asm-analysis-3.2.jar<br />
[ERROR] urls[19] = file:/Users/sourcedcodecomputer/.m2/repository/asm/asm-tree/3.2/asm-tree-3.2.jar<br />
[ERROR] urls[20] = file:/Users/sourcedcodecomputer/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.21/plexus-utils-3.0.21.jar<br />
[ERROR] urls[21] = file:/Users/sourcedcodecomputer/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-6/plexus-interactivity-api-1.0-alpha-6.jar<br />
[ERROR] urls[22] = file:/Users/sourcedcodecomputer/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar<br />
[ERROR] urls[23] = file:/Users/sourcedcodecomputer/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar<br />
[ERROR] urls[24] = file:/Users/sourcedcodecomputer/.m2/repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar<br />
[ERROR] urls[25] = file:/Users/sourcedcodecomputer/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar<br />
[ERROR] urls[26] = file:/Users/sourcedcodecomputer/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar<br />
[ERROR] urls[27] = file:/Users/sourcedcodecomputer/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar<br />
[ERROR] urls[28] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/shared/maven-invoker/2.2/maven-invoker-2.2.jar<br />
[ERROR] urls[29] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/shared/maven-artifact-transfer/0.9.0/maven-artifact-transfer-0.9.0.jar<br />
[ERROR] urls[30] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/shared/maven-common-artifact-filters/3.0.0/maven-common-artifact-filters-3.0.0.jar<br />
[ERROR] urls[31] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/shared/maven-shared-utils/3.0.0/maven-shared-utils-3.0.0.jar<br />
[ERROR] urls[32] = file:/Users/sourcedcodecomputer/.m2/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar<br />
[ERROR] urls[33] = file:/Users/sourcedcodecomputer/.m2/repository/commons-codec/commons-codec/1.6/commons-codec-1.6.jar<br />
[ERROR] urls[34] = file:/Users/sourcedcodecomputer/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar<br />
[ERROR] urls[35] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/maven/shared/maven-script-interpreter/1.0/maven-script-interpreter-1.0.jar<br />
[ERROR] urls[36] = file:/Users/sourcedcodecomputer/.m2/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar<br />
[ERROR] urls[37] = file:/Users/sourcedcodecomputer/.m2/repository/org/apache/ant/ant/1.8.1/ant-1.8.1.jar<br />
[ERROR] Number of foreign imports: 1<br />
[ERROR] import: Entry[import &nbsp;from realm ClassRealm[maven.api, parent: null]]<br />
[ERROR] <br />
[ERROR] -----------------------------------------------------: org.apache.ivy.core.report.ResolveReport<br />
[ERROR] -&gt; [Help 1]<br />
[ERROR] <br />
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.<br />
[ERROR] Re-run Maven using the -X switch to enable full debug logging.<br />
[ERROR] <br />
[ERROR] For more information about the errors and possible solutions, please read the following articles:<br />
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException</span></div></td></tr></tbody></table></div>
<p>I attempted next to build the <a href="https://github.com/adobe/aem-project-archetype" rel="noopener" target="_blank">AEM Project Archetype 24</a> project again using the -X flag to enable debug traces, and I was able to identify the causing errors. It is because maven was not able to generate folder structures and files as it requires. </p>
<hr class="spacer-large" />
<h3>The Fix</h3>
<p>The fix is quite simple, we just need to include the word <span class="code-highlight-primary">sudo</span> to the build maven command.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">sudo mvn <span style="color: #339933;">-</span>B archetype<span style="color: #339933;">:</span>generate \<br />
&nbsp;<span style="color: #339933;">-</span>D archetypeGroupId<span style="color: #339933;">=</span>com.<span style="color: #006633;">adobe</span>.<span style="color: #006633;">aem</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D archetypeArtifactId<span style="color: #339933;">=</span>aem<span style="color: #339933;">-</span>project<span style="color: #339933;">-</span>archetype \<br />
&nbsp;<span style="color: #339933;">-</span>D archetypeVersion<span style="color: #339933;">=</span><span style="color: #cc66cc;">24</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D appTitle<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;AEM SourcedCode&quot;</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D appId<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sourcedcodeaem&quot;</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D groupId<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.sourcedcode.aem&quot;</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D aemVersion<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;6.5.0&quot;</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D frontendModule<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;none&quot;</span> \<br />
&nbsp;<span style="color: #339933;">-</span>D includeExamples<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;y&quot;</span></div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/errors-while-building-the-latest-aem-project-archetype-24-on-macos">Errors while building the latest AEM Project Archetype 24 on MacOS</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/errors-while-building-the-latest-aem-project-archetype-24-on-macos/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Tool: Generate Curl Command to Update OSGI Configurations</title>
		<link>https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations</link>
					<comments>https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 18 Oct 2020 21:30:13 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2454</guid>

					<description><![CDATA[<p>Micro-Frontend, written in ReactJS 16.14.0. This tool helps generate a curl command used for updating OSGI configurations directly from the terminal, bash, or Window’s console. It&#8217;s a good idea to read the micro-front-end tool&#8217;s notes, described at the bottom of the page, before using the tool. AEM Curl Generator for Updating OSGI Configs This tool [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations">Tool: Generate Curl Command to Update OSGI Configurations</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="mention-block" align="center">
Micro-Frontend, written in ReactJS 16.14.0.
</div>
<p>This tool helps generate a curl command used for updating OSGI configurations directly from the terminal, bash, or Window’s console. It&#8217;s a good idea to read the micro-front-end tool&#8217;s notes, described at the <a href="#notes">bottom of the page</a>, before using the tool.</p>
<hr class="spacer-large"/>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/WpYW7qijBbE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h3 id="curltool">AEM Curl Generator for Updating OSGI Configs</h3>
<p><i style="font-size: 12px;margin-top: -15px;display: block;">This tool is free to use. The generated curl command and user inputs are never stored in any way from sourcedcode.com.</i><a href="/blog/aem/tool-generate-curl-command-to-update-osgi-configurations" class="curl-generator__reset-fields_link">reset fields</a><!-- HFCM by 99 Robots - Snippet # 4: Osgi Curl Generator -->
      <div id="root"></div>
      <script>!function(e){function t(t){for(var n,p,l=t[0],a=t[1],f=t[2],c=0,s=[];c<l.length;c++)p=l[c],Object.prototype.hasOwnProperty.call(o,p)&&o[p]&&s.push(o[p][0]),o[p]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(i&&i(t);s.length;)s.shift()();return u.push.apply(u,f||[]),r()}function r(){for(var e,t=0;t<u.length;t++){for(var r=u[t],n=!0,l=1;l<r.length;l++){var a=r[l];0!==o[a]&&(n=!1)}n&&(u.splice(t--,1),e=p(p.s=r[0]))}return e}var n={},o={1:0},u=[];function p(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,p),r.l=!0,r.exports}p.m=e,p.c=n,p.d=function(e,t,r){p.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},p.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},p.t=function(e,t){if(1&t&&(e=p(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(p.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)p.d(r,n,function(t){return e[t]}.bind(null,n));return r},p.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return p.d(t,"a",t),t},p.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},p.p="/";var l=this["webpackJsonptodo-app"]=this["webpackJsonptodo-app"]||[],a=l.push.bind(l);l.push=t,l=l.slice();for(var f=0;f<l.length;f++)t(l[f]);var i=a;r()}([])</script>
      <script src="/wp-content/uploads/2020/osgi-generator/2.cc09bc3f.chunk.js"></script>
      <script src="/wp-content/uploads/2020/osgi-generator/main.b2c36526.chunk.js"></script>
<!-- /end HFCM by 99 Robots -->
<br />
To report any bugs, contact me at <a href="mailto:contact@sourcedcode.com" rel="ugc">contact@sourcedcode.com</a> </p>
<hr class="spacer-extra-extra-extra-large"/>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #2 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2263738126"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-extra-large" id="notes"/>
<p><strong>Notes:</strong></p>
<ul>
<li>This tool is free to use. The generated curl command and user inputs are never stored in any way from sourcedcode.com.</li>
<li>OSGI array configurations can be achieved by adding another keypair entry with the same key name as the previous key pair.</li>
<li>Unfortunately, you cannot update a single configuration key for a given OSGI configuration. All the properties need to be identified. If other OSGI configuration keys are not identified, then the curl command will actually wipe out all the missing configurations.</li>
<li>You can share the configurations with your colleagues by clicking on the &#8220;Get Above Sharable Configuration Url&#8221; button.</li>
<li>I created this tool to help my colleagues quickly generate curl commands to update OSGI configuration to free each other&#8217;s time.</li>
</ul>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #3 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="3385248102"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations">Tool: Generate Curl Command to Update OSGI Configurations</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/tool-generate-curl-command-to-update-osgi-configurations/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>AEM inheritedpageproperties with Sightly, JSP, OSGI Bundle</title>
		<link>https://sourcedcode.com/blog/aem/aem-quick-reference/aem-inheritedpageproperties-with-sightly-jsp-osgi-bundle</link>
					<comments>https://sourcedcode.com/blog/aem/aem-quick-reference/aem-inheritedpageproperties-with-sightly-jsp-osgi-bundle#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 20 Sep 2020 17:18:31 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[OSGI]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2232</guid>

					<description><![CDATA[<p>inheritedpageproperties helps you retrieve a parent property from parent pages. Inherited page properties utilises com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap, where the search is made on the page hierarchy, upwards; searching children of the page nodes (components) are not included. Inherited page properties can be retrieved in multiple ways, where this article will only focus on 3 ways. In this [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-quick-reference/aem-inheritedpageproperties-with-sightly-jsp-osgi-bundle">AEM inheritedpageproperties with Sightly, JSP, OSGI Bundle</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>inheritedpageproperties helps you retrieve a parent property from parent pages. Inherited page properties utilises <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/commons/inherit/HierarchyNodeInheritanceValueMap.html" title="https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/commons/inherit/HierarchyNodeInheritanceValueMap.html" rel="noopener nofollow noreferrer" target="_blank">com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap</a>, where the search is made on the page hierarchy, upwards; searching children of the page nodes (components) are not included. Inherited page properties can be retrieved in multiple ways, where this article will only focus on 3 ways.</p>
<p>In this article, we will go through the 3 different ways in how we can retrieve inherited page properties.</p>
<ol>
<li><a href="#inheritedPageProperties-how-it-works">How does this work?</a></li>
<li><a href="#inheritedPageProperties-with-sightly">inheritedPageProperties with Sightly</a></li>
<li><a href="#inheritedPageProperties-with-jsp">inheritedPageProperties with JSP</a></li>
<li><a href="#inheritedPageProperties-with-java-backend">inheritedPageProperties with OSGI Bundle, Java Backend</a></li>
</ol>
<hr class="spacer-large"/>
<h2 id="inheritedPageProperties-how-it-works">How does this work?</h2>
<p>An InheritanceValueMap for a given Resource that will inherit values from ancestral pages.<br />
For example, given: /content/parent/page/jcr:content/footer/image/@width, the HierarchyNodeInheritanceValueMap will search for a footer/image/@width property in:</p>
<p><strong>look up one:</strong> /content/parent/<strong>currentPage</strong>/jcr:content/footer/image/@width<br />
<strong>look up two:</strong> /content/parent/jcr:content/footer/image/@width<br />
<strong>look up three:</strong> /content/jcr:content/footer/image/@width</p>
<hr class="spacer-large"/>
<h2 id="inheritedPageProperties-with-sightly">1. inheritedPageProperties with Sightly</h2>
<p>Sightly offers a plethora of <a href="/blog/aem/aem-global-objects-for-backend-and-front-end-sightly-htl" rel="noopener noreferrer" target="_blank">AEM Global objects</a>, and one of them notably is the &#8220;inheritedPageProperties&#8221;. Utilising the inheritedPageProperties global object, we can use dot or square bracket notation to access the interited page property value.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">${inheritedPageProperties.myCustomProperty}<br />
${inheritedPageProperties['myCustomProperty']}<br />
${inheritedPageProperties.jcr:title}<br />
${inheritedPageProperties['jcr:title']}</div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="4202452438"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h2 id="inheritedPageProperties-with-jsp">2. inheritedPageProperties with JSP</h2>
<p>Utilising the JSP include, /libs/foundation/global.jsp (purpose of retreiving the currentPage AEM global object), we can make use of the HierarchyNodeInheritanceValueMap.class, and currentPage resource to initialise the InheritanceValueMap.class object. Next, calling the method <a href="https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/commons/inherit/HierarchyNodeInheritanceValueMap.html" rel="noopener noreferrer" target="_blank">getInherited(String name, Class&lt;T&gt; type)</a>, we are able to get the inherited page property.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;%@include file<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/libs/foundation/global.jsp&quot;</span>%&gt;<br />
&lt;%@ page import<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.day.cq.commons.inherit.InheritanceValueMap&quot;</span> %&gt;<br />
&lt;%@ page import<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap&quot;</span> %&gt;<br />
<br />
&lt;%<br />
&nbsp; &nbsp; InheritanceValueMap ivm <span style="color: #66cc66;">=</span> new HierarchyNodeInheritanceValueMap<span style="color: #66cc66;">&#40;</span>currentPage.getContentResource<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; String inheritedValueMyCustomProperty <span style="color: #66cc66;">=</span> ivm.getInherited<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myCustomerProperty&quot;</span>, String.<span style="color: #000066;">class</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; String inheritedValueJcrTitle <span style="color: #66cc66;">=</span> ivm.getInherited<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;jcr:title&quot;</span>, String.<span style="color: #000066;">class</span><span style="color: #66cc66;">&#41;</span>;<br />
%&gt;<br />
inheritedValueMyCustomProperty <span style="color: #66cc66;">=</span> &lt;%<span style="color: #66cc66;">=</span> inheritedValueMyCustomProperty %&gt;<br />
inheritedValueJcrTitle <span style="color: #66cc66;">=</span> &lt;%<span style="color: #66cc66;">=</span> inheritedValueJcrTitle %&gt;</div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="inheritedPageProperties-with-java-backend">3. inheritedPageProperties with OSGI Bundle, Java Backend</h2>
<p>Similar to the JSP implementation above, we can make use of the HierarchyNodeInheritanceValueMap.class, and currentPage resource to initialise the InheritanceValueMap.class object. Next, calling the method <a href="https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/commons/inherit/HierarchyNodeInheritanceValueMap.html" rel="noopener noreferrer" target="_blank">getInherited(String name, Class&lt;T&gt; type)</a>, we are able to get the inherited page property.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.commons.inherit.InheritanceValueMap</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap</span><span style="color: #339933;">;</span><br />
<br />
@ScriptVariable <br />
<span style="color: #000000; font-weight: bold;">private</span> Page currentPage<span style="color: #339933;">;</span><br />
...<br />
<span style="color: #006633;">InheritanceValueMap</span> ivm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HierarchyNodeInheritanceValueMap<span style="color: #009900;">&#40;</span>currentPage.<span style="color: #006633;">getContentResource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003399;">String</span> inheritedValueMyCustomProperty <span style="color: #339933;">=</span> ivm.<span style="color: #006633;">getInherited</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myCustomerProperty&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003399;">String</span> inheritedValueJcrTitle <span style="color: #339933;">=</span> ivm.<span style="color: #006633;">getInherited</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jcr:title&quot;</span>, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-quick-reference/aem-inheritedpageproperties-with-sightly-jsp-osgi-bundle">AEM inheritedpageproperties with Sightly, JSP, OSGI Bundle</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-quick-reference/aem-inheritedpageproperties-with-sightly-jsp-osgi-bundle/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Basic Steps to Debug an Error in AEM</title>
		<link>https://sourcedcode.com/blog/aem/development/basic-steps-to-debug-an-error-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/development/basic-steps-to-debug-an-error-in-aem#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 26 Aug 2020 22:01:23 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=2180</guid>

					<description><![CDATA[<p>There are times when something is not working as expected from the AEM Server; relax, you are fine. The error can be quickly identified through debugging on the server with a series of steps. Once the error has been identified you can attempt to solve the error efficiently. In this article, I will share with [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/development/basic-steps-to-debug-an-error-in-aem">Basic Steps to Debug an Error in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are times when something is not working as expected from the AEM Server; relax, you are fine. The error can be quickly identified through debugging on the server with a series of steps. Once the error has been identified you can attempt to solve the error efficiently. In this article, I will share with you the basic steps I take to quickly debug an error in AEM; following the order (in steps) will help you optimise and identify the problem quickly.</p>
<p><b>Common issues you may be experiencing can be:</b></p>
<ul>
<li>Replication is not replicating properly.</li>
<li>Rendered page is missing a component.</li>
<li>Rendered page is blank.</li>
<li>Servlet is not registered.</li>
<li>etc&#8230;</li>
</ul>
<hr class="spacer-large"/>
<p><a href="https://sourcedcode.com/wp-content/uploads/2020/08/simple-steps-to-debug-a-problem-in-aem-steps-diagram.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/08/simple-steps-to-debug-a-problem-in-aem-steps-diagram.png" alt="Debugging steps diagram" width="200" height="auto" class="alignnone size-full wp-image-2189" /></a></p>
<h2>1. Analyse Browser&#8217;s Console</h2>
<p>When there&#8217;s an issue, be sure to take a look at the browser&#8217;s console log as the first action to take. The console log can show you errors that may help you pinpoint the error immediately, before looking at server logs. </p>
<p>The errors might be a third-party JavaScript library or from an external RESTFUl micro-service that is not related to AEM at all&#8230;</p>
<div class="spacer-large"></div>
<h2>2. Analyse error.log</h2>
<p>If the Browser&#8217;s console log has no relevant information, we can go ahead to review the error.log; this file can be found from ./crx-quickstart/logs/error.log.</p>
<p>The error.log catches exceptions that are output into the log file. Typically the logs in this file can help you quickly pinpoint the error. Whether the error will be from a bundle by your organisation, a bundle from the AEM product, or even a missing configuration, the logs will expose this information.</p>
<div class="spacer-large"></div>
<h2>3. Analyse &lt;custom&gt;.log</h2>
<p>When the error.log does not show you the relevant information you can take a look at your custom log files that exist in ./crx-quickstart/logs/*. The custom log files will be able to help you pinpoint your error.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/development/basic-steps-to-debug-an-error-in-aem">Basic Steps to Debug an Error in AEM</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/development/basic-steps-to-debug-an-error-in-aem/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Enable Configuration for OSGI Components with R6</title>
		<link>https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 06 Jun 2020 20:34:05 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OSGI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1738</guid>

					<description><![CDATA[<p>Adding configuration to OSGi Component(s) is as simple as annotating your class with @Designate(ocd=&#8221;&#8221;) annotation with the &#8220;ocd&#8221; property, and to make the @Activate method accepts an config param; as indicated below: 1234567891011121314// /com/sourcedcode/services/impl/MyserviceImpl.java import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.metatype.annotations.Designate; @Component&#40;service = MyService.class, immediate = true&#41; @Designate&#40;ocd = SourcedCodeSiteSettingsConfig.class&#41; public class MyserviceImpl extends MyService &#123; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6">How to Enable Configuration for OSGI Components with R6</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Adding configuration to OSGi Component(s) is as simple as annotating your class with <span class="code-highlight-primary">@Designate(ocd=&#8221;&#8221;)</span> annotation with the &#8220;ocd&#8221; property, and to make the @Activate method accepts an config param; as indicated below:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666; font-style: italic;">// /com/sourcedcode/services/impl/MyserviceImpl.java</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Activate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.Designate</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> MyService.<span style="color: #000000; font-weight: bold;">class</span>, immediate <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><br />
@Designate<span style="color: #009900;">&#40;</span>ocd <span style="color: #339933;">=</span> SourcedCodeSiteSettingsConfig.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyserviceImpl <span style="color: #000000; font-weight: bold;">extends</span> MyService <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Activate<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span>SourcedCodeSiteSettingsConfig config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// do something</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// String name = config.name();</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The &#8220;ocd&#8221; property must be set with a configuration interface class that is annotated with @ObjectClassDefinition; the annotated interface class can be an <a href="#imported-class">imported Java interface class</a> or <a href="#inner-class">inner Java interface class</a>. </p>
<p>Once the @Designate annotation on the OSGI Component&#8217;s class and the @ObjectClassDefinition configuration interface are configured, the OSGI Component(s) will have <strong>enabled the configuration successfully</strong>; you should be able to find the configuration in the OSGI Apache Felix Console, under <a href="http://localhost:4502/system/console/configMgr" target="_blank" rel="noopener noreferrer">http://localhost:4502/system/console/configMgr</a>.</p>
<div class="mention-block">
<strong>Quick Links with Code Samples:</strong><br />
This article will highlight two different ways to enable configuration to your OSGI Component(s).</p>
<ol>
<li><a href="#imported-class">Imported Class &#8211; Enable OSGI Component&#8217;s Configuration Implementation</a></li>
<li><a href="#inner-class">Inner Class &#8211; Enable OSGI Component&#8217;s Configuration Implementation</a></li>
</ol>
</div>
<hr class="spacer-large" />
<h4>What is the @ObjectClassDefinition annotation?</h4>
<p>The configuration interface is annotated with <span class="code-highlight-primary">@ObjectClassDefinition</span> where properties can be passed into the @ObjectClassDefinition annotation. The most common properties are @ObjectClassDefinition(name=&#8221;&#8221;, description=&#8221;&#8221;). The &#8220;name&#8221; property will be used as the title of the configuration <a class="foobox" title="OSGI Apache Felix Console - Active Configuration Dialog" href="https://sourcedcode.com/wp-content/uploads/2020/06/blog-img-how-to-enable-configuration-to-osgi-components-with-r6.png" target="_blank" rel="noopener noreferrer">popup</a> within the OSGI Felix console, while the description property is used for the &#8220;description&#8221; of the <a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2020/06/blog-img-how-to-enable-configuration-to-osgi-components-with-r6.png" target="_blank" rel="noopener noreferrer" title="OSGI Apache Felix Console - Active Configuration Dialog">popup</a>.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666; font-style: italic;">// Example:</span><br />
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.services</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.ObjectClassDefinition</span><span style="color: #339933;">;</span><br />
<br />
@ObjectClassDefinition<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SourcedCode - Site Settings Configuration&quot;</span>,<br />
&nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dialog description&quot;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> SourcedCodeSiteSettingsConfigExample <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// config1 @AttributeDefinition()</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// config2 @AttributeDefinition()</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// config3 @AttributeDefinition()</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h4>What is the @AttributeDefinition annotation?</h4>
<p>Declaration of the <span class="code-highlight-primary">@AttributeDefinition</span> annotations defines each configuration by identifying the type, the configuration reference name, config name and description.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.services</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.AttributeDefinition</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.AttributeType</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.ObjectClassDefinition</span><span style="color: #339933;">;</span><br />
<br />
@ObjectClassDefinition<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SourcedCode - Site Settings Configuration&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dialog description&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> SourcedCodeSiteSettingsConfigExample <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> config_string_array_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;item1&quot;</span>, <span style="color: #0000ff;">&quot;item2&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// config2 @AttributeDefinition()</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// config3 @AttributeDefinition()</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block"><strong>Note!</strong><br />
To wrap your head around some of the essentials of @AttributeDefinition, checkout this blog article : <a href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide" target="_blank" rel="noopener noreferrer">OSGI R6 Configuration @AttributeDefinition Essentials Reference Guide</a>.</div>
<hr class="spacer-large" />
<h2 id="imported-class">1. Imported Class &#8211; Defining OSGI Component&#8217;s Configuration with Configuration Interface</h2>
<p>The title of this section speaks for itself. The examples below <a href="#"imported-class-step-a">&quot;Step A&quot;</a> example provides sample code of a configuration interface class that is prepared to be imported OSGI Service Component, indicated in <a href="#"imported-class-step-b">&quot;Step B&quot;</a>. This class have one responsibility, and its to provide the definition of the OSGI Component&#8217;s configuration interface.</p>
<div class="spacer-large"></div>
<h3 id="imported-class-step-a">Step A. Defining the annotated Configuration Interface</h3>
<p>Isolated configuration interface class that prepared to be imported and referenced by the OSGI Service Component.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.services</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.AttributeDefinition</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.AttributeType</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.ObjectClassDefinition</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.Option</span><span style="color: #339933;">;</span><br />
<br />
@ObjectClassDefinition<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SourcedCode - Site Settings Configuration&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dialog description&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> @<span style="color: #000000; font-weight: bold;">interface</span> SourcedCodeSiteSettingsConfig <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> config_string_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;Default String&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> config_string_array_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;item1&quot;</span>, <span style="color: #0000ff;">&quot;item2&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Long Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Long Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">LONG</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> config_long_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> 0L<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;int Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;innt Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">INTEGER</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> config_number_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Short Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Short Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">SHORT</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">short</span> config_short_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Char Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Char Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">CHARACTER</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">char</span> config_char_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Byte Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Byte Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">BYTE</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">byte</span> config_byte_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Double Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Double Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">DOUBLE</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> config_double_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Float Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Float Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">FLOAT</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">float</span> config_float_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Boolean Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Boolean Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">BOOLEAN</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> config_boolean_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Password Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Password Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">PASSWORD</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> config_password_config_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dropdown Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dropdown Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PRODUCTION&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PRODUCTION&quot;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;STAGING&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;STAGING&quot;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UAT&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UAT&quot;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;QA&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;QA&quot;</span><span style="color: #009900;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DEVELOP&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DEVELOP&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> config_dropdown_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;DEVELOP&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="spacer-large"></div>
<h3 id="imported-class-step-b">Step B. Consuming the Configuration Interface by Imported Class</h3>
<p>To use the configuration interface within our OSGI service component, we would need to annotation our service class with <span class="code-highlight-primary">@Designate</span>, with the ocd param pointing to the imported configuration interface class. Next, it would be as simple as setting up the initial @Activate method.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.services</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Activate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.Designate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sourcedcode.core.services.SourcedCodeSiteSettingsConfig</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> SourcedCodeSiteSettingsService.<span style="color: #000000; font-weight: bold;">class</span>, immediate <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><br />
@Designate<span style="color: #009900;">&#40;</span>ocd <span style="color: #339933;">=</span> SourcedCodeSiteSettingsConfig.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SourcedCodeSiteSettingsService <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> config_string_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> config_string_array_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> config_long_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> config_number_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">short</span> config_short_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">char</span> config_char_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">byte</span> config_byte_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span> config_double_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> config_float_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> config_boolean_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> config_password_getConfig_example<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> config_dropdown_example<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Activate<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span>SourcedCodeSiteSettingsConfig config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_string_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_string_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_string_array_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_string_array_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_long_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_long_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_number_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_number_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_short_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_short_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_char_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_char_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_byte_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_byte_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_double_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_double_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_float_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_float_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_boolean_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_boolean_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_password_getConfig_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_password_config_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config_dropdown_example</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">config_dropdown_example</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block"><strong>Outcome Explained:</strong><br />
The outcome of the OSGI Service and Configuration will result in an editable configuration within the OSGI Apache Felix Console.<br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2020/06/blog-post-attribute-definition-osgi-felix-done.png" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/06/blog-post-attribute-definition-osgi-felix-done-150x150.png" alt="OSGI Apache Felix Console - Active Dialog - Result of Enablement of OSGI Configuration" width="150" height="75" /></a></div>
<hr class="spacer-large" />
<h2 id="inner-class">2. Inner Class &#8211; Defining OSGI Component&#8217;s Configuration with Configuration Interface</h2>
<p>You can also define the annotated @ObjectClassDefinition interface as an inner class as shown below. To use the inner class configuration interface within our OSGI service, we would need to annotation our service class with <span class="code-highlight-primary">@Designate</span>, with the ocd param pointing to the inner interface class. Next, it would be as simple as setting up the initial @Activate method.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.services.impl</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Activate</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.metatype.annotations.*</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> SourcedCodeSiteSettingsServiceInlineExample.<span style="color: #000000; font-weight: bold;">class</span>, immediate <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><br />
@Designate<span style="color: #009900;">&#40;</span>ocd <span style="color: #339933;">=</span> SourcedCodeSiteSettingsServiceInlineExample.<span style="color: #006633;">SourcedCodeSiteSettingsConfig</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SourcedCodeSiteSettingsServiceInlineExample <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @ObjectClassDefinition<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SourcedCode - Site Settings Configuration&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dialog description&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> @<span style="color: #000000; font-weight: bold;">interface</span> SourcedCodeSiteSettingsConfig <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> config_string_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;Default String&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> config_string_array_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;item1&quot;</span>, <span style="color: #0000ff;">&quot;item2&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; @AttributeDefinition<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Long Label&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Long Config Example Description&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">LONG</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> config_long_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> 0L<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Activate<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span>SourcedCodeSiteSettingsConfig config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h3>Thoughts&#8230;</h3>
<p>I typically try my best to keep the configuration interface decoupled with OSGi components. This promotes better readability and maintainability. I would recommend you to stick with the Single Responsibility Principle; to separate concerns.</p>
<div class="mention-block"><strong>Note!</strong><br />
@AttributeDefinitions are the underlying formatting of how each OSGI configuration interaces are put together. If you wish to learn more about this topic, checkout this article: <a href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide" target="_blank" rel="noopener noreferrer">OSGI R6 Configuration @AttributeDefinition Essentials Reference Guide</a>.</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6">How to Enable Configuration for OSGI Components with R6</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-enable-configuration-for-osgi-components-with-r6/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>OSGI R6 Configuration @AttributeDefinition Essentials Reference Guide</title>
		<link>https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide</link>
					<comments>https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 03 Jun 2020 17:52:00 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OSGI]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1643</guid>

					<description><![CDATA[<p>When defining any OSGI component&#8217;s configuration its standard practice to use Declarative Services; these configurations can be edited in the OSGI Apache Felix Console. This can be done by creating a class interface with the annotated @ObjectClassDefinition, which includes a determined list of rules as @AttributeDefinition items. The @AttributeDefinition defines the supporting configuration for a [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide">OSGI R6 Configuration @AttributeDefinition Essentials Reference Guide</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When defining any OSGI component&#8217;s configuration its standard practice to use Declarative Services; these configurations can be edited in the OSGI Apache Felix Console. This can be done by creating a class interface with the annotated @ObjectClassDefinition, which includes a determined list of rules as @AttributeDefinition items.</p>
<p>The @AttributeDefinition defines the supporting configuration for a given OSGI component&#8217;s configuration. It allows you to set data types and default values for each given configuration. When an admin user interacts with the Felix console, how the @AttributeDefinition is defined will determine the look and feel of each of the input fields are presented.</p>
<div class="mention-block">
<p><strong>Quick Links</strong></p>
<ol>
<li><a href="#essential-parameters-explained">@AttributeDefinition Essential Parameters Explained</a></li>
<li><a href="#attribute-types">Attribute Types &#8211; References</a></li>
<li><a href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-code-examples" target="_blank" rel="noopener noreferrer"><span class="code-highlight-primary">How to Enable Configuration for OSGI Components</span></a></li>
</ol>
<hr />
<p><strong>Attribute Types &#8211; References</strong></p>
<ol>
<li><a href="#attribute-type-string">String Attribute Type</a></li>
<li><a href="#attribute-type-string-array">String[] Attribute Type</a></li>
<li><a href="#attribute-type-long">Long Attribute Type</a></li>
<li><a href="#attribute-type-int">int Attribute Type</a></li>
<li><a href="#attribute-type-short">Short Attribute Type</a></li>
<li><a href="#attribute-type-char">Char Attribute Type</a></li>
<li><a href="#attribute-type-byte">byte Attribute Type</a></li>
<li><a href="#attribute-type-double">Double Attribute Type</a></li>
<li><a href="#attribute-type-float">Float Attribute Type</a></li>
<li><a href="#attribute-type-boolean">Boolean Attribute Type</a></li>
<li><a href="#attribute-type-password">Password Attribute Type</a></li>
<li><a href="#attribute-type-options">Options Attribute Type</a></li>
</ol>
</div>
<hr class="spacer-large" />
<h2 id="essential-parameters-explained">@AttributeDefinition Essential Parameters Explained</h2>
<p>As we know, the most basic way to define a configuration will be to utilise the annotation @AttributeDefinition. Let&#8217;s explore the essential configurations.</p>
<p>The @AttributeDefinition annotation accepts parameters as such:</p>
<ul>
<li>line 2: <strong>name</strong>: defines the human read-able label</li>
<li>line 3: <strong>description</strong>: description for the attribute configuration.</li>
<li>line 4: <strong>type</strong>: definition of the attribute&#8217;s data type.</li>
<li>          line 6: <strong>&lt;T&gt;</strong>: definition of the attribute&#8217;s data type</li>
<li>          line 6: <strong>name_of_conf_reference</strong>: configuration&#8217;s reference id : name.of.conf.reference</li>
<li>          line 7: <strong>&lt;T&gt;[]</strong>: multifield (multi data set) is supported.
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><br />
description<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><br />
type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><br />
<span style="color: #009900;">&#125;</span><br />
name_of_conf_reference<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// [] name_of_conf_reference_list() default &quot;&quot;;</span></div></td></tr></tbody></table></div>
<p><strong>Explained:</strong><br />
Illustrating how the label, description, and the configuration reference shows up on the OSGI Apache Felix console.<br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2020/06/blog-post-attribute-definition-legend-explained.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/06/blog-post-attribute-definition-legend-explained.png" alt="OSGI Apache Felix Console - visual description of whats being reflected by the code." width="300" /></a></p>
<hr class="spacer-extra-large" />
<h2 id="attribute-types">Attribute Types</h2>
<p>With the understanding of how the <a href="#essential-parameters-explained">@AttributeDefinition Essential Parameters are used</a>, we can go ahead to utilise and to familiarize ourselves with the supported essential data attribute types; most of the basic attributes are covered below:</p>
<ol>
<li><a href="#attribute-type-string">String Attribute Type</a></li>
<li><a href="#attribute-type-string-array">String[] Attribute Type</a></li>
<li><a href="#attribute-type-long">Long Attribute Type</a></li>
<li><a href="#attribute-type-int">int Attribute Type</a></li>
<li><a href="#attribute-type-short">Short Attribute Type</a></li>
<li><a href="#attribute-type-char">Char Attribute Type</a></li>
<li><a href="#attribute-type-byte">byte Attribute Type</a></li>
<li><a href="#attribute-type-float">Float Attribute Type</a></li>
<li><a href="#attribute-type-double">Double Attribute Type</a></li>
<li><a href="#attribute-type-boolean">Boolean Attribute Type</a></li>
<li><a href="#attribute-type-password">Password Attribute Type</a></li>
<li><a href="#attribute-type-options">Options Attribute Type</a></li>
</ol>
<p>&nbsp;</p>
<h4 id="attribute-type-string">1. String Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #003399;">String</span> config_string_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;Default String&quot;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-string-array">2. String[] Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;String[] Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">STRING</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> config_string_array_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;item1&quot;</span>, <span style="color: #0000ff;">&quot;item2&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div align="center"><strong>Explained:</strong><br />
Illustrating how the multi-fields shows up on the OSGI Felix console.<br />
<a class="foobox" href="https://sourcedcode.com/wp-content/uploads/2020/06/blog-post-attribute-definition-multi-field-example.png" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/06/blog-post-attribute-definition-multi-field-example-150x150.png" alt="OSGI Apache Felix Console - Multi-Field Highlight Example" width="150" height="75" /></a></div>
<div class="mention-block"><strong>Note:</strong><br />
Configuration can be set as multifield can be enabled without much effort, simply change the attribute type to an list type, shown in the <a href="#attribute-type-string-array">#2. String[] Attribute Type example</a>.</div>
<hr class="spacer-large" />
<h4 id="attribute-type-long">3. Long Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Long Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Long Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">LONG</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">long</span> config_long_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> 0L<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-int">4. int Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;int Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;innt Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">INTEGER</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">int</span> config_number_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-short">5. Short Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Short Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Short Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">SHORT</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">short</span> config_short_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-char">6. Char Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Char Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Char Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">CHARACTER</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">char</span> config_char_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-byte">7. Byte Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Byte Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Byte Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">BYTE</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">byte</span> config_byte_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div class="mention-block"><strong>See Code Examples!</strong><br />
Click here to view <a href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-code-examples">OSGI R6 Configuration Code Examples</a>.</div>
<h4 id="attribute-type-double">8. Double Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Double Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Double Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">DOUBLE</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">double</span> config_double_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-float">9. Float Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Float Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Float Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">FLOAT</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">float</span> config_float_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-boolean">10. Boolean Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Boolean Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Boolean Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">BOOLEAN</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> config_boolean_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-password">11. Password Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Password Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Password Config Example Description&quot;</span>,<br />
type <span style="color: #339933;">=</span> AttributeType.<span style="color: #006633;">PASSWORD</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #003399;">String</span> config_password_config_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4 id="attribute-type-options">12. Options Attribute Type</h4>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@AttributeDefinition<span style="color: #009900;">&#40;</span><br />
name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dropdown Label&quot;</span>,<br />
description <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dropdown Config Example Description&quot;</span>,<br />
options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
@<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PRODUCTION&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PRODUCTION&quot;</span><span style="color: #009900;">&#41;</span>,<br />
@<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;STAGING&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;STAGING&quot;</span><span style="color: #009900;">&#41;</span>,<br />
@<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UAT&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UAT&quot;</span><span style="color: #009900;">&#41;</span>,<br />
@<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;QA&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;QA&quot;</span><span style="color: #009900;">&#41;</span>,<br />
@<span style="color: #003399;">Option</span><span style="color: #009900;">&#40;</span>label <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DEVELOP&quot;</span>, value <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DEVELOP&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#41;</span><br />
<span style="color: #003399;">String</span> config_dropdown_example<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0000ff;">&quot;DEVELOP&quot;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<div class="mention-block"><strong>See Code Examples!</strong><br />
Click here to view <a href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-code-examples">OSGI R6 Configuration Code Examples</a>.</div>
</li>
</ul>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide">OSGI R6 Configuration @AttributeDefinition Essentials Reference Guide</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/osgi-r6-configuration-attributedefinition-essentials-reference-guide/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Creating a Basic AEM Touch UI Dialogue</title>
		<link>https://sourcedcode.com/blog/aem/creating-a-basic-aem-touch-ui-dialogue</link>
					<comments>https://sourcedcode.com/blog/aem/creating-a-basic-aem-touch-ui-dialogue#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 24 May 2020 15:24:16 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1507</guid>

					<description><![CDATA[<p>In this article, we will step through the steps of creating a new Touch UI dialogue configuration within your AEM maven project. Code examples will showcase a basic Granite UI form container &#038; component. Create basic Touch UI Dialogue Within your AEM maven source code, create create a &#8220;_cq_dialogue&#8221; folder under your targeted component. Example: [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/creating-a-basic-aem-touch-ui-dialogue">Creating a Basic AEM Touch UI Dialogue</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, we will step through the steps of creating a new Touch UI dialogue configuration within your AEM maven project. Code examples will showcase a basic Granite UI form container &#038; component.</p>
<h4>Create basic Touch UI Dialogue</h4>
<ol>
<li>Within your AEM maven source code, create create a &#8220;_cq_dialogue&#8221; folder under your targeted component. Example: <span class="code-highlight-black">/apps/weretail/components/content/text</span>.<br />
<strong>Result</strong>: /apps/weretail/components/content/text/_cq_dialogue, <a target="_blank" href="https://sourcedcode.com/wp-content/uploads/2020/05/article-img__cq_dialogue-folder.png" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/article-img__cq_dialogue-folder.png" alt="_cq_dialogue folder" width="280" /></a>.</li>
<li>Within the _cq_dialogue, create a .content.xml file: <a target="_blank" href="https://sourcedcode.com/wp-content/uploads/2020/05/article-img__cq_dialogue-xmlfile.png" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/article-img__cq_dialogue-xmlfile.png" alt="_cq_dialogue .context.xml file" width="280"/></a>.</li>
<li>Now lets paste in the basic Touch UI XML structure into the .content.xml file as:
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:sling</span>=<span style="color: #ff0000;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> <span style="color: #000066;">xmlns:granite</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/jcr/granite/1.0&quot;</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> <span style="color: #000066;">xmlns:nt</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Granite UI Converting to XML, Example&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;content</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!--<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ... insert Granite UI form components here.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/jcr:root<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<li>Use your maven skills, and build your code into AEM.</li>
</li>
<li>When we open the Touch UI dialogue, the Touch UI container should remain <span class="code-highlight-primary">empty</span>, and should look something like this:<br />
<a target="_blank" href="https://sourcedcode.com/wp-content/uploads/2020/05/article-img-granit-ui-example-no-form-component.png" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/article-img-granit-ui-example-no-form-component.png" alt="granit-ui-example-no-form-component" width="280"/></a></li>
<li>Now lets include the textfield component into the Touch UI dialogue container:
<div class="mention-block">
To learn how to write your own XML formatted Granite UI 1.0 form components, check out <a href="https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml" target="_blank" rel="noopener noreferrer">this article</a>.
</div>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;jcr:root</span> <span style="color: #000066;">xmlns:sling</span>=<span style="color: #ff0000;">&quot;http://sling.apache.org/jcr/sling/1.0&quot;</span> <span style="color: #000066;">xmlns:granite</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/jcr/granite/1.0&quot;</span> <span style="color: #000066;">xmlns:cq</span>=<span style="color: #ff0000;">&quot;http://www.day.com/jcr/cq/1.0&quot;</span> <span style="color: #000066;">xmlns:jcr</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/1.0&quot;</span> <span style="color: #000066;">xmlns:nt</span>=<span style="color: #ff0000;">&quot;http://www.jcp.org/jcr/nt/1.0&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:title</span>=<span style="color: #ff0000;">&quot;Granite UI Converting to XML, Example&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;content</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/foundation/container&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;labelTextfield</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Label: labelTextfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./labelTextfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;{String}Default Text&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Show placeholder text when input field is empty.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">autocomplete</span>=<span style="color: #ff0000;">&quot;off&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">autofocus</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">validation</span>=<span style="color: #ff0000;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">maxlength</span>=<span style="color: #ff0000;">&quot;{Long}100&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/jcr:root<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
</li>
<li>Use your maven skills, and build your code into AEM.</li>
<li>
<strong>final result</strong>:<br />
<a target="_blank" href="https://sourcedcode.com/wp-content/uploads/2020/05/article-img-granit-ui-example-ss.png" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/article-img-granit-ui-example-ss.png" alt="granite UI completed example" width="300"/></a>
</li>
</ol>
<div class="mention-block">
<strong>Learn More:</strong><br />
To learn how to write your own XML formatted Granite UI 1.0 form components, check out <a href="https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml" target="_blank" rel="noopener noreferrer">this article</a>.</p>
<p><strong>Pro Tip:</strong> Have the <a href="https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-reference-guide#granite-ui-colorpicker" rel="noopener noreferrer" target="_blank">AEM Granite UI 1.0 Form Component’s XML Reference Guide</a> opened in another tab, and accessible during development of Touch UI dialogues.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/creating-a-basic-aem-touch-ui-dialogue">Creating a Basic AEM Touch UI Dialogue</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/creating-a-basic-aem-touch-ui-dialogue/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Convert Adobe’s Granite UI 1.0 Documentation to XML</title>
		<link>https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 24 May 2020 14:06:34 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1442</guid>

					<description><![CDATA[<p>As an AEM developer, we must prepare Touch UI dialogues within code, in the XML format. When it comes to reading the Granite UI 1.0 Documentation, it can be confusing; especially for new AEM developers. These new AEM developers are confused by how properties within the documentation are mapped and converted to XML entries. This [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml">How to Convert Adobe’s Granite UI 1.0 Documentation to XML</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As an AEM developer, we must prepare Touch UI dialogues within code, in the XML format. When it comes to reading the Granite UI 1.0 Documentation, it can be confusing; especially for new AEM developers. These new AEM developers are confused by how properties within the documentation are mapped and converted to XML entries.</p>
<p>This document will help you understand how properties within the <a href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/index.html" target="_blank" rel="noopener noreferrer">Granite UI 1.0 documentation</a> are mapped and converted to XML entries.</p>
<div class="mention-block">This article will focus on how to convert the Granite UI <strong>textfield component</strong> documentation to XML format.</div>
<p><strong>Quick Links:</strong></p>
<ol>
<li><a href="#understanding-granite-ui-docs">Understanding the Adobe’s Granite UI 1.0 Documentation</a></li>
<li><a href="#question-hierarchy-examples">Question: Example Hierarchy Explained</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
<hr class="spacer-large" />
<h2 id="understanding-granite-ui-docs">Understanding the Adobe’s Granite UI 1.0 Documentation, textfield component:</h2>
<p>Before we jump straight to the code examples, let us understand how to convert Adobe&#8217;s Granite UI 1.0 Documentation to XML. When looking at an Granite UI 1.0 form component&#8217;s documentation, <strong>textfield component</strong>, we are presented with <a href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textfield/index.html" target="_blank" rel="noopener nofollow noreferrer">this</a> page:<br />
<a href="https://sourcedcode.com/wp-content/uploads/2020/05/how-to-read-granite-ui-forms-documentation-details-scaled.jpg"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/how-to-read-granite-ui-forms-documentation-details-scaled.jpg" alt="" width="100%" /></a><strong>We can see a couple of sections of the page:</strong></p>
<ul>
<li>The component&#8217;s sling:resourceType reference.</li>
<li>The details &amp; description about the current form component. From what we can see, the textfield form element extends from the <a href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/field/index.html#/libs/granite/ui/components/coral/foundation/form/field" target="_blank" rel="noopener noreferrer">Field</a>, abstract component; extended <a href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/field/index.html#/libs/granite/ui/components/coral/foundation/form/field" target="_blank" rel="noopener noreferrer">Field</a> component also makes more property configuration available to the form component.</li>
<li>The available configuration and properties for the form component.</li>
</ul>
<h3>a. Create a New textfield Component:</h3>
<p>Once we understand the configurations and properties for the textfield form component, with XML, we can create a textfield component with the following. Note that the sling resource has a primary type of <span class="code-highlight-black">jcr:primaryType=&#8221;nt:unstructured&#8221;</span>, as follows:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;labelTextfield</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<h3>b. Plug in the Necessary Properties to our textfield Form Component:</h3>
<p>Next, using the Granite UI 1.0 documentation, we can simply plug in the necessary properties to our form component, sling resource.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2020/05/how-to-read-granite-ui-forms-documentation-diagram.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/how-to-read-granite-ui-forms-documentation-diagram.jpg" alt="granite UI form components mapping" width="50%" /></a></p>
<p>Based on our requirements, we can copy properties from the Granite UI 1.0 documentation into our newly created component, within the XML:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;labelTextfield</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Label: labelTextfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./labelTextfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;{String}Default Text&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Show placeholder text when input field is empty.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autocomplete</span>=<span style="color: #ff0000;">&quot;off&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autofocus</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">validation</span>=<span style="color: #ff0000;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">maxlength</span>=<span style="color: #ff0000;">&quot;{Long}100&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
<strong>Note:</strong><br />
To learn how to Creating a Basic AEM Touch UI Dialogue, check out <a href="/blog/aem/creating-a-basic-aem-touch-ui-dialogue" target="_blank" rel="noopener noreferrer">this article</a>.
</div>
<hr class="spacer-large"/>
<h3 id="question-hierarchy-examples">Question: Example Hierarchy Explained</h3>
<p>q: How can translate hierarchy examples diagrams within the Granite UI 1.0 Documentation?<br />
Example in such diagrams:<br />
<a target="_blank" href="https://sourcedcode.com/wp-content/uploads/2020/05/article-img-hierarchical-example.png" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2020/05/article-img-hierarchical-example.png" alt="" width="100%"/></a><br />
Translated XML, looks like:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;color</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/colorfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./color&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;color1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#FF4136&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;color2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#0077D9&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/color<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="conclusion">Conclusion</h2>
<p>I hope this article has been helpful. Other than the Granite UI 1.0 Text Field form component. There are many other form components you would be using based on your requirements. Have a play with all the form components available in the Granite UI 1.0 library. They are listed here:</p>
<p>Components:</p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/actionfield/index.html" target="_blank" rel="nofollow noopener noreferrer">ActionField</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/advancedselect/index.html" target="_blank" rel="nofollow noopener noreferrer">AdvancedSelect</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/advancedselect/status/index.html" target="_blank" rel="nofollow noopener noreferrer">AdvancedSelectStatus</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/autocomplete/index.html" target="_blank" rel="nofollow noopener noreferrer">Autocomplete</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/autocomplete/list/index.html" target="_blank" rel="nofollow noopener noreferrer">AutocompleteList</a></li>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/autocomplete/tags/index.html" target="_blank" rel="nofollow noopener noreferrer">AutocompleteTags</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/buttongroup/index.html" target="_blank" rel="nofollow noopener noreferrer">ButtonGroup</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/checkbox/index.html" target="_blank" rel="nofollow noopener noreferrer">Checkbox</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/colorfield/index.html" target="_blank" rel="nofollow noopener noreferrer">ColorField</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/datepicker/index.html" target="_blank" rel="nofollow noopener noreferrer">DatePicker</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/field/index.html" target="_blank" rel="nofollow noopener noreferrer">Field</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/fieldset/index.html" target="_blank" rel="nofollow noopener noreferrer">FieldSet</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/fileupload/index.html" target="_blank" rel="nofollow noopener noreferrer">FileUpload</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/hidden/index.html" target="_blank" rel="nofollow noopener noreferrer">Hidden</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html" target="_blank" rel="nofollow noopener noreferrer">Multifield</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#examples" target="_blank" rel="nofollow noopener noreferrer">Examples</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#textfield" target="_blank" rel="nofollow noopener noreferrer">TextField</a></li>
<li class="toctree-l3"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#fileupload" target="_blank" rel="nofollow noopener noreferrer">FileUpload</a></li>
<li class="toctree-l3"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#fieldset" target="_blank" rel="nofollow noopener noreferrer">FieldSet</a></li>
<li class="toctree-l3"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#multifield-nesting-another-multifield" target="_blank" rel="nofollow noopener noreferrer">Multifield Nesting Another Multifield</a></li>
<li class="toctree-l3"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#pathfield-and-rte-rich-text-editor" target="_blank" rel="nofollow noopener noreferrer">PathField and RTE (Rich Text Editor)</a></li>
<li class="toctree-l3"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html#radiogroup" target="_blank" rel="nofollow noopener noreferrer">RadioGroup</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/nestedcheckboxlist/index.html" target="_blank" rel="nofollow noopener noreferrer">NestedCheckboxList</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/numberfield/index.html" target="_blank" rel="nofollow noopener noreferrer">NumberField</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/password/index.html" target="_blank" rel="nofollow noopener noreferrer">Password</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/pathfield/index.html" target="_blank" rel="nofollow noopener noreferrer">PathField</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/radiogroup/index.html" target="_blank" rel="nofollow noopener noreferrer">RadioGroup</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/responses/index.html" target="_blank" rel="nofollow noopener noreferrer">Responses</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/responses/openprompt/index.html" target="_blank" rel="nofollow noopener noreferrer">OpenPrompt</a></li>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/responses/redirect/index.html" target="_blank" rel="nofollow noopener noreferrer">Redirect</a></li>
<li class="toctree-l2"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/responses/reload/index.html" target="_blank" rel="nofollow noopener noreferrer">Reload</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/select/index.html" target="_blank" rel="nofollow noopener noreferrer">Select</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/switch/index.html" target="_blank" rel="nofollow noopener noreferrer">Switch</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textarea/index.html" target="_blank" rel="nofollow noopener noreferrer">Textarea</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textfield/index.html" target="_blank" rel="nofollow noopener noreferrer">TextField</a></li>
<li class="toctree-l1"><a class="reference internal" href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/userpicker/index.html" target="_blank" rel="nofollow noopener noreferrer">UserPicker</a></li>
</ul>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"></div>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml">How to Convert Adobe’s Granite UI 1.0 Documentation to XML</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Granite UI 1.0 Form Component&#8217;s XML Cheat Sheet Reference Guide</title>
		<link>https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-cheat-sheet-reference-guide</link>
					<comments>https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-cheat-sheet-reference-guide#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 24 May 2020 12:57:12 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Touch UI]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1418</guid>

					<description><![CDATA[<p>This AEM Granite UI 1.0 Form Component&#8217;s XML Reference Guide provides code snippets to help developers speed up their AEM Touch UI development. This quick reference includes the most used Granite UI form components with plug and plays XML examples. Note: If you want to understand how to convert Granite UI 1.0 Form Components from [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-cheat-sheet-reference-guide">AEM Granite UI 1.0 Form Component&#8217;s XML Cheat Sheet Reference Guide</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This AEM Granite UI 1.0 Form Component&#8217;s XML Reference Guide provides code snippets to help developers speed up their AEM Touch UI development. This quick reference includes the most used Granite UI form components with plug and plays XML examples.</p>
<div class="mention-block">
<strong>Note:</strong><br />
If you want to understand how to convert Granite UI 1.0 Form Components from Adobe&#8217;s documentation to XML format, have a look at <a href="https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml" title="How to convert Adobe’s Granite UI 1.0 Documentation to XML" rel="noopener noreferrer" target="_blank">article</a>. The article provides a step by step and easy to understand guide.
</div>
<style type="text/css">
.subtitle {
    display: block;
    font-size: 15px;
}
</style>
<p><strong>References:</strong></p>
<ol>
<li><a href="#granite-ui-checkbox">Checkbox</a></li>
<li><a href="#granite-ui-textfield">Text Field</a></li>
<li><a href="#granite-ui-textarea">Text Area</a></li>
<li><a href="#granite-ui-pathfield">Path Field</a></li>
<li><a href="#granite-ui-multifield">Multifield</a></li>
<li><a href="#granite-ui-select">Select</a></li>
<li><a href="#granite-ui-radiogroup">Radio Group</a></li>
<li><a href="#granite-ui-numberfield">Number Field</a></li>
<li><a href="#granite-ui-fileupload">File Upload</a></li>
<li><a href="#granite-ui-colorpicker">Color Picker</a></li>
<li><a href="https://sourcedcode.com/blog/aem/creating-a-basic-aem-touch-ui-dialogue" target="_blank" rel="noopener noreferrer">Creating a Basic AEM Touch UI Dialogue</a></li>
</ol>
<hr class="spacer-large"/>
<h3 id="granite-ui-checkbox">1. Checkbox <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;isChecked</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/checkbox&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;isChecked?&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./isChecked&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;isChecked flag&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">uncheckedValue</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/checkbox<br />
Documetation: <a href="https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/checkbox/index.html" rel="noopener nofollow noreferrer" target="_blank">https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/checkbox/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-textfield">2. Text Field <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;textfield-example</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;textfield-example&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./example&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;{String}Default Text&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Show placeholder text when input field is empty.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autocomplete</span>=<span style="color: #ff0000;">&quot;off&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autofocus</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">validation</span>=<span style="color: #ff0000;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">maxlength</span>=<span style="color: #ff0000;">&quot;{Long}100&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;textfield-example-brandSlogan</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Brand Slogan&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./brandSlogan&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/textfield<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textfield/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textfield/index.html</a></p>
<h3 id="granite-ui-textarea">3. Text Area <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;textarea-example-description</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textarea&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Description&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./description&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;A hint to the user of what can be entered in the field.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autocomplete</span>=<span style="color: #ff0000;">&quot;off&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autofocus</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">maxlength</span>=<span style="color: #ff0000;">&quot;{Long}160&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">rows</span>=<span style="color: #ff0000;">&quot;100&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">resize</span>=<span style="color: #ff0000;">&quot;both&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/textarea<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textarea/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/textarea/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-pathfield">4. Path Field <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;pathfield-example-logoPath</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/pathfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Logo Path&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./logoPath&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">rootPath</span>=<span style="color: #ff0000;">&quot;/content/dam&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/pathfield<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/pathfield/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/pathfield/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-multifield">5. Multifield <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// Multifield Country Eexample<br />
<span style="color: #000000; font-weight: bold;">&lt;countries</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/multifield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">composite</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Countries&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;field</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./countries&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Name&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;code</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Code&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./code&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/countries<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
// Navigation Links Example<br />
<span style="color: #000000; font-weight: bold;">&lt;navigationLinksMultifield</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/multifield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">composite</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Navigation Links&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;field</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/container&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./navLinks&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;linkLabel</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/textfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Label&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkLabel&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;linkPath</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/pathfield&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Link Path&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkPath&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">rootPath</span>=<span style="color: #ff0000;">&quot;/content&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;linkTarget</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;CTA Link Target&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkTarget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;self</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Same Page&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_self&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;blank</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;New Tab&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_blank&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/linkTarget<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/field<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/navigationLinksMultifield<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/multifield<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/multifield/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-select">6. Select <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;linkTarget</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/select&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;CTA Link Target&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./linkTarget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;self</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Same Page&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_self&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;blank</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;New Tab&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;_blank&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/linkTarget<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/select<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/select/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/select/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-radiogroup">7. Radio Group <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;radiogroup-example-columns</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/radiogroup&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">deleteHint</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Type&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./columns&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">vertical</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;columns1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">checked</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;1 Column&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;columns2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;2 Columns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;columns3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;3 Columns&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/radiogroup-example-columns<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/radiogroup<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/radiogroup/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/radiogroup/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-numberfield">8. Number Field <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;numberfield-example-ageRestriction</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/numberfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Age Restriction&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">min</span>=<span style="color: #ff0000;">&quot;{Long}1&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">max</span>=<span style="color: #ff0000;">&quot;{Double}200&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./ageRestriction&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">step</span>=<span style="color: #ff0000;">&quot;1&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/numberfield<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/numberfield/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/numberfield/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-fileupload">9. File Upload <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<p>Note: How to disable the file upload, browser button, granite UI component&#8217;s upload feature will be to set the allowUpload property to false, indicated in the examples below.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">&lt;file</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog/fileupload&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;cq-droptarget&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fileNameParameter</span>=<span style="color: #ff0000;">&quot;./fileName&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fileReferenceParameter</span>=<span style="color: #ff0000;">&quot;./fileReference&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">mimeTypes</span>=<span style="color: #ff0000;">&quot;[image/gif,image/jpeg,image/png,image/tiff,image/svg+xml]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./file&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
// in sightly <span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;${properties.fileReference}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;fileupload-example-file</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog/fileupload&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autoStart</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;cq-droptarget&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Image asset&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fileNameParameter</span>=<span style="color: #ff0000;">&quot;./fileName&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fileReferenceParameter</span>=<span style="color: #ff0000;">&quot;./fileReference&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">mimeTypes</span>=<span style="color: #ff0000;">&quot;[image/gif,image/jpeg,image/png,image/tiff,image/svg+xml]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">multiple</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./file&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Upload Image Asset&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">uploadUrl</span>=<span style="color: #ff0000;">&quot;${suffix.path}&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">useHTML5</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
// in sightly <span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;${properties.fileReference}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
<br />
// disable allow upload<br />
<span style="color: #000000; font-weight: bold;">&lt;fileupload-example-downloadAsset</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;cq/gui/components/authoring/dialog/fileupload&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">allowUpload</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autoStart</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;cq-droptarget&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Download Asset&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fileNameParameter</span>=<span style="color: #ff0000;">&quot;./fileName&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fileReferenceParameter</span>=<span style="color: #ff0000;">&quot;./fileReference&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">mimeTypes</span>=<span style="color: #ff0000;">&quot;[image/*,video/*,audio/*,.pdf,.doc,.zip,.txt]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">multiple</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./downloadAsset&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Upload Asset&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">uploadUrl</span>=<span style="color: #ff0000;">&quot;${suffix.path}&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">useHTML5</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
// in sightly <span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;${properties.fileReference}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: cq/gui/components/authoring/dialog/fileupload<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/fileupload/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/fileupload/index.html</a></p>
<hr class="spacer-large"/>
<h3 id="granite-ui-colorpicker">10. Color Picker <span class="subtitle">Granite UI 1.0, Touch UI XML Example:</span></h3>
<p>Note: the variant properties can be set for two different outcomes; &#8220;default&#8221; allows the authors to insert custom hex values, while the set value of &#8220;swatch&#8221; does not allow custom hex selection.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">//swatch example<br />
<span style="color: #000000; font-weight: bold;">&lt;colorfield-swatch-example-brandColor</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/colorfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Brand Color&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./brandColor&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Please choose a color&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">variant</span>=<span style="color: #ff0000;">&quot;swatch&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autogenerateColors</span>=<span style="color: #ff0000;">&quot;off&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">showDefaultColors</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">showProperties</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">showSwatches</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;items</span> <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;color1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#FF4136&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;color2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#0077D9&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/colorfield-swatch-example-brandColor<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
//properties example <span style="color: #66cc66;">&#40;</span>choosing colors from a color wheel<br />
<span style="color: #000000; font-weight: bold;">&lt;colorfield-properties-example-brandColor</span><br />
&nbsp; &nbsp; <span style="color: #000066;">jcr:primaryType</span>=<span style="color: #ff0000;">&quot;nt:unstructured&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">sling:resourceType</span>=<span style="color: #ff0000;">&quot;granite/ui/components/coral/foundation/form/colorfield&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">fieldLabel</span>=<span style="color: #ff0000;">&quot;Brand Color&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;./brandColor&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">emptyText</span>=<span style="color: #ff0000;">&quot;Please choose a color&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">variant</span>=<span style="color: #ff0000;">&quot;default&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">autogenerateColors</span>=<span style="color: #ff0000;">&quot;off&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">showDefaultColors</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">showProperties</span>=<span style="color: #ff0000;">&quot;{Boolean}true&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">showSwatches</span>=<span style="color: #ff0000;">&quot;{Boolean}false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>sling:resourceType: granite/ui/components/coral/foundation/form/colorfield<br />
Documentation: <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/colorfield/index.html" rel="noopener nofollow noreferrer" target="_blank">https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/colorfield/index.html</a></p>
<div class="mention-block">
<strong>Recommended Note:</strong><br />
If you want to understand how to convert Granite UI 1.0 Form Components from Adobe&#8217;s documentation to XML format, have a look at <a href="https://sourcedcode.com/blog/aem/how-to-convert-adobes-granite-ui-1-0-documentation-to-xml" title="How to convert Adobe’s Granite UI 1.0 Documentation to XML" rel="noopener noreferrer" target="_blank">article</a>. The article provides a step by step and easy to understand guide.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-cheat-sheet-reference-guide">AEM Granite UI 1.0 Form Component&#8217;s XML Cheat Sheet Reference Guide</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-cheat-sheet-reference-guide/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sling Model Constructor Injection</title>
		<link>https://sourcedcode.com/blog/aem/aem-sling-model-constructor-injection</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sling-model-constructor-injection#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 23 May 2020 19:47:44 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1400</guid>

					<description><![CDATA[<p>Sling Models field injection, @inject, are used to support injection of AEM Library-specific context objects. However, there is an alternative way to inject AEM objects into Sling Models, and its called Constructor Injection. The benefits of Sling Model Constructor Injection: Does not store the injection references to the adaptable. Since it does not store injection [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-constructor-injection">AEM Sling Model Constructor Injection</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sling Models field injection, @inject, are used to support injection of AEM Library-specific context objects. However, there is an alternative way to inject AEM objects into Sling Models, and its called <strong>Constructor Injection</strong>.</p>
<p><strong>The benefits of Sling Model Constructor Injection</strong>:</p>
<ol>
<li>Does not store the injection references to the adaptable.</li>
<li>Since it does not store injection references to the adapted object, the result of the adapted object has a smaller memory byte size.</li>
<li><a href="/blog/aem/aem-sling-model-injection-vs-constructor-injection-memory-consumption" target="_blank" rel="noopener noreferrer">Reducing AEM application consumption</a></li>
</ol>
<hr class="spacer-large"/>
<h3>1. Sling Model using Field Injection Example:</h3>
<p>The example below illustrates a Sling Model field injection of 35 different AEM objects to be available for the adapted object. This example displays how specific Sling Model annotations are being used, references are stored to the adapted object.<br />
<strong>MyModel.class:</strong></p>
<div class="code-150">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.SightlyWCMMode</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.WCMScriptHelper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.PageManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.ComponentContext</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.EditContext</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Design</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Designer</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Style</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ValueMap</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.scripting.SlingScriptHelper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.settings.SlingSettingsService</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.xss.XSSAPI</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpSession</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Component</span> component<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ComponentContext componentContext<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Design currentDesign<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Node currentNode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HttpSession currentSession<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Style</span> currentStyle<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Style</span> currentStyleCustomScriptVarName<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Designer designer<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> EditContext editContext<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Logger log<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">PrintWriter</span> out<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> PageManager pageManager<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ValueMap pageProperties<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">BufferedReader</span> reader<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest request<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolver resolver<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource resource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Design resourceDesign<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Page resourcePage<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletResponse response<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingScriptHelper sling<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> WCMScriptHelper slyWcmHelper<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SightlyWCMMode wcmmode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> XSSAPI xssAPI<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ValueMapValue<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> linkPath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ValueMapValue<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> homePagePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ChildResource<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> navLinks<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @RequestAttribute<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> socialParam<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @OSGiService<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingSettingsService slingSettingsService<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Self<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Node node<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest slingHttpServletRequest<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletResponse slingHttpServletResponse<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource currentResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolver resourceResolver<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> initModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// logic goes here</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large"/>
<h3>2. Sling Model Constructor Injection Example:</h3>
<p>Let&#8217;s convert the field injection example to use constructor injection from the above example. </p>
<p>This example below shows a Sling Model which injects 35 different AEM objects with Constructor Injection to be available for the adapted object. Once the Sling Model has been adapted, the adapted object does not store injection references. The result of the adapted object has a smaller memory byte size. </p>
<p><span class="code-highlight-black">The name of a constructor argument parameter cannot be detected via the Java Reflection API, so the <span class="code-highlight-primary">@Named annotation</span> is mandatory for injectors that require a name for resolving the injection.</span></p>
<p><strong>MyModelConstructor.class:</strong></p>
<div class="code-larger">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.SightlyWCMMode</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.WCMScriptHelper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.PageManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.ComponentContext</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.components.EditContext</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Design</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Designer</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.designer.Style</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ValueMap</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.scripting.SlingScriptHelper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.settings.SlingSettingsService</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.xss.XSSAPI</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpSession</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyModelConstructor <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> MyModelConstructor<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;component&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Component</span> component,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;componentContext&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ComponentContext componentContext,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentDesign&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Design currentDesign,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentNode&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Node currentNode,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentPage&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentSession&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> HttpSession currentSession,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentStyle&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Style</span> currentStyle,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentStyle&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Style</span> currentStyleCustomScriptVarName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;designer&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Designer designer,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;editContext&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> EditContext editContext,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;log&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Logger log,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;out&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">PrintWriter</span> out,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pageManager&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> PageManager pageManager,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pageProperties&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ValueMap pageProperties,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;reader&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">BufferedReader</span> reader,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;request&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletRequest request,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resolver&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ResourceResolver resolver,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource resource,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resourceDesign&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Design resourceDesign,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resourcePage&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Page resourcePage,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;response&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletResponse response,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sling&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingScriptHelper sling,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slyWcmHelper&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> WCMScriptHelper slyWcmHelper,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wcmmode&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SightlyWCMMode wcmmode,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xssAPI&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> XSSAPI xssAPI,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ValueMapValue @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;locationsMenusDefaultLinkPath&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> customLocationsMenusDefaultLinkPath,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ValueMapValue @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;homePagePath&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> homePagePath,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ChildResource @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;navLinks&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> List<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> navLinks,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @RequestAttribute @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;socialParam&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> socialParam,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @OSGiService @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slingSettingsService&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingSettingsService slingSettingsService,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Self @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;node&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Node node,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slingHttpServletRequest&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletRequest slingHttpServletRequest,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slingHttpServletResponse&quot;</span><span style="color: #009900;">&#41;</span> SlingHttpServletResponse slingHttpServletResponse,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentResource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource currentResource,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resourceResolver&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> ResourceResolver resourceResolver<br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// logic goes here</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<div class="mention-block">
<strong>Note</strong><br />
Using the constructor injection strategy can also reduce memory consumption of your application. <a href="https://sourcedcode.com/blog/aem/aem-sling-model-injection-vs-constructor-injection-memory-consumption">Click here</a> to learn about Sling Model Injection vs Constructor Injection Memory Consumption
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-constructor-injection">AEM Sling Model Constructor Injection</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sling-model-constructor-injection/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sling Model Field Injection vs Constructor Injection Memory Consumption</title>
		<link>https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 23 Apr 2020 15:47:02 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1361</guid>

					<description><![CDATA[<p>Article was last updated on June 7th, 2020. Sling Models field injectors are used to support injection of AEM Library-specific context objects. For example, @ScriptVariable SightlyWCMMode will inject the WCMMode object, @ScriptVariable Resource will inject the current resource object, and @ScriptVariable Style will inject the Style object. These objects are typically stored within the object, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption">AEM Sling Model Field Injection vs Constructor Injection Memory Consumption</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<hr/>
<div class="mention-block" align="center">Article was last updated on June 7th, 2020.</div>
<hr/>
<p>Sling Models field injectors are used to support injection of AEM Library-specific context objects. For example, @ScriptVariable SightlyWCMMode will inject the WCMMode object, <span class="code-highlight-primary">@ScriptVariable Resource</span> will inject the current resource object, and <span class="code-highlight-primary">@ScriptVariable Style</span> will inject the Style object. These objects are typically stored within the object, so it can be later used to construct the Sling Model&#8217;s properties to make available to the context who&#8217;s calling it. </p>
<p>With the Apache Sling Model&#8217;s injector specific annotations, we are able to inject Sling Objects, AEM Services, OSGI Components, etc&#8230; directly into the context of the Sling Model easily without much hassle. </p>
<div class="mention-block"><strong>What is the catch?</strong> Whenever we are injecting objects into our Sling Models via field injection for later use, an instantiated Sling Model adaptable stores a reference of those object in memory; stored injected objects in the Sling Model instance will consume memory.</div>
<p>The Sling Model constructor injection is also supported (as of Sling Models 1.1.0), and its documented that it does not store the reference to the adaptable, lets test this out.</p>
<p><strong>In this article, we will test the Sling Model memory consumption with two scenarios:</strong></p>
<ol>
<li><a href="#test-annotation-specific">Test 1: Sling Model Field Injection</a></li>
<li><a href="#test-constructor-injection">Test 2: Sling Model Constructor Injection</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ol>
<hr class="spacer-large"/>
<h2 id="test-annotation-specific">Test 1: Sling Model Field Injectors</h2>
<p>I have 3 injected AEM objects to be stored in my class variables into my Sling Model via field injection; another 3 variables used to expose data to the calling context. Each AEM objects will then be used in the @PostConstruct method, where data would be extracted from each object, and set in the class variables for exposure to the calling context.</p>
<p>I then ran a test for getting the bytes in size for a specific object using the Lucene&#8217;s until RamUsageEstimator. </p>
<p><strong style="color:red;">The memory byte size of the Sling Model adaptable object is 40</strong>.</p>
<p><strong>MyModel.class : RamUsageEstimator Results:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.util.RamUsageEstimator</span><span style="color: #339933;">;</span><br />
...<br />
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyModel.class + shallowSizeOf:&quot;</span> <span style="color: #339933;">+</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">lucene</span>.<span style="color: #006633;">util</span>.<span style="color: #006633;">RamUsageEstimator</span>.<span style="color: #006633;">shallowSizeOf</span><span style="color: #009900;">&#40;</span>req.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>MyModel.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>MyModel.class:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyModel <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource resource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest slingHttpServletRequest<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentResourcePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentPagePagePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> requestParam<span style="color: #339933;">;</span><br />
<br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> initModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentResourcePath <span style="color: #339933;">=</span> resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentPagePagePath <span style="color: #339933;">=</span> currentPage.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; requestParam <span style="color: #339933;">=</span> slingHttpServletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myParam&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h2 id="test-constructor-injection">Test 2: Sling Model Constructor Injection</h2>
<p>I have 3 injected AEM objects via Constructor Injection; another 3 variables used to expose data to the calling context. This time, I am not storing the AEM objects in as class variables. We can definitely see a change in byes size here.</p>
<p><strong style="color:green;">The memory byte size of the Sling Model adaptable object is 24</strong>.</p>
<p><strong>MyModelConstructor.class : RamUsageEstimator Results:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.lucene.util.RamUsageEstimator</span><span style="color: #339933;">;</span><br />
...<br />
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyModelConstructor.class + shallowSizeOf:&quot;</span> <span style="color: #339933;">+</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">lucene</span>.<span style="color: #006633;">util</span>.<span style="color: #006633;">RamUsageEstimator</span>.<span style="color: #006633;">shallowSizeOf</span><span style="color: #009900;">&#40;</span>req.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>MyModelConstructor.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><strong>MyModelConstructor.class:</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.models</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">lombok.Getter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.DefaultInjectionStrategy</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.Model</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.ScriptVariable</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.models.annotations.injectorspecific.SlingObject</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Named</span><span style="color: #339933;">;</span><br />
<br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>, Resource.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>, defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyModelConstructor <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentResourcePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> currentPagePagePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Getter<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> requestParam<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Inject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> MyModelConstructor<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currentPage&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">Page</span> currentPage,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ScriptVariable @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resource&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> Resource resource,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @SlingObject @Named<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slingHttpServletRequest&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> SlingHttpServletRequest slingHttpServletRequest<br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentResourcePath <span style="color: #339933;">=</span> resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; currentPagePagePath <span style="color: #339933;">=</span> currentPage.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; requestParam <span style="color: #339933;">=</span> slingHttpServletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myParam&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h2 id="conclusion">Conclusion</h2>
<p>An AEM object that has been field injected into a variable that is only being minimally used holds onto memory which will/can be be wasting resources. If AEM objects are not needed, then the Constructor Injection method can be appropriately used.</p>
<p>It&#8217;s not rocket science. We see the results! Test 2 has less instance variables than Test 1; of course Test 2 will have a smaller Object (in byte size) than Test 1.</p>
<p>My only recommendation is this. When you are using AEM Objects, ask yourself, how is this Object being used?</p>
<p>This article highlights why Sling Model Constructor Injection via constructor is useful in our AEM development.</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption">AEM Sling Model Field Injection vs Constructor Injection Memory Consumption</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sling-model-field-injection-vs-constructor-injection-memory-consumption/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide</title>
		<link>https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 04 Jan 2020 15:20:37 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1180</guid>

					<description><![CDATA[<p>The Apache Sling Model enables injector specific annotations which aggregate the standard annotations for each of the available injector, which are: Script Bindings, Value Map, Resource Path, Child Resources, Request Attributes, OSGI Services, Self, and the Sling Object. Sure we can invoke injectors by the @inject, followed by the @source annotation (with an injector name) [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide">AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The Apache Sling Model enables injector specific annotations which aggregate the standard annotations for each of the available injector, which are: <a href="#ScriptVariable">Script Bindings</a>, <a href="#ValueMapValue">Value Map</a>, <a href="#ResourcePath">Resource Path</a>, <a href="#ChildResource">Child Resources</a>, <a href="#RequestAttribute">Request Attributes</a>, <a href="#OSGiService">OSGI Services</a>, <a href="#Self">Self</a>, and the <a href="#SlingObject">Sling Object</a>. </p>
<p>Sure we can invoke injectors by the @inject, followed by the @source annotation (with an injector name) as so, @Inject @Source(“script-bindings”), but invoking such injectors introduces many more lines of code which is tedious and repetitive. Using the @inject annotation freely may cause injector collisions.</p>
<div class="mention-block">
<strong> Thankfully Apache&#8217;s Sling Model library delivered the injector specific annotations!</strong><br />
The injector specific annotations enable us, developers, to write less code, enables stability with injectors to demise injector collisions, and enables better IDE support.
</div>
<p>This article will provide examples (used in practice) which will include both ways to invoke injectors in Sling Models, using the @Inject &#038; @Source annotations, and also the Apache Sling Model injector specific annotations approach.</p>
<hr/>
<h2>Available Injectors</h2>
<ol>
<li><a href="#ScriptVariable">@ScriptVariable</a></li>
<li><a href="#ValueMapValue">@ValueMapValue</a></li>
<li><a href="#ResourcePath">@ResourcePath</a></li>
<li><a href="#ChildResource">@ChildResource</a></li>
<li><a href="#RequestAttribute">@RequestAttribute</a></li>
<li><a href="#OSGiService">@OSGiService</a></li>
<li><a href="#Self">@Self</a></li>
<li><a href="#SlingObject">@SlingObject</a></li>
</ol>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h4 id="ScriptVariable">1. Script Bindings (name=&#8221;script-bindings&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> 1000<br />
<b>Annotation:</b> @ScriptVariable<br />
<b>Description:</b> Injects objects via script variable defined from <a href="https://cwiki.apache.org/confluence/display/SLING/Scripting+variables#Scriptingvariables-Sling'sscriptingvariablesandscriptlanguages" rel="noopener noreferrer" target="_blank">Sling Bindings</a>; Lookup objects in the script bindings object by name.</p>
<div class="mention-block">
As you can see, the example below indicated that there are many ways to inject within the POJO:</p>
<p><strong>Without the injector specific annotations:</strong></p>
<ul>
<li>1. @Inject @Source(&#8220;script-bindings&#8221;) @Named(&#8220;component&#8221;)</li>
<li>2. @Inject @Source(&#8220;script-bindings&#8221;)</li>
</ul>
<p><strong>With the injector specific annotations:</strong></p>
<ul>
<li>3. @ScriptVariable(name = &#8220;component&#8221;)</li>
<li>4. @ScriptVariable</li>
</ul>
<p><strong>Note:</strong> If the name is not set (using the @Named annotation or name property), then the name is derived from the method/property/variable/field name. </p>
<p>A full list of the scripting variables can be found <a href="https://sourcedcode.com/aem-global-objects-for-backend-and-front-end-sightly-htl#mappings" rel="noopener noreferrer" target="_blank">here</a>.
</div>
<div class="code-large">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>Resource.<span style="color: #000000; font-weight: bold;">class</span>, SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;component&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @ScriptVariable(name = &quot;component&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Component</span> component<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;componentContext&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ComponentContext componentContext<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;currentDesign&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Design currentDesign<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;currentNode&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Node currentNode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;currentPage&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Page currentPage<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;currentSession&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> HttpSession currentSession<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;currentStyle&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Style</span> currentStyle<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;designer&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Designer designer<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;editContext&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> EditContext editContext<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;log&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Logger log<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;out&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">PrintWriter</span> out<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;pageManager&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> PageManager pageManager<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;pageProperties&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ValueMap pageProperties<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;reader&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">BufferedReader</span> reader<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;request&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest request<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;resolver&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolver resolver<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;resource&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource resource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;resourceDesign&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Design resourceDesign<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;resourcePage&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Page resourcePage<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;response&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletResponse response<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;sling&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingScriptHelper sling<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;slyWcmHelper&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> WCMScriptHelper slyWcmHelper<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;wcmmode&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SightlyWCMMode wcmmode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;) @Named(&quot;xssAPI&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;script-bindings&quot;)</span><br />
&nbsp; &nbsp; @ScriptVariable<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> XSSAPI xssAPI<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<hr class="spacer-large"/>
<h4 id="ValueMapValue">2. Value Map (name=&#8221;valuemap&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> 2000<br />
<b>Annotation:</b> @ValueMapValue<br />
<b>Description:</b> Gets a property from a ValueMap by name; If @Via is not set, it will automatically take resource if the adaptable is the SlingHttpServletRequest. If name is not set the name is derived from the method/field name.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;valuemap&quot;) @Named(&quot;jcr:title&quot;)</span><br />
&nbsp; &nbsp; @ValueMapValue<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jcr:title&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> titleText<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;valuemap&quot;)</span><br />
&nbsp; &nbsp; @ValueMapValue<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> titleDescription<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large"/>
<h4 id="ResourcePath">3. Resource Path (name=&#8221;resource-path&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> 2500<br />
<b>Annotation:</b> @ResourcePath<br />
<b>Description:</b> Injects one or multiple resources. The resource paths are either given by @Path annotations, the element path or paths of the annotation @ResourcePath or by paths given through a resource property being referenced by either @Named or element name of the annotation @ResourcePath.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;resource-path&quot;) @Path(&quot;/content/sourcedcode/en/home&quot;)</span><br />
&nbsp; &nbsp; @ResourcePath<span style="color: #009900;">&#40;</span>path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/content/sourcedcode/en/home&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; Resource sourcedCodePageResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;resource-path&quot;) @Path(&quot;/content/we-retail/language-masters/en&quot;)</span><br />
&nbsp; &nbsp; @ResourcePath<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/content/we-retail/language-masters/en&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; Resource weRetailPageResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;resource-path&quot;) @Path(paths = {&quot;/content/sourcedcode/en/home&quot;,&quot;/content/we-retail/language-masters/en&quot;})</span><br />
&nbsp; &nbsp; @ResourcePath<span style="color: #009900;">&#40;</span>paths <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/en/home&quot;</span>,<span style="color: #0000ff;">&quot;/content/we-retail/language-masters/en&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; Resource<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> &nbsp;resources<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</li>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #2 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2263738126"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h4 id="ChildResource">4. Child Resources (name=&#8221;child-resources&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> 3000<br />
<b>Annotation:</b> @ChildResource<br />
<b>Description:</b> Gets a child resource by name.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;child-resources&quot;) @Named(&quot;links&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @ChildResource(name=&quot;links&quot;)</span><br />
&nbsp; &nbsp; @ChildResource<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource links<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;child-resources&quot;) @Named(&quot;links&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @ChildResource(name=&quot;links&quot;)</span><br />
&nbsp; &nbsp; @ChildResource<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> links<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;child-resources&quot;) @Named(&quot;social&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @ChildResource(name=&quot;social&quot;)</span><br />
&nbsp; &nbsp; @ChildResource<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource social<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</li>
<hr class="spacer-large"/>
<h4 id="RequestAttribute">5. Request Attributes (name=&#8221;request-attributes&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> 4000<br />
<b>Annotation:</b> @RequestAttribute<br />
<b>Description:</b> Injects a request attribute by name. If name is not set the name is derived from the method/field name.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> SlingHttpServletRequest.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;request-attributes&quot;) @Named(&quot;social&quot;)</span><br />
&nbsp; &nbsp; @RequestAttribute<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;social&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> socialParam<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;request-attributes&quot;) @Named(&quot;link&quot;)</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @RequestAttribute(name = &quot;link&quot;)</span><br />
&nbsp; &nbsp; @RequestAttribute<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> link<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getSocialParam<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> socialParam<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> link<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The example below calls the Sling Model using input parameter:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp;<span style="color: #009900;">&lt;sly data-sly-use.example<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${'com.sourcedcode.core.models.ExampleComponent' @ social=currentPage.title,link=currentPage.path}&quot;</span>&gt;</span><br />
&nbsp; &nbsp; ${example.socialParam}<br />
&nbsp; &nbsp; ${example.link}<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>sly&gt;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
A really great example of the use of this annotation can be found in this <a href="/blog/aem/how-to-pass-parameters-to-sling-modal-from-sightly-htl-component" target="_blank" rel="noopener">article</a>.
</div>
</li>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #3 --><br />
<ins class="adsbygoogle"
     style="display: block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="3385248102"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h4 id="OSGiService">6. OSGi Services (name=&#8221;osgi-services&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> 5000<br />
<b>Annotation:</b> @OSGiService<br />
<b>Description:</b> Injects an OSGi service by type; Lookup services based on class name. Since Sling Models Impl 1.2.8 (SLING-5664) the service with the highest service ranking is returned. In case multiple services are returned, they are ordered descending by their service ranking (i.e. the one with the highest ranking first).</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;osgi-services&quot;)</span><br />
&nbsp; &nbsp; @OSGiService<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingSettingsService slingSettingsService<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;osgi-services&quot;)</span><br />
&nbsp; &nbsp; @OSGiService<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> MyCustomOSGIService myCustomOSGIService<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;osgi-services&quot;)</span><br />
&nbsp; &nbsp; @OSGiService<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> MyCustomOSGISConfigurationervice myCustomOSGISConfigurationervice<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</li>
<hr class="spacer-large"/>
<h4 id="Self">7. Self (name=&#8221;self&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> Integer.MAX_VALUE<br />
<b>Annotation:</b> @Self<br />
<b>Description:</b> Injects the adaptable object itself (if the class of the field matches or is a supertype). If the @Self annotation is present it is tried to adapt the adaptable to the field type.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;self&quot;)</span><br />
&nbsp; &nbsp; @Self<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Node node<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;self&quot;)</span><br />
&nbsp; &nbsp; @Self<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> MyCustomSlingModel myCustomSlingModel<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">///////</span><br />
<span style="color: #666666; font-style: italic;">///////</span><br />
<span style="color: #666666; font-style: italic;">/////// Example below highlights that the @self annotation can minimize the lines of code that needs to be written.</span><br />
<span style="color: #666666; font-style: italic;">///////</span><br />
<span style="color: #666666; font-style: italic;">///////</span><br />
@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource currentResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; Node node<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @PostConstruct<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// adapts the current resource to a node class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; node <span style="color: #339933;">=</span> currentResource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Node.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</li>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #4 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2079905296"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h4 id="SlingObject">8. Sling Object (name=&#8221;sling-object&#8221;) Injector</h4>
<p><b><a href="/aem-sling-models-injectors-service-ranking" target="_blank" rel="noopener noreferrer">Service Ranking:</a></b> Integer.MAX_VALUE<br />
<b>Annotation:</b> @SlingObject<br />
<b>Description:</b> Injects commonly used sling objects if the field matches with the class: request, response, resource resolver, current resource, SlingScriptHelper. This works only if the adaptable can get the according information, i.e. all objects are available via SlingHttpServletRequest while ResourceResolver can only resolve the ResourceResolver object and nothing else. A discussion around this limitation can be found at SLING-4083. Also Resources can only be injected if the according injector specific annotation is used (@SlingObject).</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">@Model<span style="color: #009900;">&#40;</span>adaptables <span style="color: #339933;">=</span> Resource.<span style="color: #000000; font-weight: bold;">class</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; defaultInjectionStrategy <span style="color: #339933;">=</span> DefaultInjectionStrategy.<span style="color: #006633;">OPTIONAL</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExampleComponent <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;sling-object&quot;)</span><br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletRequest slingHttpServletRequest<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;sling-object&quot;)</span><br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingHttpServletResponse slingHttpServletResponse<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;sling-object&quot;)</span><br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Resource currentResource<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// @Inject @Source(&quot;sling-object&quot;)</span><br />
&nbsp; &nbsp; @SlingObject<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ResourceResolver resourceResolver<span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</li>
</ul>
<div class="mention-block">
<strong>Note:</strong><br />
If the name is not set (using the @Named annotation or name property), then the name is derived from the method/property/variable/field name. An example for setting the @Named annotation would time you as a developer encounter a clash between the method/property/variable/field name or when developer not wanting to use the scripting variable names as the variables in the POJO.</p>
<p>As you can see, using the Apache Sling Model&#8217;s injector specific annotations during implementation will help you stay organised, write less code, and speed up the development process.
</p></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #5 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="5183553115"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide">AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>JUnit 4: AEM Sling Servlet Unit Test Example Using wcm.io AEM Mocks, Servlet by Resource Type</title>
		<link>https://sourcedcode.com/blog/aem/aem-sling-servlet-osgi-r7-by-resource-type-unit-test-junit-4-with-examples</link>
					<comments>https://sourcedcode.com/blog/aem/aem-sling-servlet-osgi-r7-by-resource-type-unit-test-junit-4-with-examples#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 21 Dec 2019 17:34:23 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JUNIT]]></category>
		<category><![CDATA[JUNIT4]]></category>
		<category><![CDATA[Sling Models]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1117</guid>

					<description><![CDATA[<p>This article will demonstrate how to write AEM Unit tests for @SlingServletResourceTypes (OSGi DS 1.4 (R7) component property type annotations) using the Junit4 testing framework. With developers being more visual, the source code is posted below. Technologies here used are: AEM project archetype 19 (link) Mockito 2.27.0 (link) AEM Mocks JUnit 4 2.7.2 (link) This [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-servlet-osgi-r7-by-resource-type-unit-test-junit-4-with-examples">JUnit 4: AEM Sling Servlet Unit Test Example Using wcm.io AEM Mocks, Servlet by Resource Type</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article will demonstrate how to write AEM Unit tests for @SlingServletResourceTypes (<a href="https://github.com/apache/sling-org-apache-sling-servlets-annotations" rel="noopener noreferrer" target="_blank">OSGi DS 1.4 (R7) component property type annotations</a>) using the Junit4 testing framework. With developers being more visual, the source code is posted below.</p>
<div class="mention-block">
Technologies here used are:</p>
<ul>
<li>AEM project archetype 19 (<a href="https://github.com/adobe/aem-project-archetype/tree/aem-project-archetype-19" target="_BLANK" rel="noopener noreferrer">link</a>)</li>
<li>Mockito 2.27.0 (<a href="https://mvnrepository.com/artifact/org.mockito/mockito-core/2.27.0" target="_BLANK" rel="noopener noreferrer">link</a>)</li>
<li>AEM Mocks JUnit 4 2.7.2 (<a href="https://mvnrepository.com/artifact/io.wcm/io.wcm.testing.aem-mock.junit4/2.7.2" target="_BLANK" rel="noopener noreferrer">link</a>)</li>
</ul>
</div>
<p>This example uses the AEM project archetype 19 to generate a new AEM project, Junit 4 will be used as the testing framework, Mockito 2.27.0 will be used as the mocking framework, and AEM Mocks will be used to mock AEM objects and AEM API.</p>
<p>What’s really great about the latest versions of AEM mocks, is that the setup is very minimal. After spinning up a new AEM project from the AEM project archetype 19, you simply need to include the AEM Mocks dependency, and you are ready to go!</p>
<p>Using OSGI R7 annotations for your AEM project requires some additional dependencies. Check out Adobe&#8217;s guide to <a href="https://blogs.adobe.com/experiencedelivers/experience-management/osgi/using-osgi-r7-annotations-aem" target="_blank" rel="noopener noreferrer">enable OSGI R7 annotations.</a></p>
<h3>Test Framework Dependencies</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666; font-style: italic;">// pom.xml</span><br />
<span style="color: #339933;">&lt;!--</span> Maven Surefire Plugin <span style="color: #339933;">--&gt;</span><br />
<span style="color: #339933;">&lt;</span>plugin<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">maven</span>.<span style="color: #006633;">plugins</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>maven<span style="color: #339933;">-</span>surefire<span style="color: #339933;">-</span>plugin<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">2.20</span><span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>junitArtifactName<span style="color: #339933;">&gt;</span>junit<span style="color: #339933;">:</span>junit<span style="color: #339933;">:</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">&lt;/</span>junitArtifactName<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>plugin<span style="color: #339933;">&gt;</span><br />
...<br />
<span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">testing</span>.<span style="color: #006633;">aem</span><span style="color: #339933;">-</span>mock<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>2.7.2<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>scope<span style="color: #339933;">&gt;</span>test<span style="color: #339933;">&lt;/</span>scope<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// core/pom.xml</span><br />
<span style="color: #339933;">&lt;</span>dependencies<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>io.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">testing</span>.<span style="color: #006633;">aem</span><span style="color: #339933;">-</span>mock<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #339933;">&lt;/</span>dependencies<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<h3>Sling Servlet Resource Types Class : SlingServletResourceTypes.class</h3>
<div class="code-large">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.day.cq.wcm.api.Page</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.fasterxml.jackson.databind.ObjectMapper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.Resource</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.resource.ResourceResolver</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.servlets.annotations.SlingServletResourceTypes</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">crx</span>.<span style="color: #006633;">packaging</span>.<span style="color: #006633;">JSONResponse</span>.<span style="color: #006633;">APPLICATION_JSON_UTF8</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">sling</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">servlets</span>.<span style="color: #006633;">HttpConstants</span>.<span style="color: #006633;">METHOD_GET</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* A demonstration sling servlet resource type class to demonstrate unit testing.<br />
&nbsp;* Appending &quot;.example.json&quot; on any resource will activate the doGet() method below, and return Json data.<br />
&nbsp;* Json Data returned is data from the immediate children of the &quot;/content/we-retail', parent resource node.<br />
&nbsp;*/</span><br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> Servlet.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
@SlingServletResourceTypes<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resourceTypes <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sling/servlet/default&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; methods <span style="color: #339933;">=</span> METHOD_GET,<br />
&nbsp; &nbsp; &nbsp; &nbsp; extensions <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;json&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; selectors <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;example&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SlingServletResourceTypesExampleDS14Servlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest req, SlingHttpServletResponse res<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span>APPLICATION_JSON_UTF8<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>SlingHttpServletResponse.<span style="color: #006633;">SC_OK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>PageItem<span style="color: #339933;">&gt;</span> pageItems <span style="color: #339933;">=</span> getPageItems<span style="color: #009900;">&#40;</span>req<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> json <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">writeValueAsString</span><span style="color: #009900;">&#40;</span>pageItems<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>PageItem<span style="color: #339933;">&gt;</span> getPageItems<span style="color: #009900;">&#40;</span>SlingHttpServletRequest req<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>PageItem<span style="color: #339933;">&gt;</span> pageItems <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ResourceResolver resolver <span style="color: #339933;">=</span> req.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Resource weRetail <span style="color: #339933;">=</span> resolver.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/we-retail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>weRetail <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Iterator<span style="color: #339933;">&lt;</span>Resource<span style="color: #339933;">&gt;</span> it <span style="color: #339933;">=</span> weRetail.<span style="color: #006633;">listChildren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>it.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Resource resource <span style="color: #339933;">=</span> it.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resource.<span style="color: #006633;">getResourceType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span>com.<span style="color: #006633;">day</span>.<span style="color: #006633;">cq</span>.<span style="color: #006633;">wcm</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">NameConstants</span>.<span style="color: #006633;">NT_PAGE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Page page <span style="color: #339933;">=</span> resource.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Page.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>page <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageItems.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PageItem<span style="color: #009900;">&#40;</span>page.<span style="color: #006633;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, resource.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> pageItems<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Inner class PageItem, for creating PageItem objects.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PageItem <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> pageTitle<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> pagePath<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; PageItem<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> pageTitle, <span style="color: #003399;">String</span> pagePath<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">pageTitle</span> <span style="color: #339933;">=</span> pageTitle<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">pagePath</span> <span style="color: #339933;">=</span> pagePath<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getPageTitle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> pageTitle<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getPagePath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> pagePath<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p>Results of the output from the working as expected SlingServletResourceTypesTest.class.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/12/sling-servlet-resource-type-unit-test-example-results-json.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/12/sling-servlet-resource-type-unit-test-example-results-json-1024x933.png" alt="Sling Servlet Resource TypeResults Example" width="200" /></a></p>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #6 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2559251592"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large" />
<h3>Sling Servlet Resource Types Test Class : SlingServletResourceTypesTest.class</h3>
<div class="code-large">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.servlets</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.fasterxml.jackson.databind.JsonNode</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.fasterxml.jackson.databind.ObjectMapper</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">io.wcm.testing.mock.aem.junit.AemContext</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.testing.mock.sling.ResourceResolverType</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Before</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Rule</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.runner.RunWith</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.InjectMocks</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.Mock</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mockito.junit.MockitoJUnitRunner</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> com.<span style="color: #006633;">day</span>.<span style="color: #006633;">crx</span>.<span style="color: #006633;">packaging</span>.<span style="color: #006633;">JSONResponse</span>.<span style="color: #006633;">APPLICATION_JSON_UTF8</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> junitx.<span style="color: #006633;">framework</span>.<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertEquals</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">junit</span>.<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertTrue</span><span style="color: #339933;">;</span><br />
<br />
@RunWith<span style="color: #009900;">&#40;</span>MockitoJUnitRunner.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SlingServletResourceTypesExampleDS14ServletTest <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Rule<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> AemContext context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AemContext<span style="color: #009900;">&#40;</span>ResourceResolverType.<span style="color: #006633;">JCR_MOCK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> MockSlingHttpServletRequest req<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Mock<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> MockSlingHttpServletResponse res<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @InjectMocks<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> SlingServletResourceTypesExampleDS14Servlet underTest<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Before<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SlingServletResourceTypesExampleDS14Servlet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; req <span style="color: #339933;">=</span> context.<span style="color: #006633;">request</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res <span style="color: #339933;">=</span> context.<span style="color: #006633;">response</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doGet_shouldReturnHeaderAsExpected<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest.<span style="color: #006633;">doGet</span><span style="color: #009900;">&#40;</span>req, res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span>res.<span style="color: #006633;">getContentType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, APPLICATION_JSON_UTF8<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doGet_shouldReturnPageItemListJsonAsExpected_0<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest.<span style="color: #006633;">doGet</span><span style="color: #009900;">&#40;</span>req, res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> jsonString <span style="color: #339933;">=</span> res.<span style="color: #006633;">getOutputAsString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ObjectMapper mapper <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JsonNode actualObj <span style="color: #339933;">=</span> mapper.<span style="color: #006633;">readTree</span><span style="color: #009900;">&#40;</span>jsonString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, actualObj.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doGet_shouldReturnPageItemJsonAsExpected_properties_values<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; createPagesInJcrMock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; underTest.<span style="color: #006633;">doGet</span><span style="color: #009900;">&#40;</span>req, res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> jsonString <span style="color: #339933;">=</span> res.<span style="color: #006633;">getOutputAsString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ObjectMapper mapper <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JsonNode actualObj <span style="color: #339933;">=</span> mapper.<span style="color: #006633;">readTree</span><span style="color: #009900;">&#40;</span>jsonString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JsonNode firstItem <span style="color: #339933;">=</span> actualObj.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color: #009900;">&#40;</span>firstItem.<span style="color: #006633;">has</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pageTitle&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color: #009900;">&#40;</span>firstItem.<span style="color: #006633;">has</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pagePath&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;United states&quot;</span>, firstItem.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pageTitle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">textValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/we-retail/us&quot;</span>, firstItem.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pagePath&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">textValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Test helper method to create 3 pages in the on-memory JCR Mock instance.<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> createPagesInJcrMock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">page</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/we-retail&quot;</span>, <span style="color: #0000ff;">&quot;/&quot;</span>, <span style="color: #0000ff;">&quot;We Retail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">page</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/we-retail/us&quot;</span>, <span style="color: #0000ff;">&quot;/&quot;</span>, <span style="color: #0000ff;">&quot;United states&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">page</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/we-retail/ca&quot;</span>, <span style="color: #0000ff;">&quot;/&quot;</span>, <span style="color: #0000ff;">&quot;Canada&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<div class="mention-block">
<strong>Last Thoughts:</strong><br />
Though the endpoint path is ugly (because it consists of extensions, selectors, and etc&#8230;), it is recomended to register servlet by resource types rather than by path (<a href="https://sourcedcode.com/registering-slingservletpaths-component-property-type">click here to learn why @SlingServletPaths, register by path, are not recommended</a>).</p>
<p>If there is a requirement to mask or to sugarcoat the ugly URI paths, a common strategy used is the Apache webserver. <a href="/sugar-coating-servlet-scripts-and-paths">Click here to learn to sugar coat registered AEM servlet scripts and paths endpoint</a>.
</div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #2 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2263738126"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-sling-servlet-osgi-r7-by-resource-type-unit-test-junit-4-with-examples">JUnit 4: AEM Sling Servlet Unit Test Example Using wcm.io AEM Mocks, Servlet by Resource Type</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-sling-servlet-osgi-r7-by-resource-type-unit-test-junit-4-with-examples/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Registering @SlingServletPaths Component Property Type</title>
		<link>https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type</link>
					<comments>https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Thu, 19 Dec 2019 18:44:18 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1105</guid>

					<description><![CDATA[<p>You are probably looking for the @SlingServletPaths, OSGi DS 1.4 (R7) component property type annotations for Sling Servlets, code/unit test examples and was not successful. Apache recommends not use the @SlingServletPaths annotation, Sling Servlet register by a path. Rather to use the @SlingServletResourceTypes component type. Given the drawbacks in the caveats below, it is strongly [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type">Registering @SlingServletPaths Component Property Type</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You are probably looking for the @SlingServletPaths, OSGi DS 1.4 (R7) component property type annotations for Sling Servlets, code/unit test examples and was not successful. </p>
<p>Apache recommends not use the <strong>@SlingServletPaths</strong> annotation, Sling Servlet register by a path. Rather to use the <strong>@SlingServletResourceTypes</strong> component type. Given the drawbacks in the caveats below, it is strongly recommended to bind servlets to resource types rather than paths.</p>
<p><strong>Caveats when using @SlingServletPaths:</strong></p>
<ul>
<li>Path-bound servlets cannot be access-controlled using the default JCR repository ACLs.</li>
<li>Path-bound servlets can only be registered to a path and not a resource type (i.e. no suffix handling).</li>
<li>If a path-bound servlet is not active, e.g. if the bundle is missing or not started, a POST might result in unexpected results. usually creating a node at /bin/xyz which subsequently overlays the servlets path binding.</li>
<li>The mapping is not transparent to a developer looking just at the repository.</li>
</ul>
<p><a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html#caveats-when-binding-servlets-by-path" target="_blank" rel="noopener noreferrer">Apache&#8217;s Documentation</a></p>
<p>Also, have a look at the Apache Sling Servlet Documentation for the <a href="https://www.javadoc.io/static/org.apache.sling/org.apache.sling.servlets.annotations/1.1.0/org/apache/sling/servlets/annotations/SlingServletPaths.html" target="_blank" rel="noopener noreferrer">SlingServletPaths</a> component property type, which what is mentioned above is clearly stated.</p>
<h3>Example of @SlingServletResourceTypes:</h3>
<p>The proper way to bind Sling Servlets is by binding the servlet to resource types. This is an example of a servlet binding to a resource type.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">package com.<span style="color: #660066;">sourcedcode</span>.<span style="color: #660066;">core</span>.<span style="color: #660066;">servlets</span>.<span style="color: #660066;">impl</span><span style="color: #339933;">;</span><br />
<span style="color: #FF0000;">import</span> org.<span style="color: #660066;">apache</span>.<span style="color: #660066;">sling</span>.<span style="color: #660066;">api</span>.<span style="color: #660066;">SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #FF0000;">import</span> org.<span style="color: #660066;">apache</span>.<span style="color: #660066;">sling</span>.<span style="color: #660066;">api</span>.<span style="color: #660066;">SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #FF0000;">import</span> org.<span style="color: #660066;">apache</span>.<span style="color: #660066;">sling</span>.<span style="color: #660066;">api</span>.<span style="color: #660066;">servlets</span>.<span style="color: #660066;">SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #FF0000;">import</span> org.<span style="color: #660066;">apache</span>.<span style="color: #660066;">sling</span>.<span style="color: #660066;">servlets</span>.<span style="color: #660066;">annotations</span>.<span style="color: #660066;">SlingServletResourceTypes</span><span style="color: #339933;">;</span><br />
<span style="color: #FF0000;">import</span> org.<span style="color: #660066;">osgi</span>.<span style="color: #660066;">service</span>.<span style="color: #660066;">component</span>.<span style="color: #660066;">annotations</span>.<span style="color: #660066;">Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #FF0000;">import</span> javax.<span style="color: #660066;">servlet</span>.<span style="color: #660066;">Servlet</span><span style="color: #339933;">;</span><br />
<span style="color: #FF0000;">import</span> java.<span style="color: #660066;">io</span>.<span style="color: #660066;">IOException</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #FF0000;">import</span> <span style="color: #000066; font-weight: bold;">static</span> org.<span style="color: #660066;">apache</span>.<span style="color: #660066;">sling</span>.<span style="color: #660066;">api</span>.<span style="color: #660066;">servlets</span>.<span style="color: #660066;">HttpConstants</span>.<span style="color: #660066;">METHOD_GET</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">/**<br />
&nbsp;* Enables all resources to return formatted response data from the doGet() method.<br />
&nbsp;* Appending &quot;.example.json&quot; on any resource will activate the doGet() method below. <br />
&nbsp;*/</span><br />
<span style="color: #339933;">@</span>Component<span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> Servlet.<span style="color: #FF0000;">class</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #339933;">@</span>SlingServletResourceTypes<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resourceTypes <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;sling/servlet/default&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; methods <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;get&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; extensions <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; selectors <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;example&quot;</span><span style="color: #009900;">&#41;</span><br />
public <span style="color: #FF0000;">class</span> SlingServletResourceTypesExampleServlet <span style="color: #FF0000;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #339933;">@</span>Override<br />
&nbsp; &nbsp; protected <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest req<span style="color: #339933;">,</span> SlingHttpServletResponse res<span style="color: #009900;">&#41;</span> <span style="color: #FF0000;">throws</span> IOException <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #660066;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #660066;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #660066;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #660066;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Done&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
<strong>Unit Test for @SlingServletResourceTypes</strong><br />
For an example of how to write a unit test for a sling servlet,binding by resource type, <a href="https://sourcedcode.com/aem-sling-servlet-osgi-r7-by-resource-type-unit-test-junit-4-with-examples">click here</a>.
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type">Registering @SlingServletPaths Component Property Type</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Sugar Coat Registered AEM Servlet Scripts and Paths Endpoint</title>
		<link>https://sourcedcode.com/blog/aem/sugar-coating-servlet-scripts-and-paths</link>
					<comments>https://sourcedcode.com/blog/aem/sugar-coating-servlet-scripts-and-paths#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 02 Dec 2019 21:08:21 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1037</guid>

					<description><![CDATA[<p>In AEM we tend to write Sling Servlet OSGI Services to expose JSON data using the various service reference properties such as &#8220;sling.servlet.paths&#8221;, &#8220;sling.servlet.resourceTypes&#8221;, &#8220;sling.servlet.selectors&#8221;, and &#8220;sling.servlet.extensions&#8221;. Example 1: DirectoriesServlet.Java doGet Servlet Implementation (html extension): This is an example how a servlet in AEM to retrieve the directories JSON data. 1234567891011121314151617// example for /content/mysite.directories.html @SlingServlet&#40; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/sugar-coating-servlet-scripts-and-paths">Sugar Coat Registered AEM Servlet Scripts and Paths Endpoint</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In AEM we tend to write Sling Servlet OSGI Services to expose JSON data using the various service reference properties such as &#8220;sling.servlet.paths&#8221;, &#8220;sling.servlet.resourceTypes&#8221;, &#8220;sling.servlet.selectors&#8221;, and &#8220;sling.servlet.extensions&#8221;. </p>
<p><strong>Example 1: DirectoriesServlet.Java doGet Servlet Implementation (html extension):</strong><br />
This is an example how a servlet in AEM to retrieve the directories JSON data.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666; font-style: italic;">// example for /content/mysite.directories.html</span><br />
@SlingServlet<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; resourceTypes <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/apps/mysite/components/page/basepage&quot;</span>,<br />
&nbsp; &nbsp; selectors <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;directory&quot;</span>,<br />
&nbsp; &nbsp; extensions <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;html&quot;</span>,<br />
&nbsp; &nbsp; methods <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>HttpStatus.<span style="color: #006633;">OK_200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span>APPLICATION_JSON_UTF8<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span>HttpHeaders.<span style="color: #006633;">EXPIRES</span>, EXPIRE_IN_SECONDS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span>HttpHeaders.<span style="color: #006633;">CACHE_CONTROL</span>, <span style="color: #0000ff;">&quot;max-age=&quot;</span> <span style="color: #339933;">+</span> EXPIRE_IN_SECONDS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> json <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">writeValueAsString</span><span style="color: #009900;">&#40;</span>getDirectories<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Example 2: StoresServlet.Java doGet Servlet Implementation (json extension):</strong><br />
This is an example how a servlet in AEM to retrieve the stores JSON data.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666; font-style: italic;">// example for /content/mysite.stores.json</span><br />
@SlingServlet<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; resourceTypes <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/apps/mysite/components/page/basepage&quot;</span>,<br />
&nbsp; &nbsp; selectors <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;stores&quot;</span>,<br />
&nbsp; &nbsp; extensions <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;json&quot;</span>,<br />
&nbsp; &nbsp; methods <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>HttpStatus.<span style="color: #006633;">OK_200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span>APPLICATION_JSON_UTF8<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span>HttpHeaders.<span style="color: #006633;">EXPIRES</span>, EXPIRE_IN_SECONDS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span>HttpHeaders.<span style="color: #006633;">CACHE_CONTROL</span>, <span style="color: #0000ff;">&quot;max-age=&quot;</span> <span style="color: #339933;">+</span> EXPIRE_IN_SECONDS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> json <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectMapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">writeValueAsString</span><span style="color: #009900;">&#40;</span>getStores<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>JSON Request:</strong><br />
Typically, multi-channel implementations such as mobile, smartwatches, kiosks, 3rd party websites, etc&#8230; will be requesting for JSON data with the path of:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">/content/mysite.directories.html<br />
/content/mysite.stores.json</div></td></tr></tbody></table></div>
<p>As you can tell, the path stated above looks unfinished. In such, Sling Servlet Resolver scripts/paths may not be acceptable to present to the end-users. Revealing custom selectors or custom extensions are not suitable for security reasons and detailed information exposure; this can be easily resolved. We can add a layer of security, and also sugar-coat the revealed scripts/paths by utilising the Apache Web Server&#8217;s Rewrite Flag, PT, as one of the many good practises to follow.</p>
<h3>What is the Apache Web Server&#8217;s Rewrite Flag, PT</h3>
<p>The [PT] flag causes the result of the RewriteRule to be passed back through URL mapping as an Alias. Simply the end-users will only see an alias of the JSON file while the request is internally mapped to the correct path to the AEM publisher.</p>
<h4>Examples of PT:</h4>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">RewriteRule ^<span style="color: #66cc66;">/</span>api<span style="color: #66cc66;">/</span>directories.json$ <span style="color: #66cc66;">/</span><span style="color: #000066;">content</span><span style="color: #66cc66;">/</span>mysite.directories.html <span style="color: #66cc66;">&#91;</span>PT,L<span style="color: #66cc66;">&#93;</span><br />
RewriteRule ^<span style="color: #66cc66;">/</span>api<span style="color: #66cc66;">/</span>stores.json$ <span style="color: #66cc66;">/</span><span style="color: #000066;">content</span><span style="color: #66cc66;">/</span>mysite.stores.json <span style="color: #66cc66;">&#91;</span>PT,L<span style="color: #66cc66;">&#93;</span></div></td></tr></tbody></table></div>
<p>Finally, after the Rewrite rule has been set up, multi-channel implementations can request for the JSON with this path:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #66cc66;">/</span>api<span style="color: #66cc66;">/</span>directories.json<br />
<span style="color: #66cc66;">/</span>api<span style="color: #66cc66;">/</span>stores.json</div></td></tr></tbody></table></div>
<div class="mention-block">
In summary, this is a standard way to secure your Servlets in AEM, and also to sugar-coat an AEM site&#8217;s Sling Servlet Resolver scripts/paths.</p>
<p><strong>Also, do remember to add caching strategies for optimize the load against your AEM production publish instances.</strong>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/sugar-coating-servlet-scripts-and-paths">Sugar Coat Registered AEM Servlet Scripts and Paths Endpoint</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/sugar-coating-servlet-scripts-and-paths/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>What is a Servlet in AEM?</title>
		<link>https://sourcedcode.com/blog/aem/what-is-a-servlet-in-aem</link>
					<comments>https://sourcedcode.com/blog/aem/what-is-a-servlet-in-aem#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 02 Dec 2019 20:01:16 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=1033</guid>

					<description><![CDATA[<p>What is a Servlet? A Servlet is a class used to extend capabilities of servers that host applications accessed by means of a request-response programming model; we know most the HTTP protocol. In AEM, Servlets are typically registered as an OSGI service. The reference of the &#8220;sling.servlet.paths&#8221; or &#8220;sling.servlet.resourceTypes&#8221; must be set, or the Servlet [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-is-a-servlet-in-aem">What is a Servlet in AEM?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>What is a Servlet? A Servlet is a class used to extend capabilities of servers that host applications accessed by means of a request-response programming model; we know most the HTTP protocol. </p>
<p>In AEM, Servlets are typically registered as an OSGI service. The reference of the &#8220;sling.servlet.paths&#8221; or  &#8220;sling.servlet.resourceTypes&#8221; must be set, or the Servlet service will be ignored. </p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/what-is-a-servlet-in-aem">What is a Servlet in AEM?</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/what-is-a-servlet-in-aem/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Improve Performance of AEM Components During Development Phase</title>
		<link>https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase</link>
					<comments>https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 06 Nov 2019 19:50:22 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Performance]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=965</guid>

					<description><![CDATA[<p>Web performance is how quick web pages are successfully downloaded and viewable on the visitor&#8217;s browser. When we say &#8220;Web Performance Optimization&#8221;, this means that we are optimising or increasing web performance. Quicker download speeds of websites, in general, have shown in user contentment, retention, and loyalty. Especially with AEM enterprise websites, our motive is [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase">Improve Performance of AEM Components During Development Phase</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Web performance is how quick web pages are successfully downloaded and viewable on the visitor&#8217;s browser. When we say &#8220;Web Performance Optimization&#8221;, this means that we are optimising or increasing web performance. Quicker download speeds of websites, in general, have shown in user contentment, retention, and loyalty.</p>
<p>Especially with AEM enterprise websites, our motive is to deliver high-performance websites. Us as developers, we try our best to keep the code our clean and optimum. When it comes to creating new AEM components, instead of waiting for the batch of approved non-released code to be deployed into a performance testing environment, you can monitor the performance of your AEM components beforehand in local author.</p>
<p>Quickly view and monitor the performance of your component&#8217;s Sightly front-end logic and Sling Models back-end logic has never been so easy!</p>
<div class="mention-block">
During the development of AEM page/content components, since AEM 6.2, the platform has provided a tool for us, developers, to conveniently monitor the server-side computational time. This tool is called the <strong>Developer Mode</strong>. This allows you to find a slow loading page/content components, so you can take action and optimize it to the optimal! In this article, you will learn how to understand, and then improve, the page loading speed by identifying slow components by monitoring component&#8217;s server-side computational time.</div>
<p><a href="https://sourcedcode.com/wp-content/uploads/2019/11/computational-time.jpg" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/computational-time.jpg" alt="" width="60%"/></a></p>
<h3>How to Review Server-Side Computational Time with &#8220;Developer Mode&#8221;</h3>
<p><strong>&#8220;Develop Mode&#8221; lives in authoring AEM environment, inside of the editable page.</strong></p>
<ol>
<li style="list-style-type: none;">
<ol>
<li>Visit any page that you would like to measure. Ensure the targeted component sits on the page, and if not, add the component to the editable page. <a href="http://localhost:4502/editor.html/content/we-retail/language-masters/en.html" target="_blank" rel="noopener noreferrer">http://localhost:4502/editor.html/content/we-retail/language-masters/en.html</a></li>
<li>Click on the tool-bar drop-down selector, and select on <strong>&#8220;Develop&#8221;</strong>.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-drop-down-menu.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-drop-down-menu.png" alt="" width="50%" /></a></li>
<li>The page is reviewed with a side-panel which includes the component tree; the component tree is populated structure of all the components that live within the targeted page. Immediately you can see the server-side computational time. This information is extremely useful when you are trying to optimize your AEM website. The metric used here is <strong>ms</strong> for milliseconds and <strong>s</strong> for seconds. As you can see in the image provided below, Page .033s indicates that the entire page takes 1/3 of a second to load all the components.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools.png" alt="" width="50%" /></a></p>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="6046636040"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
</li>
<li>Along with a grouped server-side computational time, Individual components computational time will also be displayed. In the screenshot below, we are taking a look at the performance of the header component.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-header-view-details-edit-script.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-header-view-details-edit-script.png" alt="" width="50%" /></a>
</li>
<li><strong>Hooray!</strong> You Have Completed this Tutorial. As an extension to this tutorial, we will learn about the &#8220;view details&#8221;, &#8220;edit script&#8221;, and also the &#8220;errors&#8221; option.<br /><a href="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools-1.png" target="_blank" rel="noopener noreferrer"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/developer-mode-tools-1-1024x659.png" alt="" width="50%" /></a><br />
<strong>Buttons Legend</strong>:<br />
<strong>View Details</strong>: a link to a list that shows all the component scripts used to render the component, and also the repository content path for this specific component.<br />
<strong>Edit Script</strong>: a link that opens the component&#8217;s script in CRXDE Lite.<br />
<strong>Component Details</strong>: a link that takes you to the component details page.</li>
</ol>
</li>
</ol>
<div class="mention-block"><b>Last Thoughts</b><br />
This tool is definitely useful for when you are trying to optimize your AEM website, looking at the underlying cause of your slow rendered AEM page. Now go and optimize your logic to reduce page loading time!</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase">Improve Performance of AEM Components During Development Phase</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/improve-performance-of-aem-components-during-development-phase/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Scenario: Building AEM Components with 3rd Party Integrations in a High Performance and Scalable Way</title>
		<link>https://sourcedcode.com/blog/aem/scenario-building-aem-components-with-3rd-party-integrations-the-right-way</link>
					<comments>https://sourcedcode.com/blog/aem/scenario-building-aem-components-with-3rd-party-integrations-the-right-way#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 02 Nov 2019 22:26:54 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=924</guid>

					<description><![CDATA[<p>we are assigned to build a hospital search component in a very high traffic website. This hospital search component allows users to search for available hospital private rooms across the United States; there are approximately 200,000 hospital private rooms across the US.  The hospital search component, presented in the view, simply has an input field [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/scenario-building-aem-components-with-3rd-party-integrations-the-right-way">Scenario: Building AEM Components with 3rd Party Integrations in a High Performance and Scalable Way</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>we are assigned to build a hospital search component in a very high traffic website. This hospital search component allows users to search for available hospital private rooms across the United States; there are approximately 200,000 hospital private rooms across the US.  The hospital search component, presented in the view, simply has an input field that allows a user to search for postal code, and a filter to filter by facilities and distance. When a search is made successful, the hospital search component will show a structured HTML grid view of 20 room availabilities to the users. When a search is made unsuccessful, a message of &#8220;no results&#8221; will be shown.</p>
<p><b>How can we build a high performance and scalable solution for this requirement?</b> Below is &#8220;the non-optimized&#8221; and &#8220;the optimized&#8221; solutions for my recommended implementations.</p>
<div class="mention-block">
<p><strong>Solutions</strong></p>
<ol>
<li><a href="#solution1">Solution 1: Non-Optimized Solution</a></li>
<li><a href="#solution2">Solution 2: Optimized, Better Solution</a></li>
</ol>
</div>
<h3 id="solution1">1. Non-Optimized, Unacceptable Solution</h3>
<p>For this solution, the Sling Servlet with the /bin/my-app/search endpoint will be utilised. This Sling Servlet will accept the HTTP POST request. When the HTTP POST request is made to /bin/my-app/search, the AEM server will process the request with logic where it will make a server-side HTTP Client request to the third-party API, waits for the response, and returns JSON as results. With the JSON results returned from the third-party API, the AEM server-side logic will format and return the appropriate JSON data to the AEM front-end component.</p>
<p><strong>The example below is an inefficient implementation because:</strong></p>
<ol>
<li>All search request hits the AEM publishers.</li>
<li>All search request made to the AEM publisher are not cached; though including a caching mechanism may be more complicated when integrating this strategy into AEM.</li>
<li>The Sling Servlet being scalable is limited by the numbers of AEM publisher servers available.</li>
<li>All search concurrent requests made to the AEM publsher will consume the CPU, memory, and I/O resources, therfore other visitors may experience a delay.</li>
</ol>
<p><a href="https://sourcedcode.com/wp-content/uploads/2019/11/sling-servlet-impl-2.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/sling-servlet-impl-2.png" alt="" width="60%" /></a></p>
<h3 id="solution2">2. Optimized, Better Solution</h3>
<p>For this solution, the AEM front-end component makes the HTTP POST request directly from the client to the third-party API. The third-party API process the request and returns the correct formatted JSON data. Next, the AEM front-end component will render HTML elements to the page.<br />
<strong>The example below is a more efficient implementation because:</strong></p>
<ol>
<li>All search requests hits a micro-service, and away from AEM.</li>
<li>The search requests will not affect any processing from the AEM publishers.</li>
<li>The search requests will not consume the CPU, memory, and I/O resources</li>
<li>The micro-service will have caching abilities.</li>
<li>The micro-service will be resuable across the organization.</li>
<li>The micro-service will be scalable.</li>
</ol>
<p><a href="https://sourcedcode.com/wp-content/uploads/2019/11/micro-service-impl-2.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/11/micro-service-impl-2.png" alt="" width="60%" /></a><br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="6046636040"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="issues" class="mention-block"><strong>Last Thoughts:</strong><br />
For most high traffic AEM sites, we typically try to offload as much processing from our AEM live-publish instances to reduce CPU resources being used, and to maintain good performance.</p>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/scenario-building-aem-components-with-3rd-party-integrations-the-right-way">Scenario: Building AEM Components with 3rd Party Integrations in a High Performance and Scalable Way</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/scenario-building-aem-components-with-3rd-party-integrations-the-right-way/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Check all Active Run Modes in a Running AEM Instance.</title>
		<link>https://sourcedcode.com/blog/aem/how-to-check-all-active-run-modes-in-a-running-aem-instance</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-check-all-active-run-modes-in-a-running-aem-instance#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Fri, 01 Nov 2019 21:38:02 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=899</guid>

					<description><![CDATA[<p>﻿The fastest way to retrieve all active run modes that are enabled within a running AEM instance would be from the OSGI console, Apache Sling Settings. Follow the two simple steps below: Log in to AEM as an admin or a user who has access to the OSGI console using this URL: http://localhost:4502/crx/de/index.jsp Navigate to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-check-all-active-run-modes-in-a-running-aem-instance">How to Check all Active Run Modes in a Running AEM Instance.</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start">﻿</span>The fastest way to retrieve all active run modes that are enabled within a running AEM instance would be from the OSGI console, Apache Sling Settings.</p>
<h4>Follow the two simple steps below:</h4>
<ol>
<li>Log in to AEM as an admin or a user who has access to the OSGI console using this URL: <a href=
"http://localhost:4502/crx/de/index.jsp" target="_blank" title="localhost crx/de login" rel="noopener noreferrer">http://localhost:4502/crx/de/index.jsp</a>
 </li>
<li>
Navigate to the Apache Sling Settings OSGI console page <a href="http://localhost:4502/system/console/status-slingsettings" target="_blank" rel="noopener noreferrer">http://localhost:4502/system/console/status-slingsettings</a></p>
<p><b>Expected screen from visiting <a href="http://localhost:4502/system/console/status-slingsettings" target="_blank" rel="noopener noreferrer">http://localhost:4502/system/console/status-slingsettings</a></b><br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/11/status-sling-settings.png" target="_blank" rel="noopener noreferrer"><img decoding="async" width="60%" src="https://sourcedcode.com/wp-content/uploads/2019/11/status-sling-settings.png" alt="status sling settings osgi console screenshot"></a>
</li>
</ol>
<p>The active AEM run modes here are: &#8220;local-local&#8221;, &#8220;s7connect&#8221;, &#8220;crx3&#8221;, &#8220;author&#8221;, &#8220;samplecontent&#8221;, &#8220;local&#8221;, &#8220;crx3tar:</p>
<h4>Propertie Breakdown</h4>
<ul>
<li><b>Sling ID</b>: A unique identifier of the running Sling instance. This value is created when Sling is first started and may be used to identify the instance, for example if multiple Sling instances are running on top of a Jackrabbit Repository Cluster.</li>
<li><b>Sling Home</b>: The absolute filesystem path to the directory where Sling stores all its content.</li>
<li><b>Sling Home URL</b>: The Sling Home path as an java.net.URL instance.</li>
<li><b>Run Modes</b>: The active Run Modes of the running Sling instance.</li>
</ul>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-check-all-active-run-modes-in-a-running-aem-instance">How to Check all Active Run Modes in a Running AEM Instance.</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-check-all-active-run-modes-in-a-running-aem-instance/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to write Javascript Unit Tests for AEM Client Libraries with Jest</title>
		<link>https://sourcedcode.com/blog/aem/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest</link>
					<comments>https://sourcedcode.com/blog/aem/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sun, 13 Oct 2019 19:40:09 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=672</guid>

					<description><![CDATA[<p>This article demonstrates how to set up and run Javascript Jest unit test for client libraries. As a part of this setup, code coverage will be produced by Jest. With this implementation, we will utilise the frontend-maven-plugin, where it makes it possible to run npm scripts apart of the maven build. Most of the time, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest">How to write Javascript Unit Tests for AEM Client Libraries with Jest</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article demonstrates how to set up and run Javascript Jest unit test for client libraries. As a part of this setup, code coverage will be produced by Jest. With this implementation, we will utilise the <a href="https://github.com/eirslett/frontend-maven-plugin" target="_blank" rel="noopener noreferrer">frontend-maven-plugin</a>, where it makes it possible to run npm scripts apart of the maven build.</p>
<p>Most of the time, AEM developers must create new components in AEM with javascript rich experiences. These experiences may be allowing the end-users to toggle the navigation header, submit a search query, or even to control a slide show. Most of the time we would not need to build a full-blown complex Javascript heavy application using the latest ES6 syntax, ES6 javascript modules, Webpack, etc&#8230;; ReactJS and AngularJS are not required. </p>
<p>With a not full-blown Javascript application, we are encouraged to write Javascript logic directly into a client library with ES5; with tools and libraries like Jquery, Underscore JS, Mustache JS, etc&#8230; so the Adobe Granite HTML Library Manager will be working as expected. </p>
<div class="mention-block">Quick Links</p>
<ol>
<li><a href="#what-is-jest">What is Jest?</a></li>
<li><a href="#introduction">Setup Introduction</a></li>
<li><a href="#setup">How to setup Jest on an AEM Project</a></li>
<li><a href="#results">Success Jest Build Results</a></li>
<li><a href="#issues">Known Issues</a></li>
</ol>
</div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large" />
<h2 id="what-is-jest">What is Jest?</h2>
<p>Jest is the unit testing framework for front-end driven projects. It is developed and used by Facebook themselves. </p>
<p><strong>Some features of Jest are:</strong></p>
<ol>
<li>Automatically find tests with files suffixed as test.js; example Header.test.js.</li>
<li>Supports dependency injection.</li>
<li>Supports mocks.</li>
<li>Runs your tests with a fake DOM implementation</li>
<li>and, Runs tests in parallel processes</li>
</ol>
<hr class="spacer-large"/>
<h2 id="introduction">Setup Introduction</h2>
<p>This example is based on AEM project built using AEM project using the <a href="https://github.com/adobe/aem-project-archetype/releases/tag/aem-project-archetype-20" target="_blank" rel="noopener noreferrer">AEM Project Archetype 20.</a></p>
<p>For this example, I have created a javascript file of Helper.js that sits directly under the clientlib-site folder. This client library will exist in the <a href="https://github.com/adobe/aem-project-archetype/releases/tag/aem-project-archetype-20" target="_blank" rel="noopener noreferrer">AEM Project Archetype 20 build.</a> Javascript tests should sit within the same directory as the Helper.js file under __tests__, as ./__tests__/Helper.test.js.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup.png"><img decoding="async" class="alignnone wp-image-673 size-medium" src="https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup.png" alt="" width="350" height="auto" srcset="https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup.png 862w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup-205x300.png 205w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup-768x1123.png 768w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup-701x1024.png 701w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-setup-600x877.png 600w" sizes="(max-width: 862px) 100vw, 862px" /></a></p>
<p>On a standard AEM application build, I will run <strong>mvn clean install. </strong>The application will build as follows:<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow.png"><img decoding="async" class="alignnone wp-image-678" src="https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow.png" alt="JEST test flow with AEM build" width="500" height="auto" srcset="https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow.png 1186w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow-300x291.png 300w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow-768x745.png 768w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow-1024x993.png 1024w, https://sourcedcode.com/wp-content/uploads/2019/10/clientlib-jest-test-flow-600x582.png 600w" sizes="(max-width: 1186px) 100vw, 1186px" /></a><br />
<strong>The run down:</strong></p>
<ol>
<li>developer runs: mvn clean install.</li>
<li>The core bundle will be built, unit tests from the <strong>core</strong> maven module will be run.</li>
<li>onSuccess, proceed to the next step; onFail stop build.</li>
<li>Javascript Jest unit tests from the <strong>ui.apps</strong> maven module will be invoked, and code coverage from the Jest test will be produced.</li>
<li>onSuccess, proceed to the next step; onFail stop build.</li>
<li>The ui.apps.zip will live in the target folder.</li>
</ol>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #4 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2079905296"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h2 id="setup">How to Setup JEST on an AEM Project</h2>
<p>This setup have been tested on the latest <a href="https://github.com/adobe/aem-project-archetype/releases/tag/aem-project-archetype-20" target="_blank" rel="noopener noreferrer">AEM Project Archetype 20</a> project build. If you wish to follow this tutorial, please first build the AEM Project Archetype 20 project.</p>
<h4>1. Add Helper.js</h4>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #006600; font-style: italic;">// create file under directory</span><br />
<span style="color: #006600; font-style: italic;">// ui.apps/src/main/content/jcr_root/apps/sourcedcode/clientlibs/clientlib-site/js/Helper.js</span><br />
<br />
<br />
window.<span style="color: #660066;">JestTest</span> <span style="color: #339933;">=</span> window.<span style="color: #660066;">JestTest</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
JestTest.<span style="color: #660066;">Helpers</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> add<span style="color: #009900;">&#40;</span>num1<span style="color: #339933;">,</span> num2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> num1 <span style="color: #339933;">+</span> num2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> divide<span style="color: #009900;">&#40;</span>num1<span style="color: #339933;">,</span> num2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> _secretDivide<span style="color: #009900;">&#40;</span>num1<span style="color: #339933;">,</span> num2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">function</span> _secretDivide<span style="color: #009900;">&#40;</span>num1<span style="color: #339933;">,</span> num2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> num1 <span style="color: #339933;">/</span> num2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; add<span style="color: #339933;">:</span> add<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; divide<span style="color: #339933;">:</span> divide<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4>2. Add Helper.test.js</h4>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #006600; font-style: italic;">// create file under directory</span><br />
<span style="color: #006600; font-style: italic;">// ui.apps/src/main/content/jcr_root/apps/sourcedcode/clientlibs/clientlib-site/js/__tests__/Helper.test.js</span><br />
<br />
<br />
require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'../Helpers'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
let Helpers <span style="color: #339933;">=</span> window.<span style="color: #660066;">JestTest</span>.<span style="color: #660066;">Helpers</span><span style="color: #339933;">;</span><br />
<br />
beforeAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Helpers <span style="color: #339933;">=</span> window.<span style="color: #660066;">JestTest</span>.<span style="color: #660066;">Helpers</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
afterAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Helpers <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
it<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'it should calculate additions as expected 1 + 2 = 3'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; expect<span style="color: #009900;">&#40;</span>Helpers.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toEqual</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
it<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'it should calculate additions as expected 0 + 2 = 2'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; expect<span style="color: #009900;">&#40;</span>Helpers.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toEqual</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
it<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'it should calculate divisions as expected 0 / 2 = 0'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; expect<span style="color: #009900;">&#40;</span>Helpers.<span style="color: #660066;">divide</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toEqual</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #5 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="5183553115"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<h4>3. Edit the ui.apps/pom.xml to exclude all directories of __tests__ from being built as apart of the AEM content package (ui.apps)</h4>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// add below configuration under -&gt; ui.apps/pom.xml<br />
<br />
<br />
<span style="color: #808080; font-style: italic;">&lt;!-- out of the box AEM Archetype 20 org.apache.jackrabbit setup --&gt;</span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.jackrabbit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>filevault-package-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extensions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extensions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sourcedcode<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;embeddeds<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;embedded<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sourcedcode<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sourcedcode.core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/apps/sourcedcode/install<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/embedded<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/embeddeds<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;subPackages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;subPackage<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.adobe.cq<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core.wcm.components.all<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/subPackage<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;subPackage<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.adobe.cq<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core.wcm.components.examples<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/subPackage<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/subPackages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- custom excludes XML properties --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;excludes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>**/*test*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exclude<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/excludes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<h4>4. Include the plugin com.github.eirslett, under ui.apps/pom.xml</h4>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// add below configuration under -<span style="color: #000000; font-weight: bold;">&gt;</span> Setup ui.apps/pom.xml<br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span>com.github.eirslett<span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span>frontend-maven-plugin<span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span>$<span style="color: #66cc66;">&#123;</span>frontend-maven-plugin.version<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;skip<span style="color: #000000; font-weight: bold;">&gt;</span></span>$<span style="color: #66cc66;">&#123;</span>skipTests<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&lt;/skip<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span>install node and npm<span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span>validate<span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span>install-node-and-npm<span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;nodeVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span>$<span style="color: #66cc66;">&#123;</span>node.version<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&lt;/nodeVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;npmVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span>$<span style="color: #66cc66;">&#123;</span>npm.version<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&lt;/npmVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span>npm ci<span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span>initialize<span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span>npm<span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;arguments<span style="color: #000000; font-weight: bold;">&gt;</span></span>install<span style="color: #000000; font-weight: bold;">&lt;/arguments<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span>npm run test<span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span>generate-resources<span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span>npm<span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;arguments<span style="color: #000000; font-weight: bold;">&gt;</span></span>run test<span style="color: #000000; font-weight: bold;">&lt;/arguments<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #2 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2263738126"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<h4>5. Include shared maven project properties in parent/pom.xml</h4>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">// add below configuration under -<span style="color: #000000; font-weight: bold;">&gt;</span> parent/pom.xml<br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &lt;!-- out of the box AEM Archetype 20 properties --<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;aem.host<span style="color: #000000; font-weight: bold;">&gt;</span></span>localhost<span style="color: #000000; font-weight: bold;">&lt;/aem.host<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;aem.port<span style="color: #000000; font-weight: bold;">&gt;</span></span>4502<span style="color: #000000; font-weight: bold;">&lt;/aem.port<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;aem.publish.host<span style="color: #000000; font-weight: bold;">&gt;</span></span>localhost<span style="color: #000000; font-weight: bold;">&lt;/aem.publish.host<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;aem.publish.port<span style="color: #000000; font-weight: bold;">&gt;</span></span>4503<span style="color: #000000; font-weight: bold;">&lt;/aem.publish.port<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;sling.user<span style="color: #000000; font-weight: bold;">&gt;</span></span>admin<span style="color: #000000; font-weight: bold;">&lt;/sling.user<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;sling.password<span style="color: #000000; font-weight: bold;">&gt;</span></span>admin<span style="color: #000000; font-weight: bold;">&lt;/sling.password<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;vault.user<span style="color: #000000; font-weight: bold;">&gt;</span></span>admin<span style="color: #000000; font-weight: bold;">&lt;/vault.user<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;vault.password<span style="color: #000000; font-weight: bold;">&gt;</span></span>admin<span style="color: #000000; font-weight: bold;">&lt;/vault.password<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;core.wcm.components.version<span style="color: #000000; font-weight: bold;">&gt;</span></span>2.5.0<span style="color: #000000; font-weight: bold;">&lt;/core.wcm.components.version<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;bnd.version<span style="color: #000000; font-weight: bold;">&gt;</span></span>4.2.0<span style="color: #000000; font-weight: bold;">&lt;/bnd.version<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;project.build.sourceEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span>UTF-8<span style="color: #000000; font-weight: bold;">&lt;/project.build.sourceEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;project.reporting.outputEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span>UTF-8<span style="color: #000000; font-weight: bold;">&lt;/project.reporting.outputEncoding<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
<br />
&nbsp; &nbsp; &lt;!-- custom properties --<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;skipTests<span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #000000; font-weight: bold;">&lt;/skipTests<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;frontend-maven-plugin.version<span style="color: #000000; font-weight: bold;">&gt;</span></span>1.6<span style="color: #000000; font-weight: bold;">&lt;/frontend-maven-plugin.version<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;node.version<span style="color: #000000; font-weight: bold;">&gt;</span></span>v10.15.0<span style="color: #000000; font-weight: bold;">&lt;/node.version<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;npm.version<span style="color: #000000; font-weight: bold;">&gt;</span></span>6.5.0<span style="color: #000000; font-weight: bold;">&lt;/npm.version<span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></div></td></tr></tbody></table></div>
<h4>6. Setup ui.apps/package.json</h4>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #006600; font-style: italic;">// add below configuration under -&gt; ui.apps/package.json</span><br />
<br />
<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;com.sourcedcode&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;version&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1.0.0&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;This is an example of testing AEM component's clientlib (with JavaScript) using NodeJS and maven build&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;scripts&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;test&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;jest --coverage&quot;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;author&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;SourcedCode&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;license&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ISC&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;devDependencies&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;babel-jest&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;^23.6.0&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;babel-preset-env&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;^1.7.0&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;babel-preset-react&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;^6.24.1&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;jest&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;^23.6.0&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;babel-preset-es2015&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;^6.24.1&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;babel-preset-stage-2&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;^6.24.1&quot;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h4>7. Add and Setup file ui.apps/.babelrc</h4>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #006600; font-style: italic;">// create a file names .babelrc</span><br />
<span style="color: #006600; font-style: italic;">// add below configuration under -&gt; ui.apps/.babelrc</span><br />
<br />
<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #3366CC;">&quot;presets&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;babel-preset-es2015&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;babel-preset-stage-2&quot;</span><span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #3 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="3385248102"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large"/>
<h2 id="results">The Results</h2>
<p>On a successfull build, the results will be as shown:<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log.png" alt="" width="700" height="auto" class="alignnone size-medium wp-image-693" srcset="https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log.png 1644w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log-300x94.png 300w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log-768x240.png 768w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log-1024x320.png 1024w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-log-600x188.png 600w" sizes="(max-width: 1644px) 100vw, 1644px" /></a></p>
<p>On a success build, the Jest coverage report will be generated. You can find the generated reports under &#8220;ui.apps/coverage&#8221;. <a href="https://medium.com/@krishankantsinghal/how-to-read-test-coverage-report-generated-using-jest-c2d1cb70da8b" rel="noopener noreferrer" target="_blank">Click here</a> to learn more about the Jest coverage.<br />
<a href="https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report.png"><img decoding="async" src="https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report.png" alt="" width="100%" height="auto" class="alignnone size-medium wp-image-699" srcset="https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report.png 3280w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report-300x94.png 300w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report-768x242.png 768w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report-1024x322.png 1024w, https://sourcedcode.com/wp-content/uploads/2019/10/jest-test-report-600x189.png 600w" sizes="(max-width: 3280px) 100vw, 3280px" /></a></p>
<div id="issues" class="mention-block">
<strong>Known Issues:</strong><br />
Please disregard marked [ERROR] tags, as this is a <a href="https://github.com/eirslett/frontend-maven-plugin/issues/584" target="_blank" rel="noopener noreferrer">known issue #584</a>. When your Javascript unit tests are invalid, the build will not be successful, and the build will not proceed.</p>
<p>To ensure that you do not lose confidence in the Maven Front-end Plugin, here is an example of Adobe using the same library in it&#8217;s production <a href="https://github.com/adobe/aem-core-wcm-components/blob/master/parent/pom.xml" rel="noopener noreferrer" target="_blank">AEM Core Components project</a>.
</div>
<div class="mention-block">
<strong>Last Tips</strong></p>
<ul>
<li>You can run <strong>mvn clean install -DskipTests=true</strong> if you want to build your AEM project without running Java or Javascript tests; this setup enabled to do so.</li>
<li>You can also change directory (CD) into the ui.apps module, and run <strong>npm tests</strong>, to only run the Jest Tests.</li>
</ul>
</div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #6 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2559251592"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest">How to write Javascript Unit Tests for AEM Client Libraries with Jest</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>JUnit 4: AEM WCMUsePojo Unit Test Example (Passing Paramaters)</title>
		<link>https://sourcedcode.com/blog/aem/junit-4-aem-wcmusepojo-unit-test-example-passing-paramaters</link>
					<comments>https://sourcedcode.com/blog/aem/junit-4-aem-wcmusepojo-unit-test-example-passing-paramaters#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 25 Sep 2019 20:35:18 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JUNIT]]></category>
		<category><![CDATA[JUNIT4]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=528</guid>

					<description><![CDATA[<p>This article will demonstrate how to write AEM Unit tests for building WCMUsePojo Java classes using the Junit4 testing framework. With developers being more visual, the source code is posted below. In this example, I am building a Sightly utils class that helps me append .html to page path that are configured by the author. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/junit-4-aem-wcmusepojo-unit-test-example-passing-paramaters">JUnit 4: AEM WCMUsePojo Unit Test Example (Passing Paramaters)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article will demonstrate how to write AEM Unit tests for building WCMUsePojo Java classes using the Junit4 testing framework. With developers being more visual, the source code is posted below.</p>
<p>In this example, I am building a Sightly utils class that helps me append .html to page path that are configured by the author. The utils class can be used by any AEM components during development. A value is passed through a parameter in this demo.</p>
<div class="mention-block">
Technologies here used are:</p>
<ul>
<li>AEM project archetype 19 (<a href="https://github.com/adobe/aem-project-archetype/tree/aem-project-archetype-19" target="_BLANK" rel="noopener noreferrer">link</a>)</li>
</ul>
</div>
<p>This example uses the AEM project archetype 19 to generate a new AEM project, Junit 4 will be used as the testing framework.</p>
<h3 id="sightly-example">Sightly Example Use:</h3>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&lt;!-- somecomponent --&gt;<br />
&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;somecomponent&quot;</span>&gt;<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;${lnk.link}&quot;</span> <span style="color: #000066;">target</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;_blank&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noopener noreferrer&quot;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Click Here<br />
&nbsp; &nbsp; &lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;<br />
&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</div></td></tr></tbody></table></div>
<h3 id="wcmusepojo-example">WCMUsePojo Example Code:</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.wcm.utils</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.adobe.cq.sightly.WCMUsePojo</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.lang3.StringUtils</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LinkChecker <span style="color: #000000; font-weight: bold;">extends</span> WCMUsePojo <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> LINK <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> link<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> activate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; resolveLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; &nbsp;* Resolves the path of a JCR page path with a .html extension<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> resolveLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; link <span style="color: #339933;">=</span> get<span style="color: #009900;">&#40;</span>LINK, <span style="color: #003399;">String</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>StringUtils.<span style="color: #006633;">isNotEmpty</span><span style="color: #009900;">&#40;</span>link<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>link.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; link <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> link<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h3 id="wcmusepojo-unit-test-example">WCMUsePojo Unit Test Example Code:</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.sourcedcode.core.wcm.utils</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.script.Bindings</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> junitx.<span style="color: #006633;">framework</span>.<span style="color: #000000; font-weight: bold;">Assert</span>.<span style="color: #006633;">assertEquals</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">mockito</span>.<span style="color: #006633;">Mockito</span>.<span style="color: #006633;">mock</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> org.<span style="color: #006633;">mockito</span>.<span style="color: #006633;">Mockito</span>.<span style="color: #006633;">when</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LinkCheckerTest <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testLinkValueWithNoHTML<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Bindings bindings <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Bindings.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>bindings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/home&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LinkChecker use <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkChecker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; use.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>bindings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/home.html&quot;</span>, use.<span style="color: #006633;">getLink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; @Test<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testLinkValueWithHTML<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Bindings bindings <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Bindings.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; when<span style="color: #009900;">&#40;</span>bindings.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenReturn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/home.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; LinkChecker use <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkChecker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; use.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>bindings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/content/sourcedcode/home.html&quot;</span>, use.<span style="color: #006633;">getLink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
<strong>Tip:</strong><br />
I hope the example above helps you out with your development of Java Classes that extend the WCMUsePojo Class. Instead of writing a new WCMUsePojo Class, you can utilise magic that sightly 1.4 offers.</p>
<p>Sightly 1.4 offers a quicker way for you to add extensions to a given url, as examples below:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">${'sourcedcode/home' @ extension='html'}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home.html --&gt;</span><br />
<br />
${'sourcedcode/home.json' @ extension='html'}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home.html --&gt;</span><br />
<br />
${'sourcedcode/home.selector.json' @ extension='html'}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home.selector.html --&gt;</span><br />
<br />
${'sourcedcode/home.json/suffix' @ extension='html'}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home.html/suffix --&gt;</span><br />
<br />
${'sourcedcode/home.json?key=value' @ extension='html'}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home.html?key=value --&gt;</span><br />
<br />
${'sourcedcode/home.json#fragment' @ extension='html'}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home.html#fragment --&gt;</span><br />
<br />
${'sourcedcode/home.json' @ extension}<br />
<span style="color: #808080; font-style: italic;">&lt;!-- outputs: sourcedcode/home --&gt;</span><br />
<br />
// documentation<br />
https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md</div></td></tr></tbody></table></div>
</div>
<div class="mention-block">
<strong>Common Questions for Writing Test Code for WCMUsePojo Classes</strong></p>
<ul>
<li>How do I pass a parameter to the WCMUsePojo class in AEM? Call the fully qualified java class name in sightly, and use the @ symbol to pass the parameter. Take a look a the example above <a href="#wcmusepojo-example">example</a></li>
</ul>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/junit-4-aem-wcmusepojo-unit-test-example-passing-paramaters">JUnit 4: AEM WCMUsePojo Unit Test Example (Passing Paramaters)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/junit-4-aem-wcmusepojo-unit-test-example-passing-paramaters/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AEM Project, WCMUsePojo &#8220;aQute.bnd.annotation.ConsumerType not found&#8221; (fix)</title>
		<link>https://sourcedcode.com/blog/aem/aem-project-wcmusepojo-class-error-of-class-file-for-aqute-bnd-annotation-consumertype-not-found</link>
					<comments>https://sourcedcode.com/blog/aem/aem-project-wcmusepojo-class-error-of-class-file-for-aqute-bnd-annotation-consumertype-not-found#respond</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Wed, 25 Sep 2019 19:41:48 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<guid isPermaLink="false">https://sourcedcode.com/?p=509</guid>

					<description><![CDATA[<p>On rare occasions, when developing a Java class that extends WCMUsePojo class, you will get the error of &#8220;class file for aQute.bnd.annotation.ConsumerType not found&#8220;. This problem can be easily solved by adding the dependency to your parent-pom.xml and core-pom.xml as shown below: 123456789101112131415//parent-pom.xml &#60;!-- https://mvnrepository.com/artifact/biz.aQute.bnd/bndlib --&#62; &#60;dependency&#62; &#160; &#160; &#60;groupId&#62;biz.aQute.bnd&#60;/groupId&#62; &#160; &#160; &#60;artifactId&#62;bndlib&#60;/artifactId&#62; &#160; &#160; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-project-wcmusepojo-class-error-of-class-file-for-aqute-bnd-annotation-consumertype-not-found">AEM Project, WCMUsePojo &#8220;aQute.bnd.annotation.ConsumerType not found&#8221; (fix)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>On rare occasions, when developing a Java class that extends WCMUsePojo class, you will get the error of &#8220;<span style="color: #ff0000;">class file for aQute.bnd.annotation.ConsumerType not found</span>&#8220;.</p>
<p><a href="https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error.png"><img loading="lazy" decoding="async" class="alignnone size-large wp-image-516" src="https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error-1024x300.png" alt="" width="640" height="188" srcset="https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error-1024x300.png 1024w, https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error-300x88.png 300w, https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error-768x225.png 768w, https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error-600x176.png 600w, https://sourcedcode.com/wp-content/uploads/2019/09/aQute.bnd_.annotation.ConsumerType-error.png 1692w" sizes="(max-width: 640px) 100vw, 640px" /></a></p>
<p>This problem can be easily solved by adding the dependency to your parent-pom.xml and core-pom.xml as shown below:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #666666; font-style: italic;">//parent-pom.xml</span><br />
<span style="color: #339933;">&lt;!--</span> https<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//mvnrepository.com/artifact/biz.aQute.bnd/bndlib --&gt;</span><br />
<span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>bndlib<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span>2.4.0<span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>scope<span style="color: #339933;">&gt;</span>provided<span style="color: #339933;">&lt;/</span>scope<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">//core-pom.xml</span><br />
<span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>biz.<span style="color: #006633;">aQute</span>.<span style="color: #006633;">bnd</span><span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>bndlib<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
<b>Summary:</b></p>
<p>The latest AEM maven archetype-20 comes pre-configured with this dependency.</p>
<p>During the time of development, an AEM engineer may have removed this maven dependency. <a href="https://github.com/adobe/aem-project-archetype/tree/aem-project-archetype-20" target="_blank" rel="noopener noreferrer">https://github.com/adobe/aem-project-archetype/tree/aem-project-archetype-20</a>
</div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-project-wcmusepojo-class-error-of-class-file-for-aqute-bnd-annotation-consumertype-not-found">AEM Project, WCMUsePojo &#8220;aQute.bnd.annotation.ConsumerType not found&#8221; (fix)</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-project-wcmusepojo-class-error-of-class-file-for-aqute-bnd-annotation-consumertype-not-found/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to use AEM JCR SQL2 query strings to query for nodes in Java Content Repository</title>
		<link>https://sourcedcode.com/blog/aem/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet</link>
					<comments>https://sourcedcode.com/blog/aem/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Mon, 02 Apr 2018 19:31:06 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quick Reference]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[Sling Servlet]]></category>
		<category><![CDATA[Video Tutorial]]></category>
		<guid isPermaLink="false">http://sourcedcode.com/?p=82</guid>

					<description><![CDATA[<p>JCR-SQL2 (Java Content Repository &#8211; Structured Query Language 2) is domain specific language used to query JCR nodes held in the JCR repository. The syntax for JCR-SQL2 is fairly similar to SQL, so if you have some experience with SQL, this tutorial will be a walk in the park for you. The best way to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet">How to use AEM JCR SQL2 query strings to query for nodes in Java Content Repository</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>JCR-SQL2 (Java Content Repository &#8211; Structured Query Language 2) is domain specific language used to query JCR nodes held in the JCR repository. The syntax for JCR-SQL2 is fairly similar to SQL, so if you have some experience with SQL, this tutorial will be a walk in the park for you.</p>
<p>The best way to learn the power of the JCR-SQL2 language is to try it out on CRX/DE Lite. Without future or do, below will be a lesson on JCR-SQL2. To locate CRX/DE Lite&#8217;s query tool, visit <a href="http://localhost:4502/crx/de/index.jsp" rel="noopener noreferrer" target="_blank">http://localhost:4502/crx/de/index.jsp</a>, then select on the tools drop down, and choose query.</p>
<div class="mention-block--gold">
<h3>2023 Added Section: SQL-JCR2 Snippets</h3>
<p>Examples can be found at the bottom of this tutorial, <a href="#jcr-sql2-code-snippets-cheat-sheet">JCR-SQL2 Code Snippets Cheat Sheet</a>, where you can find some examples for real life use cases. Head into your <a href="http://localhost:4502/crx/de/index.jsp" rel="noopener" target="_blank">crx-de > tools > query > type:JCR SQL2</a>, and try it our yourself.
</div>
<p><img loading="lazy" decoding="async" src="http://sourcedcode.com/wp-content/uploads/2018/04/tools-query-tool-1024x662.png" alt="" width="1024" height="662" class="alignnone size-large wp-image-167" srcset="https://sourcedcode.com/wp-content/uploads/2018/04/tools-query-tool-1024x662.png 1024w, https://sourcedcode.com/wp-content/uploads/2018/04/tools-query-tool-300x194.png 300w, https://sourcedcode.com/wp-content/uploads/2018/04/tools-query-tool-768x496.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<hr />
<h2>JCR-SQL2 Syntax</h2>
<ol>
<li><a href="#select-statement">SELECT Statement</a></li>
<li><a href="#name-statement">NAME() Statement</a></li>
<li><a href="#isdescendantnode-statement">ISDESCENDANTNODE Statement</a></li>
<li><a href="#contains-operator">CONTAINS Statement</a></li>
<li><a href="#like-operator">LIKE Operator</a></li>
<li><a href="#is-not-null">IS NOT NULL Property</a></li>
<li><a href="#order-by-keyword">ORDER BY Keyword</a></li>
<li><a href="#cast-statement">CAST() Statement</a></li>
<li><a href="#jcr-sql2-code-snippets-cheat-sheet">JCR-SQL2 Code Snippets Cheat Sheet</a> (new 2023)</li>
<li><a href="#jcr-sql2-java-code-example-servlet">JCR SQL2 Java Code Example Servlet</a> (new 2023)</li>
</ol>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/0sMMzJs1dpc" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<hr class="spacer-large" />
<h4 id="select-statement">1. The JCR-SQL2 SELECT Statement</h4>
<ul>
<li>The SELECT statement is used to select all JCR nodes that matches the JCR node&#8217;s primary type.</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- nt:base is a primary type that represents every single node in the JCR.</span><br />
<span style="color: #808080; font-style: italic;">-- returns all nodes in the JCR.</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:base<span style="color: #FF00FF;">&#93;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:Page] nodes</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [dam:Asset] nodes</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>dam:Asset<span style="color: #FF00FF;">&#93;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large" />
<h4 id="name-statement">2. The JCR-SQL2 NAME() Statement</h4>
<ul>
<li>Selecting nodes with a specific node name.</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all [cq:Page] nodes WHERE the node's name is equal to &quot;we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> NAME<span style="color: #FF00FF;">&#40;</span>nodes<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;we-retail&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [dam:Asset] nodes WHERE the node's name is equal to &quot;we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>dam:Asset<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> NAME<span style="color: #FF00FF;">&#40;</span>nodes<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;we-retail&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h4 id="isdescendantnode-statement">3. The JCR-SQL2 ISDESCENDANTNODE Statement</h4>
<ul>
<li>Selecting nodes under a file path.</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all nodes WHERE nodes exist under &quot;/content/we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:base<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:Page] nodes WHERE nodes exist under &quot;/content/we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [dam:Asset] nodes WHERE nodes exist under &quot;/content/dam/we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>dam:Asset<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>dam<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [nt:unstructured] nodes WHERE nodes exist under &quot;/content/we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:unstructured<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h4 id="contains-statement">4. The JCR-SQL2 CONTAINS Statement</h4>
<ul>
<li>Selecting nodes where the properties contain a value.</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all nodes WHERE node's property jcr:title CONTAINS &quot;we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:base<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #00CC00;">CONTAINS</span><span style="color: #FF00FF;">&#40;</span>nodes.title<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:Page] nodes where node's property jcr:title CONTAINS &quot;we-retail&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #00CC00;">CONTAINS</span><span style="color: #FF00FF;">&#40;</span>nodes.title<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #2 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2263738126"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large" />
<h4 id="like-operator">5. The JCR-SQL2 LIKE Operator</h4>
<ul>
<li>The LIKE operator is used to search for a specified pattern in node properties.</li>
<li>There are two wildcards used in conjunction with the LIKE operator: % and _</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under &quot;/content&quot; </span><br />
<span style="color: #808080; font-style: italic;">-- AND node's property jcr:title starts with any values and ends with &quot;w&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">&quot;<span style="color: #008080; font-weight: bold;">%</span>w&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under &quot;/content&quot; </span><br />
<span style="color: #808080; font-style: italic;">-- AND node's property jcr:title starts with &quot;w&quot; and ends with any values</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">&quot;w<span style="color: #008080; font-weight: bold;">%</span>&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under &quot;/contentl&quot; </span><br />
<span style="color: #808080; font-style: italic;">-- AND node's property jcr:title matching &quot;w&quot; in any position</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">&quot;<span style="color: #008080; font-weight: bold;">%</span>w<span style="color: #008080; font-weight: bold;">%</span>&quot;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under &quot;/content&quot; </span><br />
<span style="color: #808080; font-style: italic;">-- AND node's property jcr:title start with any values and have &quot;w&quot; in the second position and ends with any values</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">&quot;<span style="color: #008080; font-weight: bold;">_</span>w<span style="color: #008080; font-weight: bold;">%</span>&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h4 id="is-not-null">6. The JCR-SQL2 IS NOT NULL Property</h4>
<ul>
<li>Used for validation of property&#8217;s value is not null.</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all nodes WHERE nodes exist under &quot;/content&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- AND node's property jcr:title IS NOT NULL</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:base<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099; font-weight: bold;">IS NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under &quot;/content&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- AND node's property jcr:title IS NOT NULL</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099; font-weight: bold;">IS NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #3 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="3385248102"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<hr class="spacer-large" />
<h4 id="order-by-keyword">7. The JCR-SQL2 ORDER BY Keyword</h4>
<ul>
<li>The ORDER BY keyword is used to sort the result-set in ascending or descending order.</li>
<li>Returned values are sorted by default in ascending order.</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all nodes WHERE nodes exist under the &quot;/content/we-retail&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- ORDER BY jcr:created ascending</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:base<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span> <br />
<span style="color: #990099; font-weight: bold;">ORDER BY</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:created<span style="color: #FF00FF;">&#93;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all nodes WHERE nodes exist under the &quot;/content/we-retail&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- ORDER BY node's property jcr:created descending</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:base<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">ORDER BY</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:created<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">DESC</span></div></td></tr></tbody></table></div>
<hr class="spacer-large" />
<h4 id="cast-statement">8. The JCR-SQL2 CAST() Statement</h4>
<ul>
<li>Convert an expression from one data type to another.</li>
<li>Cast Types:
<ul>
<li>STRING</li>
<li>BINARY</li>
<li>DATE</li>
<li>LONG</li>
<li>DOUBLE</li>
<li>DECIMAL</li>
<li>BOOLEAN</li>
<li>NAME</li>
<li>PATH</li>
<li>REFERENCE</li>
<li>WEAKREFERENCE</li>
<li>URI</li>
</ul>
</li>
<li><b>Returns in CRX/DE Lite</b>: A list of JCR nodes in the results table with their corresponding paths.</li>
<li><b>Returns in OSGI Bundle (Sling API)</b>: All the found nodes stored in the Iterator&lt;Resource&gt; object.</li>
<li><b>Returns in OSGI Bundle (JCR API)</b>: The QueryResult object where you can call getNodes() method to get the NodeIterator object.</li>
</ul>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under the &quot;/content/we-retail&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- AND node's navRoot equals to &quot;true&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">as</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span> <br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>navRoot<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> CAST<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">&quot;true&quot;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #999900; font-weight: bold;">BOOLEAN</span><span style="color: #FF00FF;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under the &quot;/content/we-retail&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- AND node's creation date is greater than &quot;April 1st, 2018&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span> <br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>jcr:created<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">&gt;</span> CAST<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">&quot;2018-04-01T00:00:00.000Z&quot;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #999900; font-weight: bold;">DATE</span><span style="color: #FF00FF;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- returns all [cq:PageContent] nodes WHERE nodes exist under the &quot;/content/we-retail&quot;</span><br />
<span style="color: #808080; font-style: italic;">-- AND node's maxRating is less than &quot;5.0&quot;</span><br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">as</span> nodes <span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span><span style="color: #CC0099;">/</span>content<span style="color: #CC0099;">/</span>we<span style="color: #CC0099;">-</span>retail<span style="color: #FF00FF;">&#93;</span><span style="color: #FF00FF;">&#41;</span> <br />
<span style="color: #CC0099; font-weight: bold;">AND</span> nodes.<span style="color: #FF00FF;">&#91;</span>maxRating<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">&lt;</span> CAST<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">&quot;5.0&quot;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #999900; font-weight: bold;">DECIMAL</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<div class="mention-block">
<h3>Final Notes: When is the perfect time to use JCR-SQL2?</h3>
<ol>
<li>Build a images and documents search component, if your AEM site that allows consumers to search for images or documents.</li>
<li>Build a blog post search component, If your AEM site has a blog section.</li>
<li>Build a secure resources query API, If you are allowing 3rd party applications to query and find nodes in your AEM site.</li>
</ol>
<p>There&#8217;s many other things to utilize JCR-SQL2 to query nodes, but those are just some quick examples.</p>
</div>
<hr class="spacer-larger" />
<h4 id="jcr-sql2-code-snippets-cheat-sheet">9. JCR-SQL2 Code Snippets Cheat Sheet</h4>
<p>Use these code snippets below to rapidly build your AEM JCR SQL2 search queries, I will try my best to give you some really great examples:</p>
<h5>a. Find all [nt:unstructured] nodes, under the path &#8220;/content/we-retail&#8221;, where the node name = &#8220;root&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:unstructured<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> NAME<span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;root&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>b. Find all components ([nt:unstructured] nodes), under the path &#8220;/content/we-retail&#8221;, where component resourceType = &#8220;weretail/components/content/image&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:unstructured<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#91;</span>sling:resourceType<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;weretail/components/content/image&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>b. Find all components ([nt:unstructured] nodes), under the path &#8220;/content/we-retail&#8221;, where component resourceType = &#8220;weretail/components/content/image&#8221; AND the fileReference property contains with &#8220;/content/dam/we-retail/en/experiences&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:unstructured<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#91;</span>sling:resourceType<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;weretail/components/content/image&quot;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #00CC00;">CONTAINS</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span>fileReference<span style="color: #FF00FF;">&#93;</span><span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/dam/we-retail/en/experiences&quot;</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>c. Find all [nt:unstructured] nodes, under the path &#8220;/content/we-retail&#8221;,  where the property(&#8220;jcr:title&#8221;) contains &#8220;Featured products&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>nt:unstructured<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #00CC00;">CONTAINS</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#91;</span>jcr:title<span style="color: #FF00FF;">&#93;</span><span style="color: #000033;">,</span> <span style="color: #008000;">&quot;Featured products&quot;</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>d. Find all pages (cq:Page nodes), under the path &#8220;/content/we-retail&#8221;,  where the cq:lastModified date is before or equals to &#8220;January 1st, 2000&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> page.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> page<br />
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> jcrContentNode <span style="color: #990099; font-weight: bold;">ON</span> ISCHILDNODE<span style="color: #FF00FF;">&#40;</span>jcrContentNode<span style="color: #000033;">,</span> page<span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>page<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> jcrContentNode.<span style="color: #FF00FF;">&#91;</span>cq:lastModified<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">&lt;=</span> CAST<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">&quot;2023-01-01T00:00:00.000+00:00&quot;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #999900; font-weight: bold;">DATE</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>e. Find all pages (cq:Page nodes), under the path &#8220;/content/we-retail&#8221;,  where the jcr:created date is before to &#8220;July 1st, 2022&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> page.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> page<br />
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> jcrContentNode <span style="color: #990099; font-weight: bold;">ON</span> ISCHILDNODE<span style="color: #FF00FF;">&#40;</span>jcrContentNode<span style="color: #000033;">,</span> page<span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>page<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> jcrContentNode.<span style="color: #FF00FF;">&#91;</span>jcr:created<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">&lt;</span> CAST<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">&quot;2022-07-01T00:00:00.000+00:00&quot;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #999900; font-weight: bold;">DATE</span><span style="color: #FF00FF;">&#41;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>f. Find all [cq:PageContent] nodes, under the path &#8220;/content/we-retail&#8221;,  where the cq:template equals to &#8220;/conf/we-retail/settings/wcm/templates/hero-page&#8221;</h5>
<p>This AEM JCR SQ2 Query is an example for how to find all nodes with a specific template, results returned as cq:PageContent node.</p>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#91;</span>cq:template<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;/conf/we-retail/settings/wcm/templates/hero-page&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>g. Find all pages (cq:Page nodes), under the path &#8220;/content/we-retail&#8221;,  where the cq:template equals to &#8220;/conf/we-retail/settings/wcm/templates/hero-page&#8221;</h5>
<p>This AEM JCR SQ2 Query is an example for how to find all nodes with a specific template, results returned as cq:Page node.</p>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #990099; font-weight: bold;">SELECT</span> page.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:Page<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> page<br />
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> jcrContentNode <span style="color: #990099; font-weight: bold;">ON</span> ISCHILDNODE<span style="color: #FF00FF;">&#40;</span>jcrContentNode<span style="color: #000033;">,</span> page<span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>page<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> jcrContentNode.<span style="color: #FF00FF;">&#91;</span>cq:template<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;/conf/we-retail/settings/wcm/templates/hero-page&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>h. Find all [cq:PageContent] nodes, under the path &#8220;/content/we-retail&#8221;,  where the cq:tags[] contains &#8220;we-retail:gender/men&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">This AEM JCR SQ2 Query <span style="color: #CC0099; font-weight: bold;">is</span> an example for how <span style="color: #990099; font-weight: bold;">to</span> find <span style="color: #990099; font-weight: bold;">all</span> nodes <span style="color: #990099; font-weight: bold;">with</span> a single cq:tags<span style="color: #FF00FF;">&#91;</span><span style="color: #FF00FF;">&#93;</span><span style="color: #000033;">,</span> results returned <span style="color: #990099; font-weight: bold;">as</span> cq:PageContent node.<br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#91;</span>cq:tags<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;we-retail:gender/men&quot;</span></div></td></tr></tbody></table></div>
<hr class="spacer-medium"/>
<h5>i. Find all [cq:PageContent] nodes, under the path &#8220;/content/we-retail&#8221;,  where the cq:tags[] contains &#8220;we-retail:gender/men&#8221; AND cq:tags[] contains &#8220;we-retail:activity/surfing&#8221;</h5>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">This AEM JCR SQ2 Query <span style="color: #CC0099; font-weight: bold;">is</span> an example for how <span style="color: #990099; font-weight: bold;">to</span> find <span style="color: #990099; font-weight: bold;">all</span> nodes <span style="color: #990099; font-weight: bold;">with</span> multiple cq:tags<span style="color: #FF00FF;">&#91;</span><span style="color: #FF00FF;">&#93;</span><span style="color: #000033;">,</span> results returned <span style="color: #990099; font-weight: bold;">as</span> cq:PageContent node.<br />
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #FF00FF;">&#91;</span>cq:PageContent<span style="color: #FF00FF;">&#93;</span> <span style="color: #990099; font-weight: bold;">AS</span> node<br />
<span style="color: #990099; font-weight: bold;">WHERE</span> ISDESCENDANTNODE<span style="color: #FF00FF;">&#40;</span>node<span style="color: #000033;">,</span> <span style="color: #008000;">&quot;/content/we-retail&quot;</span><span style="color: #FF00FF;">&#41;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#91;</span>cq:tags<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;we-retail:gender/men&quot;</span><br />
<span style="color: #CC0099; font-weight: bold;">AND</span> <span style="color: #FF00FF;">&#91;</span>cq:tags<span style="color: #FF00FF;">&#93;</span> <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;we-retail:activity/surfing&quot;</span></div></td></tr></tbody></table></div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #4 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2079905296"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #5 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="5183553115"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<style>
h5 {
    font-size: 16px;
    font-weight: 100;
}
</style>
<hr class="spacer-larger" />
<h4 id="jcr-sql2-java-code-example-servlet">9. JCR-SQL2 Java Code Example Servlet (2023)</h4>
<p>This is an example of how an AEM servlet would actually utilize the JCR-SQL2 Query with the examples above. It will output a JSON array of the page paths.</p>
<div class="code-1200">
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Node</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.NodeIterator</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.RepositoryException</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.Session</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.Query</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryManager</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.jcr.query.QueryResult</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletRequest</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.SlingHttpServletResponse</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.sling.api.servlets.SlingSafeMethodsServlet</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.service.component.annotations.Component</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gson.JsonArray</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gson.JsonObject</span><span style="color: #339933;">;</span><br />
<br />
@<span style="color: #003399;">Component</span><span style="color: #009900;">&#40;</span>service <span style="color: #339933;">=</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span>.<span style="color: #000000; font-weight: bold;">class</span>, property <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;sling.servlet.paths=/bin/getpagedbypath&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GetPagedByPathServlet <span style="color: #000000; font-weight: bold;">extends</span> SlingSafeMethodsServlet <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>SlingHttpServletRequest request, SlingHttpServletResponse response<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the JCR session</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Session session <span style="color: #339933;">=</span> request.<span style="color: #006633;">getResourceResolver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">adaptTo</span><span style="color: #009900;">&#40;</span>Session.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Query statement</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> queryString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT page.* FROM [cq:Page] AS page &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;INNER JOIN [cq:PageContent] AS jcrContentNode ON ISCHILDNODE(jcrContentNode, page) &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;WHERE ISDESCENDANTNODE(page, '/content/we-retail') &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;AND jcrContentNode.[cq:lastModified] &lt;= CAST('2023-01-01T00:00:00.000+00:00' AS DATE)&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the query object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryManager queryManager <span style="color: #339933;">=</span> session.<span style="color: #006633;">getWorkspace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQueryManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Query query <span style="color: #339933;">=</span> queryManager.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>queryString, Query.<span style="color: #006633;">JCR_SQL2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Execute the query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QueryResult result <span style="color: #339933;">=</span> query.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the nodes from the query result</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NodeIterator nodeIterator <span style="color: #339933;">=</span> result.<span style="color: #006633;">getNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Collect the paths of the first ten pages in a list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> pagePaths <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>nodeIterator.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node pageNode <span style="color: #339933;">=</span> nodeIterator.<span style="color: #006633;">nextNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> pagePath <span style="color: #339933;">=</span> pageNode.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pagePaths.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>pagePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create a JSON object to hold the results</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JsonObject jsonResponse <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JsonArray resultsArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add the paths to the JSON array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> path <span style="color: #339933;">:</span> pagePaths<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultsArray.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add the JSON array to the response object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jsonResponse.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;results&quot;</span>, resultsArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the response content type</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Write the JSON response to the output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">PrintWriter</span> writer <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>jsonResponse.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>RepositoryException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Handle exception</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span>SlingHttpServletResponse.<span style="color: #006633;">SC_INTERNAL_SERVER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error executing query: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</div>
<p><strong>JSON response</strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">&quot;results&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page1&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page2&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page3&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page4&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page5&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page6&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page7&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page8&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page9&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/content/we-retail/page10&quot;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Curl call</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">curl -X GET http://localhost:4502/bin/getpagedbypath</div></td></tr></tbody></table></div>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/aem/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet">How to use AEM JCR SQL2 query strings to query for nodes in Java Content Repository</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/aem/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet/feed</wfw:commentRss>
			<slash:comments>26</slash:comments>
		
		
			</item>
		<item>
		<title>How to make a simple HTTP POST request to AEM with a HTTP Rest Client, Postman</title>
		<link>https://sourcedcode.com/blog/video-tutorial/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client</link>
					<comments>https://sourcedcode.com/blog/video-tutorial/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client#comments</comments>
		
		<dc:creator><![CDATA[briankasingli]]></dc:creator>
		<pubDate>Sat, 31 Mar 2018 14:27:04 +0000</pubDate>
				<category><![CDATA[AEM]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Video Tutorial]]></category>
		<guid isPermaLink="false">http://sourcedcode.com/?p=6</guid>

					<description><![CDATA[<p>This method should be used for DEVELOPMENT PURPOSES ONLY! During development in the AEM author instance, you would like to test your servlet using an HTTP Rest Client such as Postman. When making a POST request on the Rest Client, you will experience 2 errors. An authentication error, and a 403 forbidden error. What&#8217;s Happening? [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/video-tutorial/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client">How to make a simple HTTP POST request to AEM with a HTTP Rest Client, Postman</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="mention-block">This method should be used for DEVELOPMENT PURPOSES ONLY!</div>
<p><strong>During development</strong> in the AEM author instance, you would like to test your servlet using an HTTP Rest Client such as Postman. When making a POST request on the Rest Client, you will experience 2 errors. An authentication error, and a 403 forbidden error.</p>
<hr class="spacer-large" />
<h2>What&#8217;s Happening?</h2>
<p>Firstly, a typical development approach, you will be working on your author developers instance. Your Rest Client is making a POST request on the author instance, http://localhost:4502. You will get an authentication error.</p>
<p>Secondly, your POST request is being filtered and restricted by the &#8220;Apache Sling Referrer Filter&#8221; and &#8220;Adobe Granite CSRF Filter&#8221;. By default, the Apache Sling Referrer Filter blocks any incoming POST requests, and the Adobe Granite CSRF Filter blocks any incoming POST requests without the CSRF-Token token in the header.</p>
<hr class="spacer-large" />
<h2>How to solve this?</h2>
<p>We can solve this issue by including basic auth type in Postman, then allowing incoming POST request in the Apache Sling Referrer Filter OSGI configurations, and remove the requirement of the CSRF-Token in the Adobe Granite CSRF Filter OSGI configurations.</p>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/9uHMXY_QWog" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe><br />
Resource &#8211; Simple Servlet &#8211; <a href="https://gist.github.com/sourcedcode/bd1a2c150fabfc4b37857be0f389ac8a#file-simplepostservlet-java" rel="noopener noreferrer" target="_blank">https://gist.github.com/sourcedcode/bd1a2c150fabfc4b37857be0f389ac8a#file-simplepostservlet-java</a></p>
<hr class="spacer-large" />
<h3>Step 1 : Configure Basic Auth in Postman</h3>
<p>Launch Postman, then navigate to the Authentication tab. Ensure type is set to &#8220;Basic Auth&#8221;, and username and password are set to &#8220;admin&#8221;; this is the default username and password for the administrator user while developing on the author instance.</p>
<p><img loading="lazy" decoding="async" src="http://sourcedcode.com/wp-content/uploads/2018/03/post-man-basic-auth-1024x767.png" alt="" width="1024" height="767" class="alignnone size-large wp-image-40" srcset="https://sourcedcode.com/wp-content/uploads/2018/03/post-man-basic-auth-1024x767.png 1024w, https://sourcedcode.com/wp-content/uploads/2018/03/post-man-basic-auth-300x225.png 300w, https://sourcedcode.com/wp-content/uploads/2018/03/post-man-basic-auth-768x575.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<hr class="spacer-large" />
<h3>Step 2 : Configure Apache Sling Referrer Filter</h3>
<ol>
<li>Enable allow empty</li>
<li>Remove the POST method from filters</li>
</ol>
<p>In OSGI configurations (<a href="http://localhost:4502/system/console/configMgr" target="_blank" rel="noopener noreferrer">http://localhost:4502/system/console/configMgr</a>), locate &#8220;Apache Sling Referrer Filter&#8221;. Enable the allow empty property, and remove the post method from filters property.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-large wp-image-12" src="http://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-before-1024x801.png" alt="" width="1024" height="801" srcset="https://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-before-1024x801.png 1024w, https://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-before-300x235.png 300w, https://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-before-768x600.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="8658919803"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><img loading="lazy" decoding="async" class="alignnone size-large wp-image-11" src="http://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-after-1024x801.png" alt="" width="1024" height="801" srcset="https://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-after-1024x801.png 1024w, https://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-after-300x235.png 300w, https://sourcedcode.com/wp-content/uploads/2018/03/apache-sling-referrer-filter-after-768x600.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<hr class="spacer-large" />
<h3>Step 3 : Configure Adobe Granite CSRF Filter</h3>
<ol>
<li>Remove the POST method from filters</li>
</ol>
<p>In OSGI configurations (<a href="http://localhost:4502/system/console/configMgr" target="_blank" rel="noopener noreferrer">http://localhost:4502/system/console/configMgr</a>), locate &#8220;Adobe Granite CSRF Filter&#8221;. Remove the post method from filters property.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-large wp-image-18" src="http://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-before-1024x844.png" alt="" width="1024" height="844" srcset="https://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-before-1024x844.png 1024w, https://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-before-300x247.png 300w, https://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-before-768x633.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #2 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="2263738126"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><img loading="lazy" decoding="async" class="alignnone size-large wp-image-17" src="http://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-after-1024x844.png" alt="" width="1024" height="844" srcset="https://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-after-1024x844.png 1024w, https://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-after-300x247.png 300w, https://sourcedcode.com/wp-content/uploads/2018/03/adobe-granite-csrf-filter-after-768x633.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<hr class="spacer-large" />
<div class="mention-block">
<h4>Final Notes</h4>
<p>After making configurations to the two OSGI configurations, you should be able to make a POST request from your HTTP REST Client to your AEM instance.</p>
<p>For production, set Apache Sling Referrer Filter and Adobe Granite CSRF Filter settings back to default. Unless if you are giving access to other servers to make POST requests to your AEM application.</p>
<p><a href="http://sourcedcode.com/in-aem-what-is-the-apache-sling-referrer-filter-osgi-configuration/" rel="noopener noreferrer" target="_self">Read more about Apache Sling Referrer Filter.</a>
</div>
<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Horizontal Preview Ad #3 --><br />
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9053803095882933"
     data-ad-slot="3385248102"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins><br />
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>The post <a rel="nofollow" href="https://sourcedcode.com/blog/video-tutorial/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client">How to make a simple HTTP POST request to AEM with a HTTP Rest Client, Postman</a> appeared first on <a rel="nofollow" href="https://sourcedcode.com">Sourced Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sourcedcode.com/blog/video-tutorial/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
