Class FindAndReplaceUpgradeOperation
- java.lang.Object
-
- org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
-
- org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
-
- org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
-
- org.craftercms.studio.impl.v2.upgrade.operations.site.FindAndReplaceUpgradeOperation
-
- All Implemented Interfaces:
org.craftercms.commons.upgrade.UpgradeOperation<String>
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.web.context.ServletContextAware
public class FindAndReplaceUpgradeOperation extends AbstractContentUpgradeOperation
Implementation ofUpgradeOperation
that replaces text in the content repository.Supported YAML properties:
- pattern: (required) the pattern to search in the files, can be a regular expression
- replacement: (required) the expression to replace in the files, can use matched groups from the regular expression in the pattern
- Author:
- joseross
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
AbstractContentUpgradeOperation.ListFileVisitor
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_KEY_PATTERN
static String
CONFIG_KEY_REPLACEMENT
protected String
pattern
The pattern to search in the filesprotected String
replacement
The expression to replace in the files-
Fields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
CONFIG_KEY_INCLUDED_PATHS, includedPaths
-
Fields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
changedFiles, commitDetails, CONFIG_KEY_COMMIT_DETAILS, deletedFiles, servletContext, studioConfiguration
-
-
Constructor Summary
Constructors Constructor Description FindAndReplaceUpgradeOperation(StudioConfiguration studioConfiguration, DataSource dataSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
protected boolean
shouldBeUpdated(StudioUpgradeContext context, Path file)
Indicates if the given file should be updated by this classprotected void
updateFile(StudioUpgradeContext context, Path path)
Performs any needed updates on the content of the given file-
Methods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
doExecute, filterPaths, findIncludedPaths, readFile, writeFile
-
Methods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
commitAllChanges, doExecute, getCommitMessage, init, loadResource, setServletContext, trackChangedFiles, trackDeletedFiles
-
-
-
-
Field Detail
-
CONFIG_KEY_PATTERN
public static final String CONFIG_KEY_PATTERN
- See Also:
- Constant Field Values
-
CONFIG_KEY_REPLACEMENT
public static final String CONFIG_KEY_REPLACEMENT
- See Also:
- Constant Field Values
-
pattern
protected String pattern
The pattern to search in the files
-
replacement
protected String replacement
The expression to replace in the files
-
-
Constructor Detail
-
FindAndReplaceUpgradeOperation
public FindAndReplaceUpgradeOperation(StudioConfiguration studioConfiguration, DataSource dataSource)
-
-
Method Detail
-
doInit
protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
- Overrides:
doInit
in classAbstractContentUpgradeOperation
-
shouldBeUpdated
protected boolean shouldBeUpdated(StudioUpgradeContext context, Path file)
Description copied from class:AbstractContentUpgradeOperation
Indicates if the given file should be updated by this class- Specified by:
shouldBeUpdated
in classAbstractContentUpgradeOperation
- Parameters:
context
- the current upgrade contextfile
- the file to check- Returns:
- true if the file should be updated
-
updateFile
protected void updateFile(StudioUpgradeContext context, Path path) throws org.craftercms.commons.upgrade.exception.UpgradeException
Description copied from class:AbstractContentUpgradeOperation
Performs any needed updates on the content of the given file- Specified by:
updateFile
in classAbstractContentUpgradeOperation
- Parameters:
context
- the current upgrade contextpath
- the file to update- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error updating the file
-
-