Search in sources :

Example 1 with ResourceProviderFactory

use of org.apache.sling.api.resource.ResourceProviderFactory in project sling by apache.

the class LegacyResourceProviderWhiteboard method bindResourceProviderFactory.

@Reference(service = ResourceProviderFactory.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected void bindResourceProviderFactory(final ServiceReference<ResourceProviderFactory> ref) {
    final BundleContext bundleContext = ref.getBundle().getBundleContext();
    final ResourceProviderFactory factory = bundleContext.getService(ref);
    if (factory != 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<>();
                if (PropertiesUtil.toBoolean(ref.getProperty(PROPERTY_REQUIRED), false)) {
                    newProps.put(PROPERTY_AUTHENTICATE, AuthType.required.toString());
                } else {
                    newProps.put(PROPERTY_AUTHENTICATE, AuthType.lazy.toString());
                }
                newProps.put(PROPERTY_MODIFIABLE, true);
                newProps.put(PROPERTY_ADAPTABLE, true);
                newProps.put(PROPERTY_ATTRIBUTABLE, true);
                newProps.put(PROPERTY_REFRESHABLE, true);
                newProps.put(PROPERTY_NAME, factory.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 LegacyResourceProviderFactoryAdapter(factory, languages, ownsRoot), newProps);
                newServices.add(reg);
            }
        }
        registrations.put(factory, newServices);
    }
}
Also used : ResourceProviderFactory(org.apache.sling.api.resource.ResourceProviderFactory) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) 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) 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 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 ResourceProviderFactory (org.apache.sling.api.resource.ResourceProviderFactory)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