public void run()

in core/src/main/java/org/apache/sling/cms/core/internal/operations/BulkReplaceOperation.java [62:122]


    public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) {

        try {
            // calculate the paths
            String path = request.getResource().getPath();
            response.setPath(path);

            // perform the bulk replacement
            Pattern updateProperties = Pattern.compile(request.getParameter(PN_UPDATE_PROPERTIES));
            if (log.isDebugEnabled()) {
                log.debug("Updating properties matching: {}", updateProperties.pattern());
            }
            Pattern rfind = null;
            String find = request.getParameter(PN_FIND);
            if (MODE_REGEX.equals(request.getParameter(PN_MODE))) {
                if (log.isDebugEnabled()) {
                    log.debug("Using regular expressions to search for {}", CommonUtils.escapeLogMessage(find));
                }

                rfind = Pattern.compile(find);
            } else if (log.isDebugEnabled()) {
                log.debug("Searching for {}", CommonUtils.escapeLogMessage(find));
            }
            String replace = request.getParameter(PN_REPLACE);
            
            if (log.isDebugEnabled()) {
                log.debug("Replacing with {}", CommonUtils.escapeLogMessage(replace));
            }

            final List<Modification> changes = new ArrayList<>();
            updateProperties(request.getResource(), updateProperties, rfind, find, replace, response, changes);

            // invoke processors
            if (processors != null) {
                for (SlingPostProcessor processor : processors) {
                    processor.process(request, changes);
                }
            }

            // check modifications for remaining postfix and store the base path
            final Map<String, String> modificationSourcesContainingPostfix = new HashMap<>();
            final Set<String> allModificationSources = new HashSet<>(changes.size());
            for (final Modification modification : changes) {
                final String source = modification.getSource();
                if (source != null) {
                    allModificationSources.add(source);
                    final int atIndex = source.indexOf('@');
                    if (atIndex > 0) {
                        modificationSourcesContainingPostfix.put(source.substring(0, atIndex), source);
                    }
                }
            }
            request.getResourceResolver().commit();

        } catch (Exception e) {

            log.error("Exception during response processing.", e);
            response.setError(e);

        }
    }