Friday, 11 January 2013

Retrieve OSGI Configurations

Scenario: How to retrieve configuration details in jsp/class ?

Solutions

@Reference
    ConfigurationAdmin configAdmin;


Configuration config = configAdmin.getConfiguration("com.day.cq.mailer.DefaultMailService");
           
Dictionary<?, ?> d = config.getProperties();

log.debug("Configurations Dictionary:{}"+d);

String hostName= (String) d.get("smtp.host");



Sunday, 6 January 2013

Configuring Email Notification


In order to send email from CQ, the Day CQ Mail Service needs to be configured properly. 
Procedure: 1. Go to felix web console (http://<host-name>:<port>/system/console/configMgr)
2. Search for Day CQ Mail Service
3. Edit and configure as follows:

a.  The SMTP server port must be 25 or higher.
b.  The SMTP server host name must not be blank.
c.  The "From" address must not be blank.  

Screen shot:


Simple code to send an email

There are difference ways to send an email.

Method 1: Using SimpleEmail

        SimpleEmail email = new SimpleEmail();
        email.setHostName('smtp.gmail.com");
        email.addTo("mail@gmail.com", "John Doe");
        email.setFrom("yourmail@gmail.com", "Me");
        email.setSubject("Test message");
        email.setMsg("This is a simple test of commons-email");
        email.send();

Method 2: Using HtmlEmail without using MessageGateway


        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.gmail.com");
        email.addTo("mail@domain.com", "John Doe");
        email.setFrom("yourmail@domain.com", "Me");
        email.setSubject("Test email with inline image");

        // set the html message //
        email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"
        +cid+"\"></html>");
         
        // set the alternative message
        email.setTextMsg("Your email client does not support HTML messages");
        email.send();

Note: We can also read smtp details from the felix console configurations instead of passing smtp details directly. 
Ref: http://www.blogger.com/blogger.g?blogID=8547815981944994348#editor/target=post;postID=3901523167605550399






Saturday, 9 June 2012

Customize column control


      OOTB provides components related to the  column controls, but If we directly drag and drop the components on to the page, we can't find such number of columns in the column control. Because we need to add styles to define different columns:
Here you go..

Customize column control:
------------------------
Add the following styles in css:

/* layout 0 : 50% 50%  i.e., two columns wiht 50% , 50%*/

div.cq-colctrl-lt0 { }
div.cq-colctrl-lt0-c0 { width: 340px; margin-right:10px}
div.cq-colctrl-lt0-c1 { width: 340px; margin-left: 10px}

/* layout 1 : 33% 33% 33%  Three columns */
div.cq-colctrl-lt1 { }
div.cq-colctrl-lt1-c0 { width: 220px; margin-right: 10px;}
div.cq-colctrl-lt1-c1 { width: 220px; margin-left: 10px; margin-right: 10px;}
div.cq-colctrl-lt1-c2 { width: 220px; margin-left: 10px; }

Add follwoing colctrl design mode:
-----------------------------------
2;cq-colctrl-lt0      2 Columns (50%, 50%)
3;cq-colctrl-lt1      3 Columns (33%, 33%, 33%)

so that we can get options for two & three columns.