Hi,
I have a requirement to create OSGI configuration which can allow to add multiple fields dynamically. I could create configuration with fixed number of fields and provided the code snippet below which is put into meta xml. Can this be modified to add the fields dynamically ? Please assist.
<OCD description="Store Content Configuration" name="com.testosgi.config.storecontent" id="com.testosgi.config.storecontent"">
<AD name="Author Host Name" id="authorHost" required="true" type="String" default="localhost"/>
<AD name="Author Port" id="authorPort" required="true" type="String" default="4502"/>
<AD name="User Name" id="userName" required="false" type="String" default="admin"/>
</OCD>
<Designate pid="com.testosgi.config.storecontent">
<Object ocdref="com.testosgi.config.storecontent"/>
</Designate>
Thanks,
Suresh
Solved! Go to Solution.
Adding two more references to further help you:
1. Adobe Experience Manager Help | Reading Adobe Experience Manager OSGi Configuration Values
// You can download package directly and see it working
The ConfigurationServiceImpl class reads the OSGi configuration values defined in CRXDE Lite by using org.apache.sling.commons.osgi.PropertiesUtil.
This class contains this method that reads the configuration values.
protected void readProperties(Map<String, Object> properties)
{
LOG.info(properties.toString());
this.multiString = PropertiesUtil.toStringArray(properties.get("multifield"));
LOG.info("Mutli String Size: " + this.multiString.length);
this.simpleString = PropertiesUtil.toString(properties.get("simplefield"), "default");
LOG.info("Simple String: " + this.simpleString);
}
Views
Replies
Total Likes
I am sure this is what you are looking it? Please refer to this beautiful article which talks about the same.
http://www.aemcq5tutorials.com/tutorials/custom-osgi-configuration-aem/
Adding two more references to further help you:
1. Adobe Experience Manager Help | Reading Adobe Experience Manager OSGi Configuration Values
// You can download package directly and see it working
The ConfigurationServiceImpl class reads the OSGi configuration values defined in CRXDE Lite by using org.apache.sling.commons.osgi.PropertiesUtil.
This class contains this method that reads the configuration values.
protected void readProperties(Map<String, Object> properties)
{
LOG.info(properties.toString());
this.multiString = PropertiesUtil.toStringArray(properties.get("multifield"));
LOG.info("Mutli String Size: " + this.multiString.length);
this.simpleString = PropertiesUtil.toString(properties.get("simplefield"), "default");
LOG.info("Simple String: " + this.simpleString);
}
Views
Replies
Total Likes
How can we do this using the R6 annotations?
Code snippet
@Component(
immediate = true,
name = OrderStatusLineStatus.NAME,
configurationPid = OrderStatusLineStatus.CONFIG_PID
)
@Designate(ocd = OrderStatusLineStatus.Configuration.class)
public class OrderStatusLineStatus {
public static final String NAME = "OM - Line Status Description";
private static final Logger LOG = LoggerFactory.getLogger(OrderStatusLineStatus.class);
public static final String CONFIG_PID = "com.common.services.impl.OrderStatusLineStatus";
protected Configuration configuration;
protected ResourceResolver resourceResolver;
protected Resource resource;
protected Session session;
protected String[] lineStatusCode;
protected String[] getLineStatusCode() {
return this.lineStatusCode;
}
@Activate
@Modified
protected final void activate(final Configuration config) {
this.configuration = config;
lineStatusCode = config.lineStatus();
LOG.info("[*** AEM ConfigurationService" + lineStatusCode);
}
@ObjectClassDefinition(name=OrderStatusLineStatus.NAME)
public @interface Configuration {
@AttributeDefinition(
name = "Line Status",
description = "Add Line Status",
type = AttributeType.STRING)
public String[] lineStatus() default {};
}
protected void readProperties(Configuration config)
{
LOG.info("Mutli String Size: " + config.toString());
}
}
How can retreive the values of the multifield in the activate method.?
Views
Replies
Total Likes
Hi,
Yes did it right to get value from config to lineStatusCode array, but you can't captures those values in log like that you need to change your code a bit e.g.
protected final void activate(final Configuration config) {
this.configuration = config;
lineStatusCode = config.lineStatus();
LOG.info("[*** AEM ConfigurationService" + java.util.Arrays.toString(lineStatusCode));
}
Thanks
Arun
Views
Replies
Total Likes
Views
Likes
Replies