Pages

Monday 10 March 2014

Issues when using LESS CSS in Adobe CQ/AEM

When working with LESS CSS in adobe CQ, make a note point during your check in/packaging.

When you open a page, the .less files are converted to .css files as shown below:

etc/designs/myapp/
                         css/static.less

etc/designs/myapp/
                         css/generated/static.css
                         css/static.less

In this case, make sure you should not check in/package your generated folder and its sub folders/files. What you want to check in/package is just your .less files. 

If you check in/package the generated folder, you may run in to issues when your less  files are updated. This means, when a less file is updated, the generated css file may not update with the latest code all times.


Monday 20 January 2014

How to refresh a page when a component is modified

A change was made to a component by an author. The page need to be refreshed in order to immediately reflect the change. Is there a way to automate this such that the author does not need to refresh the page? 

Resolution
The cq:listeners [cq:EditListenersConfig] is used to refresh the HTML page after a certain action is performed on a component. The cq:listeners node should be located as shown:
/component-name [cq:Component]
   /cq:editConfig [cq:editConfig]
      /cq:listeners [cq:EditListenersConfig]


NOTE: Text in the "[]" is the nodetype. Text after "/" is the node name -- should be extact name except for the "component-name".

The following properties are associated with cq:listeners node are:
aftercreate
afterdelete
afteredit
afterinsert
aftermove
afterremove
 

There are three possible values that can be assigned to the properties above -- either "REFRESH_SELF", "REFRESH_PARENT", "REFRESH_PAGE".

So, if you want your text component to cause a page refresh after each edit, you would create the following structure:
...
/mytextcomponent [cq:Component]
   /cq:editConfig [cq:editConfig]
      /cq:listeners [cq:EditListenersConfig]
         - afteredit {REFRESH_PAGE}             <= property {value}
   mytextcomponent.jsp                          <= code


Refer:

http://helpx.adobe.com/experience-manager/kb/RefreshPageWhenModifyDialog.html
 
 
 

Friday 10 January 2014

what is the use of Activator.java in CQ ?


Symptoms

A change was made to a component by an author. The page need to be refreshed in order to immediately reflect the change. Is there a way to automate this such that the author does not need to refresh the page?


Resolution

The cq:listeners [cq:EditListenersConfig] is used to refresh the HTML page after a certain action is performed on a component. The cq:listeners node should be located as shown: 


/component-name [cq:Component]

   /cq:editConfig [cq:editConfig]

      /cq:listeners [cq:EditListenersConfig]


NOTE: Text in the "[]" is the nodetype. Text after "/" is the node name -- should be extact name except for the "component-name".


The following properties are associated with cq:listeners node are:

aftercreate

afterdelete

afteredit

afterinsert

aftermove

afterremove

There are three possible values that can be assigned to the properties above -- either "REFRESH_SELF", "REFRESH_PARENT", "REFRESH_PAGE".


So, if you want your text component to cause a page refresh after each edit, you would create the following structure:

...

/mytextcomponent [cq:Component]

   /cq:editConfig [cq:editConfig]

      /cq:listeners [cq:EditListenersConfig]

         - afteredit {REFRESH_PAGE}             <= property {value}

   mytextcomponent.jsp                          <= code

Refer:

 


Implementing a Custom Predicate Evaluator for the Query Builder

Check Authentication in CQ

AuthCheckerServlet.java

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.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
@SlingServlet(paths = "/bin/permissioncheck/html", generateComponent = true, generateService = true)
public class AuthCheckerServlet extends SlingSafeMethodsServlet {
    public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {       
        String uri = request.getParameter("uri");       
        Resource resource = request.getResourceResolver().resolve(uri);       
        if(ResourceUtil.isNonExistingResource(resource)) {           
            response.setStatus(SlingHttpServletResponse.SC_FORBIDDEN);           
            } else {           
            response.setStatus(SlingHttpServletResponse.SC_OK);           
        }       
    }   
} 


Converting InputStream to String

    private String convertToString(InputStream inputStreamObj)             throws IOException {         if (inputStreamObj != null) {     ...