MailMergeUtil.java

/***************************************************************************
   Copyright 2015 Emily Estes

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
***************************************************************************/
package net.metanotion.email;


import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** This class provides some simple implementations of the {@link net.metanotion.email.MailMerge} class suitable for
testing and debugging purposes. */
public final class MailMergeUtil {
	private static final Logger logger = LoggerFactory.getLogger(MailMergeUtil.class);

	/** This implementation of MailMerge logs all API calls using the logging framework. */
	public static final MailMerge LOGGING = new MailMerge() {
		@Override public void send(final String sender, final String address, final String subject, final String message) {
			logger.debug("SEND: from {}, to {}, subject {}, message {}", sender, address, subject, message);
		}

		@Override public void sendEmail(final String sender,
			final String address,
			final Map<String, Object> values,
			final String templateURN) {
			logger.debug("SEND (Merge Template: {}), from {}, to {}, variables {}", templateURN, sender, address, values);
		}

		@Override public void sendEmail(final String sender,
			final String address,
			final String subject,
			final Map<String, Object> values,
			final String templateURN) {
			logger.debug("SEND (Merge Template: {}), from {}, to {}, subject {}, variables {}",
				templateURN, sender, address, subject, values);
		}
	};

	/** This implementation of MailMerge does nothing at all. */
	public static final MailMerge NULL = new MailMerge() {
		@Override public void send(final String sender, final String address, final String subject, final String message) { }

		@Override public void sendEmail(final String sender,
			final String address,
			final Map<String, Object> values,
			final String templateURN) { }

		@Override public void sendEmail(final String sender,
			final String address,
			final String subject,
			final Map<String, Object> values,
			final String templateURN) { }
		};
}