public ResourceChangeListenerInfo()

in src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java [65:163]


    public ResourceChangeListenerInfo(final ServiceReference<ResourceChangeListener> ref, final List<String> searchPaths) {
        boolean configValid = true;
        final Set<String> pathsSet = new HashSet<>();
        final String paths[] = toStringArray(ref.getProperty(PATHS), null);
        if ( paths != null ) {
            for(final String p : paths) {
                boolean isGlobPattern = false;
                String normalisedPath = ResourceUtil.normalize(p);
                if (p.startsWith(Path.GLOB_PREFIX)) {
                    isGlobPattern = true;
                    normalisedPath =  ResourceUtil.normalize(p.substring(Path.GLOB_PREFIX.length()));
                }
                if (!".".equals(p) && normalisedPath.isEmpty()) {
                    configValid = false;
                } else if ( normalisedPath.startsWith("/") && !isGlobPattern ) {
                    pathsSet.add(normalisedPath);
                } else if (normalisedPath.startsWith("/") && isGlobPattern) {
                    pathsSet.add(Path.GLOB_PREFIX + normalisedPath);
                } else {
                    for(final String sp : searchPaths) {
                        if ( p.equals(".") ) {
                            pathsSet.add(sp);
                        } else {
                            if (isGlobPattern) {
                                pathsSet.add(Path.GLOB_PREFIX + ResourceUtil.normalize(sp + normalisedPath));
                            } else {
                                pathsSet.add(ResourceUtil.normalize(sp + normalisedPath));
                            }
                        }
                    }
                }
            }
        }
        if ( pathsSet.isEmpty() ) {
            configValid = false;
        } else {
            // check for sub paths
            final Iterator<String> iter = pathsSet.iterator();
            while ( iter.hasNext() ) {
                final String path = iter.next();
                boolean remove = false;
                for(final String p : pathsSet) {
                    if ( p.length() > path.length() && path.startsWith(p + "/") ) {
                        remove = true;
                        break;
                    }
                }
                if ( remove ) {
                    iter.remove();
                }
            }
        }
        this.paths = PathSet.fromStringCollection(pathsSet);
        if (ref.getProperty(CHANGES) != null ) {
            final Set<ChangeType> rts = new HashSet<>();
            final Set<ChangeType> pts = new HashSet<>();
            try {
                for (final String changeName : toStringArray(ref.getProperty(CHANGES))) {
                    final ChangeType ct = ChangeType.valueOf(changeName);
                    if (ct.ordinal() < ChangeType.PROVIDER_ADDED.ordinal()) {
                        rts.add(ct);
                    } else {
                        pts.add(ct);
                    }
                }
            } catch (final Exception e) {
                configValid = false;
            }
            if ( rts.isEmpty() ) {
                this.resourceChangeTypes = Collections.emptySet();
            } else if ( rts.size() == 3 ) {
                this.resourceChangeTypes = DEFAULT_CHANGE_RESOURCE_TYPES;
            } else {
                this.resourceChangeTypes = Collections.unmodifiableSet(rts);
            }
            if ( pts.isEmpty() ) {
                this.providerChangeTypes = Collections.emptySet();
            } else if ( pts.size() == 2 ) {
                this.providerChangeTypes = DEFAULT_CHANGE_PROVIDER_TYPES;
            } else {
                this.providerChangeTypes = Collections.unmodifiableSet(pts);
            }
        } else {
            // default is added, changed, removed for resources and
            // added and removed for providers
            this.resourceChangeTypes = DEFAULT_CHANGE_RESOURCE_TYPES;
            this.providerChangeTypes = DEFAULT_CHANGE_PROVIDER_TYPES;
        }

        if ( ref.getProperty(ResourceChangeListener.PROPERTY_NAMES_HINT) != null ) {
            this.propertyNamesHint = new HashSet<>();
            for(final String val : PropertiesUtil.toStringArray(ref.getProperty(ResourceChangeListener.PROPERTY_NAMES_HINT)) ) {
                this.propertyNamesHint.add(val);
            }
        } else {
            this.propertyNamesHint = null;
        }
        this.valid = configValid;
    }