1 package com.atlassian.jira.util; 2 3 import javax.servlet.http.Cookie; 4 5 import org.apache.commons.lang.StringUtils; 6 7 public class ConglomerateCookieUtils { 8 9 public static String getValueFromCookie(final String _cookieName, final String _defaultValue) { 10 String cookieValue = getCookieValue(_cookieName); 11 if (cookieValue!=null) { 12 return cookieValue; 13 } 14 return _defaultValue; 15 } 16 17 public static String readFromConglomerateCookie(final String _cookieName, final String _name, final String _defaultValue) { 18 String cookieValue = getCookieValue(_cookieName); 19 if (cookieValue!=null) { 20 String value = getValueFromCongolmerate(_name, cookieValue); 21 if (value != null) { 22 return value; 23 } 24 } 25 return _defaultValue; 26 } 27 28 public static String getValueFromCongolmerate(final String _name, final String _cookieValue) { 29 String[] cookieParts = StringUtils.split(_cookieValue, "|"); 30 for (int i = 0; i < cookieParts.length; i++) { 31 String[] cookiePart = StringUtils.split(cookieParts[i],"="); 32 if (cookiePart[0].equals(_name)) { 33 return cookiePart[1]; 34 } 35 } 36 return null; 37 } 38 39 public static String getCookieValue(final String _cookieName) { 40 String _cookieValue = null; 41 Cookie[] cookies = getCookies(); 42 for (int i = 0; i < cookies.length; i++) { 43 Cookie cookie = cookies[i]; 44 if (_cookieName.equals(cookie.getName())) { 45 _cookieValue = cookie.getValue(); 46 } 47 } 48 return _cookieValue; 49 } 50 51 public static Cookie[] getCookies() { 52 return webwork.action.ActionContext.getRequest().getCookies(); 53 } 54 55 }