/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   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 com.ajah.servlet.util;

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

import com.ajah.util.AjahUtils;

/**
 * Class for utilities that deal with {@link Cookie}s.
 * 
 * @author Eric F. Savage <code@efsavage.com>
 * 
 */
public class CookieUtils {

	/**
	 * Clears all cookies by setting {@link Cookie#setMaxAge(int)} to 0;
	 * 
	 * @param request
	 *            Request to get cookies from, required.
	 * @param response
	 *            Response to set updated cookies on, required.
	 */
	public static void clearAllCookies(HttpServletRequest request, HttpServletResponse response) {
		AjahUtils.requireParam(request, "request");
		AjahUtils.requireParam(response, "response");
		if (request.getCookies() == null) {
			return;
		}
		for (Cookie cookie : request.getCookies()) {
			cookie.setMaxAge(0);
			response.addCookie(cookie);
		}
	}

}
@@ -661,16 +661,53 @@
 .util;%0A%0A
+import javax.servlet.ServletRequest;%0A
 import j
@@ -1596,9 +1596,1054 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09/**%0A%09 * Finds a cookie by name and returns it if found.%0A%09 * %0A%09 * @param request%0A%09 *            Request to look for cookies on, required.%0A%09 * @param name%0A%09 *            Name of cookies to look for, required.%0A%09 * @return Cookie if found, otherwise null.%0A%09 */%0A%09public static Cookie getCookie(HttpServletRequest request, String name) %7B%0A%09%09AjahUtils.requireParam(request, %22request%22);%0A%09%09AjahUtils.requireParam(name, %22name%22);%0A%09%09Cookie%5B%5D cookies = request.getCookies();%0A%09%09if (cookies != null) %7B%0A%09%09%09for (Cookie cookie : cookies) %7B%0A%09%09%09%09if (cookie.getName().equals(name)) %7B%0A%09%09%09%09%09return cookie;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%0A%09/**%0A%09 * Alternate signature for%0A%09 * %7B@link CookieUtils#getCookie(HttpServletRequest, String)%7D.%0A%09 * %0A%09 * @param request%0A%09 *            Request to look for cookies on, required.%0A%09 * @param name%0A%09 *            Name of cookies to look for, required.%0A%09 * @return Cookie if found, otherwise null.%0A%09 */%0A%09public static Cookie getCookie(ServletRequest request, String name) %7B%0A%09%09return getCookie((HttpServletRequest) request, name);%0A%09%7D%0A%0A
 %7D

add getCookie