Class ReplaceText
java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.ReplaceText
- All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent,org.apache.nifi.processor.Processor
@SideEffectFree
@SupportsBatching(defaultDuration=TWENTY_FIVE_MILLIS)
@InputRequirement(INPUT_REQUIRED)
@Tags({"Text","Regular Expression","Update","Change","Replace","Modify","Regex"})
@CapabilityDescription("Updates the content of a FlowFile by searching for some textual value in the FlowFile content (via Regular Expression/regex, or literal value) and replacing the section of the content that matches with some alternate value. It can also be used to append or prepend text to the contents of a FlowFile.")
@SystemResourceConsideration(resource=MEMORY)
@UseCase(description="Append text to the end of every line in a FlowFile",keywords={"raw text","append","line"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Append\"\n\n\"Replacement Value\" is set to whatever text should be appended to the line.\nFor example, to insert the text `<fin>` at the end of every line, we would set \"Replacement Value\" to `<fin>`.\nWe can also use Expression Language. So to insert the filename at the end of every line, we set \"Replacement Value\" to `${filename}`\n") @UseCase(description="Prepend text to the beginning of every line in a FlowFile",keywords={"raw text","prepend","line"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Prepend\"\n\n\"Replacement Value\" is set to whatever text should be prepended to the line.\nFor example, to insert the text `<start>` at the beginning of every line, we would set \"Replacement Value\" to `<start>`.\nWe can also use Expression Language. So to insert the filename at the beginning of every line, we set \"Replacement Value\" to `${filename}`\n") @UseCase(description="Replace every occurrence of a literal string in the FlowFile with a different value",keywords={"replace","string","text","literal"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Literal Replace\"\n\"Search Value\" is set to whatever text is in the FlowFile that needs to be replaced.\n\"Replacement Value\" is set to the text that should replace the current text.\n\nFor example, to replace the word \"spider\" with \"arachnid\" we set \"Search Value\" to `spider` and set \"Replacement Value\" to `arachnid`.\n") @UseCase(description="Transform every occurrence of a literal string in a FlowFile",keywords={"replace","transform","raw text"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Regex Replace\"\n\"Search Value\" is set to a regular expression that matches the text that should be transformed in a capturing group.\n\"Replacement Value\" is set to a NiFi Expression Language expression that references `$1` (in quotes to escape the reference name).\n\nFor example, if we wanted to lowercase any occurrence of WOLF, TIGER, or LION, we would use a \"Search Value\" of `(WOLF|TIGER|LION)` and a \"Replacement Value\" of `${\'$1\':toLower()}`.\nIf we want to replace any identifier with a hash of that identifier, we might use a \"Search Value\" of `identifier: (.*)` and a \"Replacement Value\" of `identifier: ${\'$1\':hash(\'sha256\')}`\n") @UseCase(description="Completely replace the contents of a FlowFile to a specific text",keywords={"replace","raw text"},configuration="\"Evaluation Mode\" = \"Entire text\"\n\"Replacement Strategy\" = \"Always Replace\"\n\n\"Replacement Value\" is set to the new text that should be written to the FlowFile. This text might include NiFi Expression Language to reference one or more attributes.\n")
public class ReplaceText
extends org.apache.nifi.processor.AbstractProcessor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classprivate static classprivate static classprivate static interfaceprivate static interfaceprivate static classprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String(package private) static final org.apache.nifi.components.AllowableValuestatic final String(package private) static final org.apache.nifi.components.AllowableValue(package private) static final org.apache.nifi.components.PropertyDescriptorstatic final Stringstatic final org.apache.nifi.components.PropertyDescriptorprivate static final Stringprivate static final Stringstatic final Stringstatic final org.apache.nifi.components.PropertyDescriptorstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final org.apache.nifi.components.PropertyDescriptor(package private) static final org.apache.nifi.components.AllowableValuestatic final Stringstatic final org.apache.nifi.components.PropertyDescriptor(package private) static final org.apache.nifi.components.AllowableValue(package private) static final org.apache.nifi.components.PropertyDescriptorstatic final Stringprivate static final List<org.apache.nifi.components.PropertyDescriptor> (package private) static final org.apache.nifi.components.AllowableValuestatic final Stringstatic final org.apache.nifi.processor.Relationshipstatic final org.apache.nifi.processor.Relationshipprivate static final Set<org.apache.nifi.processor.Relationship> private static final Patternstatic final org.apache.nifi.components.PropertyDescriptorstatic final org.apache.nifi.components.PropertyDescriptorstatic final org.apache.nifi.components.PropertyDescriptor(package private) static final org.apache.nifi.components.AllowableValuestatic final String(package private) static final org.apache.nifi.components.AllowableValuestatic final Stringprivate static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext) private static StringescapeLiteralBackReferences(String unescaped, int numCapturingGroups) Set<org.apache.nifi.processor.Relationship> protected List<org.apache.nifi.components.PropertyDescriptor> private static StringnormalizeReplacementString(String replacement) If we have a '$' followed by anything other than a number, then escape it.voidonTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) voidsetup(org.apache.nifi.processor.ProcessContext context) Methods inherited from class org.apache.nifi.processor.AbstractProcessor
onTriggerMethods inherited from class org.apache.nifi.processor.AbstractSessionFactoryProcessor
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrueMethods inherited from class org.apache.nifi.components.AbstractConfigurableComponent
equals, getPropertyDescriptor, getPropertyDescriptors, getSupportedDynamicPropertyDescriptor, hashCode, onPropertyModified, validateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.nifi.components.ConfigurableComponent
getPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validateMethods inherited from interface org.apache.nifi.processor.Processor
isStateful, migrateProperties, migrateRelationships
-
Field Details
-
REPLACEMENT_NORMALIZATION_PATTERN
-
LINE_BY_LINE
- See Also:
-
ALL
- See Also:
-
FIRST_LINE
- See Also:
-
EXCEPT_FIRST_LINE
- See Also:
-
LAST_LINE
- See Also:
-
EXCEPT_LAST_LINE
- See Also:
-
ENTIRE_TEXT
- See Also:
-
prependValue
- See Also:
-
appendValue
- See Also:
-
surroundValue
- See Also:
-
regexReplaceValue
- See Also:
-
literalReplaceValue
- See Also:
-
alwaysReplace
- See Also:
-
SUBSTITUTE_VARIABLES_VALUE
- See Also:
-
unescapedBackReferencePattern
-
DEFAULT_REGEX
- See Also:
-
DEFAULT_REPLACEMENT_VALUE
- See Also:
-
PREPEND
static final org.apache.nifi.components.AllowableValue PREPEND -
APPEND
static final org.apache.nifi.components.AllowableValue APPEND -
SURROUND
static final org.apache.nifi.components.AllowableValue SURROUND -
LITERAL_REPLACE
static final org.apache.nifi.components.AllowableValue LITERAL_REPLACE -
REGEX_REPLACE
static final org.apache.nifi.components.AllowableValue REGEX_REPLACE -
ALWAYS_REPLACE
static final org.apache.nifi.components.AllowableValue ALWAYS_REPLACE -
SUBSTITUTE_VARIABLES
static final org.apache.nifi.components.AllowableValue SUBSTITUTE_VARIABLES -
REPLACEMENT_STRATEGY
public static final org.apache.nifi.components.PropertyDescriptor REPLACEMENT_STRATEGY -
SEARCH_VALUE
public static final org.apache.nifi.components.PropertyDescriptor SEARCH_VALUE -
REPLACEMENT_VALUE
public static final org.apache.nifi.components.PropertyDescriptor REPLACEMENT_VALUE -
PREPEND_TEXT
static final org.apache.nifi.components.PropertyDescriptor PREPEND_TEXT -
APPEND_TEXT
static final org.apache.nifi.components.PropertyDescriptor APPEND_TEXT -
CHARACTER_SET
public static final org.apache.nifi.components.PropertyDescriptor CHARACTER_SET -
MAX_BUFFER_SIZE
public static final org.apache.nifi.components.PropertyDescriptor MAX_BUFFER_SIZE -
EVALUATION_MODE
public static final org.apache.nifi.components.PropertyDescriptor EVALUATION_MODE -
LINE_BY_LINE_EVALUATION_MODE
public static final org.apache.nifi.components.PropertyDescriptor LINE_BY_LINE_EVALUATION_MODE -
PROPERTY_DESCRIPTORS
-
REL_SUCCESS
public static final org.apache.nifi.processor.Relationship REL_SUCCESS -
REL_FAILURE
public static final org.apache.nifi.processor.Relationship REL_FAILURE -
RELATIONSHIPS
-
replacementStrategyExecutor
-
-
Constructor Details
-
ReplaceText
public ReplaceText()
-
-
Method Details
-
getSupportedPropertyDescriptors
- Overrides:
getSupportedPropertyDescriptorsin classorg.apache.nifi.components.AbstractConfigurableComponent
-
getRelationships
- Specified by:
getRelationshipsin interfaceorg.apache.nifi.processor.Processor- Overrides:
getRelationshipsin classorg.apache.nifi.processor.AbstractSessionFactoryProcessor
-
customValidate
protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext) - Overrides:
customValidatein classorg.apache.nifi.components.AbstractConfigurableComponent
-
setup
@OnScheduled public void setup(org.apache.nifi.processor.ProcessContext context) -
onTrigger
public void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) throws org.apache.nifi.processor.exception.ProcessException - Specified by:
onTriggerin classorg.apache.nifi.processor.AbstractProcessor- Throws:
org.apache.nifi.processor.exception.ProcessException
-
escapeLiteralBackReferences
-
normalizeReplacementString
If we have a '$' followed by anything other than a number, then escape it. E.g., '$d' becomes '\$d' so that it can be used as a literal in a regex.
-