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

woko.mail.PropertyBasedMailTemplate Maven / Gradle / Ivy

There is a newer version: 2.4-beta7
Show newest version
package woko.mail;

import woko.Woko;

import java.util.List;
import java.util.Locale;
import java.util.Map;

public abstract class PropertyBasedMailTemplate implements MailTemplate {

    private final String keySubject;
    private final String keyBody;

    public PropertyBasedMailTemplate(String keySubject, String keyBody) {
        this.keySubject = keySubject;
        this.keyBody = keyBody;
    }

    @Override
    public String processSubject(Woko woko, Locale locale, Map binding) {
        return woko.getLocalizedMessage(
                locale,
                keySubject,
                listToArray(getArgsSubject(woko, locale, binding))
        );
    }

    protected abstract List getArgsSubject(Woko woko, Locale locale, Map binding);

    @Override
    public String processBody(Woko woko, Locale locale, Map binding) {
        return woko.getLocalizedMessage(
                locale,
                keyBody,
                listToArray(getArgsBody(woko, locale, binding))
        );
    }

    protected String[] listToArray(List argsBody) {
        String[] res = new String[argsBody.size()];
        return argsBody.toArray(res);
    }

    protected abstract List getArgsBody(Woko woko, Locale locale, Map binding);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy