package global.visitors;

import base.ElementVisitor;
import core.textInjection.VelocityHelper;
import global.models.Directory;
import global.models.File;
import global.utils.text.StringTools;
import global.wrappers.DirectoryWrapper;
import global.wrappers.ElementWrapper;
import global.wrappers.FileWrapper;

import java.util.HashMap;

/**
 * Вставляет переменные в имена.
 */
public class ReplaceNameVariableVisitor implements ElementVisitor {

    private HashMap<String, String> mapGlobalVars;

    public ReplaceNameVariableVisitor(HashMap<String, String> mapGlobalVars) {
        this.mapGlobalVars = mapGlobalVars;
    }


    @Override
    public void visit(DirectoryWrapper wrapper) {
        Directory directory = wrapper.getDirectory();

        directory.setName(VelocityHelper.fromTemplate(directory.getName(), mapGlobalVars));

        for (ElementWrapper elementWrapper : wrapper.getListElementWrapper()) {
            elementWrapper.accept(this);
        }
    }

    @Override
    public void visit(FileWrapper wrapper) {
        File file = wrapper.getFile();

        file.setName(VelocityHelper.fromTemplate(file.getName(), mapGlobalVars));
    }

}

@@ -47,16 +47,91 @@
 isitor;%0A
+import core.search.SearchAction;%0Aimport core.search.customPath.CustomPath;%0A
 import c
@@ -227,46 +227,8 @@
 le;%0A
-import global.utils.text.StringTools;%0A
 impo
@@ -1002,16 +1002,74 @@
        %7D
+%0A%0A        this.visitCustomPath(directory.getCustomPath());
 %0A    %7D%0A%0A
@@ -1248,18 +1248,377 @@
 lVars));
+%0A%0A        this.visitCustomPath(file.getCustomPath());%0A    %7D%0A%0A    private void visitCustomPath(CustomPath customPath) %7B%0A        if (customPath == null)%0A            return;%0A%0A        for (SearchAction searchAction : customPath.getListSearchAction()) %7B%0A            searchAction.setName(VelocityHelper.fromTemplate(searchAction.getName(), mapGlobalVars));%0A        %7D
 %0A    %7D%0A
-%0A
 %7D%0A

support global vars for custom path