You didn't said in what type of Java class you'd like to get the configuration. Let's go through options:
1. Any OSGi service (like servlet, filter or event listener)
Add following field to the OSGi component class:
@Reference
private ConfigurationAdmin configurationAdmin;
and use it in the same way as in the JSP.
2. OSGi service to which the sling:OsgiConfig belongs
If you added sling:OsgiConfig
node to configure your own OSGi component, follow Chris advice:
@Component
@Properties({
@Property(name = "propertyPath")
})
public class MyComponent {
private String[] propertyPath;
@Activate
public void activate(ComponentContext ctx) {
propertyPath = PropertiesUtil.toStringArray(context.getProperties().get("propertyPath"));
}
public void myMethod() {
// do something with the propertyPath field
}
}
The activate method is invoked automatically by the OSGi. Qualified name of ComponentContext
is org.osgi.service.component.ComponentContext
3. Plain Old Java Object
If your class is not an OSGi component, you need to have access at least to the SlingHttpServletRequest
object. If you do, you can extract SlingScriptHelper
from it and use it to obtain ConfigurationAdmin
:
SlingHttpServletRequest request = ...;
SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
SlingScriptHelper sling = bindings.getSling();
// here you can use your JSP code