Search in sources :

Example 1 with ResourceProvider

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);
    }
}
Also used : RefreshableResourceProvider(org.apache.sling.api.resource.RefreshableResourceProvider) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ModifyingResourceProvider(org.apache.sling.api.resource.ModifyingResourceProvider) RefreshableResourceProvider(org.apache.sling.api.resource.RefreshableResourceProvider) AttributableResourceProvider(org.apache.sling.api.resource.AttributableResourceProvider) ModifyingResourceProvider(org.apache.sling.api.resource.ModifyingResourceProvider) ResourceProvider(org.apache.sling.api.resource.ResourceProvider) Adaptable(org.apache.sling.api.adapter.Adaptable) AttributableResourceProvider(org.apache.sling.api.resource.AttributableResourceProvider) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) ServiceReference(org.osgi.framework.ServiceReference) Reference(org.osgi.service.component.annotations.Reference)

Aggregations

ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Adaptable (org.apache.sling.api.adapter.Adaptable)1 AttributableResourceProvider (org.apache.sling.api.resource.AttributableResourceProvider)1 ModifyingResourceProvider (org.apache.sling.api.resource.ModifyingResourceProvider)1 RefreshableResourceProvider (org.apache.sling.api.resource.RefreshableResourceProvider)1 ResourceProvider (org.apache.sling.api.resource.ResourceProvider)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Reference (org.osgi.service.component.annotations.Reference)1