All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.template.freemarker.directive.ServerBathPathDirective Maven / Gradle / Ivy

The newest version!
package org.zodiac.template.freemarker.directive;

import java.io.IOException;
import java.net.URL;
import java.util.Map;

import javax.annotation.Nonnull;

import org.zodiac.template.freemarker.constants.FreeMarkerConstants;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

public class ServerBathPathDirective extends AbstractDirective {

    private final String basePath;

    public ServerBathPathDirective(@Nonnull String serverBasePath, URL webUrl) {
        basePath =  (null != webUrl ? webUrl.toString() : serverBasePath);
    }

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
            throws TemplateException, IOException {
        String value = basePath;
        env.setVariable(VARIABLE_NAME,wrapTemplateModel(value));
        if (null != body) body.render(env.getOut());
    }

    @Override
    public String getName() {
        return FreeMarkerConstants.SERVER_PATH_VARIABLE;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy