I am extending my model class to WCMUse class to write my business logic. I have osgi configuration which has couple of properties. I want to read one of the property in my model class. I am not sure how to get the handle of osgi configuration in WCMUse class. Any pointers will be highly appreciated.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
public class SightlyComponent extends WCMUse { private String myTitle; @Override public void activate() { myTitle = "My Project " + getCurrentPage().getTitle(); MyService service = getSlingScriptHelper().getService(MyService.class); service.action(myTitle); } public String getMyTitle() { return myTitle; } }
This is demo piece of code which will help you to call a service in sightly class.
Write a small service to read those configuration properties and then call your service like above in sightly class
Views
Replies
Total Likes
Hi,
public class SightlyComponent extends WCMUse { private String myTitle; @Override public void activate() { myTitle = "My Project " + getCurrentPage().getTitle(); MyService service = getSlingScriptHelper().getService(MyService.class); service.action(myTitle); } public String getMyTitle() { return myTitle; } }
This is demo piece of code which will help you to call a service in sightly class.
Write a small service to read those configuration properties and then call your service like above in sightly class
Views
Replies
Total Likes
You can use ConfigurationAdmin and get the properties using pid of the service from where you need to read the properties
ex:
@Reference
Private ConfigurationAdmin config;
Configuration config = configAdmin.getConfiguration(<pid>);
Views
Replies
Total Likes
Hi
Apart from what mentioned in above mentioned posts, You can refer to following :-
@Reference
ConfigurationAdmin configAdmin;
/*Get the configurations based on the fully qualified name of your Bundle*/
Configuration config = configAdmin.getConfiguration(Constants.FULLY_QUALIFIED_CLASS_NAME);
/*Get the configuration properties / returns a Dictionary Object*/
Dictionary<?, ?> properties = config.getProperties();
/*Iterate through the Dictionary properties to get your configurations*/
String item = (String) properties.get(Constants.CONFIG_ITEM);
Link:- http://myadobecq.blogspot.in/2013/12/reading.html
Another Reference link :- http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html
I hope this will help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes