To access and read OSGi configuration properties in a WCMUse class in Adobe Experience Manager (AEM) 6.1, you can follow these steps:
1. Import the required packages in your Java class:
```java
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.Resource;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.Configuration;
import java.io.IOException;
import java.util.Dictionary;
```
2. Create a method to read OSGi configuration properties:
```java
public String readConfigProperty() {
String myConfigValue = "";
try {
ResourceResolver resourceResolver = resource.getResourceResolver();
ConfigurationAdmin configAdmin = resourceResolver.adaptTo(ConfigurationAdmin.class);
Configuration config = configAdmin.getConfiguration("your.configuration.pid");
if (config != null) {
Dictionary properties = config.getProperties();
if (properties != null) {
myConfigValue = (String) properties.get("your.property.name");
}
}
} catch (IOException e) {
// handle exception
}
return myConfigValue;
}
```
3. Use the readConfigProperty() method in your WCMUse class to access the OSGi configuration property:
```java
public class MyWCMUseClass extends WCMUse {
@Override
public void activate() throws Exception {
String configValue = readConfigProperty();
// Use the configValue as needed
}
private String readConfigProperty() {
// implementation of readConfigProperty method goes here
}
}
```
By following these steps, you can access and read OSGi configuration properties in a WCMUse class in AEM 6.1.
Please login or Register to submit your answer