Replace properties of given resources.<p>

@param matchedResources to replace properties
322994
private void replaceProperties(Set<CmsResource> matchedResources) {

        for (CmsResource resource : matchedResources) {
            try {
                CmsProperty prop = getCms().readPropertyObject(resource, m_settings.getProperty().getName(), false);
                Matcher matcher = Pattern.compile(m_settings.getSearchpattern()).matcher(prop.getValue());
                if (m_settings.getReplacepattern().isEmpty()) {
                    prop.setValue("", "");
                } else {
                    prop.setValue(matcher.replaceAll(m_settings.getReplacepattern()), CmsProperty.TYPE_INDIVIDUAL);
                }
                getCms().lockResource(resource);
                getCms().writePropertyObjects(resource, Collections.singletonList(prop));
                getCms().unlockResource(resource);
            } catch (CmsException e) {
                LOG.error("Ubable to change property", e);
            }
        }
    }
742820
void setMatcher(ContentMatcher m)
  {

    if (tc.isEntryEnabled())
      tc.entry(
        this,cclass,
        "setMatcher",
        "matcher: " + m + ", hasContent: " + new Boolean(hasContent));

    wildMatchers.add(m);
    this.hasContent |= m.hasTests();

    if (tc.isEntryEnabled())
      tc.exit(this,cclass, "setMatcher");
  }
119755
@Override
    public void replaceProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator,
        final Model inputModel, final RdfStream originalTriples) throws MalformedRdfException {

        final Resource selfResource = idTranslator.reverse().convert(this);
        ensureInteractionModelDefaults(selfResource.toString(), inputModel);

        // remove any statements that update "relaxed" server-managed triples so they can be updated separately
        final List<Statement> filteredStatements = new ArrayList<>();
        final StmtIterator it = inputModel.listStatements();
        final Optional<String> resourceInteractionModel = getResourceInteraction();
        final boolean hasInteractionModel = resourceInteractionModel.isPresent();
        while (it.hasNext()) {
            final Statement next = it.next();
            if (RdfLexicon.isRelaxed.test(next.getPredicate())) {
                filteredStatements.add(next);
                it.remove();
            } else {
                if (hasInteractionModel) {
                    checkInteractionModel(next.asTriple(), resourceInteractionModel);
                }
            }
        }
        // remove any "relaxed" server-managed triples from the existing triples
        final RdfStream filteredTriples = new DefaultRdfStream(originalTriples.topic(),
                originalTriples.filter(triple -> !isRelaxed.test(createProperty(triple.getPredicate().getURI()))));



        try (final RdfStream replacementStream =
                new DefaultRdfStream(selfResource.asNode())) {

            final GraphDifferencer differencer =
                new GraphDifferencer(inputModel, filteredTriples);

            final StringBuilder exceptions = new StringBuilder();
            try (final DefaultRdfStream diffStream =
                    new DefaultRdfStream(replacementStream.topic(), differencer.difference())) {
                new RdfRemover(idTranslator, getSession(), diffStream).consume();
            } catch (final MalformedRdfException e) {
                exceptions.append(e.getMessage());
                exceptions.append("\n");
            } catch (final ConstraintViolationException e) {
                throw e;
            }

            try (
                final DefaultRdfStream notCommonStream =
                        new DefaultRdfStream(replacementStream.topic(), differencer.notCommon());
                final DefaultRdfStream testStream =
                        new DefaultRdfStream(replacementStream.topic(), differencer.notCommon())) {

                // do some very basic validation to catch invalid RDF
                // this uses the same checks that updateProperties() uses
                final Collection<ConstraintViolationException> errors = testStream
                        .flatMap(FedoraResourceImpl::validateTriple)
                        .filter(x -> x != null)
                        .collect(Collectors.toList());

                throwConstraintErrorsIfPresent(errors);

                new RdfAdder(idTranslator, getSession(), notCommonStream, inputModel.getNsPrefixMap()).consume();
            } catch (final MalformedRdfException e) {
                exceptions.append(e.getMessage());
            } catch (final ConstraintViolationException e) {
                throw e;
            }

            // If this resource's structural parent is an IndirectContainer, check whether the
            // ldp:insertedContentRelation property is present in the stream of changed triples.
            // If so, set the propertyChanged value to true.
            final AtomicBoolean propertyChanged = new AtomicBoolean();
            ldpInsertedContentProperty(getNode()).ifPresent(resource -> {
                propertyChanged.set(differencer.notCommon().map(Triple::getPredicate).anyMatch(resource::equals));
            });

            removeEmptyFragments();

            if (exceptions.length() > 0) {
                throw new MalformedRdfException(exceptions.toString());
            }

            try {
                touch(propertyChanged.get(), RelaxedPropertiesHelper.getCreatedDate(filteredStatements),
                        RelaxedPropertiesHelper.getCreatedBy(filteredStatements),
                        RelaxedPropertiesHelper.getModifiedDate(filteredStatements),
                        RelaxedPropertiesHelper.getModifiedBy(filteredStatements));
            } catch (final RepositoryException e) {
                throw new RuntimeException(e);
            }
        }
    }
1232962
public void setSources(java.util.Collection<InputSource> sources) {
        if (sources == null) {
            this.sources = null;
            return;
        }

        this.sources = new java.util.ArrayList<InputSource>(sources);
    }
428945
public void setResources(Resource[] resources) throws IOException {
        clear();
        
        for (Resource resource : resources) {
            addResource(resource);
        }
    }
573788
protected void convertSearchResults(final Collection<CmsSearchResource> searchResults) {

        m_foundResources = new ArrayList<I_CmsSearchResourceBean>();
        for (final CmsSearchResource searchResult : searchResults) {
            m_foundResources.add(new CmsSearchResourceBean(searchResult, m_cmsObject));
        }
    }
506320
public void setResourceARNs(java.util.Collection<ResourceARNDetail> resourceARNs) {
        if (resourceARNs == null) {
            this.resourceARNs = null;
            return;
        }

        this.resourceARNs = new java.util.ArrayList<ResourceARNDetail>(resourceARNs);
    }
541275
public void setPropertiesLocations(List<String> locations) {
        Properties properties = null;
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        for (String location: locations) {
            properties = load(properties, resolver, location);
        }
        if (properties != null && properties.size() > 0) {
            configure(properties);
        }
    }
802952
private void replaceModuleName() throws CmsException, UnsupportedEncodingException {

        CmsResourceFilter filter = CmsResourceFilter.ALL.addRequireFile().addExcludeState(
            CmsResource.STATE_DELETED).addRequireTimerange().addRequireVisible();
        List<CmsResource> resources = getCms().readResources(
            CmsWorkplace.VFS_PATH_MODULES + m_cloneInfo.getName() + "/",
            filter);
        for (CmsResource resource : resources) {
            CmsFile file = getCms().readFile(resource);
            if (CmsResourceTypeXmlContent.isXmlContent(file)) {
                CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file);
                xmlContent.setAutoCorrectionEnabled(true);
                file = xmlContent.correctXmlStructure(getCms());
            }
            byte[] contents = file.getContents();
            String encoding = CmsLocaleManager.getResourceEncoding(getCms(), file);
            String content = new String(contents, encoding);
            Matcher matcher = Pattern.compile(m_cloneInfo.getSourceModuleName()).matcher(content);
            if (matcher.find()) {
                contents = matcher.replaceAll(m_cloneInfo.getName()).getBytes(encoding);
                if (lockResource(getCms(), file)) {
                    file.setContents(contents);
                    getCms().writeFile(file);
                }
            }
        }
    }
120325
public static String replaceResources(String string, ResourceBundle reg, Map<String, Object> map, PropertyOwner propertyOwner)
    {
        return Utility.replaceResources(string, reg, map, propertyOwner, false);
    }
1264183
public void setResourceTypes(java.util.Collection<String> resourceTypes) {
        if (resourceTypes == null) {
            this.resourceTypes = null;
            return;
        }

        this.resourceTypes = new java.util.ArrayList<String>(resourceTypes);
    }
232623
protected List<CmsPair<CmsResource, CmsResource>> getMatchingResources(String source, String target)
    throws CmsException {

        List<CmsResource> sourceResources = readTree(source);
        Map<String, CmsResource> sourceRelative = getResourcesByRelativePath(sourceResources, source);

        List<CmsResource> targetResources = readTree(target);
        Map<String, CmsResource> targetRelative = getResourcesByRelativePath(targetResources, target);

        List<CmsPair<CmsResource, CmsResource>> result = new ArrayList<CmsPair<CmsResource, CmsResource>>();
        sourceRelative.keySet().retainAll(targetRelative.keySet());
        for (Map.Entry<String, CmsResource> entry : sourceRelative.entrySet()) {
            String key = entry.getKey();
            CmsResource sourceRes = entry.getValue();
            CmsResource targetRes = targetRelative.get(key);
            result.add(CmsPair.create(sourceRes, targetRes));
        }
        return result;
    }
233711
protected void setResourcesParam(List<String> resources) {

        m_collectorParameter += I_CmsListResourceCollector.SEP_PARAM
            + I_CmsListResourceCollector.PARAM_RESOURCES
            + I_CmsListResourceCollector.SEP_KEYVAL;
        if (resources == null) {
            // search anywhere
            m_collectorParameter += "/";
        } else {
            m_collectorParameter += CmsStringUtil.collectionAsString(resources, "#");
        }
    }
325137
private byte[] replaceInContent(CmsFile file, byte[] contents) throws Exception {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_settings.getLocale())) {
            Locale contentLocale = CmsLocaleManager.getMainLocale(getCms(), file);
            if (!contentLocale.toString().equalsIgnoreCase(m_settings.getLocale())) {
                // content does not match the requested locale, skip it
                getReport().println(
                    Messages.get().container(Messages.RPT_SOURCESEARCH_NOT_MATCHED_0),
                    I_CmsReport.FORMAT_NOTE);
                return null;
            }
        }

        String encoding = CmsLocaleManager.getResourceEncoding(getCms(), file);
        String content = new String(contents, encoding);

        if (CmsSourceSearchForm.REGEX_ALL.equals(m_settings.getSearchpattern()) & !m_replace) {
            m_matchedResources.add(file);
            getReport().print(Messages.get().container(Messages.RPT_SOURCESEARCH_MATCHED_0), I_CmsReport.FORMAT_OK);
            return null;
        }

        Matcher matcher = Pattern.compile(m_settings.getSearchpattern()).matcher(content);

        if (matcher.find()) {
            // search pattern did match here, so take this file in the list with matches resources
            m_matchedResources.add(file);
            getReport().print(Messages.get().container(Messages.RPT_SOURCESEARCH_MATCHED_0), I_CmsReport.FORMAT_OK);
            if (m_replace) {
                if (m_settings.getType().equals(SearchType.renameContainer)) {

                    return renameNestedContainers(
                        file,
                        m_settings.getElementResource(),
                        m_settings.getReplacepattern().split(";")[0],
                        m_settings.getReplacepattern().split(";")[1]);
                }
                return matcher.replaceAll(m_settings.getReplacepattern()).getBytes(encoding);
            }
        } else {
            // search pattern did not match
            getReport().print(
                Messages.get().container(Messages.RPT_SOURCESEARCH_NOT_MATCHED_0),
                I_CmsReport.FORMAT_NOTE);
        }
        return null;
    }
45952
public static StringBuilder replaceResources(StringBuilder sb, ResourceBundle reg, Map<String, Object> map, PropertyOwner propertyOwner)
    {
        return Utility.replaceResources(sb, reg, map, propertyOwner, false);
    }
1191311
public static void replaceWords(StringBuilder input, String[] words, String[] replaces) {
        replaceWords(input, words, replaces, false);
    }
110063
static void replaceHeredocStrings(ASTTemplate tnode,
            List<StringProperty> strings) {

        // Only something to do if there were heredoc strings defined.
        if (strings.size() > 0) {
            processHeredocStrings(tnode, strings);
        }
    }