a patch would be welcomed.

musachy

On Tue, Aug 25, 2009 at 7:51 PM, Xyzr<[email protected]> wrote:
>
> Struts 2 must have full featured cookie utils out of the box. I saw the
> current CookieInterceptor, but it's insufficient.
>
> Needed methods (Cookie is javax.servlet.http.Cookie):
> 1) Map<String, Cookie> getCookies(); // where key - cookie name
> 2) String getCookie(String cookieName);
> 3) setCookie(String cookieName, Cookie cookie); // or "addCookie(...)"
> 4) removeCookie(String cookieName);
>
> I suppose this feature can be implemented either as Interceptor or as Util
> class.
>
> //-----------------------------------------------------------------------------
> 1) Implementing as Interceptor:
> interface CookiesAware {
>        void setCookies(Map<String, Cookie> cookies);
>
>        // Helpers - methods that return Sets of cookies to be set/remove
>        // to/from response. Or these methods can be replaced by custom
>        // CookieHashMap that overrides "put", "putAll", "remove" and "clear"
>        // to set/remove cookies to/from response.
>        Set<Cookie> getCookiesToSet();
>        Set<String> getCookiesToRemove();
> }
>
> class CookiesInterceptor {
>        public String intercept(ActionInvocation actionInvocation) {
>                Object action = actionInvocation.getAction();
>                CookiesAware cookiesAware = null;
>                if (action instanceof CookiesAware)
>                {
>                        HttpServletRequest request = 
> ServletActionContext.getRequest();
>                        Map<String, Cookie> cookies = new HashMap<String, 
> Cookie>();
>                        for (Cookie cookie : request.getCookies()) {
>                                cookies.put(cookie.getName(), cookie);
>                        }
>                        cookiesAware = (CookiesAware) action;
>                        cookiesAware.setCookies(cookies);
>                }
>
>                String actionResult = actionInvocation.invoke();
>
>                if (cookiesAware != null) {
>                        HttpServletResponse response = 
> ServletActionContext.getResponse();
>
>                        Set<Cookie> cookiesToSet = 
> cookiesAware.getCookiesToSet();
>                        if (cookiesToSet != null)
>                                for (Cookie cookie : cookiesToSet) {
>                                        response.addCookie(cookie);
>                                }
>                        }
>
>                        Set<String> cookiesToRemove = 
> cookiesAware.getCookiesToRemove();
>                        if (cookiesToRemove != null) {
>                                for (String cookieName : cookiesToRemove) {
>                                        Cookie cookie = new Cookie(cookieName, 
> "");
>                                        cookie.setMaxAge(0);
>                                        response.addCookie(cookie);
>                                }
>                        }
>                }
>
>                return actionResult;
>        }
> }
>
> //-----------------------------------------------------------------------------
> 2) Implementing as Utility class:
> // Use code from CookiesInterceptor
> class abstract CookieUtils {
>        public static Map<String, Cookie> getCookies() {...}
>        public static String getCookie(String cookieName) {...}
>        public static void setCookie(String cookieName, Cookie cookie) {...}
>        public static void removeCookie(String cookieName) {...}
> }
> --
> View this message in context: 
> http://www.nabble.com/Full-featured-cookie-utils-out-of-the-box-tp25145716p25145716.html
> Sent from the Struts - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to