package it.mice.voila.runtime.springmvc.interceptors;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AddResponseHeadersInterceptor extends HandlerInterceptorAdapter {

	Log log = LogFactory.getLog(AddResponseHeadersInterceptor.class);

	private Map<String, String> headers = new HashMap<String, String>();
	
	public Map<String, String> getHeaders() {
		return headers;
	}

	public void setHeaders(Map<String, String> headers) {
		this.headers = headers;
	}

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
		for (Map.Entry<String, String> entry : getHeaders().entrySet()) {
			response.setHeader(entry.getKey(), entry.getValue());
		}

		return super.preHandle(request, response, handler);
	}
}
