use of org.apache.sling.api.resource.ResourceProvider in project sling by apache.
the class LegacyResourceProviderWhiteboard method bindResourceProvider.
@Reference(service = ResourceProvider.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void bindResourceProvider(final ServiceReference<ResourceProvider> ref) {
final BundleContext bundleContext = ref.getBundle().getBundleContext();
final ResourceProvider provider = bundleContext.getService(ref);
if (provider != null) {
final String[] propertyNames = ref.getPropertyKeys();
final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false);
final List<ServiceRegistration> newServices = new ArrayList<>();
for (final String path : PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
if (path != null && !path.isEmpty()) {
final Dictionary<String, Object> newProps = new Hashtable<>();
newProps.put(PROPERTY_AUTHENTICATE, AuthType.no.toString());
newProps.put(PROPERTY_MODIFIABLE, provider instanceof ModifyingResourceProvider);
newProps.put(PROPERTY_ADAPTABLE, provider instanceof Adaptable);
newProps.put(PROPERTY_ATTRIBUTABLE, provider instanceof AttributableResourceProvider);
newProps.put(PROPERTY_REFRESHABLE, provider instanceof RefreshableResourceProvider);
newProps.put(PROPERTY_NAME, provider.getClass().getName());
newProps.put(PROPERTY_ROOT, normalizePath(path));
if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
newProps.put(ORIGINAL_SERVICE_PID, ref.getProperty(SERVICE_PID));
}
if (ArrayUtils.contains(propertyNames, USE_RESOURCE_ACCESS_SECURITY)) {
newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY, ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
}
if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
newProps.put(SERVICE_RANKING, ref.getProperty(SERVICE_RANKING));
}
String[] languages = PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
ServiceRegistration reg = bundleContext.registerService(org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(), new LegacyResourceProviderAdapter(provider, languages, ownsRoot), newProps);
newServices.add(reg);
}
}
registrations.put(provider, newServices);
}
}
Aggregations