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 ognl.Ognl;
import ognl.OgnlException;
import org.yaml.snakeyaml.Yaml;
import java.util.List;
import java.util.Map;
import static javax0.jamal.tools.Params.holder;
public class Add implements Macro, InnerScopeDependent {
final Yaml yaml = YamlFactory.newYaml();
@Override
public String evaluate(Input in, Processor processor) throws BadSyntax {
final var to = holder("yamlDataTarget", "to").asString();
final var key = Params.holder(null, "key").orElseNull();
final var flatten = holder(null, "flat", "flatten").asBoolean();
Params.using(processor).from(this).keys(to, key, flatten).parse(in);
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