1 package com.kodexa.client.pipeline; 2 3 import com.kodexa.client.Document; 4 import com.kodexa.client.steps.PipelineStep; 5 import lombok.extern.slf4j.Slf4j; 6 7 import java.util.Map; 8 import java.util.regex.Matcher; 9 import java.util.regex.Pattern; 10 11 @Slf4j 12 public class PipelineStepWrapper { 13 14 private final Pattern pattern = Pattern.compile("\\$\\{(.*)\\}"); 15 16 private final PipelineStep step; 17 18 private Options options; 19 20 public PipelineStepWrapper(PipelineStep step, Options options) { 21 this.step = step; 22 this.options = options; 23 } 24 25 private void replaceParameters(Map<String, Object> options, Map<String, Object> parameters) { 26 options.forEach((k, v) -> { 27 if (v instanceof String) { 28 String stringValue = (String) v; 29 Matcher matcher = pattern.matcher(stringValue); 30 if (matcher.find()) { 31 String paramName = matcher.group(1); 32 options.put(k, parameters.get(paramName)); 33 } 34 } 35 }); 36 } 37 38 public Document../../../../com/kodexa/client/Document.html#Document">Document process(Document document, PipelineContext context) { 39 log.info("Starting step " + step.getName()); 40 41 if (!this.options.isEnabled()) { 42 return document; 43 } 44 45 Options finalOptions = this.options.createClone(); 46 if (this.options.isParameterized()) { 47 replaceParameters(finalOptions.getMap(), context.getParameterMap()); 48 } 49 50 if (this.step instanceof OptionDrivenStep) { 51 ((OptionDrivenStep) this.step).setOptions(finalOptions); 52 } 53 54 document = this.step.process(document, context); 55 56 return document; 57 } 58 }