haben Sie einen Blick auf diesen Artikel Adobe Helpx: - https://helpx.adobe.com/experience-manager/using/osgi_config.html
// Lesen AEM OSGi-Konfiguration
Codewerte: -
package org.testsite.core.service.impl;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testsite.core.service.ConfigurationService;
@Service({ConfigurationServiceImpl.class})
@Component(immediate=true, metatype=true, label="Example Configuration Service")
public class ConfigurationServiceImpl
implements ConfigurationService
{
private static final Logger LOG = LoggerFactory.getLogger(ConfigurationServiceImpl.class);
private static final String CLASS_NAME = "[ConfigurationService]: ";
@Property(unbounded=PropertyUnbounded.ARRAY, label="Multi String", cardinality=50, description="Example for Multi field config")
private static final String MULTI_FIELD = "multifield";
@Property(unbounded=PropertyUnbounded.DEFAULT, label="Simple String", description="Example for Simple text field config")
private static final String SIMPLE_FIELD = "simplefield";
private String[] multiString;
private String simpleString;
public String[] getMultiString()
{
return this.multiString;
}
public String getSimpleString()
{
return this.simpleString;
}
@Activate
protected void activate(Map<String, Object> properties)
{
LOG.info("[*** AEM ConfigurationService]: activating configuration service");
readProperties(properties);
}
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);
}
}
Ein weiterer Beitrag zum gleichen Problem: - http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__pg8f-i_am_extendingmymo.html
Ich hoffe, das wird Ihnen helfen.
Danke und Grüße Kautuk Sahni
Dank @nateyolles Ich erhalte einen Fehler für ArrayUtils.EMPTY_STRING_ARRAY –
Haben Sie 'org.apache.commons.lang.ArrayUtils' oder' org.apache.commons.lang3. ArrayUtils in Ihrem Projekt? Andernfalls können Sie das durch 'new String [] {}' ersetzen. – nateyolles
Danke @nateyolles Es funktioniert –