Menu

Execute a query in AEM

Execute SQL query with the help of QueryManger interface in Adobe Experience Manager(AEM) using Java.

QueryManager interface encapsulates methods for the management of search queries. Provides methods for the creation and retrieval of search queries.

Method used: createQuery

In this sample program we have created a sling servlet and register that servlet on paths. When browser make the request to registered path then a serch query will get executed and find the all nodes which contains resourceType "granite/ui/components/foundation/form/textfield" under path "/apps/myproject/components/config".
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;

@SlingServlet(paths ="/bin/private/addMissingProperties", methods = "GET", selectors="", extensions="html", metatype=true)
public class AddDialogProperties extends SlingAllMethodsServlet{
 /**
  *
  */
 private static final long serialVersionUID = 1L;
 Logger LOGGER=org.slf4j.LoggerFactory.getLogger(AddDialogProperties.class);

 protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
  String queryStatement = "SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/apps/myproject/components/config]) AND [sling:resourceType] = \"granite/ui/components/foundation/form/textfield\"";
  ResourceResolver resourceResolver=request.getResourceResolver();
  javax.jcr.Session session=resourceResolver.adaptTo(javax.jcr.Session.class);
  QueryManager queryManager;
  try {
   queryManager = session.getWorkspace().getQueryManager();
   Query query = queryManager.createQuery(queryStatement, Query.JCR_SQL2);
   QueryResult result = query.execute();
   NodeIterator nodes;
   nodes = result.getNodes();
   while (nodes.hasNext()) {
    Node node = nodes.nextNode();
    ModifiableValueMap mvp=resourceResolver.getResource(node.getPath()).adaptTo(ModifiableValueMap.class);
    mvp.put("value", " ");
    resourceResolver.commit();
   }
  } catch (Exception e) {
   LOGGER.error("Exception occured in class AddDialogProperties {}" ,e);
  }
 }

}

Can uniform Civil Code ensure gender parity in India?

To understand the civil code we have to first understand the India. 
India is the country of 28 states, where billion of people are living together perhaps those billion of people have their own culture, custom, tradition and faith. Even the people who follow the same faith don’t have same custom and ritual. There is a very popular quote in Hindi about India is “Kosh kosh pe badle pani, char kosh pe wani” which means India is a country where taste of water has been change on every step and language on every four steps. 
Civil code includes the matters of marriage, divorce and family, which also known as personal law which is different for every family based on their geography, culture and religion. 
So when British India decided to codify a law for personal law in 1861, then they categories the personal law in two sects, one is Hindu law and another is Muslim law based on the faith of the Indian civilians. Hindu personal law includes all the religion of the India except Muslim. And Muslims got a separate personal law called Muslim law. 
Both the personal law are injustice for India, since British government is not making law based on the ritual, custom and culture followed by the people of India based on their religion, instead of that they are trying to enforce law which they are following in Britain. And anyhow the law which is implemented and followed in Britain could not be same for India, where people are completely different in geography, tradition, culture, and custom. 
Ideally Hindu law should include the common law which followed (ritual and tradition) by Hindus in all part of the country and Muslim law should include the Sharia law (law of God). And need some reform on those practices which are social evils and injustice for any gender to ensure the justice in the state. And ban those illegal practices which is not in law of God but still in practice to create a male governing society; like dowry, physical abuse, sati, and other form of exploitation. 
Since India has endless diversity in nature, ritual, culture, tradition and religion which civilians of India practice, hence uniform civil code never will be helpful to ensure the equality in the society. Government can form a uniform civil code and create a common law for all civilians, but that will be breach of personal law, and violent the fundamental rights; like right to freedom (article 21) and right to religion (article 25, 26, 27, 28). 
At conclusion I would say that; answer of this question is a big No, I don’t think uniform civil court will ensure and bring gender equality in the India.

Difference between == and === in JavaScript

In this post we will see what is the difference between double equals(==) and triple equals(===) compare operator in JavaScript program. 

Double equals (==) 

Double equals compare two values and return true when those values have exactly same text and should be in same case. Please note values are case sensitive in javascript. 
e.g. var a = "Rashid";

       var b = "rashid";
       a==b // It will return false since both the values are not in the same case.

Triple equals (===) 

Triple equals compare two values as well as it also compare the datatype of those value, and return true when both the things (text and datatype) of those values get matched with other value.
e.g. var c = 7;

       var d = "7";
       c===d // it will return false; since c stored a numeric value and d stored a string value hence datatype didn't match for those values.

Compare values ignoring case 

You can also compare the values in javascript by ignoring the case sensitive. To do that first we have to convert given values in either lowerCase or upperCase by using the toUpperCase() or toLowerCase function.
e.g. var a = "Rashid";

       var b = "rashid";
       a.toUpperCase()==b.toUpperCase() // It will return true 

Code snippet

Below is the complete code snippet which you could refer to practice double equals(==) and triple equals(===) in javaScript.

If you face any issue please fill free to ask your question in comment section.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<html>
<head>
    <title>Cpmpare values using == and ===</title>
    <script type="text/javascript">
     var a = "Rashid";
     var b = "rashid";
     var c = 7;
     var d = "7";
     document.writeln("Result of a==b, where a="+a +" b="+b +"::  ");
     document.write(a==b);
     document.write("<br />")
     document.writeln("Result of a===b, where a="+a +" b="+b +"::  ");
     document.writeln(a===b);
     document.write("<br />")
     document.writeln("Result of a===b with toUpperCase, where a="+a +" b="+b +"::  ");
     document.writeln(a.toUpperCase() === b.toUpperCase());
     document.write("<br />")
     document.writeln("Result of c==d, where a="+c +" b="+c +"::  ");
     document.writeln(c==d);
     document.write("<br />")
     document.writeln("Result of c===d, where a="+c +" b="+c +"::  ");
     document.writeln(c===d);
     document.write("<br />")
    </script>
</head>
<body>
<span>This code snippet is copyright with rashidjorvee.blogspot.com.</span>    
</body>
</html>

Output

Result of a==b, where a=Rashid b=rashid:: false
Result of a===b, where a=Rashid b=rashid:: false
Result of a===b with toUpperCase, where a=Rashid b=rashid:: true
Result of c==d, where a=7 b=7:: true
Result of c===d, where a=7 b=7:: false