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:



How to setup Maven in your development environment

You can use Maven to build an OSGi bundle. Maven manages required JAR files that a Java project needs in its class path. Instead of searching the Internet trying to find and download third-party JAR files to include in your project’s class path, Maven manages these dependencies for you.

You can download Maven 3 from the following URL:

  1. Unzip the distribution archive, i.e. apache-maven-3.1.1-bin.zip to the directory you wish to install Maven 3.1.1. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.1.1 will be created from the archive
  2. Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.1.1. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven   2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
  3. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
  4. Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
  5. In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
  6. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
  7. Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.






                Create an Adobe CQ Maven archetype project

                To create an Adobe CQ archetype project, perform these steps:

                1. Open the command prompt and go to your working directory (D:\smaple-cq-project).
                2. Run the following Maven command:
                mvn archetype:generate -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.0 -DarchetypeRepository=adobe-public-releases
                3. When prompted for additional information, specify these values:
                groupId: com.test
                artifactId: cq-test-project
                version: 1.0-SNAPSHOT : 1.0.0
                package: com.aem.coe
                appsFolderName: AEM-Training
                artifactName: AEM Training
                packageGroup: AEM
                confirm: Y
                4. Once done, you will see a message like:

                Maven Plugin to Install Bundle Directly Into OSGI in AEM/Adobe CQ5


                Use the following plugin in your POM to install bundle directly into OSGI console.


                <plugin>
                    <groupId>org.apache.sling</groupId>
                    <artifactId>maven-sling-plugin</artifactId>
                     <version>2.1.0</version>
                    <executions>
                       <execution>
                           <id>install-bundle</id>
                          <goals>
                                 <goal>install</goal>
                         </goals>
                       </execution>
                    </executions>
                    <configuration>
                             <slingUrl>http://localhost:8080/system/console/install</slingUrl>
                     <user>admin</user>
                     <password>admin</password>
                    </configuration>
                </plugin>

                Best way to use suffix in AEM/Adobe CQ5 URLs

                It is better to use the suffix with selectors only that will help the dispatcher when flush cache.

                Ex:-
                <resource path>/results.html

                <resource path>/results.html/suffix(Not recommended )

                <resource path>/results.html/suffix.suffix1  (Not recommended )

                <resource path>/results.slelector.html/suffix(Recommended)

                <resource path>/results.slelector.html/suffix.suffix1(Recommended)



                AEM /Adobe CQ 5.6.1 Supported Browsers and Java Content Repositories

                AEM 5.6.1 supports the following browsers


                Browser
                Support for Classic UI
                Support for Touch UI
                Microsoft Internet Explorer 11
                Z: Not supported
                Z: Not supported
                Microsoft Internet Explorer 10
                A: Supported
                A: Supported (1)
                Microsoft Internet Explorer 9
                A: Supported
                A: Supported
                Microsoft Internet Explorer 8
                A: Supported (6)
                Z: Not supported
                Microsoft Internet Explorer 7
                Z: Not supported
                Z: Not supported
                Microsoft Internet Explorer 6
                Z: Not supported
                Z: Not supported
                Mozilla Firefox 25
                A: Supported
                A: Supported
                Mozilla Firefox 24 (ESR) (3)
                A: Supported
                A: Supported
                Mozilla Firefox 17 (ESR) (3)
                Z: Not supported
                Z: Not supported
                Mozilla Firefox 10 (ESR) (3)
                Z: Not supported
                Z: Not supported
                Google Chrome 31+
                A: Supported
                A: Supported
                Apple Safari 7.0 (OS X)
                A: Supported
                A: Supported
                Apple Safari 6.0 (OS X)
                A: Supported
                A: Supported
                Apple Safari 6.0 (iOS) (4)(5)
                Z: Not supported
                A: Supported



                AEM 5.6.1 supported java Content Repositories


                latform
                Support Level
                Adobe CRX 2.4
                A: Supported
                Apache Jackrabbit 2.5.3
                D: Validated, optional support available



                For more information click here


                Disabling the XML and JSON render in Adobe CQ5/AEM

                To disable the XML or JSON renderer, navigate to the OSGI configuration manager at the following URL:

                http://localhost:8080/system/console/configMgr


                Click on Apache Sling GET Servlet, uncheck “Enable XML” and Enable JSON , then click save.



                Handy Urls in AEM/CQ 5.6.1

                AEM 5.6 - Quick Reference :  http://www.aemcasts.com/qr.html 

                CRX explorer   :   http://localhost:8080/crx/explorer/index.jsp

                CRXDE Lite     :   http://localhost:8080/crx/de/index.jsp

                Query debug tool : http://localhost:8080/libs/cq/search/content/querydebug.html

                Content sync console :  http://localhost:8080/libs/cq/contentsync/content/console.html

                User manager standalone ui : http://localhost:8080/libs/granite/security/content/useradmin.html

                Upgrade nodetypes : http://localhost:8080/libs/cq/compat/components/ntupgrade.html

                 Built in profiler  : http://localhost:8080/crx/explorer/diagnostic/prof.jsp

                Tag window :  http://localhost:8080/tagging


                OSGI Console

                Felix  console  :  http://localhost:8080/system/console/bundles

                Workflow maintenance :
                                   http://localhost:8080/system/console/jmx/com.adobe.granite.workflow:type=Maintenance

                Repository maintenance :  http://localhost:8080/system/console/jmx/com.adobe.granite:type=Repository

                Maven Dependency for the packages/classes : http://localhost:8080/system/console/depfinder

                List of adaptable  classes using the adaptTo() : http://localhost:8080/system/console/adapters

                Built in profiler  :  http://localhost:8080/system/console/profiler

                Sling properties : http://localhost:8080/system/console/status-slingsettings


                Client Libs

                Compile client libs : http://localhost:8080/libs/granite/ui/content/dumplibs.rebuild.html?rebuild=true

                To know dependencies : http://localhost:8080/libs/granite/ui/content/dumplibs.html

                How to debug single file Clientlibs in single file   :   ?debugClinetLibs=true

                Bookmarks









                        

                How To Set Dynamic Value For Component Edit Bar Label

                Sample code in JSP

                   
                you can set the label value of the component edit bar dynamically.



                    editContext is implicit object of com.day.cq.wcm.api.components.EditContext interface

                   editContext.getEditConfig().getToolbar().add(0, new Toolbar.Label("sample"));


                By Using cq:EditConfig

                Add the below configurations under your component's "cq:EditConfig" node

                <cq:actionConfigs jcr:primaryType="nt:unstructured">
                        <separator
                            jcr:primaryType="nt:unstructured"
                            xtype="tbseparator"/>
                        <manage
                            jcr:primaryType="nt:unstructured"
                            handler="function(){&#xa;&#x9;window.open(CQ.WCM.getPagePath()+&quot;.openNewPage.html&quot;, '_blank');&#xa;}"
                            text="Edit on Other Page"/>
                    </cq:actionConfigs>








                Performance Issue In CRXDE IDE Of AEM/Adobe CQ5

                After open the CRXDE.

                Navigate to Window > General > Workspace > 

                Uncheck Build automatically option.

                Restart the CRXDE.




                How to Disbale Target Option on Component Edit

                        To disable "target" option when edit the component you need to add   property 
                                 cq:disableTargeting="true" to cq:editConfig Node


                               cq:actions="[text:Button,-,edit,delete]"
                               cq:dialogMode="floating"
                               cq:disableTargeting="true"
                               jcr:primaryType="cq:EditConfig"

                How to Exclude Child Pages Of A Page When Creating A Package in AEM/CQ5 Package

                Open package manager

                        http://localhost:5632/crx/packmgr/index.jsp

                Click on the crate packge




                Enter package name ,version and Group. Click on OK.

                Click on the respective package icon then click on EDIT button.

                After Edit navigate to filters tab. Click on the "add filter" button.



                      Add the root path :    /content/geometrixx/en/toolbar

                Then click on the Add rule button. 

                   exclude  : /content/geometrixx/en/toolbar/*.*
                   include   : /content/geometrixx/en/toolbar/jcr:content

                Click on the done button. Then save.

                To build the package click on the build button. 



                By Using Regular Expresion


                Exclude  : /content/geometrixx/en/toolbar/[a-z].*

                        A  filter to create a package for root /content/geometrixx/en and exclude all the page
                                below /content/geometrixx/en that starts with range a to z.

                Exclude : /content/geometrixx/en/toolbar/s.*

                        A  filter to create a package for root /content/geometrixx/en and exclude all the page below 
                                 /content/geometrixx/en that starts with s.




                Runmodes and Configs in AEM/CQ 5.4 Onwards

                For the basic information and configurations of the Runmodes refer the below URL:

                     http://www.slideshare.net/MikePfaff/runmodes-and-configs-for-fun-and-profit

                Resolution of multiple Run Modes 




                Adobe CQ5 / AEM 6 Supports LESS From Adobe CQ 5.5 Onwards

                Command to Run AEM/CQ 5.6.1 Instance In Debug Mode

                Command to run the CQ 5.6.1 in debug mode

                                        java -Xmx1024M -XX:MaxPermSize=256M -debug -Xnoagent -Djava.compiler=NONE
                            -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=30303 -jar cq-author-4502.jar 

                How to Know Maven Dependency of packages/classes in AEM /CQ 5.6.1

                Click on the below URL and change port to your port

                     http://localhost:8080/system/console/depfinder



                Enter javax.servlet in the packages/classes field then click on the find.