Saturday, 5 July 2014

How to enable logging for JSP pages?

How to enable logging for JSP pages?

JSPs are compiled into a package called org.apache.jsp with the script path converted to further package parts.

Example: 











You can configure below log name to enable logging for title.jsp

log Name:   org.apache.jsp.apps.demo.components

Friday, 4 July 2014

What is Replication in CQ5 & the process.

What is Replication in CQ5 & the process.

Replication is the mechanism used to:

  • Publish (activate) content from an author to publish environment.
  • Explicitly flush content from the Dispatcher cache.
  • Return user input (eg, form input) from publish environment to the author environment (under control of the author environment)
REPLICATION PROCESS:

1)    First, the author requests that certain content to be published (activated).
2)    The request is passed to the appropriate default replication agent.
3)    Replication agent packages the content and places it in the replication queue.
4)    the content is lifted from the queue and transported to the publish environment using the   configured protocol.
5)    a servlet in the publish environment receives the request and publishes the received content, the default servlet is http://localhost:4502/bin/receive.



Tuesday, 17 December 2013

How to set up Run modes in AEM

Recommendation

Run modes allow you to tune your CQ instance for a specific purpose; for example author, publish or development. This is done by defining collections of configuration parameters for each run mode. A basic set is applied for all run modes, additional sets are each tuned to the purpose of your specific environment.

All configuration settings are stored in the one repository and activated by setting the Run Mode.

Standard run modes are:

  • author
  • publish

You can also create environment specific run mode such as,

  • author, development
  • publish, test
  • author, intranet, us or as required...

There are two mechanisms for setting standard and environment specific run mode for your instance:

  • To set up standard run mode Use the naming convention:
   cq-<standard-run-mode>-<port-number>

For example, set a standard run mode by naming the jar file cq-author-4502 or cq-publish-4503


  • To set up environment specific run mode there are two methods,

Method 1:

Through <cq-installation-dir>/crx-quickstart/config/sling.properties Add the following properties (following example is for author, prod, marketing):

   sling.jcrinstall.folder.name.regexp=.*/(install|config)?
sling.run.modes=author,prod,marketing

In above case config.author.prod.marketing will get picked up (Or whatever with maximum match)

Method 2:

Through <cq-installation-dir>/crx-quickstart/config/sling.properties and system property (In start script):

 sling.jcrinstall.folder.name.regexp=.*/(install|config)?      #<------ In sling.properties file
-Dsling.run.modes=publish,prod,marketing #<----- In start script or system property

In above case config.publish.prod.marketing will get picked up (Or whatever with maximum match)

Configuration values for the run modes are saved in the repository. You can store all configurations in one repository as the run mode is indicated by a suffix on the folder name; for example:

 config, applicable for all run modes
config.author, used in author run mode
config.publish, used in publish run mode
config.<standard-run-mode>.<env-specific-mode>, used in the applicable run mode

Java Content Assist/IntelliSense in CRXDE is not working for CQ 5.5

Below are the series of steps:

1) Stop CRXDE if it is running
2) Upload crxde-missing-libs-1.0.zip into our CQ 5.5 instance through package manager - You can download it from Packgae Share
3) Refresh /etc/crxde folder in CRXDE Lite
4) Start CRXDE - Contextual help should start working here
5) If it still doesn’t work then Stop CRXDE, delete .crxde folder from your user home directory and restart CRXDE. It should work after this action.

Query Builder in Brief


  • QueryBuilder is an API used to build Queries for Query Engine.
  • The generated queries are compatible with HTML forms also.
  • Allows us to add and remove conditions
  • Allows us to copy and paste of Queries
  •  Easily extensible
  • This QueryBuilder resides at server side and accepts a query description, creates and runs an XPath query.
  • The Query Description is simply a set of predicates.
  • Predicates are nothing but conditions. For each predicate type there is an evaluator component PredicateEvaluator that knows how to handle that specific predicate for XPath, filtering and facet extraction.

Standard Predicates:

  •  path
  •  property
  • type
  • fulltext
  •  range
  •  daterange
  • nodename
  •  similar
  • tagid & tag
  • language
  • event
  •  Also we can have the following predicates: 
    • group of predicates
    • like brackets 
    • order by predicates

Example usages

 From HTTP Form Post Request:
 Session session = request.getResourceResolver().adaptTo(Session.class);
 Query query = queryBuilder.createQuery(PredicateGroup.create(request.getParameterMap()), session);
 SearchResult result = query.getResult();
 ...
 
From key/value map:
 Map map = new HashMap();
 map.put("path", "/content");
 map.put("type", "nt:file");
 Query query = builder.createQuery(PredicateGroup.create(map), session);
 SearchResult result = query.getResult();
 ...
 
From predicates:
 PredicateGroup group = new PredicateGroup();
 group.add(new Predicate("mypath", "path").set("path", "/content"));
 group.add(new Predicate("mytype", "type").set("type", "nt:file"));
 Query query = builder.createQuery(group, session);
 SearchResult result = query.getResult();
 ...
 
QueryBuilder Debugger:
You can test and debug the queries at this URL



//Sample Application that retrieves the images from a DAM

<%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false"%>
<%@page import="com.day.cq.tagging.*, com.day.cq.wcm.api.*" %>

<%@page
import ="java.util.*,
javax.jcr.*,
org.apache.sling.api.resource.*,
org.apache.sling.api.scripting.*,
org.apache.sling.jcr.api.*,
com.day.cq.search.*,
com.day.cq.dam.api.Asset,
com.day.cq.search.result.*"
%>

<%        SlingRepository slingRep=sling.getService (SlingRepository.class);
            Session session=slingRep.loginAdministrative (null);
            //Instantiation of Map Object useful for storing the Query Description
Map<String, String> map=new HashMap<String, String>();
QueryBuilder queryBuilder;
            //Writing Query Description that goes to form a Query
map.put ("type", "dam:Asset");
map.put ("property", "jcr:content/metadata/dc:format");
map.put ("property.value", "image/jpeg");
            //resource resolving
queryBuilder=resource.getResourceResolver ().adaptTo(QueryBuilder.class);
            //creating query based on the Query Description
Query query=queryBuilder.createQuery (PredicateGroup.create(map),session);
            //Getting and storing the Results
SearchResult searchRes=query.getResult ();
String assPath=null;
            //Iterating for the no of times the requested resource found
for (Hit hit:searchRes.getHits()){
                       //Storing the path where the resource found
           String path1=hit.getPath ();
                       //Getting the resource from the path found
           Resource rs=resourceResolver.getResource (path1);
                       //Storing the resource into Asset object
          Asset asset=rs.adaptTo (Asset.class);
                      //Getting the path from the Asset object where the fetched data stored
          assPath=asset.getPath();
                      //finally rendering the asset data on the Page
             %><img src="<%=asset.getRendition ("cq5dam.thumbnail.140.100.png").getPath() %>" ></img>
<%
}
%>

Monday, 16 December 2013

Script

 

Scripts:

JSP Scripts or Servlets are usually used to render components.

According to the request processing rules of Sling the name for the default script is <componentname>.jsp.

global.jsp

The JSP script file global.jsp is used to provide quick access to specific objects (i.e. to access content) to any JSP script file used to render a component.

Therefore global.jsp should be included in every component rendering JSP script where one or more of the objects provided in global.jsp are used.

Note:

The path /libs/wcm/global.jsp, which was used by earlier versions of CQ, is now obsolete. In CQ 5.3, the correct global.jsp path changed to /libs/foundation/global.jsp

More details: http://dev.day.com/docs/en/cq/current/developing/scripts.print.html

cq:defineObject

 

The Day provided global.jsp declares the Sling, CQ and JSTL taglibs and exposes the regularly used scripting objects defined by the
<cq:defineObjects /> tag
The above tag exposes the following regularly used, scripting objects which can be referenced by the developer. It also exposes the objects defined by the <sling:defineObjects> tag.

  1. componentContext

        Package:  com.day.cq.wcm.api.components

public  interface ComponentContext

          The current component context object of the request.

   2. component

        Package: com.day.cq.wcm.api.components.Component    interface

        The current cQ5 component object of the current resource

   3. currentDesign

        Package: com.day.cq.wcm.api.designer.Design   interface

        The current design object of the current page

   4. currentPage

        Package: com.day.cq.wcm.api.Page  interface

        The current CQ WCM page object.