Content Compare and Import Tool For Adobe CQ

Content Compare and Import Tool

If you want to compare and import content differences from one CQ instance to another CQ instance. Find the below URL for more details and tool .






reCaptcha / Captcha Integration with Adobe CQ5/AEM6.0

Before going to start you should register with reCAPTCHA to get a public and private key to use in the code.

Loading widget

create a CQ component Ex : captchintegration
Add below code to your component JSP

<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@ page import="net.tanesha.recaptcha.*" %>

<%
  //Getting remote ip addres to validate catpcha 
  String ipAddress = request.getHeader("X-FORWARDED-FOR");  
  if (ipAddress == null) {  
ipAddress = request.getRemoteAddr();  
   } 

 %>
    <input type="hidden" value="<%=ipAddress%>" id="remoteIPAdderess" >
    <input type="hidden" value="<%=currentNode.getPath()%>" id="curNodePath" >
    <% ReCaptcha reCaptcha = ReCaptchaFactory.newReCaptcha("<Public Key>", "<Private Key>", false); %>
    
    <h1 id="page-title" class="title">Google Captch Integration in CQ</h1>
    <form accept-charset="UTF-8" id="testCaptcha" method="post" action="" class="contact-press-form ajax-form">
        <div id="gooleCaptcha">
            <input type="hidden" value="form-U5ArplaaF5MKYCMnyZkQDZfvXEy7bO7JLc5e6VCKses"  name="form_build_id"> 
            <input type="hidden" value="apollocontactpress_contact_form" name="form_id">
    
            <fieldset class="captcha form-wrapper">
                <legend>
                    <span class="fieldset-legend">CAPTCHA</span>
                </legend>
                <div class="fieldset-wrapper form-item form-item-captcha">
                    <%=reCaptcha.createRecaptchaHtml(null, "clean", null) %>
                    <div class="error-message"></div>
                </div>
            </fieldset>
            <input type="button" id="test" class='testCaptcha' value="test">
        </div>
    </form>

<script>

$(function() { 
  
  $('#gooleCaptcha').on('click','.testCaptcha',function(){
      alert("redy captch integration");
      var cpatchaFlag = false;
        var remoteIP=$('#remoteIPAdderess').val();
        var currentNodePath = $("#curNodePath").val();        
        var captchaField = $('#recaptcha_response_field');
        var capResponse=$('#recaptcha_response_field').val();
        var capChallange=$('#recaptcha_challenge_field').val();                 
        var captchValUrl=currentNodePath+'.validatecaptcha.html';
        if($.trim(capResponse).length === 0){
alert("response is empty");
}else{  
            var isValidCaptcha="";
            $.ajax({                          
                url: captchValUrl,
                async: false,
                data: {'remoteAddr':remoteIP,'recaptcha_response_field' : capResponse,'recaptcha_challenge_field':capChallange},
                success: function (response, status, xml) {
                    isValidCaptcha=response;
                }
            });
            
            if($.trim(isValidCaptcha) === 'true'){ 
                alert("valid captcha");
                $('#recaptcha_response_field').css({border : '1px solid black !important'});
            }else{
                alert("invalid captcha");
                $('#recaptcha_response_field').css({border : '1px solid red !important'});
            }
            
        }
  });  
});
    </script>


Validate Captcha 

To validate Captcha create validatecaptcha.jsp under you component. 
Add below code to newly created JSP

<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@ page import="net.tanesha.recaptcha.*" %>
<%
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey("<Private Key>");
String remoteAddr =  request.getParameter("remoteAddr");
String challenge = request.getParameter("recaptcha_challenge_field");
String uresponse = request.getParameter("recaptcha_response_field");
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);
if (reCaptchaResponse.isValid()) {
  out.print("true");
  log.info("valid capticha");
} else {
  out.print("false");
  log.info("invalid capticha");
}
%>

Maven dependency 

I have use the below maven dependency and exported in CORE bundle

     <dependency>
  <groupId>net.tanesha.recaptcha4j</groupId>
  <artifactId>recaptcha4j</artifactId>
  <version>0.0.7</version>
    </dependency>

Note : Replace your public key and private key

How to include clientlibs in you component using Sightly AEM/Adobe CQ/AEM6

How to use client libs in Sightly

First you should declare data-sly-use.clientlibInclude in your .html file

<div data-sly-use.clientlibInclude="${'/libs/granite/sightly/templates/clientlib.html'}"></div>

how to  include only CSS of clientlib 

<output data-sly-call="${clientlibInclude.css @ categories='clientlib1,clientlib2'}" data-sly-unwrap/>

how to  include only JS of clientlib 

<output data-sly-call="${clientlibInclude.js @ categories='clientlib1,clientlib2'}" data-sly-unwrap />

how to  include both CSS and JS of clientlib 

<output data-sly-call="${clientlibInclude.all @ categories='clientlib1,clientlib2'}" data-sly-unwrap />


Component not showing in Touch UI / SideKick of Classical UI in AEM / Adobe CQ5 / AEM6

To see component in the Touch UI

If you want to see the component in touch UI components list. The component Should have cq:editConfig node

To See Component in the SideKick in Classic UI

  • The component should have dailog.
  • if component have dialog and not showing in sidekick. Check title of Component it should starts with capital letter.






JCR-SQL2 Queries For AEM / Adobe CQ Developer

Click below link for the more Details

JCR-SQL Sample Queries

How to Install/Add Bundles, Content Packages or Configurations at Runtime CRX in AEM/Adobe CQ5

Install Bundles, Content Packages or Configurations at Runtime 

If you want to install additional packages into the CRX , Create install folder under the crx-quickstart.
Put your bundles, content packages or configurations in install folder. It will pick up while instance start and install into the CRX repository. Packages will install into CRX in the alphabetic order.

References :
AEM Documentation
Adobe Community

You can define additional bundles based on run modes

for this you need to create install.<run mode> folder.

for more information click here

AEM6 /Adobe CQ5 How to Add and Read Bundle / Service Configurations(String, Dropdown, Array/Multifield )

Adding Properties to the Bundle/ OSGI CQ Service

String / TextField

@Property(value = "GET")
static final String STRING_VAL = "string.textfield";

String Array / Multifield 

@Property ( unbounded=PropertyUnbounded.ARRAY, value={"*"},label="Template paths",description="eg: /apps/devtools/templates/page-home" )
private static final String MUTIFIELD_EX = "multifield.test";

Boolean Field

@Property(boolValue={false}, label="Boolean values", description="Booealn test")
private static final String BOOLEN_TEST = "boolean_test";

 Dropdown

@Property( options={
@PropertyOption(name="blue", value="color-blue"),
@PropertyOption(name="green", value="color-green"), 
@PropertyOption(name="red", value="color-red"), 
@PropertyOption(name="yellow", value="color-yellow"), 
private static final String SELECTION_TEST = "dropdown.test";

Reading Properties of Bundle/ OSGI CQ Service


1) You to get the ConfigurationAdmin  reference

@Reference
    ConfigurationAdmin configAdmin;

2) Get Bundle Configuratinn
            Configuration config = configAdmin.getConfiguration(this.getClass().getCanonicalName());

3) Get properties of conguration
   Dictionary<?, ?> configProperties = config.getProperties();

4) Red Properties
           

Reading String/TextField

          String texfiledValue =  (String) configProperties.get( STRING_VAL );

Reading the Dropdown 

        String dropdownTest  =  (String) configProperties.get( SELECTION_TEST );

Reading Boolean 

          Boolean booealnTest = ( Boolean ) configProperties.get( BOOLEN_TEST );

Reading  Array/Multifield   

           String[] multifieldVlaues  =  (String[]) configProperties.get( MUTIFIELD_EX );

     for( String value : multifieldVlaues ){
out.println( value );
}


Sitemaps for the Adobe CQ Site

Sitemaps for the Adobe CQ Site

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL. We don’t need to submit each Sitemap individually. Just submit the Sitemap index file and you're good to go.
Creating and submitting a Sitemap helps make sure that search engine knows about all the pages on your site, including URLs that may not be discoverable by search engine normal crawling process.
The Sitemaps protocol enables you to let search engines know what content you would like indexed. To tell search engines the content you don't want indexed.


Create sitemap index category page:


Create a page “sitemap-index-categories” in CQ. Under this page create category node with urls property. The category node name should be the page name that is under the root of your site.




Note: “/…” mean that all pages and subdirectories in that directory should be included in the referenced sitemap.


Sitemap index file generation:


Create a sitemap-index template and page component. Create xml.jsp under the sitemap index page component. Write the logic in the xml.jsp that will iterate over the category nodes which are created under the page “sitemap-index-categories” and generated the xml file in the below structure .

Sample sitemap index file

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap> <loc>http://<host>/<category-node-name>.xml</loc></sitemap>
<sitemap><loc>http://<host>/<category-node-name>..xml</loc></sitemap>

</sitemapindex>



Sitemap Generation


Create xml.jsp under the page component which would be the super type of all your templates, So that you can access in the every page in the site.
In the xml.jsp write a logic that will read the URl to get the “category-node-name”. Read the urls property of “category-node” and then generate the below xml structure.  If the URL contains “/…” at the end you need to include all pages and subdirectories in that directory in the xml file.

Sample sitemap file:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <loc>http://<host>/about_us.html</loc></url>
<url> <loc http://<host>/about_us/<page-path>.html </loc> </url>

</urlset >



Note: Create sitemap_index page using sitemap-index template under the root of your site. Access sitemap_index.xml from browser url to generate the sitemap index.

References: