Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package javax0.jamal.yaml;
import javax0.jamal.api.BadSyntax;
import javax0.jamal.api.InnerScopeDependent;
import javax0.jamal.api.Input;
import javax0.jamal.api.Macro;
import javax0.jamal.api.Processor;
import javax0.jamal.tools.Params;
import javax0.jamal.tools.Scanner;
import javax0.jamal.tools.param.BooleanParameter;
import javax0.jamal.tools.param.StringParameter;
import ognl.Ognl;
import ognl.OgnlException;
import org.yaml.snakeyaml.Yaml;
import java.util.List;
import java.util.Map;
public class Add implements Macro, InnerScopeDependent, Scanner.FirstLine {
final Yaml yaml = YamlFactory.newYaml();
@Override
public String evaluate(Input in, Processor processor) throws BadSyntax {
final var scanner = newScanner(in,processor);
final var to = scanner.str("yamlDataTarget", "to");
final var key = scanner.str(null, "key").optional();
final var flatten = scanner.bool(null, "flat", "flatten");
scanner.done();
final var dotIndex = to.get().indexOf('.');
final String id = getId(to, dotIndex);
final Object expression = getOgnlExpression(to, dotIndex);
final Object yamlStructure = getNewYamlPart(in);
final var yamlObject = Resolve.getYaml(processor, id);
final Object anchor = getAnchor(expression, to, yamlObject);
assertConsistency(to, key, flatten, anchor);
if (anchor instanceof Map) {
if (flatten.is()) {
BadSyntax.when(!(yamlStructure instanceof Map), "You can add only a Map to a Map when flat(ten) for '%s'", to.get());
((Map