Explore about adobe CQ5 and its related technologies which are involved with. !!!
Featured
Saturday, 10 May 2014
How to read config properties in cq5 from configMgr in console
Initially observe how to set a custom configuration in cq5 here .
1)Create a sling:OsgiConfig node in crxde
Name: MyOsgi_Custom_config
Type: sling:OsgiConfig
2) To this node we need add our own key value pairs
CustomProp_1 boolean myValue1
CustomProp_2 boolean myValue2
3) Save and check in system/console/configMgr for our custom configuration.
---------------And we will get this config properties for our slingservlet as follows--------------------
package com.myApp.configProps;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("unchecked")
@Component(metatype = false, immediate = true)
@Service
public class ConfigPropReader{
private static final Logger log = LoggerFactory.getLogger(ConfigPropReader.class);
private final String CONFIG_NAME = "MyOsgi_Custom_config";
private boolean CustomProp_1 = true;
@Reference
private ConfigurationAdmin configAdmin;
private void readConfigProp(){
try{
Configuration config = (Configuration)configAdmin.getConfiguration(CONFIG_NAME);
Dictionary props = config.getProperties();
CustomProp_1 = ((Boolean)props.get("CustomProp_1")).booleanValue();
}catch (Exception ex) {
System.out.println( ex.getMessage());
}
}
}
Hope it helps :)
SonyCharan
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment